Skip to content

Commit

Permalink
Swap LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Mar 7, 2024
1 parent ff18f7f commit 1d3629c
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions app/src/stp_indicators.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct zmk_stp_ble {
bool connected;
};

static struct zmk_led_hsb color0;
static struct zmk_led_hsb color1;
static struct zmk_led_hsb color0; // BLE Led
static struct zmk_led_hsb color1; // Caps

static struct zmk_stp_ble ble_status;
static bool caps;
Expand Down Expand Up @@ -152,12 +152,12 @@ static void zmk_stp_indicators_batt(struct k_work *work) {
static void zmk_stp_indicators_blink_work(struct k_work *work) {
LOG_DBG("Blink work triggered");
// If LED on turn off and vice cersa
if (color1.b)
color1.b = 0;
if (color0.b)
color0.b = 0;
else
color1.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
color0.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
// Convert HSB to RGB and update LEDs
pixels[1] = hsb_to_rgb(color1);
pixels[0] = hsb_to_rgb(color0);
int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);
if (err < 0) {
LOG_ERR("Failed to update the RGB strip (%d)", err);
Expand All @@ -180,10 +180,10 @@ static void zmk_stp_indicators_bluetooth(struct k_work *work) {
LOG_DBG("BLE PROFILE: %d", ble_status.prof);

if (ble_status.prof) {
color1.h = 240;
color1.s = 100;
color0.h = 240;
color0.s = 100;
} else
color1.s = 0;
color0.s = 0;
// If in USB HID mode
if (usb) {
LOG_DBG("USB MODE");
Expand All @@ -192,56 +192,56 @@ static void zmk_stp_indicators_bluetooth(struct k_work *work) {
k_timer_stop(&fast_blink_timer);
k_timer_stop(&connected_timeout_timer);
// Set LED to green
color1.h = 120;
color1.s = 100;
color1.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
color0.h = 120;
color0.s = 100;
color0.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
} else if (ble_status.open) {
LOG_DBG("BLE PROF OPEN");
// If profile is open (unpaired) start fast blink timer and ensure LED turns on
color1.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
color0.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
k_timer_stop(&slow_blink_timer);
k_timer_stop(&connected_timeout_timer);
k_timer_start(&fast_blink_timer, K_NO_WAIT, K_MSEC(200));
} else if (!ble_status.connected) {
LOG_DBG("BLE PROF NOT CONN");
// If profile paired but not connected start slow blink timer and ensure LED on
color1.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
color0.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
k_timer_stop(&fast_blink_timer);
k_timer_stop(&connected_timeout_timer);
k_timer_start(&slow_blink_timer, K_NO_WAIT, K_MSEC(750));
} else {
LOG_DBG("BLE PROF CONN");
// If connected start the 3 second timeout to turn LED off
color1.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
color0.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
k_timer_stop(&slow_blink_timer);
k_timer_stop(&fast_blink_timer);
k_timer_start(&connected_timeout_timer, K_SECONDS(3), K_NO_WAIT);
}
// Convert HSB to RGB and update the LEDs

pixels[1] = hsb_to_rgb(color1);
pixels[0] = hsb_to_rgb(color0);
int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);
if (err < 0) {
LOG_ERR("Failed to update the RGB strip (%d)", err);
}
}

static void zmk_stp_indicators_caps(struct k_work *work) {
if (ble_status.prof) {
color0.h = 240;
color0.s = 100;
} else if (usb) {
color0.h = 120;
color0.s = 100;
if (usb) {
color1.h = 120;
color1.s = 100;
} else if (ble_status.prof) {
color1.h = 240;
color1.s = 100;
} else
color0.s = 0;
color1.s = 0;
// Set LED on if capslock pressed
if (caps)
color0.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
color1.b = CONFIG_ZMK_STP_INDICATORS_BRT_MAX;
else
color0.b = 0;
color1.b = 0;
// Convert HSB to RGB and update the LEDs
pixels[0] = hsb_to_rgb(color0);
pixels[1] = hsb_to_rgb(color1);
int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);
if (err < 0) {
LOG_ERR("Failed to update the RGB strip (%d)", err);
Expand Down Expand Up @@ -291,13 +291,13 @@ static int zmk_stp_indicators_init(void) {

color0 = (struct zmk_led_hsb){
h : 240,
s : 0,
s : 100,
b : CONFIG_ZMK_STP_INDICATORS_BRT_MAX,
};

color1 = (struct zmk_led_hsb){
h : 240,
s : 100,
s : 0,
b : CONFIG_ZMK_STP_INDICATORS_BRT_MAX,
};

Expand Down Expand Up @@ -428,7 +428,7 @@ static int stp_indicators_event_listener(const zmk_event_t *eh) {
LOG_DBG("INDICATOR CHANGED: %d", caps);
if (!battery) {
k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &caps_ind_work);
k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &bluetooth_ind_work);
// k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &bluetooth_ind_work);
}
return 0;
}
Expand Down

0 comments on commit 1d3629c

Please sign in to comment.