-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added custom theme builder #161
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"idf.adapterTargetName": "esp32s3", | ||
"idf.port": "/dev/ttyACM0", | ||
"idf.openOcdConfigs": [ | ||
"board/esp32s3-builtin.cfg" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,159 @@ | ||
dependencies: | ||
espressif/button: | ||
component_hash: 1f5297fe16f0ee988dbb14b6f4c91782fe2baf85025bb15cc1e0093edd3fb2ee | ||
dependencies: | ||
- name: espressif/cmake_utilities | ||
registry_url: https://components.espressif.com/ | ||
require: private | ||
version: 0.* | ||
- name: idf | ||
require: private | ||
version: '>=4.0' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 3.2.0 | ||
espressif/cbor: | ||
component_hash: 440f4ee4504841cc9b4f3a8ef755776a612ac9dace355514c68b999868f990ff | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=4.3' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 0.6.0~1 | ||
espressif/cmake_utilities: | ||
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=4.1' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 0.5.3 | ||
espressif/esp-dsp: | ||
component_hash: 3e7bbd487f1357a1d4944d0c85966d049501ea281b8a4c7f93f7cfedd5b7f23d | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=4.2' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 1.4.12 | ||
espressif/esp32-camera: | ||
component_hash: a1933162caca04a3a3bb0dca00bb56fcb3c50cd3779ab2f2b03ad8536e9bd0d0 | ||
dependencies: [] | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 2.0.9 | ||
espressif/esp_lcd_touch: | ||
component_hash: d4d8f2dc33205797169a97a02e0d89a8982f59fe0509129b54422052b8522f59 | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=4.4.2' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 1.1.1 | ||
espressif/esp_lcd_touch_ft5x06: | ||
component_hash: 97759953d9436a365e9427078c5b04ecce4e6a50f50cf62c68cd6bfa229b812c | ||
dependencies: | ||
- name: espressif/esp_lcd_touch | ||
registry_url: https://components.espressif.com/ | ||
require: public | ||
version: ^1.0.4 | ||
- name: idf | ||
require: private | ||
version: '>=4.4.2' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 1.0.6 | ||
espressif/esp_tinyusb: | ||
component_hash: f151d680d6847bfcfd5d8eb6d1c3ff926c208e6b963b2e83643a141bc70baa15 | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=5.0' | ||
- name: espressif/tinyusb | ||
registry_url: https://components.espressif.com/ | ||
require: public | ||
version: '>=0.14.2' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 1.4.4 | ||
espressif/libsodium: | ||
component_hash: f6e982479a2389cb6868e8fb761cf23aba6c355a8090b3e906299807775f58a3 | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=4.2' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 1.0.20~1 | ||
espressif/nghttp: | ||
component_hash: 5e55c2fc982f7ddd257818be86f50d60705f3fd3a39d709c399434e81d458e1e | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=5.0' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
version: 1.58.0 | ||
espressif/tinyusb: | ||
component_hash: 256fd8aee92ae9f1014538b8601508907a2da386b64f6d42f35a67f9288d1b20 | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=5.0' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
targets: | ||
- esp32s2 | ||
- esp32s3 | ||
- esp32p4 | ||
version: 0.15.0~9 | ||
espressif/usb_host_msc: | ||
component_hash: fb036253308af19de381558560f3a57ead7d2139cf5212b684a408caeb7753cb | ||
dependencies: | ||
- name: idf | ||
require: private | ||
version: '>=4.4.1' | ||
source: | ||
service_url: https://api.components.espressif.com/ | ||
registry_url: https://components.espressif.com/ | ||
type: service | ||
targets: | ||
- esp32s2 | ||
- esp32s3 | ||
- esp32p4 | ||
version: 1.1.2 | ||
idf: | ||
component_hash: null | ||
source: | ||
type: idf | ||
version: 5.2.2 | ||
manifest_hash: a71d5a8d6dfacd88754066af10bbd322320a68f03e2842b3633eb0f7b4644801 | ||
direct_dependencies: | ||
- espressif/button | ||
- espressif/cbor | ||
- espressif/cmake_utilities | ||
- espressif/esp-dsp | ||
- espressif/esp32-camera | ||
- espressif/esp_lcd_touch | ||
- espressif/esp_lcd_touch_ft5x06 | ||
- espressif/esp_tinyusb | ||
- espressif/libsodium | ||
- espressif/nghttp | ||
- espressif/tinyusb | ||
- espressif/usb_host_msc | ||
- idf | ||
manifest_hash: f87516193b33af3806bb180876292cbd0a4407775edbdef8169afdad9f537888 | ||
target: esp32s3 | ||
version: 1.0.0 | ||
version: 2.0.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,8 @@ gui_activity_t* make_uninitialised_settings_activity(void); | |
gui_activity_t* make_locked_settings_activity(void); | ||
gui_activity_t* make_unlocked_settings_activity(void); | ||
|
||
gui_activity_t* make_custom_theme_activity(gui_view_node_t** red_textbox, gui_view_node_t** green_textbox, gui_view_node_t** blue_textbox); | ||
|
||
gui_activity_t* make_wallet_settings_activity(void); | ||
gui_activity_t* make_device_settings_activity(void); | ||
gui_activity_t* make_usbstorage_settings_activity(bool unlocked); | ||
|
@@ -1823,7 +1825,7 @@ static void update_home_screen_item_highlight_color(gui_view_node_t* item) | |
static void handle_display_theme(void) | ||
{ | ||
static const char* THEME_NAMES[GUI_NUM_DISPLAY_THEMES] | ||
= { "Jade Green", "Bitcoin Orange", "Liquid Blue", "Cypherpunk Black", "Open-Source Opal" }; | ||
= { "Jade Green", "Bitcoin Orange", "Liquid Blue", "Cypherpunk Black", "Open-Source Opal", "Custom Theme" }; | ||
JADE_ASSERT(GUI_NUM_DISPLAY_THEMES < GUI_FLAGS_THEMES_MASK); | ||
|
||
const uint8_t initial_gui_flags = storage_get_gui_flags(); | ||
|
@@ -1876,6 +1878,86 @@ static void handle_display_theme(void) | |
} | ||
} | ||
|
||
|
||
|
||
void generate_color_string(char* buffer, size_t size, const char* color_name, int color_value) { | ||
snprintf(buffer, size, "%s{%d}", color_name, color_value); | ||
} | ||
|
||
void handle_color_activity(const char* color_name, int* color, gui_view_node_t* color_text, gui_activity_t* parent_act) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert comments as above |
||
gui_view_node_t* color_c_text = NULL; | ||
char color_str[20]; | ||
generate_color_string(color_str, sizeof(color_str), color_name, *color); | ||
|
||
gui_activity_t* act = make_carousel_activity(color_name, NULL, &color_c_text); | ||
gui_update_text(color_c_text, color_str); | ||
gui_set_current_activity(act); | ||
|
||
int32_t ev_id; | ||
while (gui_activity_wait_event(act, GUI_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0)) { | ||
if (ev_id == GUI_WHEEL_LEFT_EVENT) { | ||
*color = (*color - 8 + 256) % 256; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe have a 'const uint16_t limit = UINT8_MAX + 1' rather than 256 or a #define ? |
||
} else if (ev_id == GUI_WHEEL_RIGHT_EVENT) { | ||
*color = (*color + 8) % 256; | ||
} else if (ev_id == gui_get_click_event()) { | ||
break; | ||
} | ||
|
||
// Update color string and repaint | ||
generate_color_string(color_str, sizeof(color_str), color_name, *color); | ||
gui_update_text(color_c_text, color_str); | ||
gui_repaint(color_c_text->parent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gui_repaint() shouldn't be needed - it should do this itself. |
||
} | ||
|
||
// Update the original color text and return to the main activity | ||
gui_update_text(color_text, color_str); | ||
gui_set_current_activity(parent_act); | ||
} | ||
|
||
// Main custom theme handler | ||
static void handle_custom_theme(void) { | ||
gui_view_node_t* red_text = NULL; | ||
gui_view_node_t* green_text = NULL; | ||
gui_view_node_t* blue_text = NULL; | ||
|
||
int red = 0, green = 0, blue = 0; | ||
char red_text_str[20], green_text_str[20], blue_text_str[20]; | ||
|
||
generate_color_string(red_text_str, sizeof(red_text_str), "Red", red); | ||
generate_color_string(green_text_str, sizeof(green_text_str), "Green", green); | ||
generate_color_string(blue_text_str, sizeof(blue_text_str), "Blue", blue); | ||
|
||
gui_activity_t* act = make_custom_theme_activity(&red_text, &green_text, &blue_text); | ||
int32_t ev_id; | ||
|
||
while (true) { | ||
gui_set_current_activity(act); | ||
bool ret = gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0); | ||
if (ret) { | ||
if (ev_id == BTN_THEME_SAVE) { | ||
// Save the current color combination as the custom theme color | ||
CUSTOM_THEME_COLOR = (red << 16) | (green << 8) | blue; | ||
break; | ||
} else if (ev_id == BTN_SETTINGS_CUSTOM_THEME_EXIT) { | ||
// Exit the custom theme screen | ||
break; | ||
} else if (ev_id == BTN_COLOR_RED) { | ||
// Handle red color adjustment | ||
handle_color_activity("Red", &red, red_text, act); | ||
} else if (ev_id == BTN_COLOR_GREEN) { | ||
// Handle green color adjustment | ||
handle_color_activity("Green", &green, green_text, act); | ||
} else if (ev_id == BTN_COLOR_BLUE) { | ||
// Handle blue color adjustment | ||
handle_color_activity("Blue", &blue, blue_text, act); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
static void handle_flip_orientation(void) | ||
{ | ||
const uint8_t initial_gui_flags = storage_get_gui_flags(); | ||
|
@@ -2191,6 +2273,10 @@ static void handle_settings(const bool startup_menu) | |
// Change to 'Device' menu | ||
act = make_display_settings_activity(); | ||
break; | ||
case BTN_SETTINGS_CREATE_CUSTOM_THEME: | ||
// Change to 'Create Custom Theme' menu | ||
handle_custom_theme(); | ||
break; | ||
|
||
case BTN_SETTINGS_AUTHENTICATION: | ||
case BTN_SETTINGS_OTP_EXIT: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually 'const' int params where possible.
We usually JADE_ASSERT pointers and sizes/length params to functions.
We usually JADE_ASSERT the result of snprintf calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotchya! will do. I will look for other places in the code to use JADE_ASSERT as well.