Skip to content

Commit f34ef75

Browse files
DerDreschnerpetejohanson
authored andcommitted
Fix broken CI builds on Zephyr 3.2 (#6)
* fix(backlight/tests): Restore original behaviour to fix backlight tests * fix(build): Remove feature-specific code when SPLIT_BLE, RGB_UNDERGLOW or BACKLIGHT isn't enabled * refactor(bluetooth): Add battery reporting config. * Add dedicated battery reporting Kconfig that is `imply`d by enabling ZMK_BLE. * fix(rgb_underglow): Use correct condition in service.c * Revert "refactor(bluetooth): Add battery reporting config." This reverts commit 881da25. --------- Co-authored-by: Peter Johanson <peter@peterjohanson.com>
1 parent cd6a3f1 commit f34ef75

File tree

11 files changed

+550
-1
lines changed

11 files changed

+550
-1
lines changed

app/include/zmk/split/bluetooth/central.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ int zmk_split_bt_update_hid_indicator(zmk_hid_indicators_t indicators);
2323

2424
int zmk_split_get_peripheral_battery_level(uint8_t source, uint8_t *level);
2525

26-
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)
26+
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)
27+
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
28+
int zmk_split_bt_update_led(struct zmk_periph_led *periph);
29+
#endif
30+
31+
#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
32+
int zmk_split_bt_update_bl(struct backlight_state *periph);
33+
#endif

app/include/zmk/split/bluetooth/service.h

+14
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ struct zmk_split_input_event_payload {
3838
uint8_t sync;
3939
} __packed;
4040

41+
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
42+
struct zmk_split_update_led_data {
43+
uint8_t layer;
44+
uint8_t indicators;
45+
} __packed;
46+
#endif
47+
48+
#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
49+
struct zmk_split_update_bl_data {
50+
uint8_t brightness;
51+
bool on;
52+
} __packed;
53+
#endif
54+
4155
int zmk_split_bt_position_pressed(uint8_t position);
4256
int zmk_split_bt_position_released(uint8_t position);
4357
int zmk_split_bt_sensor_triggered(uint8_t sensor_index,

app/src/rgb_underglow.c

+317
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ static struct led_rgb pixels[STRIP_NUM_PIXELS];
8181

8282
static struct rgb_underglow_state state;
8383

84+
static struct zmk_periph_led led_data;
85+
86+
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE)
87+
static bool last_ble_state[2];
88+
#endif
89+
90+
static bool triggered;
91+
92+
#if ZMK_BLE_IS_CENTRAL
93+
static struct zmk_periph_led old_led_data;
94+
#endif
95+
8496
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER)
8597
static const struct device *const ext_power = DEVICE_DT_GET(DT_INST(0, zmk_ext_power_generic));
8698
#endif
@@ -196,6 +208,311 @@ static void zmk_rgb_underglow_effect_swirl(void) {
196208
state.animation_step = state.animation_step % HUE_MAX;
197209
}
198210

