Skip to content

Commit

Permalink
remove toggleswitchset in favor of numset
Browse files Browse the repository at this point in the history
  • Loading branch information
Sequal32 committed Oct 11, 2020
1 parent 0bf975c commit c5137f3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
4 changes: 2 additions & 2 deletions definitions/modules/autopilot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String, Vec<ActionType>>,
// Events to listen to
events: Events,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))?,
Expand Down
28 changes: 0 additions & 28 deletions src/syncdefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,6 @@ impl Syncable<bool> 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<bool> 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,
Expand Down

0 comments on commit c5137f3

Please sign in to comment.