Skip to content

Commit

Permalink
feat(studio): Log entry into all RPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Sep 25, 2024
1 parent 21e1b2a commit 5d4b6df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/studio/behavior_subsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static bool encode_behavior_summaries(pb_ostream_t *stream, const pb_field_t *fi
}

zmk_studio_Response list_all_behaviors(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_behaviors_ListAllBehaviorsResponse beh_resp =
zmk_behaviors_ListAllBehaviorsResponse_init_zero;
beh_resp.behaviors.funcs.encode = encode_behavior_summaries;
Expand Down Expand Up @@ -164,9 +165,10 @@ static struct encode_metadata_sets_state state = {};

zmk_studio_Response get_behavior_details(const zmk_studio_Request *req) {
uint32_t behavior_id = req->subsystem.behaviors.request_type.get_behavior_details.behavior_id;

const char *behavior_name = zmk_behavior_find_behavior_name_from_local_id(behavior_id);

LOG_DBG("behavior_id %d, name %s", behavior_id, behavior_name);

if (!behavior_name) {
LOG_WRN("No behavior found for ID %d", behavior_id);
return ZMK_RPC_SIMPLE_ERR(GENERIC);
Expand Down
3 changes: 3 additions & 0 deletions app/src/studio/core_subsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static bool encode_device_info_serial_number(pb_ostream_t *stream, const pb_fiel
#endif // IS_ENABLED(CONFIG_HWINFO)

zmk_studio_Response get_device_info(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_core_GetDeviceInfoResponse resp = zmk_core_GetDeviceInfoResponse_init_zero;

resp.name.funcs.encode = encode_device_info_name;
Expand All @@ -56,12 +57,14 @@ zmk_studio_Response get_device_info(const zmk_studio_Request *req) {
}

zmk_studio_Response get_lock_state(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_core_LockState resp = zmk_studio_core_get_lock_state();

return CORE_RESPONSE(get_lock_state, resp);
}

zmk_studio_Response reset_settings(const zmk_studio_Request *req) {
LOG_DBG("");
ZMK_RPC_SUBSYSTEM_SETTINGS_RESET_FOREACH(sub) {
int ret = sub->callback();
if (ret < 0) {
Expand Down
12 changes: 12 additions & 0 deletions app/src/studio/keymap_subsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static bool encode_keymap_layers(pb_ostream_t *stream, const pb_field_t *field,
}

zmk_studio_Response get_keymap(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_keymap_Keymap resp = zmk_keymap_Keymap_init_zero;

resp.layers.funcs.encode = encode_keymap_layers;
Expand All @@ -117,6 +118,7 @@ zmk_studio_Response get_keymap(const zmk_studio_Request *req) {
}

zmk_studio_Response set_layer_binding(const zmk_studio_Request *req) {
LOG_DBG("");
const zmk_keymap_SetLayerBindingRequest *set_req =
&req->subsystem.keymap.request_type.set_layer_binding;

Expand Down Expand Up @@ -165,13 +167,15 @@ zmk_studio_Response set_layer_binding(const zmk_studio_Request *req) {
}

zmk_studio_Response check_unsaved_changes(const zmk_studio_Request *req) {
LOG_DBG("");
int layout_changes = zmk_physical_layouts_check_unsaved_selection();
int keymap_changes = zmk_keymap_check_unsaved_changes();

return KEYMAP_RESPONSE(check_unsaved_changes, layout_changes > 0 || keymap_changes > 0);
}

zmk_studio_Response save_changes(const zmk_studio_Request *req) {
LOG_DBG("");
int ret = zmk_physical_layouts_save_selected();

if (ret < 0) {
Expand All @@ -192,6 +196,7 @@ zmk_studio_Response save_changes(const zmk_studio_Request *req) {
}

zmk_studio_Response discard_changes(const zmk_studio_Request *req) {
LOG_DBG("");
int ret = zmk_physical_layouts_revert_selected();
if (ret < 0) {
return ZMK_RPC_SIMPLE_ERR(GENERIC);
Expand Down Expand Up @@ -288,6 +293,7 @@ static bool encode_layouts(pb_ostream_t *stream, const pb_field_t *field, void *
}

zmk_studio_Response get_physical_layouts(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_keymap_PhysicalLayouts resp = zmk_keymap_PhysicalLayouts_init_zero;
resp.active_layout_index = zmk_physical_layouts_get_selected();
resp.layouts.funcs.encode = encode_layouts;
Expand Down Expand Up @@ -336,6 +342,7 @@ static void migrate_keymap(const uint8_t old) {
}

zmk_studio_Response set_active_physical_layout(const zmk_studio_Request *req) {
LOG_DBG("");
uint8_t index = (uint8_t)req->subsystem.keymap.request_type.set_active_physical_layout;
int old = zmk_physical_layouts_get_selected();

Expand Down Expand Up @@ -364,6 +371,7 @@ zmk_studio_Response set_active_physical_layout(const zmk_studio_Request *req) {
}

zmk_studio_Response move_layer(const zmk_studio_Request *req) {
LOG_DBG("");
const zmk_keymap_MoveLayerRequest *move_req = &req->subsystem.keymap.request_type.move_layer;

zmk_keymap_MoveLayerResponse resp = zmk_keymap_MoveLayerResponse_init_zero;
Expand All @@ -386,6 +394,7 @@ zmk_studio_Response move_layer(const zmk_studio_Request *req) {
}

zmk_studio_Response add_layer(const zmk_studio_Request *req) {
LOG_DBG("");
// Use a static here to keep the value valid during serialization
static zmk_keymap_layer_id_t layer_id = 0;

Expand Down Expand Up @@ -428,6 +437,7 @@ zmk_studio_Response add_layer(const zmk_studio_Request *req) {
}

zmk_studio_Response remove_layer(const zmk_studio_Request *req) {
LOG_DBG("");
const zmk_keymap_RemoveLayerRequest *rm_req = &req->subsystem.keymap.request_type.remove_layer;

zmk_keymap_RemoveLayerResponse resp = zmk_keymap_RemoveLayerResponse_init_zero;
Expand Down Expand Up @@ -456,6 +466,7 @@ zmk_studio_Response remove_layer(const zmk_studio_Request *req) {
}

zmk_studio_Response restore_layer(const zmk_studio_Request *req) {
LOG_DBG("");
const zmk_keymap_RestoreLayerRequest *restore_req =
&req->subsystem.keymap.request_type.restore_layer;

Expand Down Expand Up @@ -492,6 +503,7 @@ zmk_studio_Response restore_layer(const zmk_studio_Request *req) {
}

zmk_studio_Response set_layer_props(const zmk_studio_Request *req) {
LOG_DBG("");
const zmk_keymap_SetLayerPropsRequest *set_req =
&req->subsystem.keymap.request_type.set_layer_props;

Expand Down

0 comments on commit 5d4b6df

Please sign in to comment.