working displays

This commit is contained in:
Darryldh 2022-08-28 07:43:16 -04:00
parent 0007450a2e
commit 8b1b4dd380
15 changed files with 411 additions and 165 deletions

View file

@ -1,7 +1,8 @@
{
"files.associations": {
"*.overlay": "dts",
"*.keymap": "dts"
"*.keymap": "dts",
"peripheral_status.h": "c"
},
"python.formatting.provider": "black"
}

View file

@ -11,6 +11,7 @@ if(CONFIG_ZMK_DISPLAY)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_BATTERY_STATUS app PRIVATE widgets/battery_status.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS app PRIVATE widgets/output_status.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_LAYER_STATUS app PRIVATE widgets/layer_status.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_PERIPHERAL_STATUS app PRIVATE widgets/peripheral_status.c)
# target_sources_ifdef(CONFIG_ZMK_WIDGET_WPM_STATUS app PRIVATE wpm_status.c)
add_subdirectory_ifdef(CONFIG_ZMK_DISPLAY_STATUS_SCREEN_CUSTOM widgets/icons)
@ -53,7 +54,7 @@ endif()
zephyr_library_include_directories(${ZEPHYR_LVGL_MODULE_DIR})
zephyr_library_include_directories(${ZEPHYR_BASE}/lib/gui/lvgl/)
#zephyr_library_sources_ifdef(CONFIG_ZMK_DISPLAY custom_status_screen.c)
zephyr_library_sources_ifdef(CONFIG_ZMK_DISPLAY custom_status_screen.c)
zephyr_library_sources(${ZEPHYR_BASE}/misc/empty_file.c)
zephyr_library_include_directories(${CMAKE_SOURCE_DIR}/include)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)

View file

@ -8,6 +8,9 @@ if BOARD_CORNEISH_ZEN_V2_LEFT
config ZMK_KEYBOARD_NAME
default "Corne-ish Zen"
config ZMK_SPLIT_ROLE_CENTRAL
default y
endif # BOARD_CORNEISH_ZEN_V2_LEFT
if BOARD_CORNEISH_ZEN_V2_RIGHT
@ -77,9 +80,9 @@ config ZMK_DISPLAY
select LVGL_USE_LABEL
select LVGL_USE_IMG
#choice ZMK_DISPLAY_STATUS_SCREEN
# default ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
#endchoice
choice ZMK_DISPLAY_STATUS_SCREEN
default ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
endchoice
if ZMK_DISPLAY
@ -101,14 +104,17 @@ config LVGL_DISPLAY_DEV_NAME
endif # ZMK_DISPLAY
#menuconfig CUSTOM_WIDGET_BATTERY_STATUS
# bool "custom battery status widget"
menuconfig CUSTOM_WIDGET_BATTERY_STATUS
bool "custom battery status widget"
#menuconfig CUSTOM_WIDGET_OUTPUT_STATUS
# bool "custom output status widget"
menuconfig CUSTOM_WIDGET_OUTPUT_STATUS
bool "custom output status widget"
#menuconfig CUSTOM_WIDGET_LAYER_STATUS
# bool "custom layer status widget"
menuconfig CUSTOM_WIDGET_LAYER_STATUS
bool "custom layer status widget"
menuconfig CUSTOM_WIDGET_PERIPHERAL_STATUS
bool "custom peripheral status widget"
# config CORNE_ISH_ZEN_20
# bool

View file

@ -45,9 +45,9 @@
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;
output-ohms = <2000000>;
full-ohms = <(2000000 + 806000)>;
io-channels = <&adc 0>;
output-ohms = <1960000>;
full-ohms = <(1960000 + 810000)>;
};
};

View file

