Skip to content

Commit

Permalink
Show silent running active and alert states
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdsmith committed May 4, 2021
1 parent 1d84e03 commit 2ec46bc
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Version 1.5

- Shows alert state (red/yellow flashing) on FSD buttons when active but also
overheating
- Shows active state (yellow) on silent running buttons
- Shows alert state (red/yellow flashing) on FSD and silent running buttons if
that control is active but ship is also overheating
- Shows correct states immediately, i.e. do not wait for first significant state
change before updating.
- Shows correct states consitently on buttons where one LED represents multiple
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Currently the app detects if you activate any of the following:
- Cargo scoop
- External lights
- Frame shift drive
- Silent running

When activated, any button on your X52 Pro (except currently Fire and POV 2)
configured to control the item in question will turn yellow when activated.
Expand Down
7 changes: 7 additions & 0 deletions src/game/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum Control {
Hyperspace,
HyperSuperCombination,
LandingGear,
SilentRunning,
Supercruise,
}

Expand Down Expand Up @@ -55,6 +56,7 @@ impl Controls {
Control::Hyperspace => &self.file.hyperspace,
Control::HyperSuperCombination => &self.file.hyper_super_combo,
Control::LandingGear => &self.file.landing_gear,
Control::SilentRunning => &self.file.silent_running,
Control::Supercruise => &self.file.supercruise,
};

