Support emulating low battery
This commit is contained in:
@@ -77,6 +77,15 @@ impl Controller {
|
||||
self.update_state(pressed, released)
|
||||
}
|
||||
|
||||
pub fn low_battery(&mut self, pwr: bool) -> Option<VBKey> {
|
||||
let (pressed, released) = if pwr {
|
||||
(VBKey::PWR, VBKey::empty())
|
||||
} else {
|
||||
(VBKey::empty(), VBKey::PWR)
|
||||
};
|
||||
self.update_state(pressed, released)
|
||||
}
|
||||
|
||||
fn update_state(&mut self, pressed: VBKey, released: VBKey) -> Option<VBKey> {
|
||||
let old_state = self.state;
|
||||
self.state = self.state.union(pressed).difference(released);
|
||||
@@ -133,6 +142,14 @@ impl ControllerManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_low_battery(&mut self, sim_id: SimId, pwr: bool) {
|
||||
let controller = &mut self.controllers[sim_id.to_index()];
|
||||
if let Some(pressed) = controller.low_battery(pwr) {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetKeys(controller.sim_id, pressed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn axis_presses(value: f32, pair_value: f32, neg: VBKey, pos: VBKey) -> (VBKey, VBKey) {
|
||||
|
||||
Reference in New Issue
Block a user