211+
#if ZMK_BLE_IS_CENTRAL
212+
static struct k_work_delayable led_update_work;
213+
214+
static void zmk_rgb_underglow_central_send() {
215+
int err = zmk_split_bt_update_led(&led_data);
216+
if (err) {
217+
LOG_ERR("send failed (err %d)", err);
218+
}
219+
}
220+
#endif
221+
222+
static void zmk_rgb_underglow_effect_kinesis() {
223+
#if ZMK_BLE_IS_CENTRAL
224+
// leds for central(left) side
225+
226+
old_led_data.layer = led_data.layer;
227+
old_led_data.indicators = led_data.indicators;
228+
led_data.indicators = zmk_hid_indicators_get_current_profile();
229+
led_data.layer = zmk_keymap_highest_layer_active();
230+
231+
pixels[0].r = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
232+
pixels[0].g = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
233+
pixels[0].b = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
234+
// set second led as bluetooth state
235+
switch (zmk_ble_active_profile_index()) {
236+
case 0:
237+
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
238+
pixels[1].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
239+
pixels[1].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
240+
break;
241+
case 1:
242+
pixels[1].r = 0;
243+
pixels[1].g = 0;
244+
pixels[1].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
245+
break;
246+
case 2:
247+
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
248+
pixels[1].g = 0;
249+
pixels[1].b = 0;
250+
break;
251+
case 3:
252+
pixels[1].r = 0;
253+
pixels[1].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
254+
pixels[1].b = 0;
255+
break;
256+
case 4:
257+
pixels[1].r = 0;
258+
pixels[1].g = 0;
259+
pixels[1].b = 0;
260+
break;
261+
}
262+
// blink second led slowly if bluetooth not paired, quickly if not connected
263+
if (zmk_ble_active_profile_is_open()) {
264+
pixels[1].r = pixels[1].r * last_ble_state[0];
265+
pixels[1].g = pixels[1].g * last_ble_state[0];
266+
pixels[1].b = pixels[1].b * last_ble_state[0];
267+
if (state.animation_step > 3) {
268+
last_ble_state[0] = !last_ble_state[0];
269+
state.animation_step = 0;
270+
}
271+
state.animation_step++;
272+
} else if (!zmk_ble_active_profile_is_connected()) {
273+
pixels[1].r = pixels[1].r * last_ble_state[1];
274+
pixels[1].g = pixels[1].g * last_ble_state[1];
275+
pixels[1].b = pixels[1].b * last_ble_state[1];
276+
if (state.animation_step > 14) {
277+
last_ble_state[1] = !last_ble_state[1];
278+
state.animation_step = 0;
279+
}
280+
state.animation_step++;
281+
}
282+
// set third led as layer state
283+
switch (led_data.layer) {
284+
case 0:
285+
pixels[2].r = 0;
286+
pixels[2].g = 0;
287+
pixels[2].b = 0;
288+
break;
289+
case 1:
290+
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
291+
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
292+
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
293+
break;
294+
case 2:
295+
pixels[2].r = 0;
296+
pixels[2].g = 0;
297+
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
298+
break;
299+
case 3:
300+
pixels[2].r = 0;
301+
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
302+
pixels[2].b = 0;
303+
break;
304+
case 4:
305+
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
306+
pixels[2].g = 0;
307+
pixels[2].b = 0;
308+
break;
309+
case 5:
310+
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
311+
pixels[2].g = 0;
312+
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
313+
break;
314+
case 6:
315+
pixels[2].r = 0;
316+
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
317+
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
318+
break;
319+
case 7:
320+
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
321+
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
322+
pixels[2].b = 0;
323+
break;
324+
default:
325+
pixels[2].r = 0;
326+
pixels[2].g = 0;
327+
pixels[2].b = 0;
328+
break;
329+
}
330+
if (old_led_data.layer != led_data.layer || old_led_data.indicators != led_data.indicators) {
331+
zmk_rgb_underglow_central_send();
332+
}
333+
#else
334+
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE)
335+
// leds for peripheral(right) side
336+
/* if (zmk_ble_active_profile_is_open()) {
337+
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
338+
pixels[0].g = 0;
339+
pixels[0].b = 0;
340+
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
341+
pixels[1].g = 0;
342+
pixels[1].b = 0;
343+
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
344+
pixels[2].g = 0;
345+
pixels[2].b = 0;
346+
if (state.animation_step > 3) {
347+
last_ble_state[0] = !last_ble_state[0];
348+
state.animation_step = 0;
349+
}
350+
state.animation_step++;
351+
} else */
352+
if (!zmk_split_bt_peripheral_is_connected()) {
353+
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[1];
354+
pixels[0].g = 0;
355+
pixels[0].b = 0;
356+
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[1];
357+
pixels[1].g = 0;
358+
pixels[1].b = 0;
359+
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[1];
360+
pixels[2].g = 0;
361+
pixels[2].b = 0;
362+
if (state.animation_step > 14) {
363+
last_ble_state[1] = !last_ble_state[1];
364+
state.animation_step = 0;
365+
}
366+
state.animation_step++;
367+
} else {
368+
#endif
369+
// set first led as LED_NUMLOCK
370+
pixels[2].r =
371+
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
372+
pixels[2].g =
373+
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
374+
pixels[2].b =
375+
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
376+
// set second led as scroll Lock
377+
pixels[1].r =
378+
(led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
379+
pixels[1].g =
380+
(led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
381+
pixels[1].b =
382+
(led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
383+
// set third led as layer
384+
switch (led_data.layer) {
385+
case 0:
386+
pixels[0].r = 0;
387+
pixels[0].g = 0;
388+
pixels[0].b = 0;
389+
break;
390+
case 1:
391+
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
392+
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
393+
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
394+
break;
395+
case 2:
396+
pixels[0].r = 0;
397+
pixels[0].g = 0;
398+
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
399+
break;
400+
case 3:
401+
pixels[0].r = 0;
402+
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
403+
pixels[0].b = 0;
404+
break;
405+
case 4:
406+
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
407+
pixels[0].g = 0;
408+
pixels[0].b = 0;
409+
break;
410+
case 5:
411+
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
412+
pixels[0].g = 0;
413+
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
414+
break;
415+
case 6:
416+
pixels[0].r = 0;
417+
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
418+
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
419+
break;
420+
case 7:
421+
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
422+
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
423+
pixels[0].b = 0;
424+
break;
425+
default:
426+
pixels[0].r = 0;
427+
pixels[0].g = 0;
428+
pixels[0].b = 0;
429+
break;
430+
}
431+
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE)
432+
}
433+
#endif
434+
#endif
435+
}
436+
437+
static void zmk_rgb_underglow_effect_test() {
438+
triggered = true;
439+
struct led_rgb rgb;
440+
rgb.r = 0;
441+
rgb.g = 0;
442+
rgb.b = 0;
443+
444+
for (int i = 0; i < STRIP_NUM_PIXELS; i++) {
445+
struct zmk_led_hsb hsb = state.color;
446+
hsb.h = state.animation_step;
447+
448+
pixels[i] = hsb_to_rgb(hsb_scale_min_max(hsb));
449+
}
450+
if (state.animation_step < (HUE_MAX * 3)) {
451+
struct zmk_led_hsb hsb = state.color;
452+
hsb.h = state.animation_step;
453+
rgb.r = 0;
454+
455+
pixels[0] = rgb;
456+
pixels[1] = rgb;
457+
pixels[2] = hsb_to_rgb(hsb_scale_min_max(hsb));
458+
}
459+
if (state.animation_step < (HUE_MAX * 2)) {
460+
struct zmk_led_hsb hsb = state.color;
461+
hsb.h = state.animation_step - HUE_MAX;
462+
rgb.r = 0;
463+
rgb.g = 0;
464+
rgb.b = 0;
465+
pixels[0] = rgb;
466+
pixels[1] = hsb_to_rgb(hsb_scale_min_max(hsb));
467+
pixels[2] = rgb;
468+
}
469+
if (state.animation_step < HUE_MAX) {
470+
struct zmk_led_hsb hsb = state.color;
471+
hsb.h = state.animation_step;
472+
rgb.r = 0;
473+
rgb.g = 0;
474+
rgb.b = 0;
475+
pixels[0] = hsb_to_rgb(hsb_scale_min_max(hsb));
476+
pixels[1] = rgb;
477+
pixels[2] = rgb;
478+
}
479+
480+
state.animation_step += 20;
481+
if (state.animation_step > (HUE_MAX * 3)) {
482+
483+
rgb.r = 255;
484+
rgb.g = 255;
485+
rgb.b = 255;
486+
for (int i = 0; i < STRIP_NUM_PIXELS; i++)
487+
pixels[i] = rgb;
488+
}
489+
}
490+
491+
static void zmk_rgb_underglow_effect_battery() {
492+
uint8_t soc = zmk_battery_state_of_charge();
493+
struct led_rgb rgb;
494+
if (soc > 80) {
495+
rgb.r = 0;
496+
rgb.g = 255;
497+
rgb.b = 0;
498+
} else if (soc > 50 && soc < 80) {
499+
rgb.r = 255;
500+
rgb.g = 255;
501+
rgb.b = 0;
502+
} else if (soc > 20 && soc < 51) {
503+
rgb.r = 255;
504+
rgb.g = 140;
505+
rgb.b = 0;
506+
} else {
507+
rgb.r = 255;
508+
rgb.g = 0;
509+
rgb.b = 0;
510+
}
511+
for (int i = 0; i < STRIP_NUM_PIXELS; i++) {
512+
pixels[i] = rgb;
513+
}
514+
}
515+
199516
static void zmk_rgb_underglow_tick(struct k_work *work) {
200517
switch (state.current_effect) {
201518
case UNDERGLOW_EFFECT_SOLID:

0 commit comments

Comments
 (0)