Expand Down Expand Up @@ -110,6 +112,7 @@ mod tests {
hyper_super_combo: ControlBinding::new((X52PRO_DEVICE, X52PRO_T1), ("", "")),
supercruise: ControlBinding::new((X52PRO_DEVICE, X52PRO_T3), ("", "")),
hyperspace: ControlBinding::new((X52PRO_DEVICE, X52PRO_T5), ("", "")),
silent_running: ControlBinding::new((X52PRO_DEVICE, X52PRO_FIRE_A), ("", "")),
heat_sink: ControlBinding::new((X52PRO_DEVICE, X52PRO_T6), ("", "")),
};
let controls = Controls::from_file_control_bindings(file_control_bindings);
Expand Down Expand Up @@ -138,6 +141,10 @@ mod tests {
controls.inputs_for_control(Control::Hyperspace),
vec![Input::T5]
);
assert_eq!(
controls.inputs_for_control(Control::SilentRunning),
vec![Input::FireA]
);
assert_eq!(
controls.inputs_for_control(Control::HeatSink),
vec![Input::T6]
Expand Down
11 changes: 9 additions & 2 deletions src/game/file/control_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct ControlBindings {
pub supercruise: ControlBinding,
#[serde(rename = "Hyperspace")]
pub hyperspace: ControlBinding,
#[serde(rename = "ToggleButtonUpInput")]
pub silent_running: ControlBinding,
#[serde(rename = "DeployHeatSink")]
pub heat_sink: ControlBinding,
}
Expand Down Expand Up @@ -106,9 +108,13 @@ mod tests {
<Primary Device="D11" Key="K11" />
<Secondary Device="D12" Key="K12" />
</Hyperspace>
<DeployHeatSink>
<ToggleButtonUpInput>
<Primary Device="D13" Key="K13" />
<Secondary Device="D14" Key="K14" />
</ToggleButtonUpInput>
<DeployHeatSink>
<Primary Device="D15" Key="K15" />
<Secondary Device="D16" Key="K16" />
</DeployHeatSink>
</Root>
"#,
Expand All @@ -121,7 +127,8 @@ mod tests {
hyper_super_combo: ControlBinding::new(("D7", "K7"), ("D8", "K8")),
supercruise: ControlBinding::new(("D9", "K9"), ("D10", "K10")),
hyperspace: ControlBinding::new(("D11", "K11"), ("D12", "K12")),
heat_sink: ControlBinding::new(("D13", "K13"), ("D14", "K14")),
silent_running: ControlBinding::new(("D13", "K13"), ("D14", "K14")),
heat_sink: ControlBinding::new(("D15", "K15"), ("D16", "K16")),
};

assert_eq!(ControlBindings::from_str(xml), expected);
Expand Down
41 changes: 40 additions & 1 deletion src/game/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type StatusBitField = u32;
const LANDING_GEAR_DEPLOYED: StatusBitField = 1 << 2;
const EXTERNAL_LIGHTS_ON: StatusBitField = 1 << 8;
const CARGO_SCOOP_DEPLOYED: StatusBitField = 1 << 9;
const SILENT_RUNNING: StatusBitField = 1 << 10;
const MASS_LOCKED: StatusBitField = 1 << 16;
const FRAME_SHIFT_DRIVE_CHARGING: StatusBitField = 1 << 17;
const FRAME_SHIFT_DRIVE_COOLDOWN: StatusBitField = 1 << 18;
Expand All @@ -17,7 +18,8 @@ const STATUS_FILTER: StatusBitField = LANDING_GEAR_DEPLOYED
| FRAME_SHIFT_DRIVE_CHARGING
| MASS_LOCKED
| FRAME_SHIFT_DRIVE_COOLDOWN
| OVERHEATING;
| OVERHEATING
| SILENT_RUNNING;

const FRAME_SHIFT_DRIVE_BLOCKED: StatusBitField =
CARGO_SCOOP_DEPLOYED | MASS_LOCKED | FRAME_SHIFT_DRIVE_COOLDOWN;
Expand All @@ -30,6 +32,7 @@ pub enum Attribute {
FrameShiftDrive,
HeatSink,
LandingGear,
SilentRunning,
}

/// An association of a `Attribute` to a `StatusLevel` value for a `Ship`.
Expand Down Expand Up @@ -145,6 +148,19 @@ impl Ship {
StatusLevel::Alert,
)],
),
AttributeStatusLevelMappings::new(
Attribute::SilentRunning,
vec![
ConditionStatusLevelMapping::new(
Condition::All(SILENT_RUNNING | OVERHEATING),
StatusLevel::Alert,
),
ConditionStatusLevelMapping::new(
Condition::All(SILENT_RUNNING),
StatusLevel::Active,
),
],
),
],
}
}
Expand Down Expand Up @@ -212,6 +228,7 @@ mod tests {
LANDING_GEAR_DEPLOYED,
EXTERNAL_LIGHTS_ON,
CARGO_SCOOP_DEPLOYED,
SILENT_RUNNING,
FRAME_SHIFT_DRIVE_CHARGING,
MASS_LOCKED,
FRAME_SHIFT_DRIVE_COOLDOWN,
Expand Down Expand Up @@ -256,6 +273,11 @@ mod tests {
assert_status(0, Attribute::LandingGear, StatusLevel::Inactive);
}

#[test]
fn zero_state_maps_to_silent_running_inactive() {
assert_status(0, Attribute::SilentRunning, StatusLevel::Inactive);
}

#[test]
fn cargo_scoop_deployed_maps_to_cargo_scoop_active() {
assert_status(
Expand Down Expand Up @@ -332,4 +354,21 @@ mod tests {
fn overheating_maps_to_heat_sink_alert() {
assert_status(OVERHEATING, Attribute::HeatSink, StatusLevel::Alert);
}
#[test]
fn silent_running_maps_to_silent_running_active() {
assert_status(
SILENT_RUNNING,
Attribute::SilentRunning,
StatusLevel::Active,
);
}

#[test]
fn silent_running_and_overheating_maps_to_silent_running_alert() {
assert_status(
SILENT_RUNNING + OVERHEATING,
Attribute::SilentRunning,
StatusLevel::Alert,
);
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub fn run() {
],
Attribute::HeatSink => vec![Control::HeatSink],
Attribute::LandingGear => vec![Control::LandingGear],
Attribute::SilentRunning => vec![Control::SilentRunning],
}
}

Expand Down

0 comments on commit 2ec46bc

Please sign in to comment.