Skip to content

Commit

Permalink
Merge pull request #118 from FrameworkComputer/fps-limit
Browse files Browse the repository at this point in the history
inputmodule-control: Limit FPS to 1000
  • Loading branch information
JohnAZoidberg authored Oct 21, 2024
2 parents e87571b + 53606f4 commit 310fefa
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 @@ -1006,7 +1006,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 310fefa

Please sign in to comment.