Skip to content

Commit

Permalink
feat: refactor and prep for animation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpastor committed Oct 14, 2024
1 parent 8cc7be2 commit c9c56a8
Show file tree
Hide file tree
Showing 28 changed files with 376 additions and 142 deletions.
Empty file removed config/boards/shields/.gitkeep
Empty file.
59 changes: 32 additions & 27 deletions config/boards/shields/custom_nice_view/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
if(CONFIG_ZMK_DISPLAY AND CONFIG_NICE_VIEW_WIDGET_STATUS)
zephyr_library_include_directories(${CMAKE_SOURCE_DIR}/include)

zephyr_library_sources(./src/main.c)
zephyr_library_sources(
./src/main.c
./src/fonts/custom_font_22.c
./src/fonts/custom_font_44.c
./src/images/background_0.c
./src/images/background_1.c
./src/images/background_2.c
./src/images/background_3.c
./src/images/background_4.c
./src/images/background_5.c
./src/images/background_6.c
./src/images/bluetooth_logo_outline.c
./src/images/bluetooth_logo_outlined.c
./src/images/bluetooth_logo.c
./src/images/usb_logo.c
./src/utils/draw_background.c
./src/utils/draw_battery.c
./src/utils/draw_bluetooth_logo_outline.c
./src/utils/draw_bluetooth_logo_outlined.c
./src/utils/draw_bluetooth_logo.c
./src/utils/draw_usb_logo.c
./src/utils/rotate_info_canvas.c
)