@ -9,7 +9,8 @@ CONFIG_BOARD_CORNEISH_ZEN_V2_LEFT=y
CONFIG_ZMK_SPLIT=y
#CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL=y
CONFIG_ZMK_SLEEP=y
CONFIG_BUILD_OUTPUT_UF2=y
#CONFIG_BUILD_OUTPUT_UF2=y
CONFIG_ZMK_DISPLAY=y
# Enable MPU
CONFIG_ARM_MPU=y
@ -42,12 +43,12 @@ CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM=y
# Enable TI BQ27421 Fuel Gauge
CONFIG_SENSOR=y
#CONFIG_SENSOR=y
#CONFIG_BQ274XX=y
#CONFIG_SENSOR_CAN_FETCH_ALL=n
# enable display drivers
CONFIG_ZMK_DISPLAY=y
#CONFIG_ZMK_DISPLAY=y
CONFIG_ZMK_DISPLAY_WORK_QUEUE_DEDICATED=y
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_STACK_SIZE=2048
CONFIG_SSD1306=n
@ -68,14 +69,14 @@ CONFIG_LVGL_THEME_DEFAULT_FONT_SMALL_MONTSERRAT_16=y
CONFIG_LVGL_THEME_DEFAULT_FONT_NORMAL_MONTSERRAT_26=y
# custom status screens
#CONFIG_ZMK_DISPLAY_STATUS_SCREEN_CUSTOM=y
CONFIG_ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN=y
#CONFIG_CUSTOM_WIDGET_BATTERY_STATUS=y
CONFIG_ZMK_WIDGET_BATTERY_STATUS=y
#CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS=y
CONFIG_ZMK_WIDGET_OUTPUT_STATUS=y
#CONFIG_CUSTOM_WIDGET_LAYER_STATUS=y
CONFIG_ZMK_WIDGET_LAYER_STATUS=y
CONFIG_ZMK_DISPLAY_STATUS_SCREEN_CUSTOM=y
CONFIG_ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN=n
CONFIG_CUSTOM_WIDGET_BATTERY_STATUS=y
CONFIG_ZMK_WIDGET_BATTERY_STATUS=n
CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS=y
CONFIG_ZMK_WIDGET_OUTPUT_STATUS=n
CONFIG_CUSTOM_WIDGET_LAYER_STATUS=y
CONFIG_ZMK_WIDGET_LAYER_STATUS=n
# Turn on logging, and set ZMK logging to debug output
CONFIG_LOG=y
@ -88,7 +89,7 @@ CONFIG_LOG_STRDUP_BUF_COUNT=160
CONFIG_DISPLAY_LOG_LEVEL_DBG=y
CONFIG_LVGL_LOG_LEVEL_DBG=y
CONFIG_LVGL_USE_DEBUG=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y
#CONFIG_SENSOR_LOG_LEVEL_DBG=y
# Turn on USB CDC ACM device
CONFIG_ZMK_USB=y

View file

@ -65,27 +65,26 @@ CONFIG_LVGL_THEME_DEFAULT_FONT_SMALL_MONTSERRAT_16=y
CONFIG_LVGL_THEME_DEFAULT_FONT_NORMAL_MONTSERRAT_26=y
# custom status screens
#CONFIG_ZMK_DISPLAY_STATUS_SCREEN_CUSTOM=y
CONFIG_ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN=y
#CONFIG_CUSTOM_WIDGET_BATTERY_STATUS=y
#CONFIG_ZMK_WIDGET_BATTERY_STATUS=y
#CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS=y
#CONFIG_ZMK_WIDGET_OUTPUT_STATUS=y
#CONFIG_CUSTOM_WIDGET_LAYER_STATUS=y
#CONFIG_ZMK_WIDGET_LAYER_STATUS=y
CONFIG_ZMK_DISPLAY_STATUS_SCREEN_CUSTOM=y
CONFIG_ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN=n
CONFIG_CUSTOM_WIDGET_BATTERY_STATUS=y
CONFIG_ZMK_WIDGET_BATTERY_STATUS=n
CONFIG_CUSTOM_WIDGET_PERIPHERAL_STATUS=y
CONFIG_ZMK_WIDGET_PERIPHERAL_STATUS=n
# Turn on logging, and set ZMK logging to debug output
CONFIG_LOG=y
CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS=8000
CONFIG_ZMK_USB_LOGGING=y
CONFIG_ZMK_LOG_LEVEL_DBG=y
CONFIG_LOG_BUFFER_SIZE=10000
CONFIG_LOG_BUFFER_SIZE=20000
CONFIG_LOG_STRDUP_BUF_COUNT=60
#CONFIG_I2C_LOG_LEVEL_DBG=y
#CONFIG_SPI_LOG_LEVEL_DBG=y
CONFIG_DISPLAY_LOG_LEVEL_DBG=y
#CONFIG_LVGL_LOG_LEVEL_DBG=y
#CONFIG_LVGL_USE_DEBUG=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y
#CONFIG_SENSOR_LOG_LEVEL_DBG=y
# Turn on USB CDC ACM device
CONFIG_ZMK_USB=y

