Skip to content

Commit 55db09f

Browse files
committed
inputmodule-control: Add command for debug mode
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent e10c4f1 commit 55db09f

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

fl16-inputmodules/src/control.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub enum CommandVals {
6969
SetPowerMode = 0x1B,
7070
AnimationPeriod = 0x1C,
7171
PwmFreq = 0x1E,
72+
DebugMode = 0x1F,
7273
Version = 0x20,
7374
}
7475

@@ -205,6 +206,8 @@ pub enum Command {
205206
#[cfg(feature = "ledmatrix")]
206207
SetPwmFreq(PwmFreqArg),
207208
GetPwmFreq,
209+
SetDebugMode(bool),
210+
GetDebugMode,
208211
_Unknown,
209212
}
210213

@@ -385,6 +388,11 @@ pub fn parse_module_command(count: usize, buf: &[u8]) -> Option<Command> {
385388
Some(Command::GetPwmFreq)
386389
}
387390
}
391+
Some(CommandVals::DebugMode) => Some(if let Some(debug_mode) = arg {
392+
Command::SetDebugMode(debug_mode == 1)
393+
} else {
394+
Command::GetDebugMode
395+
}),
388396
_ => None,
389397
}
390398
} else {
@@ -614,6 +622,15 @@ pub fn handle_command(
614622
response[0] = state.pwm_freq as u8;
615623
Some(response)
616624
}
625+
Command::SetDebugMode(arg) => {
626+
state.debug_mode = *arg;
627+
None
628+
}
629+
Command::GetDebugMode => {
630+
let mut response: [u8; 32] = [0; 32];
631+
response[0] = state.debug_mode as u8;
632+
Some(response)
633+
}
617634
_ => handle_generic_command(command),
618635
}
619636
}

inputmodule-control/src/inputmodule.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum Command {
4848
PowerMode = 0x1B,
4949
AnimationPeriod = 0x1C,
5050
PwmFreq = 0x1E,
51+
DebugMode = 0x1F,
5152
Version = 0x20,
5253
}
5354

@@ -225,6 +226,9 @@ pub fn serial_commands(args: &crate::ClapCli) {
225226
if let Some(freq) = ledmatrix_args.pwm_freq {
226227
pwm_freq_cmd(serialdev, freq);
227228
}
229+
if let Some(debug_mode) = ledmatrix_args.debug_mode {
230+
debug_mode_cmd(serialdev, debug_mode);
231+
}
228232

229233
if ledmatrix_args.stop_game {
230234
simple_cmd(
@@ -446,6 +450,26 @@ fn sleeping_cmd(serialdev: &str, arg: Option<bool>) {
446450
}
447451
}
448452

453+
fn debug_mode_cmd(serialdev: &str, arg: Option<bool>) {
454+
let mut port = serialport::new(serialdev, 115_200)
455+
.timeout(SERIAL_TIMEOUT)
456+
.open()
457+
.expect("Failed to open port");
458+
459+
if let Some(enable_debug) = arg {
460+
simple_cmd_port(&mut port, Command::DebugMode, &[u8::from(enable_debug)]);
461+
} else {
462+
simple_cmd_port(&mut port, Command::DebugMode, &[]);
463+
464+
let mut response: Vec<u8> = vec![0; 32];
465+
port.read_exact(response.as_mut_slice())
466+
.expect("Found no data!");
467+
468+
let debug_mode: bool = response[0] == 1;
469+
println!("Debug Mode enabled: {debug_mode}");
470+
}
471+
}
472+
449473
fn brightness_cmd(serialdev: &str, arg: Option<u8>) {
450474
let mut port = serialport::new(serialdev, 115_200)
451475
.timeout(SERIAL_TIMEOUT)

inputmodule-control/src/ledmatrix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ pub struct LedMatrixSubcommand {
131131
#[clap(value_enum)]
132132
pub pwm_freq: Option<Option<u16>>,
133133

134+
/// Set debug mode or get current mode, if no value provided
135+
#[arg(long)]
136+
pub debug_mode: Option<Option<bool>>,
137+
134138
/// Crash the firmware (TESTING ONLY!)
135139
#[arg(long)]
136140
pub panic: bool,

ledmatrix_control.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CommandVals(IntEnum):
4747
SetFps = 0x1A
4848
SetPowerMode = 0x1B
4949
PwmFreq = 0x1E
50+
DebugMode = 0x1F
5051
Version = 0x20
5152

5253

0 commit comments

Comments
 (0)