forked from zmkfirmware/zmk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(display): Add new peripheral status/display
* Add new API/status to track state of the peripheral connection to the central. * Add new peripheral status widget for displaying the current status of the connection to the central.
- Loading branch information
1 parent
0a40f92
commit 16ab6df
Showing
10 changed files
with
172 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lvgl.h> | ||
#include <kernel.h> | ||
|
||
struct zmk_widget_peripheral_status { | ||
sys_snode_t node; | ||
lv_obj_t *obj; | ||
}; | ||
|
||
int zmk_widget_peripheral_status_init(struct zmk_widget_peripheral_status *widget, | ||
lv_obj_t *parent); | ||
lv_obj_t *zmk_widget_peripheral_status_obj(struct zmk_widget_peripheral_status *widget); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zephyr.h> | ||
#include <zmk/event_manager.h> | ||
|
||
struct zmk_split_peripheral_status_changed { | ||
bool connected; | ||
}; | ||
|
||
ZMK_EVENT_DECLARE(zmk_split_peripheral_status_changed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
bool zmk_split_bt_peripheral_is_connected(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <bluetooth/services/bas.h> | ||
|
||
#include <logging/log.h> | ||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#include <zmk/display.h> | ||
#include <zmk/display/widgets/peripheral_status.h> | ||
#include <zmk/event_manager.h> | ||
#include <zmk/split/bluetooth/peripheral.h> | ||
#include <zmk/events/split_peripheral_status_changed.h> | ||
|
||
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); | ||
|
||
struct peripheral_status_state { | ||
bool connected; | ||
}; | ||
|
||
static struct peripheral_status_state get_state(const zmk_event_t *_eh) { | ||
return (struct peripheral_status_state){.connected = zmk_split_bt_peripheral_is_connected()}; | ||
} | ||
|
||
static void set_status_symbol(lv_obj_t *label, struct peripheral_status_state state) { | ||
const char *text = | ||
state.connected ? (LV_SYMBOL_WIFI " " LV_SYMBOL_OK) : (LV_SYMBOL_WIFI " " LV_SYMBOL_CLOSE); | ||
|
||
LOG_DBG("connected? %s", state.connected ? "true" : "false"); | ||
lv_label_set_text(label, text); | ||
} | ||
|
||
static void output_status_update_cb(struct peripheral_status_state state) { | ||
struct zmk_widget_peripheral_status *widget; | ||
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj, state); } | ||
} | ||
|
||
ZMK_DISPLAY_WIDGET_LISTENER(widget_peripheral_status, struct peripheral_status_state, | ||
output_status_update_cb, get_state) | ||
ZMK_SUBSCRIPTION(widget_peripheral_status, zmk_split_peripheral_status_changed); | ||
|
||
int zmk_widget_peripheral_status_init(struct zmk_widget_peripheral_status *widget, | ||
lv_obj_t *parent) { | ||
widget->obj = lv_label_create(parent, NULL); | ||
|
||
lv_obj_set_size(widget->obj, 40, 15); | ||
|
||
sys_slist_append(&widgets, &widget->node); | ||
|
||
widget_peripheral_status_init(); | ||
return 0; | ||
} | ||
|
||
lv_obj_t *zmk_widget_peripheral_status_obj(struct zmk_widget_peripheral_status *widget) { | ||
return widget->obj; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <zmk/events/split_peripheral_status_changed.h> | ||
|
||
ZMK_EVENT_IMPL(zmk_split_peripheral_status_changed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters