Skip to content

Commit

Permalink
refactor: Customizable Screen Saver
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Oct 16, 2024
1 parent 6796513 commit f447056
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 24 deletions.
25 changes: 24 additions & 1 deletion firmware/components/minino_config/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,35 @@ config FILE_MANAGER_WEB
Enable or disable the Web File Manager Feature.
endif # FILE_MANAGER_ENABLE

########################### SD_CARD #############################
########################### SD CARD #############################

config SD_CARD
bool "Enable SD Card Menus"
default true
help
Enable or disable SD Card Menus.

endmenu

########################### Screen Savers ############################

menu "Screen Saver"
config SCREEN_SAVER_LETTERS
bool "Letters"
default true
config SCREEN_SAVER_FACE
bool "Face"
default true
config SCREEN_SAVER_PWNLABS
bool "PwnLabs"
default true
config SCREEN_SAVER_EC
bool "EC"
default true
config SCREEN_SAVER_MINI_FACE
bool "Mini Face"
default true
config SCREEN_SAVER_BABY_DRAGON
bool "Baby Dragon"
default true
endmenu
58 changes: 45 additions & 13 deletions firmware/main/general/bitmaps_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
#include <stdlib.h>
#ifndef BITMAPS_GENERAL_H
#define BITMAPS_GENERAL_H

typedef enum {
MININO_LETTERS,
MININO_FACE,
MININO_PWNLABS,
MININO_ELECTRONICCATS,
MININO_FACE_MINI,
MININO_BABY_DRAGON,
MININO_COUNT
} epd_bitmap_type_t;

// 'FACE', 8x8px
const unsigned char minino_face[] = {0x42, 0xe7, 0xff, 0xff,
0x99, 0x99, 0x7e, 0x3c};

