Skip to content

Commit

Permalink
KEY_1 long press improvement.
Browse files Browse the repository at this point in the history
Long pressing KEY_1 will execute the inverse power action of on normal press.
Prior, long pressing would always force all nodes on.
See the state table:

 | state             | long_press | All nodes |
 | :---------------- | :--------: | :-------: |
 | 0b0000            |  False     | On        |
 | 0b0111            |  False     | Off       |
 | 0b1111            |  False     | Off       |
 | 0b0000            |  True      | On        |
 | 0b0111            |  True      | On        |
 | 0b1111            |  True      | Off       |
  • Loading branch information
svenrademakers committed Nov 21, 2023
1 parent 3ed15a0 commit ebb4240
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ once_cell = "1.18.0"
rockfile = { version = "0.1.1"}
rockusb = { version= "0.1.2" }
rusb = "0.9.3"
rustpiboot = { git = "https://github.com/ruslashev/rustpiboot.git", rev="89e6497"}
rustpiboot = { git = "https://github.com/ruslashev/rustpiboot.git", rev="89e6497" }
tokio-serial = { version = "5.4.4", features = ["rt", "codec"] }
serde_with = "3.4.0"
thiserror = "1.0.50"
Expand Down
31 changes: 26 additions & 5 deletions src/app/bmc_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,34 @@ impl BmcApplication {
Ok(instance)
}

pub async fn toggle_power_states(&self, force_on: bool) -> anyhow::Result<()> {
if force_on {
return self.activate_slot(0b1111, 0b1111).await;
/// toggles the power state of the nodes. When `inverse_toggle` == true, and
/// not all nodes are off nor on, it will turn off all nodes instead of
/// turning them on.
///
/// # State table
///
/// | state | long_press | All nodes |
/// | :---------------- | :--------: | :-------: |
/// | 0b0000 | False | On |
/// | 0b0111 | False | Off |
/// | 0b1111 | False | Off |
/// | 0b0000 | True | On |
/// | 0b0111 | True | On |
/// | 0b1111 | True | Off |
///
/// # Return
///
/// returns Err(e) on an internal gpio error or when there is an error
/// writing power LED status.
pub async fn toggle_power_states(&self, inverse_toggle: bool) -> anyhow::Result<()> {
let node_values = self.app_db.get::<u8>(ACTIVATED_NODES_KEY).await;

let mut on = node_values == 0;
if inverse_toggle && node_values != 0 && node_values != 0b1111 {
on = !on;
}

let mut node_values = self.app_db.get::<u8>(ACTIVATED_NODES_KEY).await;
node_values = if node_values < 15 { 0b1111 } else { 0b0000 };
let node_values = if on { 0b1111 } else { 0b0000 };
self.activate_slot(node_values, 0b1111).await
}

Expand Down

0 comments on commit ebb4240

Please sign in to comment.