Skip to content

Commit

Permalink
inputmodule-control: Limit FPS to 1000
Browse files Browse the repository at this point in the history
Otherwise the division in the CLI results in 0 and tells the firmware to
set the animation frequency to 0ms.

Fixes #113

Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 13, 2024
1 parent ad3a034 commit 807b8b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions fl16-inputmodules/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ pub enum Command {
GetFps,
SetPowerMode(u8),
GetPowerMode,
/// Set the animation period in milliseconds
SetAnimationPeriod(u16),
/// Get the animation period in milliseconds
GetAnimationPeriod,
#[cfg(feature = "ledmatrix")]
SetPwmFreq(PwmFreqArg),
Expand Down Expand Up @@ -249,6 +251,7 @@ pub struct B1DIsplayState {
pub screensaver: Option<ScreenSaverState>,
pub power_mode: PowerMode,
pub fps_config: FpsConfig,
/// Animation period in microseconds
pub animation_period: u64,
}

Expand Down
1 change: 1 addition & 0 deletions fl16-inputmodules/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct LedmatrixState {
pub sleeping: SleepState,
/// State of the current game, if any
pub game: Option<GameState>,
/// Animation perios in microseconds
pub animation_period: u64,
/// Current LED PWM frequency
pub pwm_freq: PwmFreqArg,
Expand Down
8 changes: 7 additions & 1 deletion inputmodule-control/src/inputmodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,13 @@ fn animation_fps_cmd(serialdev: &str, arg: Option<u16>) {
.expect("Failed to open port");

if let Some(fps) = arg {
let period = (1000 / fps).to_le_bytes();
const MS: u16 = 1000;
if fps < ms {
// It would need to set the animation period lower than 1ms
println!("Unable to set FPS over 1000");
return;
}
let period = (ms / fps).to_le_bytes();
simple_cmd_port(&mut port, Command::AnimationPeriod, &[period[0], period[1]]);
} else {
simple_cmd_port(&mut port, Command::AnimationPeriod, &[]);
Expand Down

0 comments on commit 807b8b2

Please sign in to comment.