View file

@ -6,7 +6,8 @@
*/
#include "widgets/battery_status.h"
/*#include "widgets/output_status.h"*/
#include "widgets/peripheral_status.h"
#include "widgets/output_status.h"
#include "widgets/layer_status.h"
#include "custom_status_screen.h"
@ -21,7 +22,11 @@ static struct zmk_widget_battery_status battery_status_widget;
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS)
//static struct zmk_widget_output_status output_status_widget;
static struct zmk_widget_output_status output_status_widget;
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_PERIPHERAL_STATUS)
static struct zmk_widget_peripheral_status peripheral_status_widget;
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS)
@ -30,6 +35,7 @@ static struct zmk_widget_layer_status layer_status_widget;
lv_obj_t *zmk_display_status_screen() {
lv_obj_t *screen;
screen = lv_obj_create(NULL, NULL);
@ -41,9 +47,15 @@ lv_obj_t *zmk_display_status_screen() {
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS)
/* zmk_widget_output_status_init(&output_status_widget, screen);
zmk_widget_output_status_init(&output_status_widget, screen);
lv_obj_align(zmk_widget_output_status_obj(&output_status_widget), NULL, LV_ALIGN_IN_TOP_MID, 0,
41); */
41);
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_PERIPHERAL_STATUS)
zmk_widget_peripheral_status_init(&peripheral_status_widget, screen);
lv_obj_align(zmk_widget_peripheral_status_obj(&peripheral_status_widget), NULL,
LV_ALIGN_IN_TOP_MID, 0, 41);
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS)
@ -54,14 +66,14 @@ lv_obj_t *zmk_display_status_screen() {
-5);
#endif
#if CONFIG_BOARD_CORNEISH_ZEN_RIGHT
#if CONFIG_BOARD_CORNEISH_ZEN_V2_RIGHT
lv_obj_t * zenlogo_icon;
zenlogo_icon = lv_img_create(screen, NULL);
lv_img_set_src(zenlogo_icon, &zenlogo);
lv_obj_align(zenlogo_icon, NULL, LV_ALIGN_IN_BOTTOM_MID, 2, -5);
#endif
#if CONFIG_BOARD_CORNEISH_ZEN_LEFT
#if CONFIG_BOARD_CORNEISH_ZEN_V2_LEFT
lv_obj_t * LayersHeading;
LayersHeading = lv_img_create(screen, NULL);
lv_obj_align(LayersHeading, NULL, LV_ALIGN_IN_BOTTOM_MID, 8, 5);

View file

@ -7,4 +7,6 @@
#pragma once
#include <lvgl.h>
#include <lvgl.h>
lv_obj_t *zmk_display_status_screen();

View file

