Skip to content

Commit

Permalink
led: flash the 5 key if USB is toggled off
Browse files Browse the repository at this point in the history
  • Loading branch information
hdhoang committed Mar 5, 2019
1 parent 3997d54 commit a74d2f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@ where
)
}

pub fn update_led(&self, led: &mut Led<BUFFER>) -> nb::Result<(), !> {
led.bluetooth_mode(self.saved_hosts, self.connected_host, self.mode)
pub fn update_led(
&self,
led: &mut Led<BUFFER>,
keyboard_send_usb_report: bool,
) -> nb::Result<(), !> {
led.bluetooth_mode(
self.saved_hosts,
self.connected_host,
self.mode,
keyboard_send_usb_report,
)
}

pub fn handle_message(
Expand Down Expand Up @@ -202,7 +211,7 @@ where
}

if keyboard.bluetooth_mode_enabled() {
self.update_led(led).log_error();
self.update_led(led, keyboard.send_usb_report).log_error();
}
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Keyboard {
let bt_layer_current: bool = self.bluetooth_mode_enabled();
let bt_layer_next: bool = self.layers.next.get_bit(LAYER_BT as usize);
if bt_layer_next && !bt_layer_current {
bluetooth.update_led(led).log_error();
bluetooth.update_led(led, self.send_usb_report).log_error();
} else if bt_layer_current && !bt_layer_next {
led.theme_mode().log_error();
}
Expand Down
9 changes: 8 additions & 1 deletion src/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ where
saved_hosts: u8,
connected_host: u8,
mode: BluetoothMode,
keyboard_send_usb_report: bool,
) -> nb::Result<(), !> {
let mode_color = match mode {
BluetoothMode::Unknown => (0xff, 0, 0),
BluetoothMode::Ble => (0, 0xff, 0),
BluetoothMode::Legacy => (0xff, 0xff, 0),
};

let usb_mode = if keyboard_send_usb_report {
LedMode::On
} else {
LedMode::Flash
};
let s1 = if (saved_hosts & 1) != 0 { 0xFF } else { 0x00 };
let s2 = if (saved_hosts & 2) != 0 { 0xFF } else { 0x00 };
let s3 = if (saved_hosts & 4) != 0 { 0xFF } else { 0x00 };
Expand All @@ -155,7 +161,7 @@ where

#[rustfmt::skip]
let payload = &[0xca,
19, // the number of keys in this request
20, // the number of keys in this request
KeyIndex::Escape as u8, 0xff, 0xff, 0x00, LedMode::On as u8,
// Select host
KeyIndex::N1 as u8, cu, 0xff, c1, LedMode::On as u8,
Expand All @@ -179,6 +185,7 @@ where
KeyIndex::B as u8, 0x00, 0xff, 0x00, LedMode::Flash as u8,
KeyIndex::Minus as u8, 0xff, 0x00, 0x00, LedMode::On as u8,
KeyIndex::N0 as u8, mode_color.0, mode_color.1, mode_color.2, LedMode::On as u8,
KeyIndex::N5 as u8, 0xff, 0xff, 0xff, usb_mode as u8,
];

self.set_keys(payload)
Expand Down

0 comments on commit a74d2f7

Please sign in to comment.