mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
1142 lines
45 KiB
Rust
1142 lines
45 KiB
Rust
mod evdev_reader;
|
|
mod gearbox;
|
|
mod haptics;
|
|
mod hidraw_ibex;
|
|
mod types;
|
|
|
|
pub use gearbox::{
|
|
brake_to_crsf, encode_gears_command, encode_rc_frame, encode_src_command, steering_to_crsf,
|
|
throttle_to_crsf, throttle_to_crsf_curved,
|
|
};
|
|
#[cfg(test)]
|
|
use haptics::encode_ibex_rumble_report;
|
|
pub use haptics::SteamHapticsSynthesizer;
|
|
pub use types::{
|
|
key_code_label, ControlSource, GearSpeedLimits, SteamControllerConfig, SteamControllerState,
|
|
};
|
|
|
|
use crate::engine::EngineControlHandle;
|
|
use crate::g29_bridge::G29State;
|
|
use crate::nomad_elrs::{CRSF_CHANNEL_MAX, CRSF_CHANNEL_MID};
|
|
use crate::telemetry_osd::TelemetryState;
|
|
use anyhow::{anyhow, Result};
|
|
use hidraw_ibex::OpenGamepad;
|
|
use parking_lot::Mutex;
|
|
use std::io::ErrorKind;
|
|
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
|
|
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
|
use std::sync::Arc;
|
|
use std::thread;
|
|
use std::time::{Duration, Instant};
|
|
use types::*;
|
|
#[cfg(test)]
|
|
use evdev_reader::{sysfs_bitmap_has_bit, AxisRange};
|
|
#[cfg(test)]
|
|
use hidraw_ibex::parse_ibex_hidraw_report;
|
|
#[cfg(test)]
|
|
use crate::nomad_elrs::CRSF_CHANNEL_MIN;
|
|
|
|
pub struct SteamControllerWorker {
|
|
state: Arc<Mutex<SteamControllerState>>,
|
|
stop_flag: Arc<AtomicBool>,
|
|
worker: Option<thread::JoinHandle<()>>,
|
|
}
|
|
|
|
impl SteamControllerWorker {
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub fn start(
|
|
target_ip: &str,
|
|
target_port: u16,
|
|
cfg: SteamControllerConfig,
|
|
active_source: Arc<AtomicU8>,
|
|
vibration_pct: Arc<AtomicU8>,
|
|
rumble_test_flag: Arc<AtomicBool>,
|
|
gear_speed_limits: Arc<Mutex<GearSpeedLimits>>,
|
|
control: EngineControlHandle,
|
|
g29_state_opt: Option<Arc<Mutex<G29State>>>,
|
|
telemetry_state_opt: Option<Arc<Mutex<TelemetryState>>>,
|
|
) -> Result<Self> {
|
|
let trimmed_ip = target_ip.trim();
|
|
let host_port = format!("{}:{}", trimmed_ip, target_port);
|
|
let target: SocketAddr = if let Ok(ip) = trimmed_ip.parse::<std::net::IpAddr>() {
|
|
SocketAddr::new(ip, target_port)
|
|
} else {
|
|
let addrs: Vec<SocketAddr> = host_port.to_socket_addrs()?.collect();
|
|
addrs
|
|
.iter()
|
|
.copied()
|
|
.find(|a| a.is_ipv4())
|
|
.or_else(|| addrs.into_iter().next())
|
|
.ok_or_else(|| anyhow!("Impossible de résoudre la cible contrôleur {}", host_port))?
|
|
};
|
|
let bind_addr = if target.is_ipv6() { "[::]:0" } else { "0.0.0.0:0" };
|
|
let socket = UdpSocket::bind(bind_addr)?;
|
|
socket.set_nonblocking(true)?;
|
|
|
|
let initial_state = SteamControllerState {
|
|
vibration_pct: vibration_pct.load(Ordering::Acquire).min(100),
|
|
..Default::default()
|
|
};
|
|
let state = Arc::new(Mutex::new(initial_state));
|
|
let state_clone = Arc::clone(&state);
|
|
let stop_flag = Arc::new(AtomicBool::new(false));
|
|
let stop_clone = Arc::clone(&stop_flag);
|
|
|
|
let worker = thread::Builder::new()
|
|
.name("steam-ctrl-worker".into())
|
|
.spawn(move || {
|
|
Self::run_loop(
|
|
socket,
|
|
target,
|
|
cfg,
|
|
active_source,
|
|
vibration_pct,
|
|
rumble_test_flag,
|
|
gear_speed_limits,
|
|
control,
|
|
g29_state_opt,
|
|
telemetry_state_opt,
|
|
state_clone,
|
|
stop_clone,
|
|
);
|
|
})?;
|
|
|
|
Ok(Self {
|
|
state,
|
|
stop_flag,
|
|
worker: Some(worker),
|
|
})
|
|
}
|
|
|
|
pub fn state(&self) -> Arc<Mutex<SteamControllerState>> {
|
|
Arc::clone(&self.state)
|
|
}
|
|
|
|
fn send_safe_disarm_burst(socket: &UdpSocket, target: SocketAddr, count: usize) {
|
|
let safe_frame = encode_rc_frame(
|
|
CRSF_CHANNEL_MID,
|
|
CRSF_CHANNEL_MID,
|
|
CRSF_CHANNEL_MID,
|
|
CRSF_CHANNEL_MID,
|
|
false,
|
|
0,
|
|
);
|
|
for i in 0..count {
|
|
for attempt in 0..3 {
|
|
match socket.send_to(safe_frame.as_bytes(), target) {
|
|
Ok(_) => break,
|
|
Err(e) if e.kind() == ErrorKind::WouldBlock && attempt < 2 => {
|
|
thread::sleep(Duration::from_millis(1));
|
|
}
|
|
Err(e) => {
|
|
if i == 0 {
|
|
log::warn!(
|
|
"[Steam Controller] Échec envoi trame désarmement vers {} : {}",
|
|
target,
|
|
e
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if i + 1 < count {
|
|
thread::sleep(Duration::from_millis(2));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn run_loop(
|
|
socket: UdpSocket,
|
|
target: SocketAddr,
|
|
cfg: SteamControllerConfig,
|
|
active_source: Arc<AtomicU8>,
|
|
vibration_pct: Arc<AtomicU8>,
|
|
rumble_test_flag: Arc<AtomicBool>,
|
|
gear_speed_limits: Arc<Mutex<GearSpeedLimits>>,
|
|
control: EngineControlHandle,
|
|
g29_state_opt: Option<Arc<Mutex<G29State>>>,
|
|
telemetry_state_opt: Option<Arc<Mutex<TelemetryState>>>,
|
|
state: Arc<Mutex<SteamControllerState>>,
|
|
stop_flag: Arc<AtomicBool>,
|
|
) {
|
|
let mut gamepad: Option<OpenGamepad> = None;
|
|
let mut last_scan: Option<Instant> = None;
|
|
let mut last_src_sync: Option<Instant> = None;
|
|
let mut last_source = ControlSource::from_u8(active_source.load(Ordering::Acquire));
|
|
let mut pressed_keys: Vec<u16> = Vec::with_capacity(16);
|
|
let mut haptics = SteamHapticsSynthesizer::new();
|
|
let mut last_haptics_tick: Option<Instant> = None;
|
|
let mut rumble_is_zero = true;
|
|
let mut consecutive_send_errors: u32 = 0;
|
|
|
|
// Garde RAII garantissant l'envoi d'une trame neutre désarmée même en cas de panic! du worker.
|
|
struct DisarmOnDrop<'a> {
|
|
socket: &'a UdpSocket,
|
|
target: SocketAddr,
|
|
active_source: &'a AtomicU8,
|
|
}
|
|
impl Drop for DisarmOnDrop<'_> {
|
|
fn drop(&mut self) {
|
|
if ControlSource::from_u8(self.active_source.load(Ordering::Acquire))
|
|
== ControlSource::SteamController
|
|
{
|
|
SteamControllerWorker::send_safe_disarm_burst(self.socket, self.target, 2);
|
|
}
|
|
}
|
|
}
|
|
let _disarm_guard = DisarmOnDrop {
|
|
socket: &socket,
|
|
target,
|
|
active_source: &active_source,
|
|
};
|
|
|
|
// Synchronisation initiale de la source souhaitée et des vitesses auprès de la RP2350
|
|
let init_cmd = encode_src_command(last_source);
|
|
let _ = socket.send_to(init_cmd.as_bytes(), target);
|
|
let mut last_sent_gears = gear_speed_limits.lock().sanitized();
|
|
let init_gears_cmd = encode_gears_command(last_sent_gears);
|
|
let _ = socket.send_to(init_gears_cmd.as_bytes(), target);
|
|
let mut last_gears_sync = Some(Instant::now());
|
|
|
|
while !stop_flag.load(Ordering::Acquire) {
|
|
let loop_start = Instant::now();
|
|
let desired_source = ControlSource::from_u8(active_source.load(Ordering::Acquire));
|
|
let current_gears = gear_speed_limits.lock().sanitized();
|
|
let is_local_armed = state.lock().armed;
|
|
let gears_due = last_gears_sync
|
|
.is_none_or(|t| t.elapsed() >= Duration::from_millis(GEARS_RESYNC_INTERVAL_MS));
|
|
if current_gears != last_sent_gears || (!is_local_armed && gears_due) {
|
|
let changed = current_gears != last_sent_gears;
|
|
last_sent_gears = current_gears;
|
|
last_gears_sync = Some(Instant::now());
|
|
let gears_cmd = encode_gears_command(current_gears);
|
|
let _ = socket.send_to(gears_cmd.as_bytes(), target);
|
|
if changed {
|
|
log::info!(
|
|
"[Contrôleur] Vitesses CRSF synchronisées vers {} : {}",
|
|
target,
|
|
gears_cmd.trim()
|
|
);
|
|
}
|
|
}
|
|
let mut haptics_force_tick = false;
|
|
|
|
// 1. Changement de source actif (G29 <-> Steam Controller)
|
|
if desired_source != last_source {
|
|
if last_source == ControlSource::SteamController {
|
|
// Garantir un neutre désarmé avant de rendre la main au G29
|
|
Self::send_safe_disarm_burst(&socket, target, 2);
|
|
}
|
|
last_source = desired_source;
|
|
haptics.reset();
|
|
if let Some(ref mut gp) = gamepad {
|
|
gp.set_rumble(0, 0);
|
|
}
|
|
rumble_is_zero = true;
|
|
{
|
|
let mut st = state.lock();
|
|
st.armed = false;
|
|
st.gear = 0;
|
|
st.steering_norm = 0.0;
|
|
st.throttle_pct = 0;
|
|
st.brake_pct = 0;
|
|
st.clutch_pct = 0;
|
|
st.steer_crsf = CRSF_CHANNEL_MID;
|
|
st.throttle_crsf = CRSF_CHANNEL_MID;
|
|
st.brake_crsf = CRSF_CHANNEL_MID;
|
|
st.clutch_crsf = CRSF_CHANNEL_MID;
|
|
st.rumble_left_pct = 0;
|
|
st.rumble_right_pct = 0;
|
|
st.set_toast(format!("CTRL: {}", desired_source.label()));
|
|
}
|
|
let cmd = encode_src_command(desired_source);
|
|
let _ = socket.send_to(cmd.as_bytes(), target);
|
|
last_src_sync = Some(Instant::now());
|
|
log::info!(
|
|
"[Contrôleur] Bascule source envoyée vers {} : {}",
|
|
target,
|
|
cmd.trim()
|
|
);
|
|
} else if last_src_sync
|
|
.is_none_or(|t| t.elapsed() >= Duration::from_millis(SRC_RESYNC_INTERVAL_MS))
|
|
{
|
|
// Resynchroniser si la RP2350 (après reboot ou paquet UDP perdu) n'est pas sur la source attendue
|
|
let needs_resync = if let Some(ref g29_st) = g29_state_opt {
|
|
let g = g29_st.lock();
|
|
(!g.is_live() && desired_source == ControlSource::SteamController)
|
|
|| (g.is_live() && !g.armed && g.remote_source != desired_source)
|
|
} else {
|
|
desired_source == ControlSource::SteamController
|
|
};
|
|
if needs_resync {
|
|
let cmd = encode_src_command(desired_source);
|
|
let _ = socket.send_to(cmd.as_bytes(), target);
|
|
}
|
|
last_src_sync = Some(Instant::now());
|
|
}
|
|
|
|
// 2. Découverte / reconnexion à chaud du Steam Controller (HIDRAW Ibex natif ou evdev)
|
|
if gamepad.is_none()
|
|
&& last_scan
|
|
.is_none_or(|t| t.elapsed() >= Duration::from_millis(DEVICE_RESCAN_INTERVAL_MS))
|
|
{
|
|
last_scan = Some(Instant::now());
|
|
if let Some(opened) = OpenGamepad::open_best(cfg.device_override.as_deref()) {
|
|
log::info!("[Steam Controller] Connecté : {}", opened.summary_log());
|
|
let mut st = state.lock();
|
|
st.connected = true;
|
|
st.device_name = opened.name().to_string();
|
|
st.device_path = opened.path().to_string();
|
|
st.armed = false;
|
|
st.gear = 0;
|
|
st.rumble_left_pct = 0;
|
|
st.rumble_right_pct = 0;
|
|
gamepad = Some(opened);
|
|
rumble_is_zero = true;
|
|
}
|
|
}
|
|
|
|
// 3. Lecture non-bloquante des événements evdev / hidraw
|
|
pressed_keys.clear();
|
|
let mut disconnected = false;
|
|
if let Some(ref mut gp) = gamepad {
|
|
if let Err(e) = gp.poll_events(&mut pressed_keys) {
|
|
log::warn!("[Steam Controller] Liaison perdue ({}) : désarmement immédiat.", e);
|
|
disconnected = true;
|
|
}
|
|
}
|
|
if disconnected {
|
|
if let Some(ref mut gp) = gamepad {
|
|
gp.set_rumble(0, 0);
|
|
}
|
|
gamepad = None;
|
|
haptics.reset();
|
|
rumble_is_zero = true;
|
|
|
|
// Sécurité critique (< 5 ms) : envoyer immédiatement 3 trames désarmées avant même
|
|
// l'expiration du watchdog 400 ms sur la RP2350.
|
|
if desired_source == ControlSource::SteamController {
|
|
Self::send_safe_disarm_burst(&socket, target, 3);
|
|
}
|
|
|
|
let mut st = state.lock();
|
|
st.connected = false;
|
|
st.armed = false;
|
|
st.gear = 0;
|
|
st.steering_norm = 0.0;
|
|
st.throttle_pct = 0;
|
|
st.brake_pct = 0;
|
|
st.clutch_pct = 0;
|
|
st.steer_crsf = CRSF_CHANNEL_MID;
|
|
st.throttle_crsf = CRSF_CHANNEL_MID;
|
|
st.brake_crsf = CRSF_CHANNEL_MID;
|
|
st.clutch_crsf = CRSF_CHANNEL_MID;
|
|
st.rumble_left_pct = 0;
|
|
st.rumble_right_pct = 0;
|
|
st.set_toast("SC DECONNECTE");
|
|
}
|
|
|
|
// 4. Traitement axes, boîte séquentielle, boutons cockpit & émission $RC à 100 Hz
|
|
if let Some(ref gp) = gamepad {
|
|
let menu_open = control.is_vr_menu_open();
|
|
let steer_norm = gp.steer_norm();
|
|
// Sécurité : couper l'accélérateur lorsque le Menu Rapide VR est ouvert
|
|
let throttle_norm = if menu_open { 0.0 } else { gp.throttle_norm() };
|
|
let brake_norm = gp.brake_norm();
|
|
let clutch_pressed = gp.clutch_pressed();
|
|
|
|
let invert_steering = control.invert_steering();
|
|
let steer_crsf = steering_to_crsf(
|
|
steer_norm,
|
|
cfg.steering_deadzone,
|
|
cfg.steering_expo,
|
|
invert_steering,
|
|
);
|
|
let (brake_pct, brake_crsf) = brake_to_crsf(brake_norm, cfg.trigger_deadzone);
|
|
let clutch_pct = if clutch_pressed { 100 } else { 0 };
|
|
let clutch_crsf = if clutch_pressed {
|
|
CRSF_CHANNEL_MAX
|
|
} else {
|
|
CRSF_CHANNEL_MID
|
|
};
|
|
|
|
let throttle_expo = control.throttle_expo();
|
|
let speed_scale = if control.crawl_mode() { 0.5 } else { 1.0 };
|
|
|
|
if desired_source == ControlSource::SteamController {
|
|
// Mode actif : armement, boîte séquentielle, raccourcis cockpit et émission $RC 100 Hz
|
|
let mut deferred_actions: Vec<DeferredControlAction> = Vec::new();
|
|
let (armed, gear, throttle_crsf) = {
|
|
let mut st = state.lock();
|
|
let (pre_throt_pct, _) = throttle_to_crsf_curved(
|
|
throttle_norm,
|
|
cfg.trigger_deadzone,
|
|
throttle_expo,
|
|
speed_scale,
|
|
st.armed,
|
|
st.gear,
|
|
current_gears,
|
|
);
|
|
let gas_released = pre_throt_pct == 0;
|
|
let mut just_armed = false;
|
|
|
|
for &key in &pressed_keys {
|
|
st.last_button = key_code_label(key);
|
|
st.last_button_at = Some(Instant::now());
|
|
let (trig_hap, action) = Self::handle_key_press_locked(
|
|
key,
|
|
gas_released,
|
|
menu_open,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
if trig_hap {
|
|
haptics_force_tick = true;
|
|
}
|
|
if let Some(act) = action {
|
|
deferred_actions.push(act);
|
|
}
|
|
}
|
|
if clutch_pressed && st.clutch_pct == 0 {
|
|
st.last_button = key_code_label(BTN_GRIPL2);
|
|
st.last_button_at = Some(Instant::now());
|
|
}
|
|
|
|
let (throt_pct, throt_crsf) = throttle_to_crsf_curved(
|
|
throttle_norm,
|
|
cfg.trigger_deadzone,
|
|
throttle_expo,
|
|
speed_scale,
|
|
st.armed,
|
|
st.gear,
|
|
current_gears,
|
|
);
|
|
st.steering_norm = steer_norm;
|
|
st.throttle_pct = throt_pct;
|
|
st.brake_pct = brake_pct;
|
|
st.clutch_pct = clutch_pct;
|
|
st.steer_crsf = steer_crsf;
|
|
st.throttle_crsf = throt_crsf;
|
|
st.brake_crsf = brake_crsf;
|
|
st.clutch_crsf = clutch_crsf;
|
|
|
|
(st.armed, st.gear, throt_crsf)
|
|
};
|
|
|
|
// Exécuter les actions EngineControlHandle HORS du verrou `state.lock()` (pas de lock imbriqué)
|
|
for act in deferred_actions {
|
|
if let Some(toast) = Self::execute_control_action(act, &control) {
|
|
state.lock().set_toast(toast);
|
|
}
|
|
}
|
|
|
|
// Sécurité watchdog RP2350 : si aucun rapport HID frais depuis >120 ms, ne plus envoyer $RC
|
|
if !gp.is_input_stale() {
|
|
let frame = encode_rc_frame(
|
|
steer_crsf,
|
|
throttle_crsf,
|
|
brake_crsf,
|
|
clutch_crsf,
|
|
armed,
|
|
gear,
|
|
);
|
|
match socket.send_to(frame.as_bytes(), target) {
|
|
Ok(_) => {
|
|
consecutive_send_errors = 0;
|
|
let mut st = state.lock();
|
|
st.packets_sent = st.packets_sent.wrapping_add(1);
|
|
}
|
|
Err(e) => {
|
|
consecutive_send_errors = consecutive_send_errors.saturating_add(1);
|
|
let mut st = state.lock();
|
|
st.send_errors = st.send_errors.wrapping_add(1);
|
|
if consecutive_send_errors == CONSECUTIVE_SEND_ERR_DISARM {
|
|
if st.armed {
|
|
st.armed = false;
|
|
st.gear = 0;
|
|
st.throttle_crsf = CRSF_CHANNEL_MID;
|
|
haptics.on_disarm();
|
|
haptics_force_tick = true;
|
|
}
|
|
st.set_toast("HUB OFFLINE / FAILSAFE");
|
|
log::warn!(
|
|
"[Steam Controller] Erreurs UDP persistantes vers {} ({}) : désarmement local !",
|
|
target,
|
|
e
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
// Mode veille (G29 actif) : mise à jour lecture seule pour le moniteur des Réglages
|
|
// sans armer, sans déclencher les actions cockpit et sans envoyer de trame $RC.
|
|
let (throt_pct, _) = throttle_to_crsf(
|
|
throttle_norm,
|
|
cfg.trigger_deadzone,
|
|
false,
|
|
0,
|
|
current_gears,
|
|
);
|
|
let mut st = state.lock();
|
|
if let Some(&last_key) = pressed_keys.last() {
|
|
st.last_button = key_code_label(last_key);
|
|
st.last_button_at = Some(Instant::now());
|
|
} else if clutch_pressed && st.clutch_pct == 0 {
|
|
st.last_button = key_code_label(BTN_GRIPL2);
|
|
st.last_button_at = Some(Instant::now());
|
|
}
|
|
st.steering_norm = steer_norm;
|
|
st.throttle_pct = throt_pct;
|
|
st.brake_pct = brake_pct;
|
|
st.clutch_pct = clutch_pct;
|
|
st.steer_crsf = steer_crsf;
|
|
st.throttle_crsf = CRSF_CHANNEL_MID;
|
|
st.brake_crsf = brake_crsf;
|
|
st.clutch_crsf = clutch_crsf;
|
|
}
|
|
}
|
|
|
|
// 5. Moteur Haptique temps réel à 25 Hz (40 ms) + réactivité immédiate sur événements
|
|
if rumble_test_flag.swap(false, Ordering::AcqRel) {
|
|
haptics.trigger_test();
|
|
haptics_force_tick = true;
|
|
}
|
|
let vib_pct = vibration_pct.load(Ordering::Acquire).min(100);
|
|
if haptics_force_tick
|
|
|| last_haptics_tick
|
|
.is_none_or(|t| t.elapsed() >= Duration::from_millis(HAPTICS_INTERVAL_MS))
|
|
{
|
|
let now_tick = Instant::now();
|
|
last_haptics_tick = Some(now_tick);
|
|
let (roughness, bat_crit, link_crit) = telemetry_state_opt
|
|
.as_ref()
|
|
.map(|t| {
|
|
let st = t.lock();
|
|
let (cells, crit_v) = control.battery_alert_params();
|
|
(
|
|
st.effective_terrain_roughness(),
|
|
st.is_battery_critical(cells, crit_v),
|
|
st.is_link_critical(),
|
|
)
|
|
})
|
|
.unwrap_or((0, false, false));
|
|
let (connected, armed, gear, throt_pct, brk_pct) = {
|
|
let st = state.lock();
|
|
(
|
|
st.connected,
|
|
st.armed,
|
|
st.gear,
|
|
st.throttle_pct,
|
|
st.brake_pct,
|
|
)
|
|
};
|
|
let base_rumble = haptics.compute(
|
|
now_tick,
|
|
desired_source == ControlSource::SteamController,
|
|
connected,
|
|
armed,
|
|
gear,
|
|
throt_pct,
|
|
brk_pct,
|
|
roughness,
|
|
vib_pct,
|
|
);
|
|
let (left, right) = haptics.apply_telemetry_alert(
|
|
base_rumble,
|
|
now_tick,
|
|
desired_source == ControlSource::SteamController,
|
|
connected,
|
|
armed,
|
|
bat_crit,
|
|
link_crit,
|
|
vib_pct,
|
|
);
|
|
if let Some(ref mut gp) = gamepad {
|
|
if left > 0 || right > 0 {
|
|
gp.set_rumble(left, right);
|
|
rumble_is_zero = false;
|
|
} else if !rumble_is_zero {
|
|
gp.set_rumble(0, 0);
|
|
rumble_is_zero = true;
|
|
}
|
|
}
|
|
let mut st = state.lock();
|
|
st.vibration_pct = vib_pct;
|
|
st.rumble_left_pct = ((left as u32 * 100 + 32767) / 65535) as u8;
|
|
st.rumble_right_pct = ((right as u32 * 100 + 32767) / 65535) as u8;
|
|
}
|
|
|
|
let elapsed = loop_start.elapsed();
|
|
let interval = Duration::from_millis(RC_SEND_INTERVAL_MS);
|
|
if elapsed < interval {
|
|
thread::sleep(interval - elapsed);
|
|
}
|
|
}
|
|
|
|
// Arrêt garanti des moteurs haptiques à la fermeture
|
|
if let Some(ref mut gp) = gamepad {
|
|
gp.set_rumble(0, 0);
|
|
}
|
|
|
|
// À l'arrêt propre, envoyer un état désarmé si le Steam Controller était actif
|
|
if ControlSource::from_u8(active_source.load(Ordering::Acquire))
|
|
== ControlSource::SteamController
|
|
{
|
|
Self::send_safe_disarm_burst(&socket, target, 2);
|
|
}
|
|
log::info!("[Steam Controller] Thread contrôleur arrêté.");
|
|
}
|
|
|
|
/// Retourne `(trigger_haptics, Option<DeferredControlAction>)`.
|
|
fn handle_key_press_locked(
|
|
key: u16,
|
|
gas_released: bool,
|
|
menu_open: bool,
|
|
just_armed: &mut bool,
|
|
st: &mut SteamControllerState,
|
|
haptics: &mut SteamHapticsSynthesizer,
|
|
) -> (bool, Option<DeferredControlAction>) {
|
|
match key {
|
|
// Armement / Désarmement (Start / Menu) — désarmement toujours autorisé, armement bloqué si menu VR ouvert
|
|
BTN_START => {
|
|
if st.armed {
|
|
st.armed = false;
|
|
st.set_toast("DESARME");
|
|
haptics.on_disarm();
|
|
log::info!("[Steam Controller] Véhicule DÉSARMÉ (Menu/Start).");
|
|
return (true, None);
|
|
} else if menu_open {
|
|
st.set_toast("FERMER MENU VR");
|
|
} else if st.gear == 0 && gas_released {
|
|
st.armed = true;
|
|
*just_armed = true;
|
|
st.set_toast("ARME (SC)");
|
|
haptics.on_arm();
|
|
log::info!("[Steam Controller] Véhicule ARMÉ (Menu/Start).");
|
|
return (true, None);
|
|
} else {
|
|
st.set_toast("ARM REFUSE (N+GAZ 0)");
|
|
log::warn!(
|
|
"[Steam Controller] Armement refusé : passer au point mort (N) et relâcher la gâchette R2 !"
|
|
);
|
|
}
|
|
}
|
|
// Boîte séquentielle : Monter un rapport (RB ou Palette arrière droite R4)
|
|
// Bloque N -> 1 sous gaz (st.gear == 0 && !gas_released), autorise toujours R -> N,
|
|
// et interdit le changement de rapport pendant l'ouverture du menu VR ou dans le même tick que l'armement.
|
|
BTN_TR | BTN_GRIPR if !menu_open && !*just_armed => {
|
|
if st.gear < 3 && !(st.gear == 0 && !gas_released) {
|
|
st.gear += 1;
|
|
let lbl = st.gear_label();
|
|
st.set_toast(format!("RAPPORT {}", lbl));
|
|
if st.armed {
|
|
haptics.on_shift(1);
|
|
return (true, None);
|
|
}
|
|
} else if st.gear == 0 && !gas_released {
|
|
st.set_toast("RELACHER GAZ (N->1)");
|
|
}
|
|
}
|
|
// Boîte séquentielle : Rétrograder (LB ou Palette arrière gauche L4)
|
|
// Bloque N -> R sous gaz (st.gear == 0 && !gas_released), autorise toujours 1 -> N.
|
|
BTN_TL | BTN_GRIPL if !menu_open && !*just_armed => {
|
|
if st.gear > -1 && !(st.gear == 0 && !gas_released) {
|
|
st.gear -= 1;
|
|
let lbl = st.gear_label();
|
|
st.set_toast(format!("RAPPORT {}", lbl));
|
|
if st.armed {
|
|
haptics.on_shift(-1);
|
|
return (true, None);
|
|
}
|
|
} else if st.gear == 0 && !gas_released {
|
|
st.set_toast("RELACHER GAZ (N->R)");
|
|
}
|
|
}
|
|
// Actions Cockpit & Menu Rapide VR (exécutées hors du verrou `state.lock()`)
|
|
BTN_SELECT => return (false, Some(DeferredControlAction::ToggleVrMenu)),
|
|
BTN_SOUTH if menu_open => return (false, Some(DeferredControlAction::VrMenuActivate)),
|
|
BTN_EAST if menu_open => return (false, Some(DeferredControlAction::VrMenuClose)),
|
|
BTN_DPAD_UP if menu_open => return (false, Some(DeferredControlAction::VrMenuMove(-1))),
|
|
BTN_DPAD_DOWN if menu_open => {
|
|
return (false, Some(DeferredControlAction::VrMenuMove(1)))
|
|
}
|
|
BTN_DPAD_LEFT if menu_open => {
|
|
return (false, Some(DeferredControlAction::VrMenuAdjust(-1)))
|
|
}
|
|
BTN_DPAD_RIGHT if menu_open => {
|
|
return (false, Some(DeferredControlAction::VrMenuAdjust(1)))
|
|
}
|
|
BTN_SOUTH | BTN_THUMBR | BTN_MODE => {
|
|
return (false, Some(DeferredControlAction::Recenter))
|
|
}
|
|
BTN_EAST => return (false, Some(DeferredControlAction::ToggleDvr)),
|
|
BTN_NORTH => return (false, Some(DeferredControlAction::ToggleTelemetry)),
|
|
BTN_WEST => return (false, Some(DeferredControlAction::CycleProjection)),
|
|
BTN_DPAD_UP => return (false, Some(DeferredControlAction::Trim(0.0, 1.0, "TILT +1"))),
|
|
BTN_DPAD_DOWN => {
|
|
return (false, Some(DeferredControlAction::Trim(0.0, -1.0, "TILT -1")))
|
|
}
|
|
BTN_DPAD_LEFT => {
|
|
return (false, Some(DeferredControlAction::Trim(-1.0, 0.0, "PAN -1")))
|
|
}
|
|
BTN_DPAD_RIGHT => {
|
|
return (false, Some(DeferredControlAction::Trim(1.0, 0.0, "PAN +1")))
|
|
}
|
|
_ => {}
|
|
}
|
|
(false, None)
|
|
}
|
|
|
|
fn execute_control_action(
|
|
action: DeferredControlAction,
|
|
control: &EngineControlHandle,
|
|
) -> Option<String> {
|
|
match action {
|
|
DeferredControlAction::ToggleVrMenu => {
|
|
let open = control.toggle_vr_menu();
|
|
Some(if open { "MENU VR ON" } else { "MENU VR OFF" }.to_string())
|
|
}
|
|
DeferredControlAction::VrMenuActivate => {
|
|
control.vr_menu_activate();
|
|
None
|
|
}
|
|
DeferredControlAction::VrMenuClose => {
|
|
let closed = control.close_vr_menu();
|
|
Some(if closed { "MENU VR OFF" } else { "RETOUR MENU" }.to_string())
|
|
}
|
|
DeferredControlAction::VrMenuMove(delta) => {
|
|
control.vr_menu_move(delta as isize);
|
|
None
|
|
}
|
|
DeferredControlAction::VrMenuAdjust(delta) => {
|
|
control.vr_menu_adjust(delta);
|
|
None
|
|
}
|
|
DeferredControlAction::Recenter => {
|
|
control.request_recenter();
|
|
Some("TARE HT OK".to_string())
|
|
}
|
|
DeferredControlAction::ToggleDvr => {
|
|
let now_rec = control.toggle_dvr();
|
|
Some(if now_rec { "DVR REC" } else { "DVR STOP" }.to_string())
|
|
}
|
|
DeferredControlAction::ToggleTelemetry => {
|
|
let now_on = control.toggle_telemetry();
|
|
Some(if now_on { "OSD ON" } else { "OSD OFF" }.to_string())
|
|
}
|
|
DeferredControlAction::CycleProjection => {
|
|
let mode_lbl = control.cycle_projection_mode();
|
|
Some(format!("PROJ: {}", mode_lbl))
|
|
}
|
|
DeferredControlAction::Trim(pan, tilt, label) => {
|
|
control.adjust_head_trim(pan, tilt);
|
|
Some(label.to_string())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
enum DeferredControlAction {
|
|
ToggleVrMenu,
|
|
VrMenuActivate,
|
|
VrMenuClose,
|
|
VrMenuMove(i32),
|
|
VrMenuAdjust(i32),
|
|
Recenter,
|
|
ToggleDvr,
|
|
ToggleTelemetry,
|
|
CycleProjection,
|
|
Trim(f32, f32, &'static str),
|
|
}
|
|
|
|
impl Drop for SteamControllerWorker {
|
|
fn drop(&mut self) {
|
|
self.stop_flag.store(true, Ordering::Release);
|
|
if let Some(handle) = self.worker.take() {
|
|
let _ = handle.join();
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_control_source_parsing() {
|
|
assert_eq!(ControlSource::from_str("g29"), ControlSource::G29);
|
|
assert_eq!(ControlSource::from_str("wheel"), ControlSource::G29);
|
|
assert_eq!(
|
|
ControlSource::from_str("steam"),
|
|
ControlSource::SteamController
|
|
);
|
|
assert_eq!(
|
|
ControlSource::from_str("EXT"),
|
|
ControlSource::SteamController
|
|
);
|
|
assert_eq!(ControlSource::G29.wire_tag(), "G29");
|
|
assert_eq!(ControlSource::SteamController.wire_tag(), "EXT");
|
|
}
|
|
|
|
#[test]
|
|
fn test_sysfs_bitmap_has_bit_steam_controller() {
|
|
// Capacités réelles d'un Wireless Steam Controller (28de:1304)
|
|
let key_caps = "ff00000000 0 0 0 7fdb004600000000 0 0 0 0";
|
|
let abs_caps = "3f001b";
|
|
assert!(sysfs_bitmap_has_bit(key_caps, BTN_SOUTH as usize));
|
|
assert!(sysfs_bitmap_has_bit(key_caps, BTN_START as usize));
|
|
assert!(sysfs_bitmap_has_bit(key_caps, BTN_GRIPR as usize));
|
|
assert!(sysfs_bitmap_has_bit(abs_caps, ABS_X as usize));
|
|
assert!(sysfs_bitmap_has_bit(abs_caps, ABS_HAT2X as usize));
|
|
assert!(sysfs_bitmap_has_bit(abs_caps, ABS_HAT2Y as usize));
|
|
assert!(!sysfs_bitmap_has_bit("40", 0));
|
|
assert!(sysfs_bitmap_has_bit("40", INPUT_PROP_ACCELEROMETER));
|
|
}
|
|
|
|
#[test]
|
|
fn test_steering_curve_and_polarity() {
|
|
// Neutre dans la zone morte
|
|
assert_eq!(steering_to_crsf(0.05, 0.08, 0.25, false), CRSF_CHANNEL_MID);
|
|
// À droite (+1.0) -> descend vers MIN (172), identique au G29
|
|
assert_eq!(steering_to_crsf(1.0, 0.08, 0.25, false), CRSF_CHANNEL_MIN);
|
|
// À gauche (-1.0) -> monte vers MAX (1811), identique au G29
|
|
assert_eq!(steering_to_crsf(-1.0, 0.08, 0.25, false), CRSF_CHANNEL_MAX);
|
|
// Inversion
|
|
assert_eq!(steering_to_crsf(1.0, 0.08, 0.25, true), CRSF_CHANNEL_MAX);
|
|
}
|
|
|
|
#[test]
|
|
fn test_sequential_gearbox_throttle_and_brake() {
|
|
let def = GearSpeedLimits::default();
|
|
// Désarmé : toujours au neutre
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, false, 2, def), (100, CRSF_CHANNEL_MID));
|
|
// Point mort N : toujours au neutre
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, true, 0, def), (100, CRSF_CHANNEL_MID));
|
|
// 1ère vitesse plein gaz -> 1100
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, true, 1, def), (100, 1100));
|
|
// 3ème vitesse plein gaz -> 1220
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, true, 3, def), (100, 1220));
|
|
// Marche arrière plein gaz -> 800
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, true, -1, def), (100, 800));
|
|
// Valeurs personnalisées
|
|
let custom = GearSpeedLimits {
|
|
forward_min: 1080,
|
|
forward_max: [1140, 1250, 1400],
|
|
reverse_min: 890,
|
|
reverse_max: 720,
|
|
};
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, true, 2, custom), (100, 1250));
|
|
assert_eq!(throttle_to_crsf(1.0, 0.05, true, -1, custom), (100, 720));
|
|
// Frein plein -> 1811
|
|
assert_eq!(brake_to_crsf(1.0, 0.05), (100, CRSF_CHANNEL_MAX));
|
|
assert_eq!(brake_to_crsf(0.02, 0.05), (0, CRSF_CHANNEL_MID));
|
|
}
|
|
|
|
#[test]
|
|
fn test_encode_rc_and_src_frames() {
|
|
let check_crc = |frame: String, expected_body: &str| {
|
|
assert!(frame.ends_with('\n'));
|
|
let (body, hex_crc) = frame.trim_end_matches('\n').split_once('*').unwrap();
|
|
assert_eq!(body, expected_body);
|
|
let expected = format!(
|
|
"{:02X}",
|
|
crate::nomad_elrs::NomadHeadTracker::crc8_dvb_s2(body.as_bytes())
|
|
);
|
|
assert_eq!(hex_crc, expected);
|
|
};
|
|
check_crc(encode_src_command(ControlSource::G29), "$SRC,G29");
|
|
check_crc(encode_src_command(ControlSource::SteamController), "$SRC,EXT");
|
|
check_crc(
|
|
encode_rc_frame(992, 1150, 992, 992, true, 2),
|
|
"$RC,992,1150,992,992,1,2",
|
|
);
|
|
check_crc(
|
|
encode_gears_command(GearSpeedLimits::default()),
|
|
"$GEARS,1065,1100,1150,1220,905,800",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_ibex_hidraw_report() {
|
|
let mut raw = [0u8; IBEX_REPORT_LEN];
|
|
raw[0] = IBEX_REPORT_ID;
|
|
raw[2] = 0x41; // A (0x01) + Menu/Start (0x40)
|
|
raw[3] = 0x02; // RB
|
|
raw[4] = 0x04; // L5 clutch
|
|
// Brake (L2) at 6..8 = 16384
|
|
raw[6..8].copy_from_slice(&16384i16.to_le_bytes());
|
|
// Throttle (R2) at 8..10 = 32767
|
|
raw[8..10].copy_from_slice(&32767i16.to_le_bytes());
|
|
// Left stick X at 10..12 = -16384
|
|
raw[10..12].copy_from_slice(&(-16384i16).to_le_bytes());
|
|
|
|
let parsed = parse_ibex_hidraw_report(&raw).expect("rapport 0x42 valide");
|
|
assert_eq!(parsed.brake_raw, 16384);
|
|
assert_eq!(parsed.throttle_raw, 32767);
|
|
assert_eq!(parsed.steer_raw, -16384);
|
|
assert!(parsed.clutch_pressed);
|
|
assert_eq!(parsed.btn_bytes, [0x41, 0x02, 0x04, 0x00]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_encode_ibex_rumble_report() {
|
|
let rep = encode_ibex_rumble_report(0x1234, 0xABCD);
|
|
assert_eq!(
|
|
rep,
|
|
[0x80, 0x00, 0x00, 0x00, 0x34, 0x12, 0x02, 0xCD, 0xAB, 0x00]
|
|
);
|
|
let zero = encode_ibex_rumble_report(0, 0);
|
|
assert_eq!(
|
|
zero,
|
|
[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_haptics_synthesizer_priorities() {
|
|
let mut h = SteamHapticsSynthesizer::new();
|
|
let t0 = h.origin;
|
|
|
|
// 1. Silence garanti si désarmé, point mort (N), ou 0%
|
|
assert_eq!(h.compute(t0, true, true, false, 1, 80, 0, 200, 80), (0, 0));
|
|
assert_eq!(h.compute(t0, true, true, true, 0, 80, 0, 200, 80), (0, 0));
|
|
assert_eq!(h.compute(t0, true, true, true, 2, 80, 0, 200, 0), (0, 0));
|
|
assert_eq!(h.compute(t0, false, true, true, 2, 80, 0, 200, 80), (0, 0));
|
|
|
|
// 2. Test manuel UI : 250 ms gauche puis 250 ms droite, même désarmé
|
|
h.trigger_test_at(t0);
|
|
let (tl1, tr1) = h.compute(
|
|
t0 + Duration::from_millis(50),
|
|
false,
|
|
true,
|
|
false,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
60,
|
|
);
|
|
assert!(tl1 > 0 && tr1 == 0);
|
|
let (tl2, tr2) = h.compute(
|
|
t0 + Duration::from_millis(300),
|
|
false,
|
|
true,
|
|
false,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
60,
|
|
);
|
|
assert!(tl2 == 0 && tr2 > 0);
|
|
// Fin du test après 500 ms -> silence
|
|
assert_eq!(
|
|
h.compute(
|
|
t0 + Duration::from_millis(520),
|
|
false,
|
|
true,
|
|
false,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
60,
|
|
),
|
|
(0, 0)
|
|
);
|
|
|
|
// 3. Montée de rapport : coup sec moteur droit uniquement (70 ms)
|
|
let t_shift = t0 + Duration::from_secs(1);
|
|
h.on_shift_at(1, t_shift);
|
|
let (sl, sr) = h.compute(
|
|
t_shift + Duration::from_millis(20),
|
|
true,
|
|
true,
|
|
true,
|
|
2,
|
|
50,
|
|
0,
|
|
0,
|
|
80,
|
|
);
|
|
assert_eq!(sl, 0);
|
|
assert!(sr > 0);
|
|
|
|
// 4. Rétrogradage : coup sec moteur gauche uniquement (70 ms)
|
|
let t_down = t_shift + Duration::from_millis(100);
|
|
h.on_shift_at(-1, t_down);
|
|
let (dl, dr) = h.compute(
|
|
t_down + Duration::from_millis(20),
|
|
true,
|
|
true,
|
|
true,
|
|
1,
|
|
50,
|
|
0,
|
|
0,
|
|
80,
|
|
);
|
|
assert!(dl > 0);
|
|
assert_eq!(dr, 0);
|
|
|
|
// 5. Freinage violent ABS (> 70%) : pulsation crête > creux sur les deux moteurs
|
|
let t_abs_crest = t0 + Duration::from_millis(2000); // 2000 / 40 = 50 (pair -> crête)
|
|
let t_abs_trough = t0 + Duration::from_millis(2040); // 2040 / 40 = 51 (impair -> creux)
|
|
let (al1, ar1) = h.compute(t_abs_crest, true, true, true, 2, 0, 95, 0, 80);
|
|
let (al2, ar2) = h.compute(t_abs_trough, true, true, true, 2, 0, 95, 0, 80);
|
|
assert!(al1 > al2 && ar1 > ar2 && al1 > 0 && ar1 > 0);
|
|
|
|
// 6. Double couche conduite : moteur gauche + grain de roulement droit croissant avec le rapport
|
|
let t_drv = t0 + Duration::from_secs(3);
|
|
let (g1_l, g1_r) = h.compute(t_drv, true, true, true, 1, 60, 0, 0, 80);
|
|
let (g3_l, g3_r) = h.compute(t_drv, true, true, true, 3, 60, 0, 0, 80);
|
|
assert!(g1_l > 0 && g1_r > 0);
|
|
assert_eq!(g1_l, g3_l);
|
|
assert!(g3_r > g1_r);
|
|
|
|
// 7. Contribution rugosité terrain sur les deux moteurs (même gaz à 0)
|
|
let (t_l, t_r) = h.compute(t_drv, true, true, true, 1, 0, 0, 220, 80);
|
|
assert!(t_l > 0 && t_r > 0);
|
|
|
|
// 8. Alertes haptiques télémétrie (batterie critique sur moteur gauche + LQ critique sur droit)
|
|
let (bl, br) = h.apply_telemetry_alert(
|
|
(0, 0),
|
|
t0 + Duration::from_millis(40),
|
|
true,
|
|
true,
|
|
true,
|
|
true,
|
|
false,
|
|
100,
|
|
);
|
|
assert!(bl > 40000 && br == 0);
|
|
let (ll, lr) = h.apply_telemetry_alert(
|
|
(0, 0),
|
|
t0 + Duration::from_millis(30),
|
|
true,
|
|
true,
|
|
true,
|
|
false,
|
|
true,
|
|
100,
|
|
);
|
|
assert!(ll == 0 && lr > 35000);
|
|
// Désarmé -> jamais d'alerte haptique
|
|
assert_eq!(
|
|
h.apply_telemetry_alert((0, 0), t0 + Duration::from_millis(40), true, true, false, true, true, 100),
|
|
(0, 0)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_nan_and_infinite_inputs_fail_safe_to_neutral() {
|
|
let def = GearSpeedLimits::default();
|
|
assert_eq!(
|
|
steering_to_crsf(f32::NAN, 0.08, 0.25, false),
|
|
CRSF_CHANNEL_MID
|
|
);
|
|
assert_eq!(
|
|
steering_to_crsf(f32::INFINITY, 0.08, 0.25, false),
|
|
CRSF_CHANNEL_MID
|
|
);
|
|
assert_eq!(
|
|
throttle_to_crsf(f32::NAN, 0.05, true, 3, def),
|
|
(0, CRSF_CHANNEL_MID)
|
|
);
|
|
assert_eq!(brake_to_crsf(f32::NAN, 0.05), (0, CRSF_CHANNEL_MID));
|
|
}
|
|
|
|
#[test]
|
|
fn test_axis_range_full_i32_bounds_no_overflow() {
|
|
let axis = AxisRange::centered(i32::MIN, i32::MAX, 0);
|
|
assert!(axis.normalized_signed().abs() < 1e-4);
|
|
assert!((axis.normalized_unsigned() - 0.5).abs() < 1e-4);
|
|
}
|
|
|
|
#[test]
|
|
fn test_gear_interlocks_and_vr_menu_safety() {
|
|
let mut st = SteamControllerState::default();
|
|
let mut haptics = SteamHapticsSynthesizer::new();
|
|
let mut just_armed = false;
|
|
|
|
// N -> 1 sous gaz : BLOQUÉ
|
|
st.gear = 0;
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_TR,
|
|
false,
|
|
false,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert_eq!(st.gear, 0);
|
|
|
|
// R -> N sous gaz : AUTORISÉ (toujours pouvoir revenir au neutre)
|
|
st.gear = -1;
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_TR,
|
|
false,
|
|
false,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert_eq!(st.gear, 0);
|
|
|
|
// N -> R sous gaz : BLOQUÉ
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_TL,
|
|
false,
|
|
false,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert_eq!(st.gear, 0);
|
|
|
|
// Armement + montée de rapport dans le même tick : rapport bloqué
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_START,
|
|
true,
|
|
false,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert!(st.armed && just_armed);
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_TR,
|
|
true,
|
|
false,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert_eq!(st.gear, 0);
|
|
|
|
// Menu VR ouvert : désarmement toujours autorisé, ré-armement bloqué
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_START,
|
|
true,
|
|
true,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert!(!st.armed);
|
|
SteamControllerWorker::handle_key_press_locked(
|
|
BTN_START,
|
|
true,
|
|
true,
|
|
&mut just_armed,
|
|
&mut st,
|
|
&mut haptics,
|
|
);
|
|
assert!(!st.armed);
|
|
}
|
|
}
|