@ -20,6 +20,14 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/events/battery_state_changed.h>
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
struct battery_status_state {
uint8_t level;
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
bool usb_present;
#endif
};
static lv_style_t label_style;
LV_IMG_DECLARE(batt_100);
@ -35,15 +43,15 @@ LV_IMG_DECLARE(batt_5_chg);
LV_IMG_DECLARE(batt_0);
LV_IMG_DECLARE(batt_0_chg);
static bool style_initialized = false;
//static bool style_initialized = false;
void battery_status_init() {
if (style_initialized) {
return;
}
// if (style_initialized) {
// return;
// }
style_initialized = true;
//style_initialized = true;
lv_style_init(&label_style);
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_26);
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1);
@ -55,79 +63,96 @@ void battery_status_init() {
//lv_img_set_src(batt_full_chg_icon, &batt_full_chg);
}
K_MUTEX_DEFINE(battery_status_mutex);
//K_MUTEX_DEFINE(battery_status_mutex);
struct {
uint8_t level;
#if IS_ENABLED(CONFIG_USB)
bool usb_present;
#endif
} battery_status_state;
static void set_battery_symbol(lv_obj_t *icon, struct battery_status_state state) {
//void set_battery_symbol(lv_obj_t *icon) {
void set_battery_symbol(lv_obj_t *icon) {
//k_mutex_lock(&battery_status_mutex, K_FOREVER);
k_mutex_lock(&battery_status_mutex, K_FOREVER);
uint8_t level = state.level;
uint8_t level = battery_status_state.level;
#if IS_ENABLED(CONFIG_USB)
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
if (level > 95) {
if (battery_status_state.usb_present) {
if (state.usb_present) {
lv_img_set_src(icon, &batt_100_chg);
}else{
lv_img_set_src(icon, &batt_100);
}
} else if (level > 74) {
if (battery_status_state.usb_present) {
if (state.usb_present) {
lv_img_set_src(icon, &batt_75_chg);
}else{
lv_img_set_src(icon, &batt_75);
}
} else if (level > 49) {
if (battery_status_state.usb_present) {
if (state.usb_present) {
lv_img_set_src(icon, &batt_50_chg);
}else{
lv_img_set_src(icon, &batt_50);
}
} else if (level > 24) {
if (battery_status_state.usb_present) {
if (state.usb_present) {
lv_img_set_src(icon, &batt_25_chg);
}else{
lv_img_set_src(icon, &batt_25);
}
} else if (level > 5) {
if (battery_status_state.usb_present) {
if (state.usb_present) {
lv_img_set_src(icon, &batt_5_chg);
}else{
lv_img_set_src(icon, &batt_5);
}
} else {
if (battery_status_state.usb_present) {
if (state.usb_present) {
lv_img_set_src(icon, &batt_0_chg);
}else{
lv_img_set_src(icon, &batt_0);
}
}
//lv_label_set_text(label, text);
//lv_img_set_src(icon, );
#endif /* IS_ENABLED(CONFIG_USB) */
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */
k_mutex_unlock(&battery_status_mutex);
//k_mutex_unlock(&battery_status_mutex);
}
void battery_status_update_cb(struct battery_status_state state) {
struct zmk_widget_battery_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_battery_symbol(widget->obj, state); }
}
static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) {
return (struct battery_status_state) {
.level = bt_bas_get_battery_level(),
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
.usb_present = zmk_usb_is_powered(),
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */
};
}
ZMK_DISPLAY_WIDGET_LISTENER(widget_battery_status, struct battery_status_state,
battery_status_update_cb, battery_status_get_state)
ZMK_SUBSCRIPTION(widget_battery_status, zmk_battery_state_changed);
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
ZMK_SUBSCRIPTION(widget_battery_status, zmk_usb_conn_state_changed);
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */
int zmk_widget_battery_status_init(struct zmk_widget_battery_status *widget, lv_obj_t *parent) {
battery_status_init();
//widget->obj = lv_label_create(parent, NULL);
widget->obj = lv_img_create(parent, NULL);
//widget->obj2 = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
//lv_obj_set_size(widget->obj, 40, 15);
set_battery_symbol(widget->obj);
//set_battery_symbol(widget->obj);
sys_slist_append(&widgets, &widget->node);
widget_battery_status_init();
return 0;
}
@ -136,11 +161,8 @@ lv_obj_t *zmk_widget_battery_status_obj(struct zmk_widget_battery_status *widget
return widget->obj;
}
void battery_status_update_cb(struct k_work *work) {
struct zmk_widget_battery_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_battery_symbol(widget->obj); }
}
/*
K_WORK_DEFINE(battery_status_update_work, battery_status_update_cb);
int battery_status_listener(const zmk_event_t *eh) {
@ -150,7 +172,7 @@ int battery_status_listener(const zmk_event_t *eh) {
#if IS_ENABLED(CONFIG_USB)
battery_status_state.usb_present = zmk_usb_is_powered();
#endif /* IS_ENABLED(CONFIG_USB) */
#endif IS_ENABLED(CONFIG_USB)
k_mutex_unlock(&battery_status_mutex);
@ -162,4 +184,5 @@ ZMK_LISTENER(widget_battery_status, battery_status_listener)
ZMK_SUBSCRIPTION(widget_battery_status, zmk_battery_state_changed);
#if IS_ENABLED(CONFIG_USB)
ZMK_SUBSCRIPTION(widget_battery_status, zmk_usb_conn_state_changed);
#endif /* IS_ENABLED(CONFIG_USB) */
#endif IS_ENABLED(CONFIG_USB)
*/

View file

@ -8,6 +8,7 @@
#include <kernel.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/display.h>
#include "layer_status.h"
#include <zmk/events/layer_state_changed.h>
@ -22,10 +23,10 @@ static bool style_initialized = false;
K_MUTEX_DEFINE(layer_status_mutex);
struct {
struct layer_status_state {
uint8_t index;
const char *label;
} layer_status_state;
};
void layer_status_init() {
if (style_initialized) {
@ -40,14 +41,12 @@ void layer_status_init() {
}
void set_layer_symbol(lv_obj_t *label) {
static void set_layer_symbol(lv_obj_t *label, struct layer_status_state state) {
k_mutex_lock(&layer_status_mutex, K_FOREVER);
const char *layer_label = layer_status_state.label;
uint8_t active_layer_index = layer_status_state.index;
k_mutex_unlock(&layer_status_mutex);
//LOG_DBG("Layer Label: %s", layer_label);
//k_mutex_lock(&layer_status_mutex, K_FOREVER);
const char *layer_label = state.label;
uint8_t active_layer_index = state.index;
//k_mutex_unlock(&layer_status_mutex);
if (layer_label == NULL) {
char text[6] = {};
@ -60,6 +59,45 @@ void set_layer_symbol(lv_obj_t *label) {
}
}
//void layer_status_update_cb(struct k_work *work) {
static void layer_status_update_cb(struct layer_status_state state) {
struct zmk_widget_layer_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_layer_symbol(widget->obj, state); }
}
static struct layer_status_state layer_status_get_state(const zmk_event_t *eh) {
uint8_t index = zmk_keymap_highest_layer_active();
return (struct layer_status_state){.index = index, .label = zmk_keymap_layer_label(index)};
}
ZMK_DISPLAY_WIDGET_LISTENER(widget_layer_status, struct layer_status_state, layer_status_update_cb,
layer_status_get_state)
ZMK_SUBSCRIPTION(widget_layer_status, zmk_layer_state_changed);
int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent) {
layer_status_init();
widget->obj = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
sys_slist_append(&widgets, &widget->node);
widget_layer_status_init();
return 0;
}
lv_obj_t *zmk_widget_layer_status_obj(struct zmk_widget_layer_status *widget) {
return widget->obj;
}
/*
static void update_state() {
k_mutex_lock(&layer_status_mutex, K_FOREVER);
layer_status_state.index = zmk_keymap_highest_layer_active();
@ -69,25 +107,6 @@ static void update_state() {
k_mutex_unlock(&layer_status_mutex);
}
int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent) {
layer_status_init();
update_state();
widget->obj = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
set_layer_symbol(widget->obj);
sys_slist_append(&widgets, &widget->node);
return 0;
}
lv_obj_t *zmk_widget_layer_status_obj(struct zmk_widget_layer_status *widget) {
return widget->obj;
}
void layer_status_update_cb(struct k_work *work) {
struct zmk_widget_layer_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_layer_symbol(widget->obj); }
}
K_WORK_DEFINE(layer_status_update_work, layer_status_update_cb);
@ -97,6 +116,4 @@ int layer_status_listener(const zmk_event_t *eh) {
k_work_submit_to_queue(zmk_display_work_q(), &layer_status_update_work);
return 0;
}
ZMK_LISTENER(widget_layer_status, layer_status_listener)
ZMK_SUBSCRIPTION(widget_layer_status, zmk_layer_state_changed);
*/

View file

@ -13,7 +13,6 @@
struct zmk_widget_layer_status {
sys_snode_t node;
lv_obj_t *obj;
//lv_obj_t *obj2;
};
int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent);

View file

@ -41,14 +41,7 @@ static lv_style_t label_style;
static bool style_initialized = false;
K_MUTEX_DEFINE(output_status_mutex);
struct {
enum zmk_endpoint selected_endpoint;
bool active_profile_connected;
bool active_profile_bonded;
uint8_t active_profile_index;
} output_status_state;
//K_MUTEX_DEFINE(output_status_mutex);
void output_status_init() {
if (style_initialized) {
@ -63,30 +56,48 @@ void output_status_init() {
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1);
}
void set_status_symbol(lv_obj_t *icon) {
struct output_status_state {
//k_mutex_lock(&output_status_mutex, K_FOREVER);
enum zmk_endpoint selected_endpoint;
bool active_profile_connected;
bool active_profile_bonded;
uint8_t active_profile_index;
//k_mutex_unlock(&output_status_mutex);
};
k_mutex_lock(&output_status_mutex, K_FOREVER);
static struct output_status_state get_state(const zmk_event_t *_eh) {
return (struct output_status_state){.selected_endpoint = zmk_endpoints_selected(),
.active_profile_connected =
zmk_ble_active_profile_is_connected(),
.active_profile_bonded = !zmk_ble_active_profile_is_open(),
.active_profile_index = zmk_ble_active_profile_index()};
;
}
static void set_status_symbol(lv_obj_t *icon, struct output_status_state state) {
/*k_mutex_lock(&output_status_mutex, K_FOREVER);
enum zmk_endpoint selected_endpoint = output_status_state.selected_endpoint;
bool active_profile_connected = output_status_state.active_profile_connected;
bool active_profie_bonded = output_status_state.active_profile_bonded;
uint8_t active_profile_index = output_status_state.active_profile_index;
k_mutex_unlock(&output_status_mutex);
k_mutex_unlock(&output_status_mutex); */
switch (selected_endpoint) {
switch (state.selected_endpoint) {
case ZMK_ENDPOINT_USB:
lv_img_set_src(icon, &USB_connected);
break;
case ZMK_ENDPOINT_BLE:
if (active_profie_bonded) {
if (active_profile_connected) {
if (state.active_profile_bonded) {
if (state.active_profile_connected) {
//sprintf(text, LV_SYMBOL_BLUETOOTH "%i " LV_SYMBOL_OK, active_profile_index);
switch (active_profile_index) {
switch (state.active_profile_index) {
case 0:
#if CONFIG_BOARD_CORNEISH_ZEN_RIGHT
lv_img_set_src(icon, &bluetooth_connected_right);
#else
//#if CONFIG_BOARD_CORNEISH_ZEN_RIGHT
// lv_img_set_src(icon, &bluetooth_connected_right);
//#else
lv_img_set_src(icon, &bluetooth_connected_1);
#endif
//#endif
break;
case 1:
lv_img_set_src(icon, &bluetooth_connected_2);
@ -102,13 +113,10 @@ void set_status_symbol(lv_obj_t *icon) {
break;
}
} else {
//sprintf(text, LV_SYMBOL_BLUETOOTH "%i " LV_SYMBOL_CLOSE, active_profile_index);
lv_img_set_src(icon, &bluetooth_disconnected_right);
}
} else {
//sprintf(text, LV_SYMBOL_BLUETOOTH "%i " LV_SYMBOL_SETTINGS, active_profile_index);
//lv_img_set_src(icon, &bluetooth_advertising);
switch (active_profile_index) {
switch (state.active_profile_index) {
case 0:
lv_img_set_src(icon, &bluetooth_advertising_1);
break;
@ -132,6 +140,51 @@ void set_status_symbol(lv_obj_t *icon) {
//lv_label_set_text(label, text);
}
/*
void output_status_update_cb(struct k_work *work) {
struct zmk_widget_output_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); }
} */
static void output_status_update_cb(struct output_status_state state) {
struct zmk_widget_output_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj, state); }
}
ZMK_DISPLAY_WIDGET_LISTENER(widget_output_status, struct output_status_state,
output_status_update_cb, get_state)
ZMK_SUBSCRIPTION(widget_output_status, zmk_endpoint_selection_changed);
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed);
#endif
#if defined(CONFIG_ZMK_BLE)
ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed);
#endif
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) {
output_status_init();
widget->obj = lv_img_create(parent, NULL);
lv_obj_set_size(widget->obj, 40, 15);
sys_slist_append(&widgets, &widget->node);
widget_output_status_init();
return 0;
}
lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget) {
return widget->obj;
}
/*
static void update_state() {
k_mutex_lock(&output_status_mutex, K_FOREVER);
output_status_state.selected_endpoint = zmk_endpoints_selected();
@ -141,27 +194,6 @@ static void update_state() {
k_mutex_unlock(&output_status_mutex);
}
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) {
output_status_init();
//update_state();
//widget->obj = lv_label_create(parent, NULL);
widget->obj = lv_img_create(parent, NULL);
set_status_symbol(widget->obj);
sys_slist_append(&widgets, &widget->node);
return 0;
}
lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget) {
return widget->obj;
}
void output_status_update_cb(struct k_work *work) {
struct zmk_widget_output_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); }
}
K_WORK_DEFINE(output_status_update_work, output_status_update_cb);
@ -179,12 +211,4 @@ int output_status_listener(const zmk_event_t *eh) {
k_work_submit_to_queue(zmk_display_work_q(), &output_status_update_work);
return ZMK_EV_EVENT_BUBBLE;
}
ZMK_LISTENER(widget_output_status, output_status_listener)
ZMK_SUBSCRIPTION(widget_output_status, zmk_endpoint_selection_changed);
#if defined(CONFIG_USB)
ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed);
#endif
#if defined(CONFIG_ZMK_BLE)
ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed);
#endif
*/

View file

@ -0,0 +1,129 @@
/*
*
* Copyright (c) 2021 Darryl deHaan
* 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 "peripheral_status.h"
#include <zmk/event_manager.h>
#include <zmk/split/bluetooth/peripheral.h>
#include <zmk/events/split_peripheral_status_changed.h>
LV_IMG_DECLARE(bluetooth_connected_right);
LV_IMG_DECLARE(bluetooth_disconnected_right);
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
static lv_style_t label_style;
static bool style_initialized = false;
struct peripheral_status_state {
bool connected;
};
//K_MUTEX_DEFINE(output_status_mutex);
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 *icon, struct peripheral_status_state state) {
if (state.connected) {
LOG_WRN("peripheral connected");
lv_img_set_src(icon, &bluetooth_connected_right);
}else{
LOG_WRN("peripheral disconnected");
lv_img_set_src(icon, &bluetooth_disconnected_right);
}
LOG_DBG("halves connected? %s", state.connected ? "true" : "false");
}
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);
void output_status_init() {
if (style_initialized) {
return;
}
style_initialized = true;
lv_style_init(&label_style);
lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_26);
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1);
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1);
}
/*
void output_status_update_cb(struct k_work *work) {
struct zmk_widget_output_status *widget;
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); }
} */
int zmk_widget_peripheral_status_init(struct zmk_widget_peripheral_status *widget,
lv_obj_t *parent) {
output_status_init();
widget->obj = lv_img_create(parent, NULL);
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;
}
/*
static void update_state() {
k_mutex_lock(&output_status_mutex, K_FOREVER);
output_status_state.selected_endpoint = zmk_endpoints_selected();
output_status_state.active_profile_connected = zmk_ble_active_profile_is_connected();
output_status_state.active_profile_bonded = !zmk_ble_active_profile_is_open();
output_status_state.active_profile_index = zmk_ble_active_profile_index();
k_mutex_unlock(&output_status_mutex);
}
K_WORK_DEFINE(output_status_update_work, output_status_update_cb);
int output_status_listener(const zmk_event_t *eh) {
// Be sure we have widgets initialized before doing any work,
// since the status event can fire before display code inits.
if (!style_initialized) {
return ZMK_EV_EVENT_BUBBLE;
}
//update_state();
k_work_submit_to_queue(zmk_display_work_q(), &output_status_update_work);
return ZMK_EV_EVENT_BUBBLE;
}
*/

View file

@ -0,0 +1,20 @@
/*
*
* Copyright (c) 2021 Darryl deHaan
* 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);

View file

@ -74,10 +74,22 @@ static int bvd_sample_fetch(const struct device *dev, enum sensor_channel chan)
as->calibrate = false;
if (rc == 0) {
/*
CALCULATE SOC BASED ON VOLTAGE
- the raw value from the analog pin represents the voltage it senses
-
*/
int32_t val = drv_data->value.adc_raw;
LOG_DBG("Raw 1: %d", val);
adc_raw_to_millivolts(adc_ref_internal(drv_data->adc), drv_data->acc.gain, as->resolution,
&val);
LOG_DBG("Raw 2: %d", val);
LOG_DBG("Internal Reference Voltage: %d", adc_ref_internal(drv_data->adc));
LOG_DBG("Gain: %d", drv_data->acc.gain);
LOG_DBG("Resolution: %d", as->resolution);
LOG_DBG("Resistor values: %d / %d", drv_cfg->full_ohm, drv_cfg->output_ohm);
uint16_t millivolts = val * (uint64_t)drv_cfg->full_ohm / drv_cfg->output_ohm;
LOG_DBG("ADC raw %d ~ %d mV => %d mV", drv_data->value.adc_raw, val, millivolts);