Skip to content

Commit

Permalink
Merge pull request #16 from MvEerd/LedToggle
Browse files Browse the repository at this point in the history
Add LedToggle function for FN+R
  • Loading branch information
ah- authored Mar 6, 2018
2 parents 5dd7438 + cb6f18f commit 9820d8b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Action {

LedOn, // = 0x30,
LedOff,
LedToggle,
LedNextTheme,
LedNextBrightness,
LedNextAnimationSpeed,
Expand Down
1 change: 1 addition & 0 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl<'a> EventProcessor for Led<'a> {
let result = match action {
&Action::LedOn => self.on(),
&Action::LedOff => self.off(),
&Action::LedToggle => self.toggle(),
&Action::LedNextTheme => self.next_theme(),
&Action::LedNextBrightness => self.next_brightness(),
&Action::LedNextAnimationSpeed => self.next_animation_speed(),
Expand Down
10 changes: 5 additions & 5 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub const BASE: Layout = layout![
];

pub const FN: Layout = layout![
Grave F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 __
__ __ Up __ LedOn LedNAS LedNB LedNT Up Scrolllock Pause Home End PScreen
__ Left Down Right __ __ __ Left Down Right PgUp PgDown No __
__ __ __ __ __ __ __ __ __ Insert Delete No No __
__ __ __ No No __ No No No No __ __ __ __
Grave F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 __
__ __ Up __ LedToggle LedNAS LedNB LedNT Up Scrolllock Pause Home End PScreen
__ Left Down Right __ __ __ Left Down Right PgUp PgDown No __
__ __ __ __ __ __ __ __ __ Insert Delete No No __
__ __ __ No No __ No No No No __ __ __ __
];

pub const LED: Layout = layout![
Expand Down
12 changes: 12 additions & 0 deletions src/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Led<'a> {
pub serial: Serial<'a, LedUsart>,
pub rx_transfer: Option<Transfer>,
pub pc15: PC15<Output>,
pub state: bool
}

impl<'a> Led<'a> {
Expand All @@ -24,6 +25,7 @@ impl<'a> Led<'a> {
serial: serial,
rx_transfer: Some(rx_transfer),
pc15: pc15.into_output().pull_up(),
state: true
}
}

Expand All @@ -37,6 +39,16 @@ impl<'a> Led<'a> {
Ok(())
}

pub fn toggle(&mut self) -> nb::Result<(), !> {
if(!self.state){
self.pc15.set_high();
} else {
self.pc15.set_low();
}
self.state = !self.state;
Ok(())
}

// next_* cycles through themes/brightness/speed
pub fn next_theme(&mut self) -> nb::Result<(), !> {
self.serial.send(MsgType::Led, LedOp::ConfigCmd as u8, &[1, 0, 0])
Expand Down

0 comments on commit 9820d8b

Please sign in to comment.