Skip to content

Commit 310fefa

Browse files
Merge pull request #118 from FrameworkComputer/fps-limit
inputmodule-control: Limit FPS to 1000
2 parents e87571b + 53606f4 commit 310fefa

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
@@ -1006,7 +1006,13 @@ fn animation_fps_cmd(serialdev: &str, arg: Option<u16>) {
10061006
.expect("Failed to open port");
10071007

10081008
if let Some(fps) = arg {
1009-
let period = (1000 / fps).to_le_bytes();
1009+
const MS: u16 = 1000;
1010+
if fps < MS {
1011+
// It would need to set the animation period lower than 1ms
1012+
println!("Unable to set FPS over 1000");
1013+
return;
1014+
}
1015+
let period = (MS / fps).to_le_bytes();
10101016
simple_cmd_port(&mut port, Command::AnimationPeriod, &[period[0], period[1]]);
10111017
} else {
10121018
simple_cmd_port(&mut port, Command::AnimationPeriod, &[]);

0 commit comments

Comments
 (0)