typedef struct {
const epd_bitmap_type_t idx;
const char* name;
const unsigned char* bitmap;
uint8_t width;
uint8_t height;
Expand Down Expand Up @@ -137,54 +150,73 @@ unsigned char* epd_startup_logo[] = {epd_bitmap_minino_text_logo,
epd_bitmap_face_logo};

const epd_bitmap_t minino_face_bitmap = {
.idx = MININO_FACE_MINI,
.name = "Mini Face",
.bitmap = minino_face,
.width = 8,
.height = 8,
};

const epd_bitmap_t minino_letters_bitmap = {
.idx = MININO_LETTERS,
.name = "Letters",
.bitmap = epd_bitmap_minino_text_logo,
.width = 64,
.height = 32,
};

const epd_bitmap_t minino_face_logo = {
.idx = MININO_FACE,
.name = "Face",
.bitmap = epd_bitmap_face_logo,
.width = 32,
.height = 32,
};

const epd_bitmap_t minino_pwnlabs_logo = {
.idx = MININO_PWNLABS,
.name = "PwnLabs",
.bitmap = epd_bitmap_pwn_02,
.width = 64,
.height = 11,
};

const epd_bitmap_t minino_electroniccats_logo = {
.idx = MININO_ELECTRONICCATS,
.name = "EC",
.bitmap = epd_bitmap_electroniccats,
.width = 48,
.height = 30,
};

const epd_bitmap_t minino_baby_dragon_bitmap = {
.idx = MININO_BABY_DRAGON,
.name = "Baby Dragon",
.bitmap = epd_bitmap_baby_dragon_ss,
.width = 32,
.height = 32,
};

typedef enum {
MININO_LETTERS,
MININO_FACE,
MININO_PWNLABS,
MININO_ELECTRONICCATS,
MININO_FACE_MINI,
MININO_BABY_DRAGON,
MININO_COUNT
} epd_bitmap_type_t;

epd_bitmap_t screen_savers[] = {
minino_letters_bitmap, minino_face_logo, minino_pwnlabs_logo,
minino_electroniccats_logo, minino_face_bitmap, minino_baby_dragon_bitmap};
const epd_bitmap_t* screen_savers[] = {
#if CONFIG_SCREEN_SAVER_LETTERS
&minino_letters_bitmap,
#endif
#if CONFIG_SCREEN_SAVER_FACE
&minino_face_logo,
#endif
#if CONFIG_SCREEN_SAVER_PWNLABS
&minino_pwnlabs_logo,
#endif
#if CONFIG_SCREEN_SAVER_EC
&minino_electroniccats_logo,
#endif
#if CONFIG_SCREEN_SAVER_MINI_FACE
&minino_face_bitmap,
#endif
#if CONFIG_SCREEN_SAVER_BABY_DRAGON
&minino_baby_dragon_bitmap,
#endif
};

char* epd_bitmaps_list[] = {"Letters", "Face", "PwnLabs", "EC",
"Mini face", "Baby Dragon", NULL};
Expand Down
40 changes: 36 additions & 4 deletions firmware/main/modules/settings/display/display_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include "bitmaps_general.h"
#include "esp_log.h"
#include "general_radio_selection.h"
#include "led_events.h"
#include "menus_module.h"
#include "modals_module.h"
Expand Down Expand Up @@ -29,6 +30,7 @@ typedef enum { DISPLAY_MENU, DISPLAY_LIST, DISPLAY_COUNT } display_menu_t;

static char* display_settings_menu_items[] = {"Screen Logo", "Screen Time",
NULL};
static char** screen_saver_options = NULL;
static int selected_item = 0;
static int screen_selected = 0;
static int time_default_time = 30;
Expand All @@ -41,6 +43,7 @@ static void display_config_module_state_machine_menu_time(uint8_t button_name,
uint8_t button_event);
static void display_config_module_state_machine_modal(uint8_t button_name,
uint8_t button_event);
void screen_saver_selector_menu();

static void config_module_wifi_display_selected_item(char* item_text,
uint8_t item_number) {
Expand Down Expand Up @@ -140,10 +143,7 @@ static void display_config_module_state_machine(uint8_t button_name,
case BUTTON_RIGHT:
ESP_LOGI(TAG_DISPLAY_CONFIG, "Selected item: %d", selected_item);
if (selected_item == 0) {
selected_item = 0;
menus_module_set_app_state(
true, display_config_module_state_machine_menu_logo);
display_config_display_list_logo();
screen_saver_selector_menu();
} else {
selected_item = 0;
menus_module_set_app_state(
Expand Down Expand Up @@ -279,4 +279,36 @@ static void display_config_module_state_machine_modal(uint8_t button_name,
default:
break;
}
}
static void screen_saver_selection_exit() {
selected_item = 0;
menus_module_set_app_state(true, display_config_module_state_machine);
display_config_display_menu_item();
}

static void screen_saver_selection_handler(uint8_t screen_saver) {
preferences_put_int("dp_select", screen_saver);
}

char** get_screen_saver_names() {
uint8_t screen_savers_count = sizeof(screen_savers) / sizeof(epd_bitmap_t*);
char** names = malloc(sizeof(char*) * screen_savers_count);
for (uint8_t i = 0; i < screen_savers_count; i++) {
names[i] = screen_savers[i]->name;
}
return names;
}
void screen_saver_selector_menu() {
uint8_t screen_savers_count = sizeof(screen_savers) / sizeof(epd_bitmap_t*);
screen_saver_options = get_screen_saver_names();
general_radio_selection_menu_t screen_saver_logo_menu;
screen_saver_logo_menu.banner = "Screen Saver";
screen_saver_logo_menu.exit_cb = screen_saver_selection_exit;
screen_saver_logo_menu.options = screen_saver_options;
screen_saver_logo_menu.options_count = screen_savers_count;
screen_saver_logo_menu.style = RADIO_SELECTION_OLD_STYLE;
screen_saver_logo_menu.current_option =
MIN(screen_savers_count - 1, preferences_get_int("dp_select", 0));
screen_saver_logo_menu.select_cb = screen_saver_selection_handler;
general_radio_selection(screen_saver_logo_menu);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ static void timer_callback() {
}

static void show_splash_screen() {
int get_logo = preferences_get_int("dp_select", 0);
epd_bitmap_t logo;
uint8_t screen_savers_count = sizeof(screen_savers) / sizeof(epd_bitmap_t*);
int get_logo =
MIN(screen_savers_count - 1, preferences_get_int("dp_select", 0));
epd_bitmap_t* logo;
logo = screen_savers[get_logo];

screen_saver_running = true;
int w_screen_space = SCREEN_WIDTH2 - logo.width;
int h_screen_space = SCREEN_HEIGHT2 - logo.height;
int w_screen_space = SCREEN_WIDTH2 - logo->width;
int h_screen_space = SCREEN_HEIGHT2 - logo->height;
h_screen_space = h_screen_space == 0 ? 2 : h_screen_space;
int start_x_position = w_screen_space / 2;
#if CONFIG_RESOLUTION_128X64
Expand All @@ -52,8 +54,8 @@ static void show_splash_screen() {
static int x_direction = 1;

while (screen_saver_running) {
oled_screen_display_bitmap(logo.bitmap, start_x_position, start_y_position,
logo.width, logo.height, OLED_DISPLAY_NORMAL);
oled_screen_display_bitmap(logo->bitmap, start_x_position, start_y_position,
logo->width, logo->height, OLED_DISPLAY_NORMAL);

start_x_position += x_direction;
start_y_position += y_direction;
Expand Down
11 changes: 11 additions & 0 deletions firmware/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@ CONFIG_BUZZER_COMPONENT_ENABLED=y
#
CONFIG_LEDS_COMPONENT_ENABLED=y
# end of LEDs Configuration

#
# Screen Savers Configuration
#
CONFIG_SCREEN_SAVER_LETTERS=y
CONFIG_SCREEN_SAVER_FACE=y
CONFIG_SCREEN_SAVER_PWNLABS=y
CONFIG_SCREEN_SAVER_EC=y
CONFIG_SCREEN_SAVER_MINI_FACE=y
CONFIG_SCREEN_SAVER_BABY_DRAGON=y
# end of Screen Savers Configuration

0 comments on commit f447056

Please sign in to comment.