if(NOT CONFIG_ZMK_SPLIT OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
zephyr_library_sources(./src/initialize_central_listeners.c)
zephyr_library_sources(./src/render_central.c)
zephyr_library_sources(
./src/central/initialize_listeners.c
./src/central/render_central.c
)
else()
zephyr_library_sources(./src/initialize_peripheral_listeners.c)
zephyr_library_sources(./src/render_peripheral.c)
zephyr_library_sources(
./src/peripheral/initialize_listeners.c
./src/peripheral/render_peripheral.c
)
endif()

zephyr_library_sources(./src/fonts/custom_font_22.c)
zephyr_library_sources(./src/fonts/custom_font_44.c)

zephyr_library_sources(./src/images/background_0.c)
zephyr_library_sources(./src/images/background_1.c)
zephyr_library_sources(./src/images/background_2.c)
zephyr_library_sources(./src/images/background_3.c)
zephyr_library_sources(./src/images/background_4.c)

zephyr_library_sources(./src/images/bluetooth_logo_outline.c)
zephyr_library_sources(./src/images/bluetooth_logo_outlined.c)
zephyr_library_sources(./src/images/bluetooth_logo.c)
zephyr_library_sources(./src/images/usb_logo.c)

zephyr_library_sources(./src/utils/draw_background.c)
zephyr_library_sources(./src/utils/draw_battery.c)
zephyr_library_sources(./src/utils/draw_bluetooth_logo_outline.c)
zephyr_library_sources(./src/utils/draw_bluetooth_logo_outlined.c)
zephyr_library_sources(./src/utils/draw_bluetooth_logo.c)
zephyr_library_sources(./src/utils/draw_usb_logo.c)
zephyr_library_sources(./src/utils/rotate_info_canvas.c)
endif()
73 changes: 31 additions & 42 deletions config/boards/shields/custom_nice_view/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,44 @@
# SPDX-License-Identifier: MIT

if SHIELD_CUSTOM_NICE_VIEW
config LV_Z_VDB_SIZE
default 100

config LV_Z_VDB_SIZE
default 100
config LV_DPI_DEF
default 161

config LV_DPI_DEF
default 161
config LV_Z_BITS_PER_PIXEL
default 1

config LV_Z_BITS_PER_PIXEL
default 1
choice LV_COLOR_DEPTH
default LV_COLOR_DEPTH_1
endchoice

choice LV_COLOR_DEPTH
default LV_COLOR_DEPTH_1
endchoice
choice ZMK_DISPLAY_WORK_QUEUE
default ZMK_DISPLAY_WORK_QUEUE_DEDICATED
endchoice

choice ZMK_DISPLAY_WORK_QUEUE
default ZMK_DISPLAY_WORK_QUEUE_DEDICATED
endchoice
choice ZMK_DISPLAY_STATUS_SCREEN
default ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
endchoice

choice ZMK_DISPLAY_STATUS_SCREEN
default ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
endchoice
config LV_Z_MEM_POOL_SIZE
default 4096 if ZMK_DISPLAY_STATUS_SCREEN_CUSTOM

config LV_Z_MEM_POOL_SIZE
default 4096 if ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
imply NICE_VIEW_WIDGET_STATUS

config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
imply NICE_VIEW_WIDGET_STATUS
config NICE_VIEW_WIDGET_STATUS
bool "Custom nice!view status widget"
select LV_FONT_MONTSERRAT_16
select LV_USE_IMG
select LV_USE_CANVAS

config NICE_VIEW_WIDGET_STATUS
bool "Custom nice!view status widget"
select LV_FONT_MONTSERRAT_16
select LV_USE_IMG
select LV_USE_CANVAS
config NICE_VIEW_WIDGET_INVERTED
bool "Invert custom status widget colors"

config NICE_VIEW_WIDGET_INVERTED
bool "Invert custom status widget colors"

if !ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL

config NICE_VIEW_WIDGET_STATUS
select LV_FONT_MONTSERRAT_44
select LV_FONT_MONTSERRAT_18
select LV_FONT_MONTSERRAT_14
select LV_FONT_UNSCII_8
select ZMK_WPM

endif # !ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL

config ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN
select LV_FONT_MONTSERRAT_26

endif # SHIELD_CUSTOM_NICE_VIEW
if !ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL
config NICE_VIEW_WIDGET_STATUS
select ZMK_WPM
endif
endif
4 changes: 1 addition & 3 deletions config/boards/shields/custom_nice_view/custom_nice_view.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Enable nice!view
# ZMK setting that enables the call to `lv_obj_t* zmk_display_status_screen()`.
CONFIG_ZMK_DISPLAY=y
# Disable idle blanking
CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE=n
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "./initialize_listeners.h"
#include "../initialize_listeners.h"

#include <lvgl.h>
#include <stdbool.h>
#include <zmk/endpoints.h>
#include <zmk/keymap.h>
#include "./utils/draw_battery.h"
#include "../utils/draw_battery.h"

struct central_connectivity_state {
struct zmk_endpoint_instance selected_endpoint;
Expand All @@ -23,7 +23,9 @@ struct states {
struct central_connectivity_state connectivity;
struct layer_state layer;
struct battery_state battery;
uint8_t background_index;
unsigned background_index;
};

extern struct states states;

void initialize_listeners();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <lvgl.h>

extern const lv_img_dsc_t background_5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <lvgl.h>

extern const lv_img_dsc_t background_6;

This file was deleted.

2 changes: 2 additions & 0 deletions config/boards/shields/custom_nice_view/include/main.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <zmk/display/status_screen.h>

#include <lvgl.h>

#define SCREEN_WIDTH 160
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "../initialize_listeners.h"

#include <stdbool.h>
#include "../utils/draw_battery.h"

struct peripheral_connectivity_state {
bool connected;
};

struct states {
struct peripheral_connectivity_state connectivity;
struct battery_state battery;
unsigned background_index;
};

extern struct states states;

void initialize_listeners();
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include <lvgl.h>

void draw_background(lv_obj_t* canvas, uint8_t index);
void draw_background(lv_obj_t* canvas, unsigned index);
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "../include/initialize_central_listeners.h"
#include "../../include/central/initialize_listeners.h"

#include <limits.h>
#include <lvgl.h>
#include <stdint.h>
#include <zmk/battery.h>
#include <zmk/ble.h>
#include <zmk/display.h>
#include <zmk/endpoints.h>
Expand All @@ -9,11 +13,9 @@
#include <zmk/events/endpoint_changed.h>
#include <zmk/events/layer_state_changed.h>
#include <zmk/events/usb_conn_state_changed.h>
#include <zmk/events/wpm_state_changed.h>
#include <zmk/keymap.h>
#include <zmk/usb.h>
#include <zmk/wpm.h>
#include "../include/render_central.h"
#include "../../include/central/render_central.h"

struct states states;

Expand Down Expand Up @@ -155,8 +157,17 @@ ZMK_SUBSCRIPTION(
zmk_usb_conn_state_changed
);

void background_update_timer(lv_timer_t * timer)
{
states.background_index = (states.background_index + 1) % UINT_MAX;

render_central();
}

void initialize_listeners() {
widget_layer_state_update_init();
widget_central_connectivity_state_update_init();
widget_battery_state_update_init();

// lv_timer_create(background_update_timer, 200, NULL);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#include "../include/render_central.h"

#include "../include/colors.h"
#include "../include/initialize_central_listeners.h"
#include "../include/main.h"
#include "../include/fonts/custom_font_22.h"
#include "../include/fonts/custom_font_44.h"
#include "../include/utils/draw_battery.h"
#include "../include/utils/draw_background.h"
#include "../include/utils/draw_bluetooth_logo_outline.h"
#include "../include/utils/draw_bluetooth_logo_outlined.h"
#include "../include/utils/draw_bluetooth_logo.h"
#include "../include/utils/draw_usb_logo.h"
#include "../include/utils/rotate_info_canvas.h"
#include "../../include/central/render_central.h"

#include <ctype.h>
#include <lvgl.h>
#include <stdlib.h>
#include <string.h>
#include "../../include/colors.h"
#include "../../include/central/initialize_listeners.h"
#include "../../include/fonts/custom_font_22.h"
#include "../../include/fonts/custom_font_44.h"
#include "../../include/main.h"
#include "../../include/utils/draw_battery.h"
#include "../../include/utils/draw_background.h"
#include "../../include/utils/draw_bluetooth_logo_outline.h"
#include "../../include/utils/draw_bluetooth_logo_outlined.h"
#include "../../include/utils/draw_bluetooth_logo.h"
#include "../../include/utils/draw_usb_logo.h"
#include "../../include/utils/rotate_info_canvas.h"

static void render_bluetooth_logo() {
if (states.connectivity.active_profile_bonded) {
Expand Down Expand Up @@ -81,12 +85,18 @@ static void draw_layer_name() {
const int actual_font_height = 38;
int padding = (MAIN_CANVAS_HEIGHT - actual_font_height) / 2;

lv_canvas_draw_text(main_canvas, 0, padding, MAIN_CANVAS_WIDTH, &layer_name_dsc, states.layer.name);
char* upperCasedName = malloc((strlen(states.layer.name) + 1) * sizeof(char));
for (int i = 0; states.layer.name[i] != '\0'; i++) {
upperCasedName[i] = toupper(states.layer.name[i]);
}
upperCasedName[strlen(states.layer.name)] = '\0';

lv_canvas_draw_text(main_canvas, 0, padding, MAIN_CANVAS_WIDTH, &layer_name_dsc, upperCasedName);
free(upperCasedName);
}

static void render_main() {
draw_background(main_canvas, states.background_index);
states.background_index = states.background_index + 1;

draw_layer_name();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../../include/images/background_4.h"


#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
Expand Down
Loading

0 comments on commit c9c56a8

Please sign in to comment.