From c5137f35aeeb8839833294d9a4d146017369655f Mon Sep 17 00:00:00 2001 From: Sequal32 Date: Sun, 11 Oct 2020 18:48:05 -0400 Subject: [PATCH] remove toggleswitchset in favor of numset --- definitions/modules/autopilot.yaml | 4 ++-- src/definitions.rs | 14 ++------------ src/syncdefs.rs | 28 ---------------------------- 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/definitions/modules/autopilot.yaml b/definitions/modules/autopilot.yaml index 6e7570f30..5fd711a48 100644 --- a/definitions/modules/autopilot.yaml +++ b/definitions/modules/autopilot.yaml @@ -29,10 +29,10 @@ shared: var_type: i32 event_name: AP_ALT_VAR_SET_ENGLISH - - type: ToggleSwitchSet + type: NumSet var_name: A:AUTOPILOT AIRSPEED HOLD var_units: Bool - var_type: bool + var_type: i32 event_name: AP_AIRSPEED_SET - type: NumSet diff --git a/src/definitions.rs b/src/definitions.rs index ab6cb8705..cb787bb63 100644 --- a/src/definitions.rs +++ b/src/definitions.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use simconnect::SimConnector; use std::{collections::HashMap, collections::HashSet, collections::hash_map::Entry, fmt::Display, fs::File, time::Instant}; -use crate::{interpolate::Interpolate, interpolate::InterpolateOptions, sync::AircraftVars, sync::Events, sync::LVarSyncer, syncdefs::{NumIncrement, NumIncrementSet, NumSet, NumSetMultiply, NumSetSwap, SwitchOn, Syncable, ToggleSwitch, ToggleSwitchParam, ToggleSwitchSet, ToggleSwitchTwo}, util::Category, util::InDataTypes, util::VarReaderTypes}; +use crate::{interpolate::Interpolate, interpolate::InterpolateOptions, sync::AircraftVars, sync::Events, sync::LVarSyncer, syncdefs::{NumIncrement, NumIncrementSet, NumSet, NumSetMultiply, NumSetSwap, SwitchOn, Syncable, ToggleSwitch, ToggleSwitchParam, ToggleSwitchTwo}, util::Category, util::InDataTypes, util::VarReaderTypes}; #[derive(Debug)] pub enum ConfigLoadError { @@ -239,7 +239,7 @@ impl Period { } pub struct Definitions { - // Data that can be synced using booleans (ToggleSwitch, ToggleSwitchSet, ToggleSwitchParam) + // Data that can be synced using booleans (ToggleSwitch, ToggleSwitchParam) action_maps: HashMap>, // Events to listen to events: Events, @@ -386,15 +386,6 @@ impl Definitions { Ok(()) } - fn add_toggle_switch_set(&mut self, category: &str, var: VarEventEntry) -> Result<(), VarAddError> { - let event_id = self.events.get_or_map_event_id(&var.event_name, false); - - let (var_string, _) = self.add_var_string(category, &var.var_name, var.var_units.as_deref(), InDataTypes::Bool)?; - self.add_bool_mapping( &var_string, Box::new(ToggleSwitchSet::new(event_id))); - - Ok(()) - } - fn add_toggle_switch_two(&mut self, category: &str, var: ToggleSwitchTwoEntry) -> Result<(), VarAddError> { let on_event_id = self.events.get_or_map_event_id(&var.on_event_name, false); let off_event_id = self.events.get_or_map_event_id(&var.off_event_name, false); @@ -526,7 +517,6 @@ impl Definitions { match type_str.to_uppercase().as_str() { "TOGGLESWITCH" => self.add_toggle_switch(category, try_cast_yaml!(value))?, - "TOGGLESWITCHSET" => self.add_toggle_switch_set(category, try_cast_yaml!(value))?, "TOGGLESWITCHPARAM" => self.add_toggle_switch_param(category, try_cast_yaml!(value))?, "TOGGLESWITCHTWO" => self.add_toggle_switch_two(category, try_cast_yaml!(value))?, "NUMINCREMENTFLOAT" => self.add_num_increment_float(category, try_cast_yaml!(value))?, diff --git a/src/syncdefs.rs b/src/syncdefs.rs index a33d7262c..8980063de 100644 --- a/src/syncdefs.rs +++ b/src/syncdefs.rs @@ -33,34 +33,6 @@ impl Syncable for ToggleSwitch { } } -pub struct ToggleSwitchSet { - event_id: u32, - current: bool -} - -impl ToggleSwitchSet { - pub fn new(event_id: u32) -> Self { - return Self { - event_id: event_id, - current: false - } - } -} - -impl Syncable for ToggleSwitchSet { - fn set_current(&mut self, current: bool) { - self.current = current; - } - - fn set_new(&mut self, new: bool, conn: &simconnect::SimConnector) { - if self.current == new {return} - match new { - true => conn.transmit_client_event(1, self.event_id, 1, GROUP_ID, 0), - false => conn.transmit_client_event(1, self.event_id, 0, GROUP_ID, 0) - }; - } -} - pub struct ToggleSwitchParam { event_id: u32, param: u32,