Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions crates/connector/serial/src/serial/serial_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ pub trait Serial {

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(),
};
let ports = serialport::available_ports().unwrap_or_else(|_| Vec::new());
let ports_output = ports
.iter()
.map(|port| {
Expand Down Expand Up @@ -91,10 +88,16 @@ impl Serial for SerialDevice {
}
}
fn write(&mut self, data: &[u8]) {
match self.port.write_all(data) {
Ok(_) => {}
Err(e) => {
error!(target: "connections", "Failed to send data: {}", e);
let mut remaining_data = data;
while !remaining_data.is_empty() {
match self.port.write(remaining_data) {
Ok(written) => {
remaining_data = &remaining_data[written..];
}
Err(e) => {
error!(target: "connections", "Failed to send data: {}", e);
break;
}
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions crates/connector/serial/src/serial/serial_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use serialport::SerialPortType;

pub fn get_serial_devices() -> Vec<String> {
let ports = match serialport::available_ports() {
Ok(ports) => ports,
Err(_) => Vec::new(),
};
let ports = serialport::available_ports().unwrap_or_else(|_| Vec::new());
let ports_output = ports
.iter()
.map(|port| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ BitsAndDroidsFlightConnector::BitsAndDroidsFlightConnector() {
BitsAndDroidsFlightConnector::BitsAndDroidsFlightConnector(Serial_ *serial) {
this->serial = serial;
}
#elif defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) || defined(PICO_RP2040)
#endif
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) || defined(PICO_RP2040) || \
defined(ARDUINO_SAM_DUE)
BitsAndDroidsFlightConnector::BitsAndDroidsFlightConnector(
HardwareSerial *serial) {
this->serial = &Serial;
Expand Down Expand Up @@ -514,7 +516,18 @@ void BitsAndDroidsFlightConnector::switchHandling() {
trueVerticalSpeed = cutValue.toInt();
break;
}

case 331: {
velocityBodyX = cutValue.toInt();
break;
}
case 332: {
velocityBodyY = cutValue.toInt();
break;
}
case 341: {
velocityBodyZ = cutValue.toInt();
break;
}
case 326: {
indicatedAirspeed = cutValue.toInt();
break;
Expand All @@ -527,7 +540,6 @@ void BitsAndDroidsFlightConnector::switchHandling() {
indicatedAltitude2 = cutValue.toInt();
break;
}

case 337: {
kohlmanAltimeter = cutValue.toInt();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ class BitsAndDroidsFlightConnector {
BitsAndDroidsFlightConnector();
#if defined(ARDUINO_SAM_DUE)
BitsAndDroidsFlightConnector(Serial_ *serial);
BitsAndDroidsFlightConnector(HardwareSerial *serial);
#elif defined(ESP32) || \
defined( \
ESP8266) // This will handle all boards except ESP32 and Arduino Due
Expand Down Expand Up @@ -706,6 +707,9 @@ class BitsAndDroidsFlightConnector {
int getIndicatedAltitudeCalibrated() { return indicatedAltitudeCalibrated; };
int getIndicatedHeading() { return indicatedHeading; };
int getIndicatedGPSGroundspeed() { return indicatedGPSGroundspeed; };
int getVelocityBodyX() { return velocityBodyX; };
int getVelocityBodyY() { return velocityBodyY; };
int getVelocityBodyZ() { return velocityBodyZ; };
int getTrueVerticalSpeed() { return trueVerticalSpeed; };
int getLastPrefix();

Expand Down Expand Up @@ -936,6 +940,9 @@ class BitsAndDroidsFlightConnector {
int indicatedAltitudeCalibrated;
int indicatedHeading;
int indicatedGPSGroundspeed;
int velocityBodyX;
int velocityBodyY;
int velocityBodyZ;
int trueVerticalSpeed;

int headingGyro;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bits and Droids flight sim library
version=1.6.16
version=1.6.17
author=Bits and Droids <info@bitsanddroids.com>
maintainer=Bits and Droids <info@bitsanddroids.com>
sentence=Use serial communication to control Microsoft Flight Simulator 2020.
Expand Down
2 changes: 1 addition & 1 deletion crates/connector/src-tauri/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn get_wasm_events(app: tauri::AppHandle) -> Vec<WasmEvent> {
pub async fn get_latest_custom_event_version(app: tauri::AppHandle) -> String {
let mut wasm_registry = events::wasm_registry::WASMRegistry::new();
wasm_registry.load_wasm(&app);
wasm_registry.get_latest_custom_event_version(&app)
wasm_registry.get_latest_custom_event_version()
}

#[tauri::command]
Expand Down
20 changes: 9 additions & 11 deletions crates/connector/src-tauri/src/events/action.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use simconnect::SimConnector;

pub struct Action {
pub id: u32,
pub name: ActionName,
pub _id: u32,
pub _name: ActionName,
pub excecute_action: Box<dyn Fn(&SimConnector, String, f32, i32)>,
}

impl Action {
pub const fn new(
id: u32,
name: ActionName,
_id: u32,
_name: ActionName,
excecute_action: Box<dyn Fn(&SimConnector, String, f32, i32)>,
) -> Action {
Action {
id,
name,
_id,
_name,
excecute_action,
}
}
Expand All @@ -31,9 +31,7 @@ impl Action {
}

pub enum ActionName {
THROTTLE,
PROP,
MIXTURE,
RUDDER,
AILERON,
Throttle,
Prop,
Mixture,
}
2 changes: 1 addition & 1 deletion crates/connector/src-tauri/src/events/action_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ impl ActionRegistry {
}

pub fn get_action_by_id(&self, id: u32) -> Option<&Action> {
return self.actions.get(&id);
self.actions.get(&id)
}
}
6 changes: 3 additions & 3 deletions crates/connector/src-tauri/src/events/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ pub fn get_actions() -> HashMap<u32, Action> {
let mut action_map = HashMap::new();
action_map.insert(
199,
Action::new(199, ActionName::THROTTLE, Box::new(throttle_action)),
Action::new(199, ActionName::Throttle, Box::new(throttle_action)),
);
action_map.insert(
115,
Action::new(115, ActionName::MIXTURE, Box::new(mixture_action)),
Action::new(115, ActionName::Mixture, Box::new(mixture_action)),
);
action_map.insert(
198,
Action::new(198, ActionName::PROP, Box::new(propeller_action)),
Action::new(198, ActionName::Prop, Box::new(propeller_action)),
);
action_map
}
4 changes: 0 additions & 4 deletions crates/connector/src-tauri/src/events/input_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ impl InputRegistry {
}
}

pub fn get_inputs(&self) -> &HashMap<u32, Input> {
&self.inputs
}

pub fn get_input(&self, input_id: u32) -> Option<&Input> {
self.inputs.get(&input_id)
}
Expand Down
4 changes: 1 addition & 3 deletions crates/connector/src-tauri/src/events/output_registry.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use std::collections::HashMap;

use connector_types::types::{category::Category, output::Output, wasm_event::WasmEvent};
use connector_types::types::{output::Output, wasm_event::WasmEvent};
use file_parsers::parsers::output_parser;

#[derive(Clone, Debug)]
pub struct OutputRegistry {
pub categories: Vec<Category>,
pub outputs: HashMap<u32, Output>,
output_path: String,
}

impl OutputRegistry {
pub fn new() -> OutputRegistry {
OutputRegistry {
categories: Vec::new(),
outputs: HashMap::new(),
output_path: String::from("src/events/outputs.json"),
}
Expand Down
29 changes: 28 additions & 1 deletion crates/connector/src-tauri/src/events/outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,40 @@
},
{
"simvar": "VERTICAL SPEED",
"metric": "Feet per second",
"metric": "Feet per minute",
"update_every": 10,
"cb_text": "Vertical speed",
"id": 330,
"output_type": "integer",
"category": "Data"
},
{
"simvar": "VELOCITY BODY X",
"metric": "Feet per minute",
"update_every": 10,
"cb_text": "Velocity body x",
"id": 331,
"output_type": "integer",
"category": "Data"
},
{
"simvar": "VELOCITY BODY Y",
"metric": "Feet per minute",
"update_every": 10,
"cb_text": "Velocity body y",
"id": 332,
"output_type": "integer",
"category": "Data"
},
{
"simvar": "VELOCITY BODY Z",
"metric": "Feet per minute",
"update_every": 10,
"cb_text": "Velocity body z",
"id": 341,
"output_type": "integer",
"category": "Data"
},
{
"simvar": "TITLE",
"metric": "NULL",
Expand Down
24 changes: 5 additions & 19 deletions crates/connector/src-tauri/src/events/wasm_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use connector_types::types::{output::Output, wasm_event::WasmEvent};
use serde_json::json;
use tauri_plugin_store::StoreExt;

use crate::simconnect_mod::wasm::send_wasm_command;
use crate::{simconnect_mod::wasm::send_wasm_command, utils::store::save_store};
#[derive(Debug, Clone)]
pub struct WASMRegistry {
wasm_outputs: HashMap<u32, WasmEvent>,
Expand Down Expand Up @@ -37,11 +37,11 @@ impl WASMRegistry {
for event in &self.wasm_default_events {
store.set(event.id.to_string().clone(), json!(event));
}
store.save();
save_store(store);
self.load_wasm(&app);
}

pub fn get_latest_custom_event_version(&mut self, app: &tauri::AppHandle) -> String {
pub fn get_latest_custom_event_version(&mut self) -> String {
let parsed_custom_event_file =
file_parsers::parsers::wasm_event_parser::parse_events_from_file(&self.wasm_file_path);
parsed_custom_event_file.version
Expand All @@ -64,11 +64,7 @@ impl WASMRegistry {
self.wasm_inputs.insert(wasm_event.id, wasm_event);
}
}
store.save();
}

pub fn get_wasm_output_by_id(&mut self, output_id: u32) -> Option<&Output> {
self.parsed_wasm_outputs.get(&output_id)
save_store(store);
}

pub fn get_wasm_event_by_id(&self, event_id: u32) -> Option<&WasmEvent> {
Expand All @@ -79,10 +75,6 @@ impl WASMRegistry {
&self.wasm_outputs
}

pub fn get_wasm_inputs(&self) -> &HashMap<u32, WasmEvent> {
&self.wasm_inputs
}

pub fn get_wasm_events(&self) -> HashMap<u32, WasmEvent> {
let mut events = self.wasm_outputs.clone();
events.extend(self.wasm_inputs.clone());
Expand All @@ -93,20 +85,14 @@ impl WASMRegistry {
self.wasm_default_events.clone()
}

pub fn set_wasm_output_value(&mut self, output_id: u32, value: f64) {
if let Some(output) = self.wasm_outputs.get_mut(&output_id) {
output.value = value;
}
}

pub fn init_custom_events_to_store(&mut self, app: &tauri::AppHandle) {
let store = app.store(".events.dat").unwrap();
self.load_default_events();
let events = self.get_default_wasm_events();
for event in events {
store.set(event.id.to_string().clone(), json!(event));
}
store.save();
save_store(store);
}

pub fn register_wasm_inputs_to_simconnect(&self, conn: &mut simconnect::SimConnector) {
Expand Down
9 changes: 5 additions & 4 deletions crates/connector/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use utils::library_handler::generate_library;
use utils::library_handler::get_library_header_content;
use utils::library_handler::get_library_outputs;
use utils::library_handler::get_library_source_content;
use utils::store::save_store;
use utils::wasm_installer::{check_if_wasm_up_to_date, install_wasm};

use std::{env, thread};
Expand Down Expand Up @@ -106,14 +107,14 @@ async fn get_outputs(app: tauri::AppHandle) -> Vec<Output> {
}

#[tauri::command]
fn send_debug_message(app: tauri::AppHandle, message: Message) {
fn send_debug_message(message: Message) {
println!("Received message: {:?}", message);
let sender = SENDER.lock().unwrap().deref().clone().unwrap();
sender.send(message).unwrap();
}

#[tauri::command]
fn start_simconnect_connection(app: tauri::AppHandle, run_bundles: Vec<RunBundle>, debug: bool) {
fn start_simconnect_connection(app: tauri::AppHandle, run_bundles: Vec<RunBundle>) {
let (tx, rx) = mpsc::channel();
*SENDER.lock().unwrap() = Some(tx);
*RECEIVER.lock().unwrap() = Some(rx);
Expand All @@ -122,7 +123,7 @@ fn start_simconnect_connection(app: tauri::AppHandle, run_bundles: Vec<RunBundle
thread::spawn(|| {
#[cfg(target_os = "windows")]
let mut simconnect_handler =
simconnect_mod::simconnect_handler::SimconnectHandler::new(app, receiver, true);
simconnect_mod::simconnect_handler::SimconnectHandler::new(app, receiver);
#[cfg(target_os = "windows")]
simconnect_handler.start_connection(run_bundles);
});
Expand All @@ -143,7 +144,7 @@ fn init_wasm_events_to_store(app: tauri::AppHandle) {
let mut wasm_registry = events::wasm_registry::WASMRegistry::new();
wasm_registry.init_custom_events_to_store(&app);
}
store.save();
save_store(store);
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn create_new_exe_xml(
.resolve("resources/exe.xml", BaseDirectory::Resource)
{
Ok(path) => path,
Err(e) => {
Err(_) => {
Copy link

Copilot AI Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discarding the error information by replacing 'Err(e)' with 'Err(_)' removes potentially useful details for debugging. Consider logging or preserving the error details to aid in troubleshooting.

Suggested change
Err(_) => {
Err(e) => {
error!("Failed to resolve exe.xml resource path: {:?}", e);

Copilot uses AI. Check for mistakes.
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Failed to resolve exe.xml resource path",
Expand Down
Loading