Skip to content

Commit

Permalink
CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE fixed, layer status long fixed, new …
Browse files Browse the repository at this point in the history
…small fonts added
  • Loading branch information
mctechnology17 committed Dec 2, 2024
1 parent 73bfa5f commit f67688f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion boards/shields/nice_oled/assets/custom_fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CUSTOM_FONTS_H

LV_FONT_DECLARE(pixel_operator_mono);
// LV_FONT_DECLARE(pixel_operator_mono_8);
LV_FONT_DECLARE(pixel_operator_mono_8);
// LV_FONT_DECLARE(pixel_operator_mono_12);
// the default font is 16px as global
// LV_FONT_DECLARE(pixel_operator_mono_16);
Expand Down
24 changes: 12 additions & 12 deletions boards/shields/nice_oled/assets/pixel_operator_mono_8.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*----------------*/

/*Store the image of the glyphs*/
static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap_8[] = {
/* U+0020 " " */
0x0,

Expand Down Expand Up @@ -312,7 +312,7 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
* GLYPH DESCRIPTION
*--------------------*/

static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc_8[] = {
{.bitmap_index = 0,
.adv_w = 0,
.box_w = 0,
Expand Down Expand Up @@ -895,7 +895,7 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
*--------------------*/

/*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = {
static const lv_font_fmt_txt_cmap_t cmaps_8[] = {
{.range_start = 32,
.range_length = 95,
.glyph_id_start = 1,
Expand All @@ -914,13 +914,13 @@ static lv_font_fmt_txt_glyph_cache_t cache;
#endif

#if LVGL_VERSION_MAJOR >= 8
static const lv_font_fmt_txt_dsc_t font_dsc = {
static const lv_font_fmt_txt_dsc_t font_dsc_8 = {
#else
static lv_font_fmt_txt_dsc_t font_dsc = {
static lv_font_fmt_txt_dsc_t font_dsc_8 = {
#endif
.glyph_bitmap = glyph_bitmap,
.glyph_dsc = glyph_dsc,
.cmaps = cmaps,
.glyph_bitmap = glyph_bitmap_8,
.glyph_dsc = glyph_dsc_8,
.cmaps = cmaps_8,
.kern_dsc = NULL,
.kern_scale = 0,
.cmap_num = 1,
Expand All @@ -942,8 +942,8 @@ const lv_font_t pixel_operator_mono_8 = {
#else
lv_font_t pixel_operator_mono_8 = {
#endif
.get_glyph_dsc =
lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
.get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to
get glyph's data*/
.get_glyph_bitmap =
lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/
.line_height = 7, /*The maximum line height required by the font*/
Expand All @@ -955,8 +955,8 @@ lv_font_t pixel_operator_mono_8 = {
.underline_position = -1,
.underline_thickness = 1,
#endif
.dsc = &font_dsc, /*The custom font data. Will be accessed by
`get_glyph_bitmap/dsc` */
.dsc = &font_dsc_8, /*The custom font data. Will be accessed by
`get_glyph_bitmap_8/dsc` */
#if LV_VERSION_CHECK(8, 2, 0) || LVGL_VERSION_MAJOR >= 9
.fallback = NULL,
#endif
Expand Down
2 changes: 1 addition & 1 deletion boards/shields/nice_oled/assets/readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
download the fonts: https://fonts2u.com/pixel-operator-mono.font
install the font converter: npm install -g lv_font_conv
convert the font:
lv_font_conv --font PixelOperatorMono.ttf --size 8 --format lvgl --bpp 1 --range 0x20-0x7F --no-compress -o pixel_operator_mono.c
lv_font_conv --font PixelOperatorMono.ttf --size 8 --format lvgl --bpp 1 --range 0x20-0x7F --no-compress -o pixel_operator_mono_8.c
1 change: 1 addition & 0 deletions boards/shields/nice_oled/custom_status_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#include "assets/pixel_operator_mono.c"
#include "assets/pixel_operator_mono_8.c"
// auto save conflict
#include "assets/custom_fonts.h"

Expand Down
4 changes: 2 additions & 2 deletions boards/shields/nice_oled/nice_oled.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CONFIG_ZMK_DISPLAY=y
CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE=n
# CONFIG_ZMK_DISPLAY=y
# CONFIG_ZMK_DISPLAY_BLANK_ON_IDLE=n
23 changes: 17 additions & 6 deletions boards/shields/nice_oled/widgets/layer.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
#include "layer.h"
#include "../assets/custom_fonts.h"
#include <ctype.h> // Para toupper()
#include <zephyr/kernel.h>

// MC: better implementation
void draw_layer_status(lv_obj_t *canvas, const struct status_state *state) {
lv_draw_label_dsc_t label_dsc;
// init_label_dsc(&label_dsc, LVGL_FOREGROUND, &pixel_operator_mono,
// LV_TEXT_ALIGN_CENTER);
init_label_dsc(&label_dsc, LVGL_FOREGROUND, &pixel_operator_mono,
LV_TEXT_ALIGN_LEFT);

char text[10] = {};
char text[14] = {};
int result;

if (state->layer_label == NULL) {
sprintf(text, "Layer %i", state->layer_index);
result = snprintf(text, sizeof(text), "Layer %i", state->layer_index);
} else {
strcpy(text, state->layer_label);
to_uppercase(text);
result = snprintf(text, sizeof(text), "%s", state->layer_label);
for (int i = 0; text[i] != '\0'; i++) {
// toupper( ... ): This function, found in the ctype.h library, takes a
// character as an argument and converts it to its uppercase equivalent.
// If the character is already uppercase or not a letter, the function
// returns it unchanged.
text[i] = toupper(text[i]);
}
}

if (result >= sizeof(text)) {
LV_LOG_WARN("truncated");
}

lv_canvas_draw_text(canvas, 0, 146, 68, &label_dsc, text);
Expand Down
13 changes: 8 additions & 5 deletions boards/shields/nice_oled/widgets/profile.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "profile.h"
// use custom_fonts.h only for the draw_active_profile_text function
#include "../assets/custom_fonts.h"
#include <stdio.h>
#include <zephyr/kernel.h>

LV_IMG_DECLARE(profiles);
Expand All @@ -25,21 +26,23 @@ static void draw_active_profile(lv_obj_t *canvas,
// lv_canvas_draw_rect(canvas, 18 + offset, 129, 3, 3, &rect_white_dsc);
}

// MC: mejor implementación
static void draw_active_profile_text(lv_obj_t *canvas,
const struct status_state *state) {
// new label_dsc
lv_draw_label_dsc_t label_dsc;
init_label_dsc(&label_dsc, LVGL_FOREGROUND, &pixel_operator_mono,
init_label_dsc(&label_dsc, LVGL_FOREGROUND, &pixel_operator_mono_8,
LV_TEXT_ALIGN_LEFT);

char text[3] = {}; // Aumenta el tamaño del búfer
sprintf(text, "%d", state->active_profile_index + 1);
// snprintf(text, sizeof(text), "%d", state->active_profile_index + 1);
// buffer size should be enough for largest number + null character
char text[14] = {};
snprintf(text, sizeof(text), "%d", state->active_profile_index + 1);

lv_canvas_draw_text(canvas, 25, 32, 35, &label_dsc, text);
}

void draw_profile_status(lv_obj_t *canvas, const struct status_state *state) {
// draw_active_profile_text(canvas, state);
draw_active_profile_text(canvas, state);
draw_inactive_profiles(canvas, state);
draw_active_profile(canvas, state);
}

0 comments on commit f67688f

Please sign in to comment.