Skip to content

Commit

Permalink
Merge pull request #228 from BitsAndDroids/main
Browse files Browse the repository at this point in the history
App v0.5.0
  • Loading branch information
BitsAndDroids authored Sep 4, 2024
2 parents 71d9263 + 3bd3810 commit 95b4e4c
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 130 deletions.
19 changes: 9 additions & 10 deletions crates/src-tauri/src/serial/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ use log::{error, info};
use serialport::{Error, SerialPort, SerialPortType};
use std::time::Duration;

pub struct Serial {
pub struct SerialDevice {
port: Box<dyn SerialPort>,
name: String,
_trs: bool,
}

pub trait Commands {
pub trait Serial {
fn new(device_name: String, trs: bool) -> Result<Self, Error>
where
Self: Sized;
fn get_name(&self) -> String;
fn send_connected_signal(&mut self, connected: bool);
fn read_full_message(&mut self) -> Option<String>;
fn write(&mut self, data: &[u8]);
fn get_name(&self) -> String;
}

impl Serial {
pub fn new(device_name: String, trs: bool) -> Result<Self, Error> {
impl Serial for SerialDevice {
fn new(device_name: String, trs: bool) -> Result<Self, Error> {
let ports = match serialport::available_ports() {
Ok(ports) => ports,
Err(_) => Vec::new(),
Expand Down Expand Up @@ -54,7 +57,6 @@ impl Serial {
.open()
{
Ok(mut port) => {
// if connector_settings is Some()
if trs {
match port.write_data_terminal_ready(true) {
Ok(_) => {
Expand All @@ -75,7 +77,7 @@ impl Serial {
};
}
std::thread::sleep(Duration::from_millis(400));
Ok(Serial {
Ok(SerialDevice {
port,
_trs: trs,
name: device_name,
Expand All @@ -87,9 +89,6 @@ impl Serial {
}
}
}
}

impl Commands for Serial {
fn write(&mut self, data: &[u8]) {
match self.port.write_all(data) {
Ok(_) => {}
Expand Down
8 changes: 4 additions & 4 deletions crates/src-tauri/src/simconnect_mod/simconnect_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::events::action_registry::ActionRegistry;
use crate::events::input_registry::InputRegistry;
use crate::events::output_registry::OutputRegistry;
use crate::events::wasm_registry::WASMRegistry;
use crate::serial::serial::Commands;
use crate::serial::serial::Serial;
use crate::serial::serial::SerialDevice;
use crate::settings::connector_settings::load_connector_settings;
use crate::sim_utils::input_converters::convert_dec_to_dcb;
use crate::simconnect_mod::wasm::register_wasm_event;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct SimconnectHandler {
pub(crate) wasm_registry: WASMRegistry,
pub(crate) app_handle: tauri::AppHandle,
pub(crate) rx: mpsc::Receiver<u16>,
active_com_ports: HashMap<String, Serial>,
active_com_ports: HashMap<String, Box<dyn Serial>>,
run_bundles: Vec<RunBundle>,
connector_settings: ConnectorSettings,
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl SimconnectHandler {
fn connect_to_devices(&mut self) {
let mut connected_ports: Vec<Connections> = vec![];
for run_bundle in self.run_bundles.iter() {
match Serial::new(run_bundle.com_port.clone(), self.connector_settings.use_trs) {
match SerialDevice::new(run_bundle.com_port.clone(), self.connector_settings.use_trs) {
Ok(serial) => {
info!(target: "connections", "Connected to port: {}", run_bundle.com_port);
connected_ports.push(Connections {
Expand All @@ -144,7 +144,7 @@ impl SimconnectHandler {
id: run_bundle.id,
});
self.active_com_ports
.insert(run_bundle.com_port.clone(), serial);
.insert(run_bundle.com_port.clone(), Box::new(serial));
}
Err(e) => {
error!(target: "connections", "Failed to open port: {}", e);
Expand Down
2 changes: 1 addition & 1 deletion crates/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.2",
"version": "0.5.0",
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm run build",
Expand Down
4 changes: 4 additions & 0 deletions crates/types/src/types/connector_settings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[cfg(test)]
#[path = "connector_settings_tests.rs"]
mod connector_settings_tests;

use serde::{Deserialize, Serialize};

pub const USE_TRS: bool = false;
Expand Down
19 changes: 19 additions & 0 deletions crates/types/src/types/connector_settings_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[cfg(test)]
use crate::types::connector_settings::ConnectorSettings;

use super::SavedConnectorSettings;

#[test]
fn test_setting_default_settings_missing_settings() {
let saved_settings = SavedConnectorSettings {
adc_resolution: None,
send_every_ms: None,
use_trs: None,
installed_wasm_version: None,
};
let settings = ConnectorSettings::from(saved_settings);
assert_eq!(settings.adc_resolution, 1023);
assert_eq!(settings.send_every_ms, 6);
assert!(!settings.use_trs);
assert_eq!(settings.installed_wasm_version, "");
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"devDependencies": {
"@jest/types": "^29.6.3",
"@tailwindcss/forms": "^0.5.8",
"@tauri-apps/cli": "2.0.0-beta.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Header } from "@/components/elements/header";
import { RunComponent } from "../components/RunComponent";
export default function HomePage() {
return (
<div className="flex justify-start align-middle h-full w-full flex-col ">
<div className="flex justify-start align-middle h-full w-full flex-col">
<div className="flex flex-col justify-center align-middle items-center">
<Header level={1} title="FLIGHT CONNECTOR" />
</div>
Expand Down
33 changes: 29 additions & 4 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
--background-end-rgb: 255, 255, 255;
}

.tooltip {
@apply invisible absolute;
@apply -mt-7;
@apply ml-2;
}

.tooltip-bot {
@apply invisible absolute;
@apply mt-7;
@apply ml-2;
}

.has-tooltip {
@apply cursor-help;
}

.has-tooltip:hover .tooltip {
@apply visible z-50;
@apply cursor-help;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
Expand All @@ -17,12 +38,13 @@
}

html {
height: 100%;
height: 100vh;
width: 100%;
overflow: hidden;
}

body {
height: 100%;
height: 100vh;
width: 100%;
}

Expand All @@ -49,10 +71,13 @@ body {
background: #5bbec3;
}

.tooltip {
.tooltip,
.tooltip-bot {
@apply invisible absolute;
overflow: visible;
}

.has-tooltip:hover .tooltip {
.has-tooltip:hover .tooltip,
.has-tooltip:hover .tooltip-bot {
@apply visible z-50;
}
4 changes: 2 additions & 2 deletions src/app/options/outputs/OutputsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const OutputsPage = () => {
/>
)}
<div
className="flex flex-row relative z-0"
className="flex flex-row relative z-0 mt-2"
tabIndex={dialogOpen ? -1 : 1}
>
<BundleEditWidget
Expand All @@ -143,7 +143,7 @@ const OutputsPage = () => {
<OutputList bundle={selectedBundle} />
)}
{editMode && (
<div className="flex flex-row items-center">
<div className="ml-4 flex flex-row items-center">
<BundleEditControls saveBundle={saveBundle} />
<h2 className="text-white text-4xl font-bold pl-2">
{bundles.length > 0 && selectedBundle?.name}
Expand Down
37 changes: 0 additions & 37 deletions src/components/CategoryCheckboxes.tsx

This file was deleted.

74 changes: 74 additions & 0 deletions src/components/OutputSelectRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Output } from "@/model/Output";
interface CategoryCheckboxesProps {
outputs: Output[];
dialogOpen: boolean;
toggleOutput: (output: Output) => void;
}

export const OutputSelectRow = ({
outputs,
dialogOpen,
toggleOutput,
}: CategoryCheckboxesProps) => {
return (
<div className="flex flex-col h-full w-full overflow-y-scroll pl-2">
{outputs.map((output, index) => {
return (
<div key={output.id} className="flex flex-row items-center">
<input
type="checkbox"
className="text-green-600 focus:ring-green-500 rounded-md mr-2 h-6 w-6 -mt-1 accent-green-600"
onChange={() => {
toggleOutput(output);
}}
tabIndex={dialogOpen ? -1 : 1}
checked={output.selected}
/>
<div
className={`p-2 w-full bg-gradient-to-r from-[rgba(255,255,255,0.9)] ${output.selected ? "to-[rgba(200,255,200,0.7)]" : "to-[rgba(200,200,220,0.7)]"} rounded-md mb-2 flex flex-row items-center drop-shadow mr-2 align-middle shadow-[inset_0_-2px_4px_rgba(180,255,255,0.9)]`}
>
<div className="flex flex-col w-3/4">
<span className="has-tooltip">
<span
className={`${index === 0 ? "tooltip-bot" : "tooltip"} rounded shadow-lg p-1 bg-gray-100`}
>
{output.simvar}
</span>
<p className="rounded-md font-bold text-lg">
{output.cb_text}
</p>
</span>
<div className="flex flex-row">
<span className="has-tooltip">
<span className="tooltip rounded shadow-lg p-1 bg-gray-100">
category
</span>
<img
src="https://api.iconify.design/tabler:category-2.svg"
className={"fill-amber-50 mr-2"}
alt="update_every"
/>
</span>
<p className="text-xs text-gray-500 ">{output.category}</p>
</div>
</div>
<div className="ml-2 flex flex-row items-center">
<span className="has-tooltip">
<span className="tooltip rounded shadow-lg p-1 bg-gray-100">
update every X
</span>
<img
src="https://api.iconify.design/lucide:between-horizontal-start.svg"
className={"fill-amber-50 mr-2"}
alt="update_every"
/>
</span>
<p className="">{output.update_every}</p>
</div>
</div>
</div>
);
})}
</div>
);
};
Loading

0 comments on commit 95b4e4c

Please sign in to comment.