Skip to content

Commit

Permalink
fix(tests): Tweak source handling for non-BLE environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Dec 29, 2020
1 parent 0387410 commit 6970b68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/include/zmk/behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#pragma once



struct zmk_behavior_binding {
char *behavior_dev;
uint32_t param1;
Expand Down
10 changes: 7 additions & 3 deletions app/include/zmk/events/position_state_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
#include <zmk/event_manager.h>
#include <bluetooth/addr.h>

struct position_state_changed {
struct zmk_event_header header;
#if IS_ENABLED(CONFIG_ZMK_BLE)
const bt_addr_le_t *source;
typedef const bt_addr_le_t *zmk_position_state_changed_source_t;
#else
typedef void *zmk_position_state_changed_source_t;
#endif

struct position_state_changed {
struct zmk_event_header header;
zmk_position_state_changed_source_t source;
uint32_t position;
bool state;
int64_t timestamp;
Expand Down
4 changes: 2 additions & 2 deletions app/include/zmk/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include <bluetooth/addr.h>
#include <zmk/events/position_state_changed.h>

typedef uint32_t zmk_keymap_layers_state_t;

Expand All @@ -18,5 +18,5 @@ int zmk_keymap_layer_activate(uint8_t layer);
int zmk_keymap_layer_deactivate(uint8_t layer);
int zmk_keymap_layer_toggle(uint8_t layer);

int zmk_keymap_position_state_changed(const bt_addr_le_t *source, uint32_t position, bool pressed,
int zmk_keymap_position_state_changed(zmk_position_state_changed_source_t source, uint32_t position, bool pressed,
int64_t timestamp);
14 changes: 7 additions & 7 deletions app/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ int invoke_locally(struct zmk_behavior_binding *binding, struct zmk_behavior_bin
}
}

int zmk_keymap_apply_position_state(const bt_addr_le_t *source, int layer, uint32_t position,
bool pressed, int64_t timestamp) {
int zmk_keymap_apply_position_state(zmk_position_state_changed_source_t source, int layer,
uint32_t position, bool pressed, int64_t timestamp) {
struct zmk_behavior_binding *binding = &zmk_keymap[layer][position];
const struct device *behavior;
struct zmk_behavior_binding_event event = {
Expand All @@ -156,10 +156,10 @@ int zmk_keymap_apply_position_state(const bt_addr_le_t *source, int layer, uint3
return err;
}

char source_str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(source, source_str, sizeof(source_str));
// char source_str[BT_ADDR_LE_STR_LEN];
// bt_addr_le_to_str(source, source_str, sizeof(source_str));

LOG_DBG("Behavior locality: %d, event source: %s", locality, log_strdup(source_str));
// LOG_DBG("Behavior locality: %d, event source: %s", locality, log_strdup(source_str));

switch (locality) {
case BEHAVIOR_LOCALITY_CENTRAL:
Expand All @@ -184,8 +184,8 @@ int zmk_keymap_apply_position_state(const bt_addr_le_t *source, int layer, uint3
return -ENOTSUP;
}

int zmk_keymap_position_state_changed(const bt_addr_le_t *source, uint32_t position, bool pressed,
int64_t timestamp) {
int zmk_keymap_position_state_changed(zmk_position_state_changed_source_t source, uint32_t position,
bool pressed, int64_t timestamp) {
if (pressed) {
zmk_keymap_active_behavior_layer[position] = _zmk_keymap_layer_state;
}
Expand Down

0 comments on commit 6970b68

Please sign in to comment.