Skip to content

Commit 53606f4

Browse files
committed
inputmodule-control: Limit FPS to 1000
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]>
1 parent ad3a034 commit 53606f4

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

fl16-inputmodules/src/control.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ pub enum Command {
202202
GetFps,
203203
SetPowerMode(u8),
204204
GetPowerMode,
205+
/// Set the animation period in milliseconds
205206
SetAnimationPeriod(u16),
207+
/// Get the animation period in milliseconds
206208
GetAnimationPeriod,
207209
#[cfg(feature = "ledmatrix")]
208210
SetPwmFreq(PwmFreqArg),
@@ -249,6 +251,7 @@ pub struct B1DIsplayState {
249251
pub screensaver: Option<ScreenSaverState>,
250252
pub power_mode: PowerMode,
251253
pub fps_config: FpsConfig,
254+
/// Animation period in microseconds
252255
pub animation_period: u64,
253256
}
254257

fl16-inputmodules/src/matrix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct LedmatrixState {
3737
pub sleeping: SleepState,
3838
/// State of the current game, if any
3939
pub game: Option<GameState>,
40+
/// Animation perios in microseconds
4041
pub animation_period: u64,
4142
/// Current LED PWM frequency
4243
pub pwm_freq: PwmFreqArg,

inputmodule-control/src/inputmodule.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,13 @@ fn animation_fps_cmd(serialdev: &str, arg: Option<u16>) {
10001000
.expect("Failed to open port");
10011001

10021002
if let Some(fps) = arg {
1003-
let period = (1000 / fps).to_le_bytes();
1003+
const MS: u16 = 1000;
1004+
if fps < MS {
1005+
// It would need to set the animation period lower than 1ms
1006+
println!("Unable to set FPS over 1000");
1007+
return;
1008+
}
1009+
let period = (MS / fps).to_le_bytes();
10041010
simple_cmd_port(&mut port, Command::AnimationPeriod, &[period[0], period[1]]);
10051011
} else {
10061012
simple_cmd_port(&mut port, Command::AnimationPeriod, &[]);

0 commit comments

Comments
 (0)