Improve the thing
This commit is contained in:
parent
892a0b0ab6
commit
36ce024665
3 changed files with 26 additions and 13 deletions
|
@ -80,17 +80,7 @@ impl Driver {
|
|||
pub fn maybe_do_button() {
|
||||
match super::auto_detect_provider() {
|
||||
DriverJson::SteamDeck | DriverJson::SteamDeckAdvance => {
|
||||
let period = std::time::Duration::from_millis(500);
|
||||
for _ in 0..10 {
|
||||
if let Err(e) = crate::settings::steam_deck::set_led(false, true, false) {
|
||||
log::error!("Thing err: {}", e);
|
||||
}
|
||||
std::thread::sleep(period);
|
||||
if let Err(e) = crate::settings::steam_deck::set_led(false, false, false) {
|
||||
log::error!("Thing err: {}", e);
|
||||
};
|
||||
std::thread::sleep(period);
|
||||
}
|
||||
crate::settings::steam_deck::flash_led();
|
||||
},
|
||||
DriverJson::Generic => log::warn!("You need to come up with something fun on generic"),
|
||||
DriverJson::Unknown => log::warn!("Can't do button activities on unknown platform"),
|
||||
|
|
|
@ -7,4 +7,4 @@ pub use battery::Battery;
|
|||
pub use cpu::{Cpu, Cpus};
|
||||
pub use gpu::Gpu;
|
||||
|
||||
pub use util::set_led;
|
||||
pub use util::flash_led;
|
||||
|
|
|
@ -60,11 +60,34 @@ fn wait_ready_for_read() -> Result<(), Error> {
|
|||
}
|
||||
|
||||
pub fn set_led(red_unused: bool, green_aka_white: bool, blue_unused: bool) -> Result<usize, Error> {
|
||||
let payload: u8 = 0x80 + (red_unused as u8 & 1) + ((green_aka_white as u8 & 1) << 1) + ((blue_unused as u8 & 1) << 2);
|
||||
let payload: u8 = 0x80 | (red_unused as u8 & 1) | ((green_aka_white as u8 & 1) << 1) | ((blue_unused as u8 & 1) << 2);
|
||||
//log::info!("Payload: {:b}", payload);
|
||||
write2(Setting::LEDStatus as _, payload)
|
||||
}
|
||||
|
||||
const THINGS: &[u8] = &[
|
||||
1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
const TIME_UNIT: std::time::Duration = std::time::Duration::from_millis(200);
|
||||
|
||||
pub fn flash_led() {
|
||||
let old_led_state = write_read(Setting::LEDStatus as _).map_err(|e| log::error!("Failed to read LED status: {}", e));
|
||||
for &code in THINGS {
|
||||
let on = code != 0;
|
||||
if let Err(e) = set_led(on, on, false) {
|
||||
log::error!("Thing err: {}", e);
|
||||
}
|
||||
std::thread::sleep(TIME_UNIT);
|
||||
}
|
||||
if let Ok(old_led_state) = old_led_state {
|
||||
log::debug!("Restoring LED state to {:#02b}", old_led_state);
|
||||
write2(Setting::LEDStatus as _, old_led_state).map_err(|e| log::error!("Failed to restore LED status: {}", e)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(setting: Setting, mode: u8) -> Result<usize, Error> {
|
||||
write2(setting as u8, mode)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue