Skip to content

Commit

Permalink
Send RGB state over to the peripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Jan 22, 2025
1 parent 0c1fe74 commit 548af64
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/include/zmk/rgb_underglow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct zmk_led_hsb {
struct zmk_periph_led {
uint8_t layer;
zmk_hid_indicators_t indicators;
uint8_t effect;
bool on;
};

Expand Down
1 change: 1 addition & 0 deletions app/include/zmk/split/bluetooth/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct zmk_split_input_event_payload {
struct zmk_split_update_led_data {
uint8_t layer;
uint8_t indicators;
uint8_t effect;
bool on;
} __packed;
#endif
Expand Down
30 changes: 29 additions & 1 deletion app/src/behaviors/behavior_rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,36 @@ static const struct behavior_parameter_metadata_set hsv_value_metadata_set = {
*/

static const struct behavior_parameter_value_metadata effect_p1_value_metadata_values[] = {
{
.display_name = "Set effect",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
.value = RGB_EFS_CMD,
},
{
.display_name = "Set Momentary Effect",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
.value = RGB_MEFS_CMD,
},
};

static const struct behavior_parameter_value_metadata effect_p2_value_metadata_values[] = {
{
.display_name = "Effect",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_RANGE,
.range = {.min = 0, .max = 6},
},
};

static const struct behavior_parameter_metadata_set effect_value_metadata_set = {
.param1_values = effect_p1_value_metadata_values,
.param1_values_len = ARRAY_SIZE(effect_p1_value_metadata_values),
.param2_values = effect_p2_value_metadata_values,
.param2_values_len = ARRAY_SIZE(effect_p2_value_metadata_values),
};

static const struct behavior_parameter_metadata_set sets[] = {
no_args_set,
no_args_set, effect_value_metadata_set,
// hsv_value_metadata_set,
};

Expand Down
8 changes: 8 additions & 0 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ int zmk_rgb_underglow_set_periph(struct zmk_periph_led periph) {
else if (state.on && !led_data.on)
zmk_rgb_underglow_off();

state.current_effect = led_data.effect;
LOG_DBG("Update led_data %d %d %d", led_data.layer, led_data.indicators, led_data.on);
return 0;
}
Expand Down Expand Up @@ -482,6 +483,7 @@ static int zmk_rgb_underglow_init(void) {
};
led_data.indicators = 0;
led_data.on = IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_ON_START);
led_data.effect = state.current_effect;

#if ZMK_BLE_IS_CENTRAL
k_work_init_delayable(&led_update_work, zmk_rgb_underglow_central_send);
Expand Down Expand Up @@ -579,6 +581,12 @@ int zmk_rgb_underglow_select_effect(int effect) {
state.current_effect = effect;
state.animation_step = 0;

#if ZMK_BLE_IS_CENTRAL
led_data.effect = effect;

zmk_rgb_underglow_central_send();
#endif

return 0;
}

Expand Down
6 changes: 4 additions & 2 deletions app/src/split/bluetooth/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,10 @@ static int split_bt_update_led_payload(struct zmk_split_update_led_data payload)
};

int zmk_split_bt_update_led(struct zmk_periph_led *periph) {
struct zmk_split_update_led_data payload = {
.layer = periph->layer, .indicators = periph->indicators, .on = periph->on};
struct zmk_split_update_led_data payload = {.layer = periph->layer,
.indicators = periph->indicators,
.effect = periph->effect,
.on = periph->on};

return split_bt_update_led_payload(payload);
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ static ssize_t split_svc_update_led(struct bt_conn *conn, const struct bt_gatt_a
// 1: We've gotten all the position/state/param data.
// 2: We have a null terminated string for the behavior device label.
if ((end_addr == sizeof(struct zmk_split_update_led_data))) {
struct zmk_periph_led periph = {
.layer = payload->layer, .indicators = payload->indicators, .on = payload->on};
struct zmk_periph_led periph = {.layer = payload->layer,
.indicators = payload->indicators,
.effect = payload->effect,
.on = payload->on};
zmk_rgb_underglow_set_periph(periph);
LOG_DBG("Update leds with params %d and %d", periph.layer, periph.indicators);
}
Expand Down

0 comments on commit 548af64

Please sign in to comment.