From 53d8e98b14cbb43cc83c6375500a5f054c300609 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 13:18:18 +0100 Subject: [PATCH 01/29] First draft of an OnboardingApp --- firmware/src/apps/apps.cpp | 39 +++++++++ firmware/src/apps/apps.h | 7 +- firmware/src/apps/onboarding.cpp | 144 +++++++++++++++++++++++++++++++ firmware/src/apps/onboarding.h | 36 ++++++++ firmware/src/display_task.cpp | 50 +++++------ 5 files changed, 251 insertions(+), 25 deletions(-) create mode 100644 firmware/src/apps/onboarding.cpp create mode 100644 firmware/src/apps/onboarding.h diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index dc759ff0..e0b55b72 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -1,6 +1,7 @@ #pragma once #include "apps.h" #include "menu.h" +#include "onboarding.h" #include "settings.h" #include @@ -132,6 +133,44 @@ void Apps::reload(cJSON *apps_) cJSON_Delete(apps_); } +void Apps::createOnboarding() +{ + clear(); + + OnboardingApp *onboarding_app = new OnboardingApp(this->spr_); + uint16_t app_position = 0; + + onboarding_app->add_item( + app_position, + OnboardingItem{ + "SMART KNOB", + "DEV KIT V0.1", + 1, + spr_->color565(255, 255, 255), + nullptr, + nullptr, + "ROTATE TO START", + }); + + app_position++; + + onboarding_app->add_item( + app_position, + OnboardingItem{ + "HOME ASSISTANT", + "INTEGRATION", + 1, + spr_->color565(255, 255, 255), + nullptr, + nullptr, + "PRESS TO CONTINUE", + }); + + add(0, onboarding_app); + + // setActive(0); +} + void Apps::updateMenu() { // re - generate new menu based on loaded apps diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index db45db01..278688c6 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -11,11 +11,14 @@ #include "climate.h" #include "light_dimmer.h" #include "light_switch.h" -#include "menu.h" #include "music.h" #include "settings.h" #include "stopwatch.h" +// include all "menu" apps +#include "menu.h" +#include "onboarding.h" + // TODO: generate menu based on items in the map class Apps { @@ -31,7 +34,9 @@ class Apps void setSprite(TFT_eSprite *spr_); void loadApp(uint8_t position, std::string app_slug, std::string app_id, std::string friendly_name); void updateMenu(); + void reload(cJSON *apps_); + void createOnboarding(); private: QueueHandle_t mutex; diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp new file mode 100644 index 00000000..f79d4cda --- /dev/null +++ b/firmware/src/apps/onboarding.cpp @@ -0,0 +1,144 @@ +#include "onboarding.h" + +OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) +{ + // sprintf(room, "%s", ""); + + motor_config = PB_SmartKnobConfig{ + 0, + 0, + 0, + 0, + -1, // max position < min position indicates no bounds + 25 * PI / 180, + 2, + 1, + 0.55, + "SKDEMO_Menu", // TODO: clean this + 0, + {}, + 0, + 20, + }; +} + +EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) +{ + // TODO: cache menu size + + int32_t position_for_onboarding_calc = state.current_position; + + // needed to next reload of App + motor_config.position_nonce = position_for_onboarding_calc; + motor_config.position = position_for_onboarding_calc; + + if (state.current_position < 0) + { + position_for_onboarding_calc = items.size() * 10000 + state.current_position; + } + + current_onboarding_position = position_for_onboarding_calc % items.size(); + + return EntityStateUpdate{}; +} + +void OnboardingApp::updateStateFromSystem(AppState state) {} + +uint8_t OnboardingApp::navigationNext() +{ + return current_onboarding_position + 1; // +1 to shift from 0 position which is menu itself +} + +TFT_eSprite *OnboardingApp::render() +{ + OnboardingItem current_item = find_item(current_onboarding_position); + OnboardingItem prev_item; + OnboardingItem next_item; + if (current_onboarding_position == 0) + { + // prev_item = find_item(items.size() - 1); + next_item = find_item(current_onboarding_position + 1); + } + else if (current_onboarding_position == items.size() - 1) + { + prev_item = find_item(current_onboarding_position - 1); + // next_item = find_item(0); + } + else + { + prev_item = find_item(current_onboarding_position - 1); + next_item = find_item(current_onboarding_position + 1); + } + render_onboarding_screen(current_item, prev_item, next_item); + return this->spr_; +} + +void OnboardingApp::add_item(uint8_t id, OnboardingItem item) +{ + items[id] = item; + onboarding_items_count++; +} + +// TODO: add protection, could cause panic +OnboardingItem OnboardingApp::find_item(uint8_t id) +{ + return (*items.find(id)).second; +} + +void OnboardingApp::render_onboarding_screen(OnboardingItem current, OnboardingItem prev, OnboardingItem next) +{ + uint32_t color_active = current.color; + uint32_t color_inactive = spr_->color565(150, 150, 150); + uint32_t label_color = color_inactive; + uint32_t background = spr_->color565(0, 0, 0); + + uint16_t center_h = TFT_WIDTH / 2; + uint16_t center_v = TFT_WIDTH / 2; + + int8_t screen_name_label_w = 100; + int8_t screen_name_label_h = spr_->fontHeight(1); + int8_t label_vertical_offset = 25; + + uint8_t icon_size_active = 80; + uint8_t icon_size_inactive = 40; + + spr_->setTextDatum(CC_DATUM); + spr_->setTextSize(1); + spr_->setFreeFont(&NDS1210pt7b); + + // spr_->fillRect(center_h - room_lable_w / 2, label_vertical_offset, room_lable_w, room_lable_h + 1, label_color); // +1 for height to draw circle right + // spr_->fillCircle(center_h - room_lable_w / 2, label_vertical_offset + room_lable_h / 2, room_lable_h / 2, label_color); + // spr_->fillCircle(center_h + room_lable_w / 2, label_vertical_offset + room_lable_h / 2, room_lable_h / 2, label_color); + + if (current.big_icon == nullptr) + { + if (current.small_icon == nullptr) + { + spr_->setTextColor(color_active); + spr_->drawString(current.screen_name, center_v, center_h - screen_name_label_h * 2, 1); + spr_->drawString(current.screen_description, center_v, center_h - screen_name_label_h, 1); + + spr_->setTextColor(spr_->color565(128, 255, 80)); + spr_->drawString(current.call_to_action, center_v, center_v + icon_size_active / 2, 1); + } + else + { + spr_->setTextColor(color_active); + spr_->drawString(current.screen_name, center_v, label_vertical_offset + screen_name_label_h / 2 - 1, 1); + + spr_->setTextColor(spr_->color565(128, 255, 80)); + spr_->drawString(current.call_to_action, center_v, center_v + icon_size_active / 2 + 30, 1); + } + } + + // spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); + + // spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current.big_icon, icon_size_active, icon_size_active, color_active, background); + // ESP_LOGD("menu.cpp", "%s", current.screen_name); + + // left one + // spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + + // right one + // spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); +}; \ No newline at end of file diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h new file mode 100644 index 00000000..99baaf40 --- /dev/null +++ b/firmware/src/apps/onboarding.h @@ -0,0 +1,36 @@ +#pragma once + +#include "app.h" +#include "font/NDS1210pt7b.h" + +#include + +struct OnboardingItem +{ + const char *screen_name; + const char *screen_description; + uint16_t app_id; + uint32_t color; + const unsigned char *small_icon; + const unsigned char *big_icon; + const char *call_to_action; +}; + +class OnboardingApp : public App +{ +public: + OnboardingApp(TFT_eSprite *spr_); + TFT_eSprite *render(); + EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); + void updateStateFromSystem(AppState state); + uint8_t navigationNext(); + void add_item(uint8_t id, OnboardingItem item); + OnboardingItem find_item(uint8_t id); + +private: + std::map items; + uint8_t onboarding_items_count = 0; + uint8_t current_onboarding_position = 0; + + void render_onboarding_screen(OnboardingItem current, OnboardingItem prev, OnboardingItem next); +}; diff --git a/firmware/src/display_task.cpp b/firmware/src/display_task.cpp index df0fbdfa..8d0cd0d5 100644 --- a/firmware/src/display_task.cpp +++ b/firmware/src/display_task.cpp @@ -56,43 +56,45 @@ void DisplayTask::run() } spr_.setTextColor(0xFFFF, TFT_BLACK); - std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; - // std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch-office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"}]"; + // std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; + // // std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch-office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"}]"; - cJSON *json_root = cJSON_Parse(apps_config.c_str()); + // cJSON *json_root = cJSON_Parse(apps_config.c_str()); - if (json_root == NULL) - { - ESP_LOGE("display_task.cpp", "failed to parse JSON"); - } + // if (json_root == NULL) + // { + // ESP_LOGE("display_task.cpp", "failed to parse JSON"); + // } apps.setSprite(&spr_); - cJSON *json_app = NULL; + // cJSON *json_app = NULL; - uint16_t app_position = 1; + // uint16_t app_position = 1; - cJSON_ArrayForEach(json_app, json_root) - { - cJSON *json_app_slug = cJSON_GetObjectItemCaseSensitive(json_app, "app_slug"); - cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); - cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); - snprintf(buf_, sizeof(buf_), "fromJSON > app_slug=%s", json_app_slug->valuestring); - log(buf_); - // ESP_LOGD("display_task.cpp", "%s", buf_); + // cJSON_ArrayForEach(json_app, json_root) + // { + // cJSON *json_app_slug = cJSON_GetObjectItemCaseSensitive(json_app, "app_slug"); + // cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); + // cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); + // snprintf(buf_, sizeof(buf_), "fromJSON > app_slug=%s", json_app_slug->valuestring); + // log(buf_); + // // ESP_LOGD("display_task.cpp", "%s", buf_); - apps.loadApp(app_position, std::string(json_app_slug->valuestring), std::string(json_app_id->valuestring), json_friendly_name->valuestring); + // apps.loadApp(app_position, std::string(json_app_slug->valuestring), std::string(json_app_id->valuestring), json_friendly_name->valuestring); - app_position++; - } + // app_position++; + // } - cJSON_Delete(json_root); + // cJSON_Delete(json_root); - SettingsApp *settings_app = new SettingsApp(&spr_); - apps.add(app_position, settings_app); + // SettingsApp *settings_app = new SettingsApp(&spr_); + // apps.add(app_position, settings_app); // generate menu from apps list - apps.updateMenu(); + // apps.updateMenu(); + + apps.createOnboarding(); AppState app_state; From 3b8ea2923565bb7367df41ecae77ddc593d96621 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 14:14:43 +0100 Subject: [PATCH 02/29] Added HASS screen and WiFi screen. Support for "small" icon on onboarding screens. --- firmware/src/apps/apps.cpp | 26 +++++++++++++-- firmware/src/apps/onboarding.cpp | 56 ++++++++++++++++++++++++-------- firmware/src/apps/onboarding.h | 4 ++- 3 files changed, 69 insertions(+), 17 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index e0b55b72..b303dfee 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -143,12 +143,14 @@ void Apps::createOnboarding() onboarding_app->add_item( app_position, OnboardingItem{ + 1, "SMART KNOB", "DEV KIT V0.1", - 1, spr_->color565(255, 255, 255), nullptr, + spr_->color565(255, 255, 255), nullptr, + spr_->color565(255, 255, 255), "ROTATE TO START", }); @@ -157,15 +159,33 @@ void Apps::createOnboarding() onboarding_app->add_item( app_position, OnboardingItem{ + 2, "HOME ASSISTANT", "INTEGRATION", - 1, spr_->color565(255, 255, 255), + home_assistant_80, + spr_->color565(17, 189, 242), nullptr, - nullptr, + spr_->color565(255, 255, 255), "PRESS TO CONTINUE", }); + app_position++; + + onboarding_app->add_item( + app_position, + OnboardingItem{ + 3, + "", + "WIFI", + spr_->color565(255, 255, 255), + wifi_40, + spr_->color565(255, 255, 255), + nullptr, + spr_->color565(255, 255, 255), + "PRESS TO CONFIGURE", + }); + add(0, onboarding_app); // setActive(0); diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index f79d4cda..fb7f5830 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -9,12 +9,12 @@ OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) 0, 0, 0, - -1, // max position < min position indicates no bounds - 25 * PI / 180, - 2, + 0, // max position < min position indicates no bounds + 60 * PI / 180, + 1, 1, 0.55, - "SKDEMO_Menu", // TODO: clean this + "SKDEMO_Onboarding", // TODO: clean this 0, {}, 0, @@ -77,6 +77,7 @@ void OnboardingApp::add_item(uint8_t id, OnboardingItem item) { items[id] = item; onboarding_items_count++; + motor_config.max_position = onboarding_items_count; } // TODO: add protection, could cause panic @@ -93,14 +94,18 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current, OnboardingI uint32_t background = spr_->color565(0, 0, 0); uint16_t center_h = TFT_WIDTH / 2; - uint16_t center_v = TFT_WIDTH / 2; + uint16_t center_w = TFT_WIDTH / 2; + + uint16_t screen_radius = TFT_WIDTH / 2; - int8_t screen_name_label_w = 100; + // int8_t screen_name_label_w = 100; int8_t screen_name_label_h = spr_->fontHeight(1); int8_t label_vertical_offset = 25; - uint8_t icon_size_active = 80; - uint8_t icon_size_inactive = 40; + int8_t call_to_action_label_h = spr_->fontHeight(1); + + uint8_t icon_size_big = 80; // TODO MAKE BIGGER + uint8_t icon_size_small = 80; spr_->setTextDatum(CC_DATUM); spr_->setTextSize(1); @@ -115,20 +120,45 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current, OnboardingI if (current.small_icon == nullptr) { spr_->setTextColor(color_active); - spr_->drawString(current.screen_name, center_v, center_h - screen_name_label_h * 2, 1); - spr_->drawString(current.screen_description, center_v, center_h - screen_name_label_h, 1); + spr_->drawString(current.screen_name, center_w, center_h - screen_name_label_h * 2, 1); + spr_->drawString(current.screen_description, center_w, center_h - screen_name_label_h, 1); spr_->setTextColor(spr_->color565(128, 255, 80)); - spr_->drawString(current.call_to_action, center_v, center_v + icon_size_active / 2, 1); + spr_->drawString(current.call_to_action, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); } else { spr_->setTextColor(color_active); - spr_->drawString(current.screen_name, center_v, label_vertical_offset + screen_name_label_h / 2 - 1, 1); + spr_->drawString(current.screen_name, center_w, screen_name_label_h * 2, 1); + spr_->drawString(current.screen_description, center_w, screen_name_label_h * 3, 1); + + spr_->drawBitmap(center_w - icon_size_big / 2, center_h - icon_size_big / 2 + 6, current.small_icon, icon_size_big, icon_size_big, current.color_small_icon, background); spr_->setTextColor(spr_->color565(128, 255, 80)); - spr_->drawString(current.call_to_action, center_v, center_v + icon_size_active / 2 + 30, 1); + spr_->drawString(current.call_to_action, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); + } + } + + uint32_t menu_item_color; + uint8_t menu_item_diameter = 6; + uint8_t position_circle_radius = screen_radius - menu_item_diameter; // the radius of the circle where you want the dots to lay. + float degree_per_item = 8 * PI / 180; // the degree (angle) between two points in radian + float center_point_degree = 270 * PI / 180; // + float menu_starting_angle = center_point_degree - ((onboarding_items_count * degree_per_item) / 2); + + for (uint16_t i = 0; i < onboarding_items_count; i++) + { + // draw a circle + if (current_onboarding_position == i) + { + menu_item_color = TFT_GREENYELLOW; + } + else + { + menu_item_color = TFT_WHITE; } + // polar coordinates + spr_->fillCircle(screen_radius + (position_circle_radius * cosf(menu_starting_angle + degree_per_item * i)), screen_radius - position_circle_radius * sinf(menu_starting_angle + degree_per_item * i), menu_item_diameter / 2, menu_item_color); } // spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h index 99baaf40..b37aeac9 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding.h @@ -7,12 +7,14 @@ struct OnboardingItem { + uint16_t app_id; const char *screen_name; const char *screen_description; - uint16_t app_id; uint32_t color; const unsigned char *small_icon; + uint16_t color_small_icon; const unsigned char *big_icon; + uint16_t color_big_icon; const char *call_to_action; }; From 6e147a20137424ad80d5a07af8bfab42885050d6 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 14:57:19 +0100 Subject: [PATCH 03/29] Removed prev and next item on onboarding left behind from menu implementation. --- firmware/src/apps/onboarding.cpp | 21 ++------------------- firmware/src/apps/onboarding.h | 2 +- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index fb7f5830..52a74781 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -52,24 +52,7 @@ uint8_t OnboardingApp::navigationNext() TFT_eSprite *OnboardingApp::render() { OnboardingItem current_item = find_item(current_onboarding_position); - OnboardingItem prev_item; - OnboardingItem next_item; - if (current_onboarding_position == 0) - { - // prev_item = find_item(items.size() - 1); - next_item = find_item(current_onboarding_position + 1); - } - else if (current_onboarding_position == items.size() - 1) - { - prev_item = find_item(current_onboarding_position - 1); - // next_item = find_item(0); - } - else - { - prev_item = find_item(current_onboarding_position - 1); - next_item = find_item(current_onboarding_position + 1); - } - render_onboarding_screen(current_item, prev_item, next_item); + render_onboarding_screen(current_item); return this->spr_; } @@ -86,7 +69,7 @@ OnboardingItem OnboardingApp::find_item(uint8_t id) return (*items.find(id)).second; } -void OnboardingApp::render_onboarding_screen(OnboardingItem current, OnboardingItem prev, OnboardingItem next) +void OnboardingApp::render_onboarding_screen(OnboardingItem current) { uint32_t color_active = current.color; uint32_t color_inactive = spr_->color565(150, 150, 150); diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h index b37aeac9..50adb4cb 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding.h @@ -34,5 +34,5 @@ class OnboardingApp : public App uint8_t onboarding_items_count = 0; uint8_t current_onboarding_position = 0; - void render_onboarding_screen(OnboardingItem current, OnboardingItem prev, OnboardingItem next); + void render_onboarding_screen(OnboardingItem current); }; From 0b5ed9af834d4881b14ccf462e934490ad786f89 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 14:57:54 +0100 Subject: [PATCH 04/29] Added new wifi_conn icon and demo icon --- firmware/src/apps/apps.cpp | 36 +++++++- firmware/src/apps/icons.h | 164 +++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+), 2 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index b303dfee..d4ea7a91 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -176,16 +176,48 @@ void Apps::createOnboarding() app_position, OnboardingItem{ 3, - "", "WIFI", + "", spr_->color565(255, 255, 255), - wifi_40, + wifi_conn_80, spr_->color565(255, 255, 255), nullptr, spr_->color565(255, 255, 255), "PRESS TO CONFIGURE", }); + app_position++; + + onboarding_app->add_item( + app_position, + OnboardingItem{ + 4, + "DEMO MODE", + "", + spr_->color565(255, 255, 255), + demo_80, + spr_->color565(255, 255, 255), + nullptr, + spr_->color565(255, 255, 255), + "PRESS TO START", + }); + + app_position++; + + onboarding_app->add_item( + app_position, + OnboardingItem{ + 5, + "FIRMWARE: 0.1b", + "HARDWARE: DEVKIT V0.1", + spr_->color565(255, 255, 255), + nullptr, + spr_->color565(255, 255, 255), + nullptr, + spr_->color565(255, 255, 255), + "SEEDLABS.IT ®", + }); + add(0, onboarding_app); // setActive(0); diff --git a/firmware/src/apps/icons.h b/firmware/src/apps/icons.h index d32c2dc8..a507ae1e 100644 --- a/firmware/src/apps/icons.h +++ b/firmware/src/apps/icons.h @@ -664,6 +664,170 @@ PROGMEM const unsigned char wifi_40[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +PROGMEM const unsigned char wifi_conn_80[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x05, 0xff, 0xff, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, + 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, + 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, + 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, + 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, + 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, + 0x1f, 0xff, 0xff, 0xff, 0x00, 0x01, 0x7f, 0xff, 0xff, 0xf8, + 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, + 0x7f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xfe, + 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, + 0x7f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xfe, + 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfc, + 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xf8, + 0x0f, 0xfe, 0x00, 0x00, 0x2f, 0xf4, 0x00, 0x00, 0x7f, 0xf0, + 0x07, 0xfc, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x3f, 0xe0, + 0x03, 0xf8, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x1f, 0xc0, + 0x01, 0xe0, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x07, 0x80, + 0x00, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x03, 0x00, + 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, + 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, + 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0xff, 0xf4, 0x17, 0xff, 0xfe, 0x00, 0x00, + 0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0xff, 0xfc, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, + 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, + 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +PROGMEM const unsigned char demo_80[] = { + 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, + 0x01, 0xf8, 0x00, 0xff, 0xff, 0x80, 0x02, 0x80, 0x00, + 0x07, 0xfe, 0x00, 0x7f, 0xff, 0x00, 0x1f, 0xf0, 0x00, + 0x1f, 0xff, 0x00, 0x3f, 0xfe, 0x00, 0x7f, 0xf8, 0x00, + 0x3f, 0xff, 0x80, 0x1f, 0xfc, 0x00, 0xff, 0xfc, 0x00, + 0x7f, 0xff, 0xc0, 0x0f, 0xf8, 0x00, 0xff, 0xfe, 0x00, + 0x7f, 0xff, 0xc0, 0x01, 0x40, 0x01, 0xff, 0xff, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, + 0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, + 0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, + 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, + 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, + 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, + 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x00, + 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, + 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, + 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x05, 0x40, 0x00, + 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x15, 0x50, 0x00, + 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x2a, 0xa8, 0x00, + 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, + 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x01, 0x55, 0x54, 0x00, + 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, + 0xff, 0xff, 0xf0, 0x00, 0x00, 0x02, 0xaa, 0xaa, 0x80, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, + 0xff, 0xff, 0xf0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, + 0xff, 0xff, 0xe0, 0x00, 0x00, 0x02, 0xaa, 0xaa, 0x00, + 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, + 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x01, 0x55, 0x54, 0x00, + 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x55, 0x54, 0x00, + 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xa8, 0x00, + 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x15, 0x50, 0x00, + 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + // 75 174 PROGMEM const unsigned char omnitrix_char_1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, From 290e2e356c510ac4a7fe39fb51514b14f0d239f2 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 15:00:25 +0100 Subject: [PATCH 05/29] Prevent onboarding from going back to first "page" when turning knob to the right on last "page" --- firmware/src/apps/onboarding.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 52a74781..6834dbd6 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -60,7 +60,7 @@ void OnboardingApp::add_item(uint8_t id, OnboardingItem item) { items[id] = item; onboarding_items_count++; - motor_config.max_position = onboarding_items_count; + motor_config.max_position = onboarding_items_count - 1; } // TODO: add protection, could cause panic @@ -94,10 +94,6 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current) spr_->setTextSize(1); spr_->setFreeFont(&NDS1210pt7b); - // spr_->fillRect(center_h - room_lable_w / 2, label_vertical_offset, room_lable_w, room_lable_h + 1, label_color); // +1 for height to draw circle right - // spr_->fillCircle(center_h - room_lable_w / 2, label_vertical_offset + room_lable_h / 2, room_lable_h / 2, label_color); - // spr_->fillCircle(center_h + room_lable_w / 2, label_vertical_offset + room_lable_h / 2, room_lable_h / 2, label_color); - if (current.big_icon == nullptr) { if (current.small_icon == nullptr) @@ -143,15 +139,4 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current) // polar coordinates spr_->fillCircle(screen_radius + (position_circle_radius * cosf(menu_starting_angle + degree_per_item * i)), screen_radius - position_circle_radius * sinf(menu_starting_angle + degree_per_item * i), menu_item_diameter / 2, menu_item_color); } - - // spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); - - // spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current.big_icon, icon_size_active, icon_size_active, color_active, background); - // ESP_LOGD("menu.cpp", "%s", current.screen_name); - - // left one - // spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); - - // right one - // spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); }; \ No newline at end of file From 4e2fc86aeab1ed924fe0c4de52de6eacec9d2d3a Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 15:24:09 +0100 Subject: [PATCH 06/29] Added TextItem to simplify having different colors on text --- firmware/src/apps/apps.cpp | 57 +++++++++++++++++++++++--------- firmware/src/apps/onboarding.cpp | 10 +++--- firmware/src/apps/onboarding.h | 10 ++++-- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index d4ea7a91..aad163b2 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -144,9 +144,14 @@ void Apps::createOnboarding() app_position, OnboardingItem{ 1, - "SMART KNOB", - "DEV KIT V0.1", - spr_->color565(255, 255, 255), + TextItem{ + "SMART KNOB", + spr_->color565(255, 255, 255), + }, + TextItem{ + "DEV KIT V0.1", + spr_->color565(255, 255, 255), + }, nullptr, spr_->color565(255, 255, 255), nullptr, @@ -160,9 +165,14 @@ void Apps::createOnboarding() app_position, OnboardingItem{ 2, - "HOME ASSISTANT", - "INTEGRATION", - spr_->color565(255, 255, 255), + TextItem{ + "HOME ASSISTANT", + spr_->color565(255, 255, 255), + }, + TextItem{ + "INTEGRATION", + spr_->color565(255, 255, 255), + }, home_assistant_80, spr_->color565(17, 189, 242), nullptr, @@ -176,9 +186,14 @@ void Apps::createOnboarding() app_position, OnboardingItem{ 3, - "WIFI", - "", - spr_->color565(255, 255, 255), + TextItem{ + "WIFI", + spr_->color565(255, 255, 255), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, wifi_conn_80, spr_->color565(255, 255, 255), nullptr, @@ -192,9 +207,14 @@ void Apps::createOnboarding() app_position, OnboardingItem{ 4, - "DEMO MODE", - "", - spr_->color565(255, 255, 255), + TextItem{ + "DEMO MODE", + spr_->color565(255, 255, 255), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, demo_80, spr_->color565(255, 255, 255), nullptr, @@ -208,9 +228,14 @@ void Apps::createOnboarding() app_position, OnboardingItem{ 5, - "FIRMWARE: 0.1b", - "HARDWARE: DEVKIT V0.1", - spr_->color565(255, 255, 255), + TextItem{ + "FIRMWARE 0.1b", + spr_->color565(255, 255, 255), + }, + TextItem{ + "HARDWARE: DEVKIT V0.1", + spr_->color565(255, 255, 255), + }, nullptr, spr_->color565(255, 255, 255), nullptr, @@ -220,7 +245,7 @@ void Apps::createOnboarding() add(0, onboarding_app); - // setActive(0); + setActive(0); } void Apps::updateMenu() diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 6834dbd6..220ec9ae 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -71,7 +71,7 @@ OnboardingItem OnboardingApp::find_item(uint8_t id) void OnboardingApp::render_onboarding_screen(OnboardingItem current) { - uint32_t color_active = current.color; + uint32_t color_active = current.screen_name.color; uint32_t color_inactive = spr_->color565(150, 150, 150); uint32_t label_color = color_inactive; uint32_t background = spr_->color565(0, 0, 0); @@ -99,8 +99,8 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current) if (current.small_icon == nullptr) { spr_->setTextColor(color_active); - spr_->drawString(current.screen_name, center_w, center_h - screen_name_label_h * 2, 1); - spr_->drawString(current.screen_description, center_w, center_h - screen_name_label_h, 1); + spr_->drawString(current.screen_name.text, center_w, center_h - screen_name_label_h * 2, 1); + spr_->drawString(current.screen_description.text, center_w, center_h - screen_name_label_h, 1); spr_->setTextColor(spr_->color565(128, 255, 80)); spr_->drawString(current.call_to_action, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); @@ -108,8 +108,8 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current) else { spr_->setTextColor(color_active); - spr_->drawString(current.screen_name, center_w, screen_name_label_h * 2, 1); - spr_->drawString(current.screen_description, center_w, screen_name_label_h * 3, 1); + spr_->drawString(current.screen_name.text, center_w, screen_name_label_h * 2, 1); + spr_->drawString(current.screen_description.text, center_w, screen_name_label_h * 3, 1); spr_->drawBitmap(center_w - icon_size_big / 2, center_h - icon_size_big / 2 + 6, current.small_icon, icon_size_big, icon_size_big, current.color_small_icon, background); diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h index 50adb4cb..452f77ee 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding.h @@ -5,12 +5,16 @@ #include +struct TextItem +{ + const char *text; + uint16_t color; +}; struct OnboardingItem { uint16_t app_id; - const char *screen_name; - const char *screen_description; - uint32_t color; + TextItem screen_name; + TextItem screen_description; const unsigned char *small_icon; uint16_t color_small_icon; const unsigned char *big_icon; From d64ee3853fc093b626713f5f43456e58dbe9e16e Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 15:34:18 +0100 Subject: [PATCH 07/29] Added IconItem --- firmware/src/apps/apps.cpp | 86 ++++++++++++++++++++++---------- firmware/src/apps/onboarding.cpp | 26 +++++----- firmware/src/apps/onboarding.h | 14 ++++-- 3 files changed, 83 insertions(+), 43 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index aad163b2..c7c11b50 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -152,11 +152,18 @@ void Apps::createOnboarding() "DEV KIT V0.1", spr_->color565(255, 255, 255), }, - nullptr, - spr_->color565(255, 255, 255), - nullptr, - spr_->color565(255, 255, 255), - "ROTATE TO START", + TextItem{ + "ROTATE TO START", + spr_->color565(128, 255, 80), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, }); app_position++; @@ -173,11 +180,18 @@ void Apps::createOnboarding() "INTEGRATION", spr_->color565(255, 255, 255), }, - home_assistant_80, - spr_->color565(17, 189, 242), - nullptr, - spr_->color565(255, 255, 255), - "PRESS TO CONTINUE", + TextItem{ + "PRESS TO CONTINUE", + spr_->color565(128, 255, 80), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, + IconItem{ + home_assistant_80, + spr_->color565(17, 189, 242), + }, }); app_position++; @@ -194,11 +208,18 @@ void Apps::createOnboarding() "", spr_->color565(255, 255, 255), }, - wifi_conn_80, - spr_->color565(255, 255, 255), - nullptr, - spr_->color565(255, 255, 255), - "PRESS TO CONFIGURE", + TextItem{ + "PRESS TO CONFIGURE", + spr_->color565(128, 255, 80), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, + IconItem{ + wifi_conn_80, + spr_->color565(255, 255, 255), + }, }); app_position++; @@ -215,11 +236,18 @@ void Apps::createOnboarding() "", spr_->color565(255, 255, 255), }, - demo_80, - spr_->color565(255, 255, 255), - nullptr, - spr_->color565(255, 255, 255), - "PRESS TO START", + TextItem{ + "PRESS TO START", + spr_->color565(128, 255, 80), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, + IconItem{ + demo_80, + spr_->color565(255, 255, 255), + }, }); app_position++; @@ -236,11 +264,19 @@ void Apps::createOnboarding() "HARDWARE: DEVKIT V0.1", spr_->color565(255, 255, 255), }, - nullptr, - spr_->color565(255, 255, 255), - nullptr, - spr_->color565(255, 255, 255), - "SEEDLABS.IT ®", + TextItem{ + "SEEDLABS.IT ®", // TODO "®" doesnt show up + spr_->color565(255, 255, 255), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, + IconItem{ + nullptr, + spr_->color565(255, 255, 255), + }, + }); add(0, onboarding_app); diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 220ec9ae..7d004bab 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -69,9 +69,9 @@ OnboardingItem OnboardingApp::find_item(uint8_t id) return (*items.find(id)).second; } -void OnboardingApp::render_onboarding_screen(OnboardingItem current) +void OnboardingApp::render_onboarding_screen(OnboardingItem item) { - uint32_t color_active = current.screen_name.color; + uint32_t color_active = item.screen_name.color; uint32_t color_inactive = spr_->color565(150, 150, 150); uint32_t label_color = color_inactive; uint32_t background = spr_->color565(0, 0, 0); @@ -94,27 +94,27 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem current) spr_->setTextSize(1); spr_->setFreeFont(&NDS1210pt7b); - if (current.big_icon == nullptr) + if (item.big_icon.icon == nullptr) { - if (current.small_icon == nullptr) + if (item.small_icon.icon == nullptr) { spr_->setTextColor(color_active); - spr_->drawString(current.screen_name.text, center_w, center_h - screen_name_label_h * 2, 1); - spr_->drawString(current.screen_description.text, center_w, center_h - screen_name_label_h, 1); + spr_->drawString(item.screen_name.text, center_w, center_h - screen_name_label_h * 2, 1); + spr_->drawString(item.screen_description.text, center_w, center_h - screen_name_label_h, 1); - spr_->setTextColor(spr_->color565(128, 255, 80)); - spr_->drawString(current.call_to_action, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); + spr_->setTextColor(item.call_to_action.color); + spr_->drawString(item.call_to_action.text, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); } else { spr_->setTextColor(color_active); - spr_->drawString(current.screen_name.text, center_w, screen_name_label_h * 2, 1); - spr_->drawString(current.screen_description.text, center_w, screen_name_label_h * 3, 1); + spr_->drawString(item.screen_name.text, center_w, screen_name_label_h * 2, 1); + spr_->drawString(item.screen_description.text, center_w, screen_name_label_h * 3, 1); - spr_->drawBitmap(center_w - icon_size_big / 2, center_h - icon_size_big / 2 + 6, current.small_icon, icon_size_big, icon_size_big, current.color_small_icon, background); + spr_->drawBitmap(center_w - icon_size_big / 2, center_h - icon_size_big / 2 + 6, item.small_icon.icon, icon_size_big, icon_size_big, item.small_icon.color, background); - spr_->setTextColor(spr_->color565(128, 255, 80)); - spr_->drawString(current.call_to_action, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); + spr_->setTextColor(item.call_to_action.color); + spr_->drawString(item.call_to_action.text, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); } } diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h index 452f77ee..b207b732 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding.h @@ -10,16 +10,20 @@ struct TextItem const char *text; uint16_t color; }; + +struct IconItem +{ + const unsigned char *icon; + uint16_t color; +}; struct OnboardingItem { uint16_t app_id; TextItem screen_name; TextItem screen_description; - const unsigned char *small_icon; - uint16_t color_small_icon; - const unsigned char *big_icon; - uint16_t color_big_icon; - const char *call_to_action; + TextItem call_to_action; + IconItem big_icon; + IconItem small_icon; }; class OnboardingApp : public App From b927e3efff49d8a52c3f58a96b1e36b1caf0eb0f Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 15:49:33 +0100 Subject: [PATCH 08/29] Added some fake apps to "go into" on press of knob from onboarding call to action --- firmware/src/apps/apps.cpp | 9 +++++++++ firmware/src/apps/onboarding.cpp | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index c7c11b50..15e09c2a 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -281,6 +281,15 @@ void Apps::createOnboarding() add(0, onboarding_app); + SettingsApp *app0 = new SettingsApp(this->spr_); + add(1, app0); + + StopwatchApp *app1 = new StopwatchApp(this->spr_, "lol"); + add(2, app1); + + LightDimmerApp *app3 = new LightDimmerApp(this->spr_, "lol", "lol"); + add(3, app3); + setActive(0); } diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 7d004bab..dd77c21f 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -46,7 +46,10 @@ void OnboardingApp::updateStateFromSystem(AppState state) {} uint8_t OnboardingApp::navigationNext() { - return current_onboarding_position + 1; // +1 to shift from 0 position which is menu itself + if (current_onboarding_position >= 1 && current_onboarding_position <= 3) + return current_onboarding_position; + + return 0; // +1 to shift from 0 position which is menu itself } TFT_eSprite *OnboardingApp::render() From 0ccdb37c84e76c45abecebbafb25753238b49efe Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 16:41:49 +0100 Subject: [PATCH 09/29] Added functionality for menu to be connected to specific app id. Wich works well to enable us to have the demo page. --- firmware/src/apps/apps.cpp | 55 +++++++++++-- firmware/src/apps/apps.h | 2 +- firmware/src/apps/menu.cpp | 2 +- firmware/src/apps/onboarding/demo.cpp | 108 ++++++++++++++++++++++++++ firmware/src/apps/onboarding/demo.h | 23 ++++++ 5 files changed, 180 insertions(+), 10 deletions(-) create mode 100644 firmware/src/apps/onboarding/demo.cpp create mode 100644 firmware/src/apps/onboarding/demo.h diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 15e09c2a..0e198b39 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -281,14 +281,53 @@ void Apps::createOnboarding() add(0, onboarding_app); + // APPS FOR OTHER ONBOARDING SCREENS SettingsApp *app0 = new SettingsApp(this->spr_); add(1, app0); - StopwatchApp *app1 = new StopwatchApp(this->spr_, "lol"); + StopwatchApp *app1 = new StopwatchApp(this->spr_, ""); add(2, app1); - LightDimmerApp *app3 = new LightDimmerApp(this->spr_, "lol", "lol"); - add(3, app3); + MenuApp *menu_app = new MenuApp(spr_); + menu_app->add_item( + 0, + MenuItem{ + "SETTINGS", + 4, + spr_->color565(0, 255, 200), + settings_40, + settings_80, + }); + menu_app->add_item( + 1, + MenuItem{ + "STOPWATCH", + 5, + spr_->color565(0, 255, 200), + stopwatch_40, + stopwatch_80, + }); + menu_app->add_item( + 2, + MenuItem{ + "LIGHTDIMMER", + 6, + spr_->color565(0, 255, 200), + light_switch_40, + light_switch_80, + }); + + add(3, menu_app); + + // // APPS FOR DEMO ONBOARDING SCREEN + SettingsApp *app2 = new SettingsApp(this->spr_); + add(4, app2); + + StopwatchApp *app3 = new StopwatchApp(this->spr_, ""); + add(5, app3); + + LightDimmerApp *app4 = new LightDimmerApp(this->spr_, "", "Kitchen"); + add(6, app4); setActive(0); } @@ -405,11 +444,11 @@ PB_SmartKnobConfig Apps::getActiveMotorConfig() return motor_config; } -// App *Apps::find(uint8_t id) -// { -// // TODO: add protection with array size -// return apps[id]; -// } +std::shared_ptr Apps::find(std::string id) +{ + // TODO: add protection with array size + return apps[id]; +} void Apps::lock() { diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index 278688c6..9025a0cf 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -49,7 +49,7 @@ class Apps TFT_eSprite *rendered_spr_; - // App *find(uint8_t id); + std::shared_ptr find(std::string id); void lock(); void unlock(); }; diff --git a/firmware/src/apps/menu.cpp b/firmware/src/apps/menu.cpp index b889ee5d..48653317 100644 --- a/firmware/src/apps/menu.cpp +++ b/firmware/src/apps/menu.cpp @@ -46,7 +46,7 @@ void MenuApp::updateStateFromSystem(AppState state) {} uint8_t MenuApp::navigationNext() { - return current_menu_position + 1; // +1 to shift from 0 position which is menu itself + return find_item(current_menu_position).app_id; } TFT_eSprite *MenuApp::render() diff --git a/firmware/src/apps/onboarding/demo.cpp b/firmware/src/apps/onboarding/demo.cpp new file mode 100644 index 00000000..f6b6b5de --- /dev/null +++ b/firmware/src/apps/onboarding/demo.cpp @@ -0,0 +1,108 @@ +#include "demo.h" + +#include "../settings.h" +#include "semaphore_guard.h" + +DemoApp::DemoApp(TFT_eSprite *spr_) : App(spr_) +{ + mutex_ = xSemaphoreCreateMutex(); + assert(mutex_ != NULL); + + motor_config = PB_SmartKnobConfig{ + 0, + 0, + 0, + 0, + 0, // max position < min position indicates no bounds + 60 * PI / 180, + 1, + 1, + 0.55, + "SKDEMO_Demo", // TODO: clean this + 0, + {}, + 0, + 20, + }; +} + +EntityStateUpdate DemoApp::updateStateFromKnob(PB_SmartKnobState state) +{ +} + +void DemoApp::updateStateFromSystem(AppState state) +{ +} + +uint8_t DemoApp::navigationNext() +{ + return 0; // +1 to shift from 0 position which is menu itself +} + +TFT_eSprite *DemoApp::render() +{ + std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; + + cJSON *json_root = cJSON_Parse(apps_config.c_str()); + + if (json_root == NULL) + { + ESP_LOGE("display_task.cpp", "failed to parse JSON"); + } + + apps->setSprite(spr_); + + cJSON *json_app = NULL; + + uint16_t app_position = 1; + + cJSON_ArrayForEach(json_app, json_root) + { + cJSON *json_app_slug = cJSON_GetObjectItemCaseSensitive(json_app, "app_slug"); + cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); + cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); + + apps->loadApp(app_position, std::string(json_app_slug->valuestring), std::string(json_app_id->valuestring), json_friendly_name->valuestring); + + app_position++; + } + + cJSON_Delete(json_root); + + SettingsApp *settings_app = new SettingsApp(spr_); + apps->add(app_position, settings_app); + + apps->updateMenu(); + + unsigned long last_rendering_ms = millis(); + unsigned long last_fps_check = millis(); + + const uint16_t wanted_fps = 60; + uint16_t fps_counter = 0; + + while (1) + { + + if (millis() - last_rendering_ms > 1000 / wanted_fps) + { + spr_->fillSprite(TFT_BLACK); + apps->renderActive()->pushSprite(0, 0); + + { + SemaphoreGuard lock(mutex_); + // ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, brightness_); + } + last_rendering_ms = millis(); + + fps_counter++; + if (last_fps_check + 1000 < millis()) + { + ESP_LOGD("display_task.cpp", "Screen real FPS %d", fps_counter); + fps_counter = 0; + last_fps_check = millis(); + } + } + + delay(1); + } +} \ No newline at end of file diff --git a/firmware/src/apps/onboarding/demo.h b/firmware/src/apps/onboarding/demo.h new file mode 100644 index 00000000..e8a24371 --- /dev/null +++ b/firmware/src/apps/onboarding/demo.h @@ -0,0 +1,23 @@ +#include "../app.h" + +#include "../apps.h" + +class DemoApp : public App +{ +public: + DemoApp(TFT_eSprite *spr_); + TFT_eSprite *render(); + EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); + void updateStateFromSystem(AppState state); + uint8_t navigationNext(); + std::string getClassName(); + +private: + Apps *apps; + uint8_t demo_apps_count = 0; + uint8_t current_demo_position = 0; + SemaphoreHandle_t mutex_; + + App find(uint8_t id); + void render_demo_screen(); +}; \ No newline at end of file From 1c87c3148a725d11292e1f4d85e524bfdb507dde Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 17:02:06 +0100 Subject: [PATCH 10/29] Cleaned up init of demo menu --- firmware/src/apps/apps.cpp | 94 +++++++++++----------- firmware/src/apps/apps.h | 2 +- firmware/src/apps/onboarding/demo.cpp | 108 -------------------------- firmware/src/apps/onboarding/demo.h | 23 ------ 4 files changed, 49 insertions(+), 178 deletions(-) delete mode 100644 firmware/src/apps/onboarding/demo.cpp delete mode 100644 firmware/src/apps/onboarding/demo.h diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 0e198b39..1ea3f992 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -138,10 +138,9 @@ void Apps::createOnboarding() clear(); OnboardingApp *onboarding_app = new OnboardingApp(this->spr_); - uint16_t app_position = 0; onboarding_app->add_item( - app_position, + 0, OnboardingItem{ 1, TextItem{ @@ -166,10 +165,8 @@ void Apps::createOnboarding() }, }); - app_position++; - onboarding_app->add_item( - app_position, + 1, OnboardingItem{ 2, TextItem{ @@ -194,10 +191,8 @@ void Apps::createOnboarding() }, }); - app_position++; - onboarding_app->add_item( - app_position, + 2, OnboardingItem{ 3, TextItem{ @@ -221,11 +216,8 @@ void Apps::createOnboarding() spr_->color565(255, 255, 255), }, }); - - app_position++; - onboarding_app->add_item( - app_position, + 3, OnboardingItem{ 4, TextItem{ @@ -249,11 +241,8 @@ void Apps::createOnboarding() spr_->color565(255, 255, 255), }, }); - - app_position++; - onboarding_app->add_item( - app_position, + 4, OnboardingItem{ 5, TextItem{ @@ -282,13 +271,17 @@ void Apps::createOnboarding() add(0, onboarding_app); // APPS FOR OTHER ONBOARDING SCREENS - SettingsApp *app0 = new SettingsApp(this->spr_); + SettingsApp *app0 = new SettingsApp(spr_); add(1, app0); - StopwatchApp *app1 = new StopwatchApp(this->spr_, ""); + StopwatchApp *app1 = new StopwatchApp(spr_, ""); add(2, app1); + // FOR DEMO MenuApp *menu_app = new MenuApp(spr_); + SettingsApp *settings_app = new SettingsApp(spr_); + add(4, settings_app); + menu_app->add_item( 0, MenuItem{ @@ -298,36 +291,38 @@ void Apps::createOnboarding() settings_40, settings_80, }); - menu_app->add_item( - 1, - MenuItem{ - "STOPWATCH", - 5, - spr_->color565(0, 255, 200), - stopwatch_40, - stopwatch_80, - }); - menu_app->add_item( - 2, - MenuItem{ - "LIGHTDIMMER", - 6, - spr_->color565(0, 255, 200), - light_switch_40, - light_switch_80, - }); - add(3, menu_app); + std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; + + cJSON *json_root = cJSON_Parse(apps_config.c_str()); + cJSON *json_app = NULL; - // // APPS FOR DEMO ONBOARDING SCREEN - SettingsApp *app2 = new SettingsApp(this->spr_); - add(4, app2); + uint16_t app_position = 5; + uint16_t menu_position = 1; + + cJSON_ArrayForEach(json_app, json_root) + { + cJSON *json_app_slug = cJSON_GetObjectItemCaseSensitive(json_app, "app_slug"); + cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); + cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); - StopwatchApp *app3 = new StopwatchApp(this->spr_, ""); - add(5, app3); + App *app = loadApp(app_position, std::string(json_app_slug->valuestring), std::string(json_app_id->valuestring), json_friendly_name->valuestring); - LightDimmerApp *app4 = new LightDimmerApp(this->spr_, "", "Kitchen"); - add(6, app4); + menu_app->add_item( + menu_position, + MenuItem{ + app->friendly_name, + app_position, + spr_->color565(0, 255, 200), + app->small_icon, + app->big_icon, + }); + + app_position++; + menu_position++; + } + + add(3, menu_app); setActive(0); } @@ -362,12 +357,11 @@ void Apps::updateMenu() } // settings and menu apps kept aside for a reason. We will add them manually later -void Apps::loadApp(uint8_t position, std::string app_slug, std::string app_id, std::string friendly_name) +App *Apps::loadApp(uint8_t position, std::string app_slug, std::string app_id, std::string friendly_name) { if (position < 1) { ESP_LOGE("apps.cpp", "can't load app at %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); - return; } ESP_LOGD("apps.cpp", "loading app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); @@ -376,47 +370,55 @@ void Apps::loadApp(uint8_t position, std::string app_slug, std::string app_id, s ClimateApp *app = new ClimateApp(this->spr_, app_id); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else if (app_slug.compare(APP_SLUG_3D_PRINTER) == 0) { PrinterChamberApp *app = new PrinterChamberApp(this->spr_, app_id); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else if (app_slug.compare(APP_SLUG_BLINDS) == 0) { BlindsApp *app = new BlindsApp(this->spr_, app_id); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else if (app_slug.compare(APP_SLUG_LIGHT_DIMMER) == 0) { LightDimmerApp *app = new LightDimmerApp(this->spr_, app_id, friendly_name); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else if (app_slug.compare(APP_SLUG_LIGHT_SWITCH) == 0) { LightSwitchApp *app = new LightSwitchApp(this->spr_, app_id, friendly_name); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else if (app_slug.compare(APP_SLUG_MUSIC) == 0) { MusicApp *app = new MusicApp(this->spr_, app_id); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else if (app_slug.compare(APP_SLUG_STOPWATCH) == 0) { StopwatchApp *app = new StopwatchApp(this->spr_, app_id); add(position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); + return app; } else { ESP_LOGE("apps.cpp", "can't find app with slug '%s'", app_slug); } + return nullptr; } uint8_t Apps::navigationNext() diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index 9025a0cf..1d91426e 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -32,7 +32,7 @@ class Apps uint8_t navigationNext(); PB_SmartKnobConfig getActiveMotorConfig(); void setSprite(TFT_eSprite *spr_); - void loadApp(uint8_t position, std::string app_slug, std::string app_id, std::string friendly_name); + App *loadApp(uint8_t position, std::string app_slug, std::string app_id, std::string friendly_name); void updateMenu(); void reload(cJSON *apps_); diff --git a/firmware/src/apps/onboarding/demo.cpp b/firmware/src/apps/onboarding/demo.cpp deleted file mode 100644 index f6b6b5de..00000000 --- a/firmware/src/apps/onboarding/demo.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "demo.h" - -#include "../settings.h" -#include "semaphore_guard.h" - -DemoApp::DemoApp(TFT_eSprite *spr_) : App(spr_) -{ - mutex_ = xSemaphoreCreateMutex(); - assert(mutex_ != NULL); - - motor_config = PB_SmartKnobConfig{ - 0, - 0, - 0, - 0, - 0, // max position < min position indicates no bounds - 60 * PI / 180, - 1, - 1, - 0.55, - "SKDEMO_Demo", // TODO: clean this - 0, - {}, - 0, - 20, - }; -} - -EntityStateUpdate DemoApp::updateStateFromKnob(PB_SmartKnobState state) -{ -} - -void DemoApp::updateStateFromSystem(AppState state) -{ -} - -uint8_t DemoApp::navigationNext() -{ - return 0; // +1 to shift from 0 position which is menu itself -} - -TFT_eSprite *DemoApp::render() -{ - std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; - - cJSON *json_root = cJSON_Parse(apps_config.c_str()); - - if (json_root == NULL) - { - ESP_LOGE("display_task.cpp", "failed to parse JSON"); - } - - apps->setSprite(spr_); - - cJSON *json_app = NULL; - - uint16_t app_position = 1; - - cJSON_ArrayForEach(json_app, json_root) - { - cJSON *json_app_slug = cJSON_GetObjectItemCaseSensitive(json_app, "app_slug"); - cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); - cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); - - apps->loadApp(app_position, std::string(json_app_slug->valuestring), std::string(json_app_id->valuestring), json_friendly_name->valuestring); - - app_position++; - } - - cJSON_Delete(json_root); - - SettingsApp *settings_app = new SettingsApp(spr_); - apps->add(app_position, settings_app); - - apps->updateMenu(); - - unsigned long last_rendering_ms = millis(); - unsigned long last_fps_check = millis(); - - const uint16_t wanted_fps = 60; - uint16_t fps_counter = 0; - - while (1) - { - - if (millis() - last_rendering_ms > 1000 / wanted_fps) - { - spr_->fillSprite(TFT_BLACK); - apps->renderActive()->pushSprite(0, 0); - - { - SemaphoreGuard lock(mutex_); - // ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, brightness_); - } - last_rendering_ms = millis(); - - fps_counter++; - if (last_fps_check + 1000 < millis()) - { - ESP_LOGD("display_task.cpp", "Screen real FPS %d", fps_counter); - fps_counter = 0; - last_fps_check = millis(); - } - } - - delay(1); - } -} \ No newline at end of file diff --git a/firmware/src/apps/onboarding/demo.h b/firmware/src/apps/onboarding/demo.h deleted file mode 100644 index e8a24371..00000000 --- a/firmware/src/apps/onboarding/demo.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "../app.h" - -#include "../apps.h" - -class DemoApp : public App -{ -public: - DemoApp(TFT_eSprite *spr_); - TFT_eSprite *render(); - EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); - void updateStateFromSystem(AppState state); - uint8_t navigationNext(); - std::string getClassName(); - -private: - Apps *apps; - uint8_t demo_apps_count = 0; - uint8_t current_demo_position = 0; - SemaphoreHandle_t mutex_; - - App find(uint8_t id); - void render_demo_screen(); -}; \ No newline at end of file From 1ec7a2ae51d147160153344aa2d5d91a51b4cbd8 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 18:03:55 +0100 Subject: [PATCH 11/29] Demo mostly finished, new way to go back not done. Added new color circles for demo "screen". Small fixes --- firmware/src/apps/apps.cpp | 2 +- firmware/src/apps/icons.h | 82 -------------------------------- firmware/src/apps/onboarding.cpp | 33 +++++++++++-- 3 files changed, 31 insertions(+), 86 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 1ea3f992..35d12100 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -237,7 +237,7 @@ void Apps::createOnboarding() spr_->color565(255, 255, 255), }, IconItem{ - demo_80, + nullptr, spr_->color565(255, 255, 255), }, }); diff --git a/firmware/src/apps/icons.h b/firmware/src/apps/icons.h index a507ae1e..9463013e 100644 --- a/firmware/src/apps/icons.h +++ b/firmware/src/apps/icons.h @@ -746,88 +746,6 @@ PROGMEM const unsigned char wifi_conn_80[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -PROGMEM const unsigned char demo_80[] = { - 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, - 0x01, 0xf8, 0x00, 0xff, 0xff, 0x80, 0x02, 0x80, 0x00, - 0x07, 0xfe, 0x00, 0x7f, 0xff, 0x00, 0x1f, 0xf0, 0x00, - 0x1f, 0xff, 0x00, 0x3f, 0xfe, 0x00, 0x7f, 0xf8, 0x00, - 0x3f, 0xff, 0x80, 0x1f, 0xfc, 0x00, 0xff, 0xfc, 0x00, - 0x7f, 0xff, 0xc0, 0x0f, 0xf8, 0x00, 0xff, 0xfe, 0x00, - 0x7f, 0xff, 0xc0, 0x01, 0x40, 0x01, 0xff, 0xff, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, - 0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, - 0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, - 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, - 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, - 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, - 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x00, - 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, - 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, - 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x05, 0x40, 0x00, - 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x15, 0x50, 0x00, - 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x2a, 0xa8, 0x00, - 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, - 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x01, 0x55, 0x54, 0x00, - 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, - 0xff, 0xff, 0xf0, 0x00, 0x00, 0x02, 0xaa, 0xaa, 0x80, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, - 0xff, 0xff, 0xf0, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, - 0xff, 0xff, 0xe0, 0x00, 0x00, 0x02, 0xaa, 0xaa, 0x00, - 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, - 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x01, 0x55, 0x54, 0x00, - 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x55, 0x54, 0x00, - 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xa8, 0x00, - 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x15, 0x50, 0x00, - 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - // 75 174 PROGMEM const unsigned char omnitrix_char_1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index dd77c21f..1de16218 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -101,9 +101,18 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) { if (item.small_icon.icon == nullptr) { - spr_->setTextColor(color_active); - spr_->drawString(item.screen_name.text, center_w, center_h - screen_name_label_h * 2, 1); - spr_->drawString(item.screen_description.text, center_w, center_h - screen_name_label_h, 1); + if (item.app_id == 4) + { + spr_->setTextColor(color_active); + spr_->drawString(item.screen_name.text, center_w, screen_name_label_h * 2, 1); + spr_->drawString(item.screen_description.text, center_w, screen_name_label_h * 3, 1); + } + else + { + spr_->setTextColor(color_active); + spr_->drawString(item.screen_name.text, center_w, center_h - screen_name_label_h * 2, 1); + spr_->drawString(item.screen_description.text, center_w, center_h - screen_name_label_h, 1); + } spr_->setTextColor(item.call_to_action.color); spr_->drawString(item.call_to_action.text, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); @@ -121,6 +130,24 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) } } + if (item.app_id == 4) + { + uint32_t colors[6] = {TFT_BLUE, TFT_PURPLE, TFT_RED, TFT_YELLOW, TFT_GREENYELLOW, TFT_GREEN}; + float angle_step = 2 * PI / 6; + float circle_radius = 24; // Adjust as needed + uint8_t small_circle_radius = 8; + + for (uint16_t i = 0; i < 6; i++) + { + int16_t x; + int16_t y; + x = center_w + circle_radius * sinf((i + 3) * angle_step); + y = center_h + circle_radius * cosf((i + 3) * angle_step); + + spr_->fillCircle(x, y, small_circle_radius, colors[i]); + } + } + uint32_t menu_item_color; uint8_t menu_item_diameter = 6; uint8_t position_circle_radius = screen_radius - menu_item_diameter; // the radius of the circle where you want the dots to lay. From b729e94b5d26f7d2d561f716052e1369fd7e4b5c Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 19:11:38 +0100 Subject: [PATCH 12/29] Fixed string rendering on demo "screen" --- firmware/src/apps/onboarding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 1de16218..dd58bdcf 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -132,7 +132,7 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) if (item.app_id == 4) { - uint32_t colors[6] = {TFT_BLUE, TFT_PURPLE, TFT_RED, TFT_YELLOW, TFT_GREENYELLOW, TFT_GREEN}; + uint32_t colors[6] = {TFT_CYAN, TFT_PURPLE, TFT_RED, TFT_YELLOW, TFT_GREENYELLOW, TFT_GREEN}; float angle_step = 2 * PI / 6; float circle_radius = 24; // Adjust as needed uint8_t small_circle_radius = 8; From e26de2f2f311c7bbb00488c8200a8eb05507b726 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 19:24:37 +0100 Subject: [PATCH 13/29] Cleaned up onboarding.cpp --- firmware/src/apps/onboarding.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index dd58bdcf..427d692a 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -2,8 +2,6 @@ OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) { - // sprintf(room, "%s", ""); - motor_config = PB_SmartKnobConfig{ 0, 0, @@ -46,10 +44,11 @@ void OnboardingApp::updateStateFromSystem(AppState state) {} uint8_t OnboardingApp::navigationNext() { + // Makes sure only apps 1 - 3 have a "second depth" of navigation if (current_onboarding_position >= 1 && current_onboarding_position <= 3) return current_onboarding_position; - return 0; // +1 to shift from 0 position which is menu itself + return 0; } TFT_eSprite *OnboardingApp::render() @@ -74,9 +73,6 @@ OnboardingItem OnboardingApp::find_item(uint8_t id) void OnboardingApp::render_onboarding_screen(OnboardingItem item) { - uint32_t color_active = item.screen_name.color; - uint32_t color_inactive = spr_->color565(150, 150, 150); - uint32_t label_color = color_inactive; uint32_t background = spr_->color565(0, 0, 0); uint16_t center_h = TFT_WIDTH / 2; @@ -84,7 +80,6 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) uint16_t screen_radius = TFT_WIDTH / 2; - // int8_t screen_name_label_w = 100; int8_t screen_name_label_h = spr_->fontHeight(1); int8_t label_vertical_offset = 25; @@ -103,14 +98,18 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) { if (item.app_id == 4) { - spr_->setTextColor(color_active); + spr_->setTextColor(item.screen_name.color); spr_->drawString(item.screen_name.text, center_w, screen_name_label_h * 2, 1); + + spr_->setTextColor(item.screen_description.color); spr_->drawString(item.screen_description.text, center_w, screen_name_label_h * 3, 1); } else { - spr_->setTextColor(color_active); + spr_->setTextColor(item.screen_name.color); spr_->drawString(item.screen_name.text, center_w, center_h - screen_name_label_h * 2, 1); + + spr_->setTextColor(item.screen_description.color); spr_->drawString(item.screen_description.text, center_w, center_h - screen_name_label_h, 1); } @@ -119,11 +118,13 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) } else { - spr_->setTextColor(color_active); + spr_->setTextColor(item.screen_name.color); spr_->drawString(item.screen_name.text, center_w, screen_name_label_h * 2, 1); + + spr_->setTextColor(item.screen_description.color); spr_->drawString(item.screen_description.text, center_w, screen_name_label_h * 3, 1); - spr_->drawBitmap(center_w - icon_size_big / 2, center_h - icon_size_big / 2 + 6, item.small_icon.icon, icon_size_big, icon_size_big, item.small_icon.color, background); + spr_->drawBitmap(center_w - icon_size_big / 2, center_h - icon_size_big / 2 + 6, item.small_icon.icon, icon_size_big, icon_size_big, item.small_icon.color); spr_->setTextColor(item.call_to_action.color); spr_->drawString(item.call_to_action.text, center_w, TFT_WIDTH - (40 + call_to_action_label_h), 1); From edef0b3728cdfe188f41efa0e07c0b205bdb1901 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 19:26:23 +0100 Subject: [PATCH 14/29] Cleaned up apps.cpp --- firmware/src/apps/apps.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 35d12100..fdebe26e 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -23,12 +23,7 @@ void Apps::add(uint8_t id, App *app) char buf_[10]; sprintf(buf_, "%d", id); - // MenuApp *app = new MenuApp(spr_); - apps.insert(std::make_pair(buf_, app)); - // ESP_LOGD("apps.cpp", ">>> inserted menu App"); - - // apps.insert(apps.begin() + id, std::move(app), std::move(app)); unlock(); } @@ -45,10 +40,8 @@ EntityStateUpdate Apps::update(AppState state) lock(); char buf_[10]; sprintf(buf_, "%d", active_id); - // ESP_LOGD("apps.cpp", ">>> pre-updated"); EntityStateUpdate new_state_update = apps[buf_]->updateStateFromKnob(state.motor_state); apps[buf_]->updateStateFromSystem(state); - // ESP_LOGD("apps.cpp", ">>> updated"); unlock(); return new_state_update; @@ -60,13 +53,10 @@ TFT_eSprite *Apps::renderActive() lock(); if (active_app != nullptr) { - // ESP_LOGE("apps.cpp", "fast rendering"); rendered_spr_ = active_app->render(); - // rendered_spr_ = spr_; unlock(); return rendered_spr_; } - // ESP_LOGE("apps.cpp", "slow rendering"); char buf_[10]; sprintf(buf_, "%d", active_id); @@ -118,8 +108,6 @@ void Apps::reload(cJSON *apps_) cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); - // ESP_LOGD("apps.cpp", "%s", json_app_id->valuestring); - loadApp(app_position, std::string(json_app_slug->valuestring), json_app_id->valuestring, json_friendly_name->valuestring); app_position++; @@ -426,9 +414,7 @@ uint8_t Apps::navigationNext() lock(); char buf_[10]; sprintf(buf_, "%d", active_id); - // ESP_LOGD("apps.cpp", ">>> pre-updated"); uint8_t next = apps[buf_]->navigationNext(); - // ESP_LOGD("apps.cpp", ">>> updated"); unlock(); return next; } @@ -438,9 +424,7 @@ PB_SmartKnobConfig Apps::getActiveMotorConfig() lock(); char buf_[10]; sprintf(buf_, "%d", active_id); - // ESP_LOGD("apps.cpp", ">>> pre-updated"); PB_SmartKnobConfig motor_config = apps[buf_]->getMotorConfig(); - // ESP_LOGD("apps.cpp", ">>> updated"); unlock(); return motor_config; From 88361a195af93b6f8933c0ade3ef3c00ac4d9e48 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 19:28:22 +0100 Subject: [PATCH 15/29] Cleanup of menu.cpp --- firmware/src/apps/menu.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/firmware/src/apps/menu.cpp b/firmware/src/apps/menu.cpp index 48653317..b1bc508b 100644 --- a/firmware/src/apps/menu.cpp +++ b/firmware/src/apps/menu.cpp @@ -51,21 +51,10 @@ uint8_t MenuApp::navigationNext() TFT_eSprite *MenuApp::render() { - // ESP_LOGD("menu.cpp", "called real method"); - // return; - // spr_->fillRect(0, 0, TFT_WIDTH, TFT_HEIGHT, TFT_ORANGE); - - // spr_->setTextColor(TFT_BLACK); - // spr_->setFreeFont(&Roboto_Thin_24); - // spr_->drawString("Menu", TFT_WIDTH / 2, TFT_HEIGHT / 2, 1); - - // current_menu_position = 0; - - // ESP_LOGD("menu.cpp", "pre-render"); - MenuItem current_item = find_item(current_menu_position); MenuItem prev_item; MenuItem next_item; + if (current_menu_position == 0) { prev_item = find_item(items.size() - 1); @@ -81,9 +70,9 @@ TFT_eSprite *MenuApp::render() prev_item = find_item(current_menu_position - 1); next_item = find_item(current_menu_position + 1); } - // ESP_LOGD("menu.cpp", "mid-render"); + render_menu_screen(current_item, prev_item, next_item); - // ESP_LOGD("menu.cpp", "post-render"); + return this->spr_; } @@ -101,7 +90,6 @@ MenuItem MenuApp::find_item(uint8_t id) // TODO: add protection of overwriting same items void MenuApp::add_item(uint8_t id, MenuItem item) { - // items[id] = item; items.insert(std::make_pair(id, item)); } @@ -133,7 +121,6 @@ void MenuApp::render_menu_screen(MenuItem current, MenuItem prev, MenuItem next) spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current.big_icon, icon_size_active, icon_size_active, color_active, background); - // ESP_LOGD("menu.cpp", "%s", current.screen_name); // left one spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); From 77758e0a331979e09beeff1f6ec69361ca89e860 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 19:28:56 +0100 Subject: [PATCH 16/29] Cleanup of display_task.cpp --- firmware/src/display_task.cpp | 38 ----------------------------------- 1 file changed, 38 deletions(-) diff --git a/firmware/src/display_task.cpp b/firmware/src/display_task.cpp index 8d0cd0d5..416d96fc 100644 --- a/firmware/src/display_task.cpp +++ b/firmware/src/display_task.cpp @@ -56,50 +56,12 @@ void DisplayTask::run() } spr_.setTextColor(0xFFFF, TFT_BLACK); - // std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; - // // std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch-office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"}]"; - - // cJSON *json_root = cJSON_Parse(apps_config.c_str()); - - // if (json_root == NULL) - // { - // ESP_LOGE("display_task.cpp", "failed to parse JSON"); - // } - apps.setSprite(&spr_); - // cJSON *json_app = NULL; - - // uint16_t app_position = 1; - - // cJSON_ArrayForEach(json_app, json_root) - // { - // cJSON *json_app_slug = cJSON_GetObjectItemCaseSensitive(json_app, "app_slug"); - // cJSON *json_app_id = cJSON_GetObjectItemCaseSensitive(json_app, "app_id"); - // cJSON *json_friendly_name = cJSON_GetObjectItemCaseSensitive(json_app, "friendly_name"); - // snprintf(buf_, sizeof(buf_), "fromJSON > app_slug=%s", json_app_slug->valuestring); - // log(buf_); - // // ESP_LOGD("display_task.cpp", "%s", buf_); - - // apps.loadApp(app_position, std::string(json_app_slug->valuestring), std::string(json_app_id->valuestring), json_friendly_name->valuestring); - - // app_position++; - // } - - // cJSON_Delete(json_root); - - // SettingsApp *settings_app = new SettingsApp(&spr_); - // apps.add(app_position, settings_app); - - // generate menu from apps list - // apps.updateMenu(); - apps.createOnboarding(); AppState app_state; - // apps.setActive(3); - spr_.setTextDatum(CC_DATUM); spr_.setTextColor(TFT_WHITE); From 4488a7200d68dce5dbb7e591631c896254e55136 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 21:18:59 +0100 Subject: [PATCH 17/29] Added C QRCode library --- platformio.ini | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 3392013e..4a2a77fb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -57,6 +57,7 @@ lib_deps = askuric/Simple FOC@2.3.0 adafruit/Adafruit_VL53L0X@^1.2.2 knolleary/PubSubClient@^2.8 + ricmoo/QRCode@^0.0.1 build_flags = ${base_config.build_flags} -DSK_FORCE_UART_STREAM=0 @@ -130,9 +131,10 @@ build_flags = [env:seedlabs_devkit_github_action] extends = env:seedlabs_devkit build_flags = - ${base_config.build_flags} - ${env:seedlabs_devkit.build_flags} - -DSK_NETWORKING=0 + ${base_config.build_flags} + ${env:seedlabs_devkit.build_flags} + -DSK_NETWORKING=0 +lib_deps = ricmoo/QRCode@^0.0.1 [env:brushknight_esp32s3] extends = base_config @@ -148,6 +150,7 @@ lib_deps = adafruit/Adafruit VEML7700 Library @ 1.1.1 askuric/Simple FOC@2.3.0 knolleary/PubSubClient@^2.8 + ricmoo/QRCode@^0.0.1 build_flags = ${base_config.build_flags} -DMONITOR_SPEED=115200 @@ -213,4 +216,4 @@ build_flags = -DFASTLED_UNUSABLE_PIN_MASK=0x100740LL -DSOC_GPIO_VALID_GPIO_MASK=0xFF0EFFFFFF - -DSOC_GPIO_VALID_OUTPUT_GPIO_MASK=0x30EFFFFFF \ No newline at end of file + -DSOC_GPIO_VALID_OUTPUT_GPIO_MASK=0x30EFFFFFF From 1d25455124a116274fa7174c8bd5647588a3d50c Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Thu, 18 Jan 2024 21:19:42 +0100 Subject: [PATCH 18/29] Created HassSetupApp uses QRCode lib to generate qrcode then draws it with tft_espi. Added smaller font since bigger one takes to much space and qrcode wont fit. --- firmware/src/apps/apps.cpp | 4 +- firmware/src/apps/apps.h | 3 + firmware/src/apps/onboarding/hass_setup.cpp | 83 ++++++++++++ firmware/src/apps/onboarding/hass_setup.h | 14 ++ firmware/src/font/NDS125_small.h | 143 ++++++++++++++++++++ 5 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 firmware/src/apps/onboarding/hass_setup.cpp create mode 100644 firmware/src/apps/onboarding/hass_setup.h create mode 100644 firmware/src/font/NDS125_small.h diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index fdebe26e..4a395765 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -259,8 +259,8 @@ void Apps::createOnboarding() add(0, onboarding_app); // APPS FOR OTHER ONBOARDING SCREENS - SettingsApp *app0 = new SettingsApp(spr_); - add(1, app0); + HassSetupApp *hass_setup_app = new HassSetupApp(spr_); + add(1, hass_setup_app); StopwatchApp *app1 = new StopwatchApp(spr_, ""); add(2, app1); diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index 1d91426e..88191d23 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -19,6 +19,9 @@ #include "menu.h" #include "onboarding.h" +// include all "setup" apps +#include "onboarding/hass_setup.h" + // TODO: generate menu based on items in the map class Apps { diff --git a/firmware/src/apps/onboarding/hass_setup.cpp b/firmware/src/apps/onboarding/hass_setup.cpp new file mode 100644 index 00000000..bcf7c46d --- /dev/null +++ b/firmware/src/apps/onboarding/hass_setup.cpp @@ -0,0 +1,83 @@ +#include "hass_setup.h" + +#include "font/NDS125_small.h" +#include "qrcode.h" + +HassSetupApp::HassSetupApp(TFT_eSprite *spr_) : App(spr_) +{ + motor_config = PB_SmartKnobConfig{ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0.55, // Note the snap point is slightly past the midpoint (0.5); compare to normal detents which use a snap point *past* the next value (i.e. > 1) + "SKDEMO_Light_switch", + 0, + {}, + 0, + 20, + }; +} + +EntityStateUpdate HassSetupApp::updateStateFromKnob(PB_SmartKnobState state) +{ + // needed to next reload of App + motor_config.position_nonce = state.current_position; + motor_config.position = state.current_position; + + return EntityStateUpdate{}; +} + +void HassSetupApp::updateStateFromSystem(AppState state) {} + +uint8_t HassSetupApp::navigationNext() +{ + return 0; +} + +TFT_eSprite *HassSetupApp::render() +{ + uint16_t center_h = TFT_WIDTH / 2; + uint16_t center_w = TFT_WIDTH / 2; + + int8_t screen_name_label_h = spr_->fontHeight(1); + + spr_->setTextDatum(CC_DATUM); + spr_->setTextSize(1); + spr_->setFreeFont(&NDS125_small); + + spr_->drawString("SCAN TO CONNECT", center_w, screen_name_label_h * 2, 1); + spr_->drawString("TO THE SMART KNOB", center_w, screen_name_label_h * 3, 1); + + QRCode qrcode; + uint8_t qrcodeData[qrcode_getBufferSize(2)]; + qrcode_initText(&qrcode, qrcodeData, 2, 0, "https://store.seedlabs.it/"); + + int moduleSize = 3; + + int qrCodeWidth = qrcode.size * moduleSize; + int qrCodeHeight = qrcode.size * moduleSize; + + int startX = center_w - qrCodeWidth / 2; + int startY = center_h - qrCodeHeight / 2; + + for (uint8_t y = 0; y < qrcode.size; y++) + { + for (uint8_t x = 0; x < qrcode.size; x++) + { + if (qrcode_getModule(&qrcode, x, y)) + { + spr_->fillRect(startX + x * moduleSize, startY + y * moduleSize, moduleSize, moduleSize, TFT_WHITE); + } + } + } + + spr_->drawString("OR CONNECT TO", center_w, TFT_WIDTH - screen_name_label_h * 4, 1); + spr_->drawString("SMARTKNOB-AP WIFI", center_w, TFT_WIDTH - screen_name_label_h * 3, 1); + + return this->spr_; +} diff --git a/firmware/src/apps/onboarding/hass_setup.h b/firmware/src/apps/onboarding/hass_setup.h new file mode 100644 index 00000000..4ca1fa5a --- /dev/null +++ b/firmware/src/apps/onboarding/hass_setup.h @@ -0,0 +1,14 @@ +#include "../app.h" + +class HassSetupApp : public App +{ +public: + HassSetupApp(TFT_eSprite *spr_); + TFT_eSprite *render(); + EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); + void updateStateFromSystem(AppState state); + uint8_t navigationNext(); + +private: + void render_hass_setup_screen(); +}; \ No newline at end of file diff --git a/firmware/src/font/NDS125_small.h b/firmware/src/font/NDS125_small.h new file mode 100644 index 00000000..a4679cd6 --- /dev/null +++ b/firmware/src/font/NDS125_small.h @@ -0,0 +1,143 @@ +#pragma once + +const uint8_t NDS125_small_Bitmaps[] PROGMEM = { + 0x00, 0xFD, 0x80, 0xB4, 0x14, 0x29, 0xF9, 0x42, 0x85, 0x3F, 0x28, 0x50, + 0x23, 0xAB, 0x47, 0x16, 0xAE, 0x20, 0x45, 0x4A, 0xA2, 0x41, 0x04, 0x8A, + 0xA5, 0x44, 0x21, 0x45, 0x14, 0x21, 0x58, 0xA2, 0x74, 0xC0, 0x29, 0x49, + 0x12, 0x20, 0x89, 0x12, 0x52, 0x80, 0x11, 0x25, 0x51, 0xC5, 0x52, 0x44, + 0x00, 0x21, 0x3E, 0x42, 0x00, 0x60, 0xF8, 0x80, 0x24, 0xA4, 0xA4, 0x80, + 0x74, 0x67, 0x3A, 0xE7, 0x31, 0x70, 0xD5, 0x55, 0x40, 0xF0, 0x42, 0x17, + 0x42, 0x10, 0xF8, 0xF0, 0x42, 0x17, 0x04, 0x21, 0xF0, 0x8A, 0x28, 0xA2, + 0x89, 0xF0, 0x82, 0x08, 0xFC, 0x21, 0x0F, 0x04, 0x21, 0xF0, 0x74, 0x21, + 0x0F, 0x46, 0x31, 0x70, 0xF8, 0x42, 0x22, 0x10, 0x84, 0x20, 0x74, 0x63, + 0x17, 0x46, 0x31, 0x70, 0x74, 0x63, 0x17, 0x84, 0x21, 0x70, 0x88, 0x40, + 0x60, 0x2A, 0x22, 0xF8, 0x3E, 0x88, 0xA8, 0xE1, 0x12, 0x44, 0x04, 0x40, + 0x38, 0x8A, 0x6D, 0x5A, 0xB5, 0x67, 0x20, 0x3C, 0x21, 0x14, 0xA5, 0x7E, + 0x31, 0x88, 0xF4, 0x63, 0x1F, 0x46, 0x31, 0xF0, 0x7C, 0x21, 0x08, 0x42, + 0x10, 0x78, 0xF4, 0x63, 0x18, 0xC6, 0x31, 0xF0, 0xF8, 0x88, 0xF8, 0x88, + 0xF0, 0xF8, 0x88, 0xF8, 0x88, 0x80, 0x7C, 0x21, 0x0B, 0xC6, 0x31, 0x70, + 0x8C, 0x63, 0x1F, 0xC6, 0x31, 0x88, 0xFF, 0x80, 0x11, 0x11, 0x11, 0x11, + 0xE0, 0x8C, 0xA5, 0x4C, 0x52, 0x52, 0x88, 0x88, 0x88, 0x88, 0x88, 0xF0, + 0x8C, 0x77, 0xBA, 0xD6, 0x31, 0x88, 0x8E, 0x73, 0x5A, 0xCE, 0x71, 0x88, + 0x74, 0x63, 0x18, 0xC6, 0x31, 0x70, 0xF4, 0x63, 0x1F, 0x42, 0x10, 0x80, + 0x74, 0x63, 0x18, 0xC6, 0x35, 0x70, 0xC0, 0xF4, 0x63, 0x1F, 0x4A, 0x51, + 0x88, 0x78, 0x88, 0x61, 0x11, 0xE0, 0xF9, 0x08, 0x42, 0x10, 0x84, 0x20, + 0x8C, 0x63, 0x18, 0xC6, 0x31, 0x70, 0x8C, 0x62, 0xA5, 0x29, 0x44, 0x20, + 0x8C, 0x6B, 0x5A, 0xD5, 0x4A, 0x50, 0x8C, 0x54, 0xA2, 0x29, 0x51, 0x88, + 0x8C, 0x54, 0xA2, 0x10, 0x84, 0x20, 0xF1, 0x22, 0x64, 0x48, 0xF0, 0xF2, + 0x49, 0x24, 0xE0, 0x92, 0x24, 0x89, 0x20, 0xE4, 0x92, 0x49, 0xE0, 0x54, + 0xF8, 0x90, 0xF0, 0x5F, 0x18, 0xBC, 0x84, 0x21, 0xE8, 0xC6, 0x31, 0xF0, + 0x7C, 0x21, 0x08, 0x3C, 0x08, 0x42, 0xF8, 0xC6, 0x31, 0x78, 0x74, 0x7F, + 0x08, 0x3C, 0x34, 0x4F, 0x44, 0x44, 0x40, 0x7C, 0x63, 0x17, 0x87, 0xC0, + 0x84, 0x21, 0xE8, 0xC6, 0x31, 0x88, 0xBF, 0x20, 0x92, 0x49, 0xC0, 0x88, + 0x89, 0xAC, 0xA9, 0x90, 0xAA, 0xAA, 0x40, 0xFD, 0x26, 0x4C, 0x99, 0x32, + 0x40, 0xF4, 0x63, 0x18, 0xC4, 0x74, 0x63, 0x18, 0xB8, 0xF4, 0x63, 0x1F, + 0x42, 0x00, 0x7C, 0x63, 0x17, 0x84, 0x20, 0xBC, 0x88, 0x88, 0x78, 0x61, + 0x1E, 0x44, 0xF4, 0x44, 0x43, 0x8C, 0x63, 0x18, 0xBC, 0x8C, 0x54, 0xA2, + 0x10, 0x8D, 0x6B, 0x55, 0x28, 0x8A, 0x88, 0x45, 0x44, 0x8C, 0x54, 0xA2, + 0x13, 0x00, 0xF8, 0x88, 0x88, 0x7C, 0x34, 0x44, 0x84, 0x44, 0x30, 0xFF, + 0x80, 0xC2, 0x22, 0x12, 0x22, 0xC0, 0x45, 0x44}; + +const GFXglyph NDS125_small_Glyphs[] PROGMEM = { + {0, 1, 1, 3, 0, 0}, // 0x20 ' ' + {1, 1, 9, 4, 1, -8}, // 0x21 '!' + {3, 3, 2, 4, 0, -8}, // 0x22 '"' + {4, 7, 9, 8, 0, -8}, // 0x23 '#' + {12, 5, 9, 6, 0, -8}, // 0x24 '$' + {18, 7, 9, 8, 0, -8}, // 0x25 '%' + {26, 6, 9, 7, 0, -8}, // 0x26 '&' + {33, 1, 2, 2, 0, -8}, // 0x27 ''' + {34, 3, 9, 4, 0, -8}, // 0x28 '(' + {38, 3, 9, 4, 0, -8}, // 0x29 ')' + {42, 7, 7, 8, 0, -7}, // 0x2A '*' + {49, 5, 5, 6, 0, -6}, // 0x2B '+' + {53, 2, 2, 4, 0, 0}, // 0x2C ',' + {54, 5, 1, 6, 0, -4}, // 0x2D '-' + {55, 1, 1, 4, 1, 0}, // 0x2E '.' + {56, 3, 9, 6, 1, -8}, // 0x2F '/' + {60, 5, 9, 6, 0, -8}, // 0x30 '0' + {66, 2, 9, 4, 0, -8}, // 0x31 '1' + {69, 5, 9, 6, 0, -8}, // 0x32 '2' + {75, 5, 9, 6, 0, -8}, // 0x33 '3' + {81, 6, 9, 7, 0, -8}, // 0x34 '4' + {88, 5, 9, 6, 0, -8}, // 0x35 '5' + {94, 5, 9, 6, 0, -8}, // 0x36 '6' + {100, 5, 9, 6, 0, -8}, // 0x37 '7' + {106, 5, 9, 6, 0, -8}, // 0x38 '8' + {112, 5, 9, 6, 0, -8}, // 0x39 '9' + {118, 1, 5, 4, 1, -6}, // 0x3A ':' + {119, 2, 6, 5, 1, -6}, // 0x3B ';' + {121, 3, 5, 4, 0, -6}, // 0x3C '<' + {123, 5, 3, 6, 0, -5}, // 0x3D '=' + {125, 3, 5, 4, 0, -6}, // 0x3E '>' + {127, 4, 9, 5, 0, -8}, // 0x3F '?' + {132, 7, 9, 8, 0, -8}, // 0x40 '@' + {140, 5, 9, 6, 0, -8}, // 0x41 'A' + {146, 5, 9, 6, 0, -8}, // 0x42 'B' + {152, 5, 9, 6, 0, -8}, // 0x43 'C' + {158, 5, 9, 6, 0, -8}, // 0x44 'D' + {164, 4, 9, 5, 0, -8}, // 0x45 'E' + {169, 4, 9, 5, 0, -8}, // 0x46 'F' + {174, 5, 9, 6, 0, -8}, // 0x47 'G' + {180, 5, 9, 6, 0, -8}, // 0x48 'H' + {186, 1, 9, 2, 0, -8}, // 0x49 'I' + {188, 4, 9, 5, 0, -8}, // 0x4A 'J' + {193, 5, 9, 6, 0, -8}, // 0x4B 'K' + {199, 4, 9, 5, 0, -8}, // 0x4C 'L' + {204, 5, 9, 6, 0, -8}, // 0x4D 'M' + {210, 5, 9, 6, 0, -8}, // 0x4E 'N' + {216, 5, 9, 6, 0, -8}, // 0x4F 'O' + {222, 5, 9, 6, 0, -8}, // 0x50 'P' + {228, 5, 10, 6, 0, -8}, // 0x51 'Q' + {235, 5, 9, 6, 0, -8}, // 0x52 'R' + {241, 4, 9, 5, 0, -8}, // 0x53 'S' + {246, 5, 9, 6, 0, -8}, // 0x54 'T' + {252, 5, 9, 6, 0, -8}, // 0x55 'U' + {258, 5, 9, 6, 0, -8}, // 0x56 'V' + {264, 5, 9, 6, 0, -8}, // 0x57 'W' + {270, 5, 9, 6, 0, -8}, // 0x58 'X' + {276, 5, 9, 6, 0, -8}, // 0x59 'Y' + {282, 4, 9, 5, 0, -8}, // 0x5A 'Z' + {287, 3, 9, 4, 0, -8}, // 0x5B '[' + {291, 3, 9, 6, 1, -8}, // 0x5C '\' + {295, 3, 9, 4, 0, -8}, // 0x5D ']' + {299, 3, 2, 4, 0, -8}, // 0x5E '^' + {300, 5, 1, 6, 0, 0}, // 0x5F '_' + {301, 2, 2, 3, 0, -8}, // 0x60 '`' + {302, 5, 6, 6, 0, -5}, // 0x61 'a' + {306, 5, 9, 6, 0, -8}, // 0x62 'b' + {312, 5, 6, 6, 0, -5}, // 0x63 'c' + {316, 5, 9, 6, 0, -8}, // 0x64 'd' + {322, 5, 6, 6, 0, -5}, // 0x65 'e' + {326, 4, 9, 5, 0, -8}, // 0x66 'f' + {331, 5, 7, 6, 0, -5}, // 0x67 'g' + {336, 5, 9, 6, 0, -8}, // 0x68 'h' + {342, 1, 8, 2, 0, -7}, // 0x69 'i' + {343, 3, 9, 4, 0, -7}, // 0x6A 'j' + {347, 4, 9, 5, 0, -8}, // 0x6B 'k' + {352, 2, 9, 3, 0, -8}, // 0x6C 'l' + {355, 7, 6, 8, 0, -5}, // 0x6D 'm' + {361, 5, 6, 6, 0, -5}, // 0x6E 'n' + {365, 5, 6, 6, 0, -5}, // 0x6F 'o' + {369, 5, 7, 6, 0, -5}, // 0x70 'p' + {374, 5, 7, 6, 0, -5}, // 0x71 'q' + {379, 4, 6, 5, 0, -5}, // 0x72 'r' + {382, 4, 6, 5, 0, -5}, // 0x73 's' + {385, 4, 8, 5, 0, -7}, // 0x74 't' + {389, 5, 6, 6, 0, -5}, // 0x75 'u' + {393, 5, 6, 6, 0, -5}, // 0x76 'v' + {397, 5, 6, 6, 0, -5}, // 0x77 'w' + {401, 5, 6, 6, 0, -5}, // 0x78 'x' + {405, 5, 7, 6, 0, -5}, // 0x79 'y' + {410, 5, 6, 6, 0, -5}, // 0x7A 'z' + {414, 4, 9, 5, 0, -8}, // 0x7B '{' + {419, 1, 9, 2, 0, -8}, // 0x7C '|' + {421, 4, 9, 5, 0, -8}, // 0x7D '}' + {426, 5, 3, 6, 0, -8}}; // 0x7E '~' + +const GFXfont NDS125_small PROGMEM = { + (uint8_t *)NDS125_small_Bitmaps, + (GFXglyph *)NDS125_small_Glyphs, + 0x20, 0x7E, 12}; + +// Approx. 1100 bytes From 016d453dc1f2bcbe4a12be145006fce04e1d75a5 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 10:51:33 +0100 Subject: [PATCH 19/29] BIG CHANGE!!!! First draft rework of how we store apps. Now storing a map in a map using a app type to differentiate between "normal" apps and menus. --- firmware/src/app_task.cpp | 10 +-- firmware/src/app_task.h | 2 +- ...ter_chamger.cpp => 3d_printer_chamber.cpp} | 6 -- firmware/src/apps/3d_printer_chamber.h | 1 - firmware/src/apps/app.h | 16 ++++- firmware/src/apps/apps.cpp | 72 +++++++++---------- firmware/src/apps/apps.h | 11 +-- firmware/src/apps/blinds.cpp | 6 -- firmware/src/apps/blinds.h | 1 - firmware/src/apps/climate.cpp | 6 -- firmware/src/apps/climate.h | 1 - firmware/src/apps/light_dimmer.cpp | 6 -- firmware/src/apps/light_dimmer.h | 1 - firmware/src/apps/light_switch.cpp | 6 -- firmware/src/apps/light_switch.h | 1 - firmware/src/apps/menu.cpp | 4 +- firmware/src/apps/menu.h | 2 +- firmware/src/apps/music.cpp | 6 -- firmware/src/apps/music.h | 1 - firmware/src/apps/onboarding.cpp | 14 ++-- firmware/src/apps/onboarding.h | 4 +- firmware/src/apps/onboarding/hass_setup.cpp | 21 +++--- firmware/src/apps/onboarding/hass_setup.h | 1 - firmware/src/apps/settings.cpp | 6 -- firmware/src/apps/settings.h | 1 - firmware/src/apps/stopwatch.cpp | 6 -- firmware/src/apps/stopwatch.h | 1 - 27 files changed, 88 insertions(+), 125 deletions(-) rename firmware/src/apps/{3d_printer_chamger.cpp => 3d_printer_chamber.cpp} (98%) diff --git a/firmware/src/app_task.cpp b/firmware/src/app_task.cpp index f530725a..bde70f74 100644 --- a/firmware/src/app_task.cpp +++ b/firmware/src/app_task.cpp @@ -94,12 +94,12 @@ void AppTask::run() log("Giving 0.5s for Apps to initialize"); delay(500); - apps->setActive(0); + apps->setActive(menu_type, 0); applyConfig(apps->getActiveMotorConfig(), false); motor_task_.addListener(knob_state_queue_); plaintext_protocol_.init([this]() - { changeConfig(0); }, + { changeConfig(std::make_pair(menu_type, 0)); }, [this]() { if (!configuration_loaded_) @@ -199,7 +199,7 @@ void AppTask::run() if (app_state.screen_state.has_been_engaged == false && app_state.screen_state.brightness > app_state.screen_state.MIN_LCD_BRIGHTNESS && millis() > app_state.screen_state.awake_until) - { + { // TODO, this can be timed better (ideally by subtracting MAX_BRIGHTNESS - MIN_BRIGHTNESS/fps/second_of_animation) app_state.screen_state.brightness = app_state.screen_state.brightness - 1000; if (app_state.screen_state.brightness < app_state.screen_state.MIN_LCD_BRIGHTNESS) @@ -291,9 +291,9 @@ void AppTask::log(const char *msg) xQueueSendToBack(log_queue_, &msg_str, 0); } -void AppTask::changeConfig(uint32_t id) +void AppTask::changeConfig(std::pair next) { - apps->setActive(id); + apps->setActive(next.first, next.second); // TODO LOOK OVER applyConfig(apps->getActiveMotorConfig(), false); } diff --git a/firmware/src/app_task.h b/firmware/src/app_task.h index 79fb42ff..fad6d5b3 100644 --- a/firmware/src/app_task.h +++ b/firmware/src/app_task.h @@ -87,7 +87,7 @@ class AppTask : public Task, SerialProtocolPlaintext plaintext_protocol_; SerialProtocolProtobuf proto_protocol_; - void changeConfig(uint32_t id); + void changeConfig(std::pair next); void updateHardware(AppState app_state); void publishState(); void applyConfig(PB_SmartKnobConfig config, bool from_remote); diff --git a/firmware/src/apps/3d_printer_chamger.cpp b/firmware/src/apps/3d_printer_chamber.cpp similarity index 98% rename from firmware/src/apps/3d_printer_chamger.cpp rename to firmware/src/apps/3d_printer_chamber.cpp index 67da81d9..fb4136da 100644 --- a/firmware/src/apps/3d_printer_chamger.cpp +++ b/firmware/src/apps/3d_printer_chamber.cpp @@ -33,12 +33,6 @@ PrinterChamberApp::PrinterChamberApp(TFT_eSprite *spr_, std::string entity_name) friendly_name = "3D Printer"; } -uint8_t PrinterChamberApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate PrinterChamberApp::updateStateFromKnob(PB_SmartKnobState state) { wanted_temperature_position = state.current_position; diff --git a/firmware/src/apps/3d_printer_chamber.h b/firmware/src/apps/3d_printer_chamber.h index baaf32df..859174dd 100644 --- a/firmware/src/apps/3d_printer_chamber.h +++ b/firmware/src/apps/3d_printer_chamber.h @@ -13,7 +13,6 @@ class PrinterChamberApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: uint8_t current_temperature = 0; diff --git a/firmware/src/apps/app.h b/firmware/src/apps/app.h index b3273afd..17a06c7b 100644 --- a/firmware/src/apps/app.h +++ b/firmware/src/apps/app.h @@ -13,9 +13,16 @@ const char APP_SLUG_3D_PRINTER[48] = "3d_printer"; const char APP_SLUG_LIGHT_DIMMER[48] = "light_dimmer"; const char APP_SLUG_LIGHT_SWITCH[48] = "light_switch"; const char APP_SLUG_STOPWATCH[48] = "stopwatch"; + +enum app_types +{ + menu_type = 1, + apps_type = 2 +}; class App { public: + const app_types type = apps_type; App(TFT_eSprite *spr_) { this->spr_ = spr_; @@ -35,7 +42,14 @@ class App return "App"; } - virtual uint8_t navigationNext(); + virtual std::pair navigationNext() + { + ESP_LOGD("app.h", "type: %d", type); + if (type == menu_type) + return std::make_pair(apps_type, 1); + + return std::make_pair(menu_type, 0); + } const unsigned char *small_icon; const unsigned char *big_icon; diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 4a395765..41f1ef0d 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -17,13 +17,13 @@ void Apps::setSprite(TFT_eSprite *spr_) this->spr_ = spr_; } -void Apps::add(uint8_t id, App *app) +void Apps::add(app_types type, uint8_t id, App *app) { lock(); char buf_[10]; sprintf(buf_, "%d", id); - apps.insert(std::make_pair(buf_, app)); + apps[type].insert(std::make_pair(buf_, app)); unlock(); } @@ -38,10 +38,9 @@ EntityStateUpdate Apps::update(AppState state) { // TODO: update with AppState lock(); - char buf_[10]; - sprintf(buf_, "%d", active_id); - EntityStateUpdate new_state_update = apps[buf_]->updateStateFromKnob(state.motor_state); - apps[buf_]->updateStateFromSystem(state); + // TODO: check if active_app is not null + EntityStateUpdate new_state_update = active_app->updateStateFromKnob(state.motor_state); + active_app->updateStateFromSystem(state); unlock(); return new_state_update; @@ -58,9 +57,10 @@ TFT_eSprite *Apps::renderActive() return rendered_spr_; } + //! MIGHT BE WRONG char buf_[10]; sprintf(buf_, "%d", active_id); - if (apps[buf_] == nullptr) + if (apps[apps_type][buf_] == nullptr) { rendered_spr_ = spr_; ESP_LOGE("apps.cpp", "null pointer instead of app"); @@ -68,7 +68,7 @@ TFT_eSprite *Apps::renderActive() return rendered_spr_; } - active_app = apps[buf_]; + active_app = apps[apps_type][buf_]; rendered_spr_ = active_app->render(); @@ -76,13 +76,13 @@ TFT_eSprite *Apps::renderActive() return rendered_spr_; } -void Apps::setActive(uint8_t id) +void Apps::setActive(app_types type, uint8_t id) { lock(); active_id = id; char buf_[10]; sprintf(buf_, "%d", active_id); - if (apps[buf_] == nullptr) + if (apps[type][buf_] == nullptr) { // TODO: panic? ESP_LOGE("apps.cpp", "null pointer instead of app"); @@ -90,7 +90,7 @@ void Apps::setActive(uint8_t id) } else { - active_app = apps[buf_]; + active_app = apps[type][buf_]; unlock(); } } @@ -114,10 +114,10 @@ void Apps::reload(cJSON *apps_) } SettingsApp *settings_app = new SettingsApp(this->spr_); - add(app_position, settings_app); + add(apps_type, app_position, settings_app); updateMenu(); - setActive(0); + setActive(menu_type, 0); cJSON_Delete(apps_); } @@ -256,19 +256,19 @@ void Apps::createOnboarding() }); - add(0, onboarding_app); + add(menu_type, 0, onboarding_app); // APPS FOR OTHER ONBOARDING SCREENS HassSetupApp *hass_setup_app = new HassSetupApp(spr_); - add(1, hass_setup_app); + add(apps_type, 1, hass_setup_app); StopwatchApp *app1 = new StopwatchApp(spr_, ""); - add(2, app1); + add(apps_type, 2, app1); // FOR DEMO MenuApp *menu_app = new MenuApp(spr_); SettingsApp *settings_app = new SettingsApp(spr_); - add(4, settings_app); + add(apps_type, 4, settings_app); menu_app->add_item( 0, @@ -310,9 +310,9 @@ void Apps::createOnboarding() menu_position++; } - add(3, menu_app); + add(menu_type, 1, menu_app); - setActive(0); + setActive(menu_type, 0); } void Apps::updateMenu() @@ -324,7 +324,7 @@ void Apps::updateMenu() uint16_t position = 0; - for (it = apps.begin(); it != apps.end(); it++) + for (it = apps[apps_type].begin(); it != apps[apps_type].end(); it++) { ESP_LOGD("apps.cpp", "menu add item %d", position); @@ -341,7 +341,7 @@ void Apps::updateMenu() position++; } - add(0, menu_app); + add(menu_type, 0, menu_app); } // settings and menu apps kept aside for a reason. We will add them manually later @@ -356,49 +356,49 @@ App *Apps::loadApp(uint8_t position, std::string app_slug, std::string app_id, s if (app_slug.compare(APP_SLUG_CLIMATE) == 0) { ClimateApp *app = new ClimateApp(this->spr_, app_id); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } else if (app_slug.compare(APP_SLUG_3D_PRINTER) == 0) { PrinterChamberApp *app = new PrinterChamberApp(this->spr_, app_id); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } else if (app_slug.compare(APP_SLUG_BLINDS) == 0) { BlindsApp *app = new BlindsApp(this->spr_, app_id); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } else if (app_slug.compare(APP_SLUG_LIGHT_DIMMER) == 0) { LightDimmerApp *app = new LightDimmerApp(this->spr_, app_id, friendly_name); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } else if (app_slug.compare(APP_SLUG_LIGHT_SWITCH) == 0) { LightSwitchApp *app = new LightSwitchApp(this->spr_, app_id, friendly_name); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } else if (app_slug.compare(APP_SLUG_MUSIC) == 0) { MusicApp *app = new MusicApp(this->spr_, app_id); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } else if (app_slug.compare(APP_SLUG_STOPWATCH) == 0) { StopwatchApp *app = new StopwatchApp(this->spr_, app_id); - add(position, app); + add(apps_type, position, app); ESP_LOGD("apps.cpp", "added app %d %s %s %s", position, app_slug.c_str(), app_id.c_str(), friendly_name); return app; } @@ -409,22 +409,20 @@ App *Apps::loadApp(uint8_t position, std::string app_slug, std::string app_id, s return nullptr; } -uint8_t Apps::navigationNext() +std::pair Apps::navigationNext() { lock(); - char buf_[10]; - sprintf(buf_, "%d", active_id); - uint8_t next = apps[buf_]->navigationNext(); + // TODO MAYBE CHECK IF ACTIVE APP IS NOT NULL + std::pair next = active_app->navigationNext(); unlock(); - return next; + return std::make_pair(next.first, next.second); } PB_SmartKnobConfig Apps::getActiveMotorConfig() { lock(); - char buf_[10]; - sprintf(buf_, "%d", active_id); - PB_SmartKnobConfig motor_config = apps[buf_]->getMotorConfig(); + // TODO MAYBE CHECK IF ACTIVE APP IS NOT NULL + PB_SmartKnobConfig motor_config = active_app->getMotorConfig(); unlock(); return motor_config; @@ -433,7 +431,7 @@ PB_SmartKnobConfig Apps::getActiveMotorConfig() std::shared_ptr Apps::find(std::string id) { // TODO: add protection with array size - return apps[id]; + return apps[apps_type][id]; } void Apps::lock() diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index 88191d23..372d52c9 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -23,16 +23,18 @@ #include "onboarding/hass_setup.h" // TODO: generate menu based on items in the map + class Apps { + public: Apps(); - void add(uint8_t id, App *app); + void add(app_types type, uint8_t id, App *app); void clear(); EntityStateUpdate update(AppState state); TFT_eSprite *renderActive(); - void setActive(uint8_t id); - uint8_t navigationNext(); + void setActive(app_types type, uint8_t id); + std::pair navigationNext(); PB_SmartKnobConfig getActiveMotorConfig(); void setSprite(TFT_eSprite *spr_); App *loadApp(uint8_t position, std::string app_slug, std::string app_id, std::string friendly_name); @@ -43,7 +45,8 @@ class Apps private: QueueHandle_t mutex; - std::map> apps; + // std::map> apps; + std::map>> apps; // std::vector> apps; uint8_t active_id = 0; diff --git a/firmware/src/apps/blinds.cpp b/firmware/src/apps/blinds.cpp index 17f42b4f..6980094d 100644 --- a/firmware/src/apps/blinds.cpp +++ b/firmware/src/apps/blinds.cpp @@ -26,12 +26,6 @@ BlindsApp::BlindsApp(TFT_eSprite *spr_, std::string entity_name) : App(spr_) friendly_name = "Shades"; } -uint8_t BlindsApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate BlindsApp::updateStateFromKnob(PB_SmartKnobState state) { current_closed_position = state.current_position; diff --git a/firmware/src/apps/blinds.h b/firmware/src/apps/blinds.h index 8e440e91..bb5b4a94 100644 --- a/firmware/src/apps/blinds.h +++ b/firmware/src/apps/blinds.h @@ -12,7 +12,6 @@ class BlindsApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: std::string entity_name; diff --git a/firmware/src/apps/climate.cpp b/firmware/src/apps/climate.cpp index 2ddf4215..845ae515 100644 --- a/firmware/src/apps/climate.cpp +++ b/firmware/src/apps/climate.cpp @@ -36,12 +36,6 @@ ClimateApp::ClimateApp(TFT_eSprite *spr_, std::string entity_name) : App(spr_) friendly_name = "Climate"; } -uint8_t ClimateApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate ClimateApp::updateStateFromKnob(PB_SmartKnobState state) { wanted_temperature = state.current_position; diff --git a/firmware/src/apps/climate.h b/firmware/src/apps/climate.h index b4ea10f3..7140ec88 100644 --- a/firmware/src/apps/climate.h +++ b/firmware/src/apps/climate.h @@ -12,7 +12,6 @@ class ClimateApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: uint8_t current_temperature = 0; diff --git a/firmware/src/apps/light_dimmer.cpp b/firmware/src/apps/light_dimmer.cpp index 729427a5..48d587f9 100644 --- a/firmware/src/apps/light_dimmer.cpp +++ b/firmware/src/apps/light_dimmer.cpp @@ -32,12 +32,6 @@ LightDimmerApp::LightDimmerApp(TFT_eSprite *spr_, std::string app_id, std::strin small_icon = light_top_40; } -uint8_t LightDimmerApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate LightDimmerApp::updateStateFromKnob(PB_SmartKnobState state) { current_position = state.current_position; diff --git a/firmware/src/apps/light_dimmer.h b/firmware/src/apps/light_dimmer.h index b71699b4..5b31d0f5 100644 --- a/firmware/src/apps/light_dimmer.h +++ b/firmware/src/apps/light_dimmer.h @@ -10,7 +10,6 @@ class LightDimmerApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: uint16_t current_position = 0; diff --git a/firmware/src/apps/light_switch.cpp b/firmware/src/apps/light_switch.cpp index c5d20e28..e0416743 100644 --- a/firmware/src/apps/light_switch.cpp +++ b/firmware/src/apps/light_switch.cpp @@ -28,12 +28,6 @@ LightSwitchApp::LightSwitchApp(TFT_eSprite *spr_, std::string entity_name, std:: small_icon = light_switch_40; } -uint8_t LightSwitchApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate LightSwitchApp::updateStateFromKnob(PB_SmartKnobState state) { current_position = state.current_position; diff --git a/firmware/src/apps/light_switch.h b/firmware/src/apps/light_switch.h index b5c32589..48425901 100644 --- a/firmware/src/apps/light_switch.h +++ b/firmware/src/apps/light_switch.h @@ -11,7 +11,6 @@ class LightSwitchApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: uint16_t current_position = 0; diff --git a/firmware/src/apps/menu.cpp b/firmware/src/apps/menu.cpp index b1bc508b..f76dd377 100644 --- a/firmware/src/apps/menu.cpp +++ b/firmware/src/apps/menu.cpp @@ -44,9 +44,9 @@ EntityStateUpdate MenuApp::updateStateFromKnob(PB_SmartKnobState state) void MenuApp::updateStateFromSystem(AppState state) {} -uint8_t MenuApp::navigationNext() +std::pair MenuApp::navigationNext() { - return find_item(current_menu_position).app_id; + return std::make_pair(type, find_item(current_menu_position).app_id); } TFT_eSprite *MenuApp::render() diff --git a/firmware/src/apps/menu.h b/firmware/src/apps/menu.h index d52b8362..bba8515d 100644 --- a/firmware/src/apps/menu.h +++ b/firmware/src/apps/menu.h @@ -27,7 +27,7 @@ class MenuApp : public App void add_item(uint8_t id, MenuItem item); MenuItem find_item(uint8_t id); std::string getClassName(); - uint8_t navigationNext(); + std::pair navigationNext(); private: uint8_t menu_items_count = 0; diff --git a/firmware/src/apps/music.cpp b/firmware/src/apps/music.cpp index 4e9ce574..0b84a0df 100644 --- a/firmware/src/apps/music.cpp +++ b/firmware/src/apps/music.cpp @@ -28,12 +28,6 @@ MusicApp::MusicApp(TFT_eSprite *spr_, std::string entity_name) : App(spr_) friendly_name = "Music"; } -uint8_t MusicApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate MusicApp::updateStateFromKnob(PB_SmartKnobState state) { current_volume_position = state.current_position; diff --git a/firmware/src/apps/music.h b/firmware/src/apps/music.h index 6e6546cb..0a67476b 100644 --- a/firmware/src/apps/music.h +++ b/firmware/src/apps/music.h @@ -14,7 +14,6 @@ class MusicApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: std::string entity_name; diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 427d692a..01bde2bc 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -2,6 +2,7 @@ OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) { + motor_config = PB_SmartKnobConfig{ 0, 0, @@ -23,7 +24,6 @@ OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) { // TODO: cache menu size - int32_t position_for_onboarding_calc = state.current_position; // needed to next reload of App @@ -42,13 +42,19 @@ EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) void OnboardingApp::updateStateFromSystem(AppState state) {} -uint8_t OnboardingApp::navigationNext() +std::pair OnboardingApp::navigationNext() { // Makes sure only apps 1 - 3 have a "second depth" of navigation if (current_onboarding_position >= 1 && current_onboarding_position <= 3) - return current_onboarding_position; + { + if (current_onboarding_position == 3) + { + return std::make_pair(menu_type, 1); + } + return std::make_pair(apps_type, current_onboarding_position); + } - return 0; + return std::make_pair(type, 0); } TFT_eSprite *OnboardingApp::render() diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h index b207b732..22618ed0 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding.h @@ -28,12 +28,14 @@ struct OnboardingItem class OnboardingApp : public App { + public: + const app_types type = menu_type; OnboardingApp(TFT_eSprite *spr_); TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); + std::pair navigationNext(); void add_item(uint8_t id, OnboardingItem item); OnboardingItem find_item(uint8_t id); diff --git a/firmware/src/apps/onboarding/hass_setup.cpp b/firmware/src/apps/onboarding/hass_setup.cpp index bcf7c46d..e13beeb9 100644 --- a/firmware/src/apps/onboarding/hass_setup.cpp +++ b/firmware/src/apps/onboarding/hass_setup.cpp @@ -34,11 +34,6 @@ EntityStateUpdate HassSetupApp::updateStateFromKnob(PB_SmartKnobState state) void HassSetupApp::updateStateFromSystem(AppState state) {} -uint8_t HassSetupApp::navigationNext() -{ - return 0; -} - TFT_eSprite *HassSetupApp::render() { uint16_t center_h = TFT_WIDTH / 2; @@ -50,20 +45,22 @@ TFT_eSprite *HassSetupApp::render() spr_->setTextSize(1); spr_->setFreeFont(&NDS125_small); - spr_->drawString("SCAN TO CONNECT", center_w, screen_name_label_h * 2, 1); - spr_->drawString("TO THE SMART KNOB", center_w, screen_name_label_h * 3, 1); + spr_->drawString("SCAN TO CONNECT", center_w, screen_name_label_h * 3, 1); + spr_->drawString("TO THE SMART KNOB", center_w, screen_name_label_h * 4, 1); QRCode qrcode; - uint8_t qrcodeData[qrcode_getBufferSize(2)]; - qrcode_initText(&qrcode, qrcodeData, 2, 0, "https://store.seedlabs.it/"); + uint8_t qrcodeVersion = 6; + uint8_t qrcodeData[qrcode_getBufferSize(qrcodeVersion)]; + std::string wifiqrcode = "WIFI:T:WPA;S:SMARTKNOB-AP;P:SMARTKNOB;H:;;https://seedlabs.it"; + qrcode_initText(&qrcode, qrcodeData, qrcodeVersion, 0, wifiqrcode.c_str()); - int moduleSize = 3; + int moduleSize = 2; int qrCodeWidth = qrcode.size * moduleSize; int qrCodeHeight = qrcode.size * moduleSize; int startX = center_w - qrCodeWidth / 2; - int startY = center_h - qrCodeHeight / 2; + int startY = center_h - 4 - qrCodeHeight / 2; for (uint8_t y = 0; y < qrcode.size; y++) { @@ -77,7 +74,7 @@ TFT_eSprite *HassSetupApp::render() } spr_->drawString("OR CONNECT TO", center_w, TFT_WIDTH - screen_name_label_h * 4, 1); - spr_->drawString("SMARTKNOB-AP WIFI", center_w, TFT_WIDTH - screen_name_label_h * 3, 1); + spr_->drawString("SMARTKNOB-AP WiFi", center_w, TFT_WIDTH - screen_name_label_h * 3, 1); return this->spr_; } diff --git a/firmware/src/apps/onboarding/hass_setup.h b/firmware/src/apps/onboarding/hass_setup.h index 4ca1fa5a..8debaec8 100644 --- a/firmware/src/apps/onboarding/hass_setup.h +++ b/firmware/src/apps/onboarding/hass_setup.h @@ -7,7 +7,6 @@ class HassSetupApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: void render_hass_setup_screen(); diff --git a/firmware/src/apps/settings.cpp b/firmware/src/apps/settings.cpp index 7fe421a0..68c659dd 100644 --- a/firmware/src/apps/settings.cpp +++ b/firmware/src/apps/settings.cpp @@ -31,12 +31,6 @@ SettingsApp::SettingsApp(TFT_eSprite *spr_) : App(spr_) startup_ms = millis(); } -uint8_t SettingsApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate SettingsApp::updateStateFromKnob(PB_SmartKnobState state) { current_position = state.current_position; diff --git a/firmware/src/apps/settings.h b/firmware/src/apps/settings.h index d4785f8e..04517d8b 100644 --- a/firmware/src/apps/settings.h +++ b/firmware/src/apps/settings.h @@ -12,7 +12,6 @@ class SettingsApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: // uint8_t current_volume = 0; diff --git a/firmware/src/apps/stopwatch.cpp b/firmware/src/apps/stopwatch.cpp index 7c9b328f..5fa21913 100644 --- a/firmware/src/apps/stopwatch.cpp +++ b/firmware/src/apps/stopwatch.cpp @@ -27,12 +27,6 @@ StopwatchApp::StopwatchApp(TFT_eSprite *spr_, std::string entity_name) : App(spr friendly_name = "Stopwatch"; } -uint8_t StopwatchApp::navigationNext() -{ - // back to menu - return 0; -} - EntityStateUpdate StopwatchApp::updateStateFromKnob(PB_SmartKnobState state) { current_position = state.current_position; diff --git a/firmware/src/apps/stopwatch.h b/firmware/src/apps/stopwatch.h index f1ac6464..9bdbe620 100644 --- a/firmware/src/apps/stopwatch.h +++ b/firmware/src/apps/stopwatch.h @@ -12,7 +12,6 @@ class StopwatchApp : public App TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - uint8_t navigationNext(); private: std::string entity_name; From e9f7cf170d69521718b0d0b02a7250da41b9595b Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 13:46:16 +0100 Subject: [PATCH 20/29] Fixes knob rotation on boot --- firmware/src/apps/onboarding.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index 01bde2bc..d3482d9d 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -9,7 +9,7 @@ OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) 0, 0, 0, // max position < min position indicates no bounds - 60 * PI / 180, + 55 * PI / 180, 1, 1, 0.55, @@ -30,12 +30,7 @@ EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) motor_config.position_nonce = position_for_onboarding_calc; motor_config.position = position_for_onboarding_calc; - if (state.current_position < 0) - { - position_for_onboarding_calc = items.size() * 10000 + state.current_position; - } - - current_onboarding_position = position_for_onboarding_calc % items.size(); + current_onboarding_position = position_for_onboarding_calc; return EntityStateUpdate{}; } From f46e09c46778d58b05850ca7494a8b5b6931d5a4 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 13:47:33 +0100 Subject: [PATCH 21/29] Fixes etc --- firmware/src/apps/apps.cpp | 21 ++++++---------- firmware/src/apps/apps.h | 6 ++--- firmware/src/apps/menu.cpp | 51 +++++++++++++++++++++++++------------- firmware/src/apps/menu.h | 14 +++++++++-- 4 files changed, 55 insertions(+), 37 deletions(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 41f1ef0d..8bdf4ab3 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -20,10 +20,7 @@ void Apps::setSprite(TFT_eSprite *spr_) void Apps::add(app_types type, uint8_t id, App *app) { lock(); - char buf_[10]; - sprintf(buf_, "%d", id); - - apps[type].insert(std::make_pair(buf_, app)); + apps[type].insert(std::make_pair(id, app)); unlock(); } @@ -58,9 +55,7 @@ TFT_eSprite *Apps::renderActive() } //! MIGHT BE WRONG - char buf_[10]; - sprintf(buf_, "%d", active_id); - if (apps[apps_type][buf_] == nullptr) + if (apps[apps_type][active_id] == nullptr) { rendered_spr_ = spr_; ESP_LOGE("apps.cpp", "null pointer instead of app"); @@ -68,7 +63,7 @@ TFT_eSprite *Apps::renderActive() return rendered_spr_; } - active_app = apps[apps_type][buf_]; + active_app = apps[apps_type][active_id]; rendered_spr_ = active_app->render(); @@ -80,9 +75,7 @@ void Apps::setActive(app_types type, uint8_t id) { lock(); active_id = id; - char buf_[10]; - sprintf(buf_, "%d", active_id); - if (apps[type][buf_] == nullptr) + if (apps[type][active_id] == nullptr) { // TODO: panic? ESP_LOGE("apps.cpp", "null pointer instead of app"); @@ -90,7 +83,7 @@ void Apps::setActive(app_types type, uint8_t id) } else { - active_app = apps[type][buf_]; + active_app = apps[type][active_id]; unlock(); } } @@ -320,7 +313,7 @@ void Apps::updateMenu() // re - generate new menu based on loaded apps MenuApp *menu_app = new MenuApp(spr_); - std::map>::iterator it; + std::map>::iterator it; uint16_t position = 0; @@ -428,7 +421,7 @@ PB_SmartKnobConfig Apps::getActiveMotorConfig() return motor_config; } -std::shared_ptr Apps::find(std::string id) +std::shared_ptr Apps::find(uint8_t id) { // TODO: add protection with array size return apps[apps_type][id]; diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index 372d52c9..abf5fa51 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -45,9 +45,7 @@ class Apps private: QueueHandle_t mutex; - // std::map> apps; - std::map>> apps; - // std::vector> apps; + std::map>> apps; uint8_t active_id = 0; TFT_eSprite *spr_ = nullptr; @@ -55,7 +53,7 @@ class Apps TFT_eSprite *rendered_spr_; - std::shared_ptr find(std::string id); + std::shared_ptr find(uint8_t id); void lock(); void unlock(); }; diff --git a/firmware/src/apps/menu.cpp b/firmware/src/apps/menu.cpp index f76dd377..d45be133 100644 --- a/firmware/src/apps/menu.cpp +++ b/firmware/src/apps/menu.cpp @@ -4,10 +4,13 @@ MenuApp::MenuApp(TFT_eSprite *spr_) : App(spr_) { sprintf(room, "%s", "Office"); + // mutex + mutex = xSemaphoreCreateMutex(); + motor_config = PB_SmartKnobConfig{ + 1, 0, - 0, - 0, + 1, 0, -1, // max position < min position indicates no bounds 25 * PI / 180, @@ -25,6 +28,9 @@ MenuApp::MenuApp(TFT_eSprite *spr_) : App(spr_) EntityStateUpdate MenuApp::updateStateFromKnob(PB_SmartKnobState state) { // TODO: cache menu size + // might be needed to make sure first item is selected on "reload" but might fuck if user returns from app to menu again + // motor_config.position_nonce = 1; + // motor_config.position = 1; int32_t position_for_menu_calc = state.current_position; @@ -46,14 +52,13 @@ void MenuApp::updateStateFromSystem(AppState state) {} std::pair MenuApp::navigationNext() { - return std::make_pair(type, find_item(current_menu_position).app_id); + return std::make_pair(type, find_item(current_menu_position)->app_id); } TFT_eSprite *MenuApp::render() { - MenuItem current_item = find_item(current_menu_position); - MenuItem prev_item; - MenuItem next_item; + lock(); + current_item = find_item(current_menu_position); if (current_menu_position == 0) { @@ -70,9 +75,9 @@ TFT_eSprite *MenuApp::render() prev_item = find_item(current_menu_position - 1); next_item = find_item(current_menu_position + 1); } + unlock(); - render_menu_screen(current_item, prev_item, next_item); - + render_menu_screen(); return this->spr_; } @@ -82,9 +87,9 @@ std::string MenuApp::getClassName() } // TODO: add protection, could cause panic -MenuItem MenuApp::find_item(uint8_t id) +MenuItem *MenuApp::find_item(uint8_t id) { - return (*items.find(id)).second; + return &(*items.find(id)).second; } // TODO: add protection of overwriting same items @@ -93,9 +98,10 @@ void MenuApp::add_item(uint8_t id, MenuItem item) items.insert(std::make_pair(id, item)); } -void MenuApp::render_menu_screen(MenuItem current, MenuItem prev, MenuItem next) +void MenuApp::render_menu_screen() { - uint32_t color_active = current.color; + lock(); + uint32_t color_active = current_item->color; uint32_t color_inactive = spr_->color565(150, 150, 150); uint32_t label_color = color_inactive; uint32_t background = spr_->color565(0, 0, 0); @@ -120,15 +126,26 @@ void MenuApp::render_menu_screen(MenuItem current, MenuItem prev, MenuItem next) spr_->setFreeFont(&Roboto_Thin_Bold_24); spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); - spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current.big_icon, icon_size_active, icon_size_active, color_active, background); + spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon, icon_size_active, icon_size_active, color_active, background); // left one - spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); // right one - spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next.small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); spr_->setTextColor(color_active); spr_->setFreeFont(&Roboto_Thin_24); - spr_->drawString(current.screen_name, center_h, center_v + icon_size_active / 2 + 30, 1); -}; \ No newline at end of file + spr_->drawString(current_item->screen_name, center_h, center_v + icon_size_active / 2 + 30, 1); + unlock(); +}; + +void MenuApp::lock() +{ + xSemaphoreTake(mutex, portMAX_DELAY); +} + +void MenuApp::unlock() +{ + xSemaphoreGive(mutex); +} \ No newline at end of file diff --git a/firmware/src/apps/menu.h b/firmware/src/apps/menu.h index bba8515d..da503574 100644 --- a/firmware/src/apps/menu.h +++ b/firmware/src/apps/menu.h @@ -25,14 +25,24 @@ class MenuApp : public App void updateStateFromSystem(AppState state); void add_item(uint8_t id, MenuItem item); - MenuItem find_item(uint8_t id); + MenuItem *find_item(uint8_t id); std::string getClassName(); std::pair navigationNext(); + void lock(); + private: uint8_t menu_items_count = 0; uint8_t current_menu_position = 0; std::map items; char room[12]; - void render_menu_screen(MenuItem current, MenuItem prev, MenuItem next); + void render_menu_screen(); + + SemaphoreHandle_t mutex; + + MenuItem *current_item; + MenuItem *prev_item; + MenuItem *next_item; + + void unlock(); }; \ No newline at end of file From d16add36b66de2ad40f781cd89cf19a8cdf7a9ad Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 13:50:22 +0100 Subject: [PATCH 22/29] Removed esp_logd --- firmware/src/apps/app.h | 1 - 1 file changed, 1 deletion(-) diff --git a/firmware/src/apps/app.h b/firmware/src/apps/app.h index 17a06c7b..b552ec97 100644 --- a/firmware/src/apps/app.h +++ b/firmware/src/apps/app.h @@ -44,7 +44,6 @@ class App virtual std::pair navigationNext() { - ESP_LOGD("app.h", "type: %d", type); if (type == menu_type) return std::make_pair(apps_type, 1); From 2db5e04088486d87d8dc810871cc91d5a70c7f97 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 14:27:25 +0100 Subject: [PATCH 23/29] Sync bug fix --- firmware/src/apps/apps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 8bdf4ab3..53cbb12f 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -325,7 +325,7 @@ void Apps::updateMenu() position, MenuItem{ it->second->friendly_name, - 1, + position + 1, //! FIXES BUG WITH SYNC MIGHT CREATE MORE?? spr_->color565(0, 255, 200), it->second->small_icon, it->second->big_icon, From 4f89d6814333f4ab0f49713477a06722546d5531 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 15:34:33 +0100 Subject: [PATCH 24/29] Changed menu.cpp name to app_menu.cpp, more descriptive and in preparation of adding new menu.h file --- firmware/src/apps/{menu.cpp => app_menu.cpp} | 2 +- firmware/src/apps/{menu.h => app_menu.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename firmware/src/apps/{menu.cpp => app_menu.cpp} (99%) rename firmware/src/apps/{menu.h => app_menu.h} (100%) diff --git a/firmware/src/apps/menu.cpp b/firmware/src/apps/app_menu.cpp similarity index 99% rename from firmware/src/apps/menu.cpp rename to firmware/src/apps/app_menu.cpp index d45be133..d41f9998 100644 --- a/firmware/src/apps/menu.cpp +++ b/firmware/src/apps/app_menu.cpp @@ -1,4 +1,4 @@ -#include "menu.h" +#include "app_menu.h" MenuApp::MenuApp(TFT_eSprite *spr_) : App(spr_) { diff --git a/firmware/src/apps/menu.h b/firmware/src/apps/app_menu.h similarity index 100% rename from firmware/src/apps/menu.h rename to firmware/src/apps/app_menu.h From a5dbd88c1cc9ef2e56d3cd0fd35cf6bf93d61768 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 16:28:40 +0100 Subject: [PATCH 25/29] Reworked how "menu apps" work and updated onboarding to work with this new way --- firmware/src/apps/menu.h | 61 ++++++++++++++++++++++++++++++++ firmware/src/apps/onboarding.cpp | 32 ++++++----------- firmware/src/apps/onboarding.h | 35 ++---------------- 3 files changed, 74 insertions(+), 54 deletions(-) create mode 100644 firmware/src/apps/menu.h diff --git a/firmware/src/apps/menu.h b/firmware/src/apps/menu.h new file mode 100644 index 00000000..c945a70a --- /dev/null +++ b/firmware/src/apps/menu.h @@ -0,0 +1,61 @@ +#pragma once + +#include "app.h" +#include "font/NDS1210pt7b.h" + +#include + +struct TextItem +{ + const char *text; + uint16_t color; +}; + +struct IconItem +{ + const unsigned char *icon; + uint16_t color; +}; + +struct MenuItem +{ + id app_id; + TextItem screen_name; + TextItem screen_description; + TextItem call_to_action; + IconItem big_icon; + IconItem small_icon; +}; + +class Menu : public App +{ +public: + const app_types type = menu_type; + + Menu(TFT_eSprite *spr_) : App(spr_) {} + virtual ~Menu() {} + TFT_eSprite *render(); + EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); + void updateStateFromSystem(AppState state); + std::pair navigationNext(); + + void add_item(uint8_t id, MenuItem item) + { + items[id] = item; + motor_config.max_position = menu_items_count; + menu_items_count++; + }; + MenuItem find_item(uint8_t id) { return items[id]; }; + + uint8_t get_menu_position() { return current_menu_position; }; + void set_menu_position(uint8_t position) { current_menu_position = position; }; + + uint8_t get_menu_items_count() { return menu_items_count; }; + void set_menu_items_count(uint8_t count) { menu_items_count = count; }; + +private: + uint8_t menu_items_count = 0; + uint8_t current_menu_position = 0; + + std::map items; +}; \ No newline at end of file diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding.cpp index d3482d9d..42ebd626 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -1,6 +1,6 @@ #include "onboarding.h" -OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : App(spr_) +OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : Menu(spr_) { motor_config = PB_SmartKnobConfig{ @@ -30,7 +30,7 @@ EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) motor_config.position_nonce = position_for_onboarding_calc; motor_config.position = position_for_onboarding_calc; - current_onboarding_position = position_for_onboarding_calc; + set_menu_position(position_for_onboarding_calc); return EntityStateUpdate{}; } @@ -39,6 +39,7 @@ void OnboardingApp::updateStateFromSystem(AppState state) {} std::pair OnboardingApp::navigationNext() { + uint8_t current_onboarding_position = get_menu_position(); // Makes sure only apps 1 - 3 have a "second depth" of navigation if (current_onboarding_position >= 1 && current_onboarding_position <= 3) { @@ -54,26 +55,8 @@ std::pair OnboardingApp::navigationNext() TFT_eSprite *OnboardingApp::render() { - OnboardingItem current_item = find_item(current_onboarding_position); - render_onboarding_screen(current_item); - return this->spr_; -} - -void OnboardingApp::add_item(uint8_t id, OnboardingItem item) -{ - items[id] = item; - onboarding_items_count++; - motor_config.max_position = onboarding_items_count - 1; -} - -// TODO: add protection, could cause panic -OnboardingItem OnboardingApp::find_item(uint8_t id) -{ - return (*items.find(id)).second; -} + MenuItem item = find_item(get_menu_position()); -void OnboardingApp::render_onboarding_screen(OnboardingItem item) -{ uint32_t background = spr_->color565(0, 0, 0); uint16_t center_h = TFT_WIDTH / 2; @@ -150,6 +133,9 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) } } + uint8_t onboarding_items_count = get_menu_items_count(); + uint8_t current_onboarding_position = get_menu_position(); + uint32_t menu_item_color; uint8_t menu_item_diameter = 6; uint8_t position_circle_radius = screen_radius - menu_item_diameter; // the radius of the circle where you want the dots to lay. @@ -171,4 +157,6 @@ void OnboardingApp::render_onboarding_screen(OnboardingItem item) // polar coordinates spr_->fillCircle(screen_radius + (position_circle_radius * cosf(menu_starting_angle + degree_per_item * i)), screen_radius - position_circle_radius * sinf(menu_starting_angle + degree_per_item * i), menu_item_diameter / 2, menu_item_color); } -}; \ No newline at end of file + + return this->spr_; +} \ No newline at end of file diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding.h index 22618ed0..978b8417 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding.h @@ -1,48 +1,19 @@ #pragma once -#include "app.h" +#include "menu.h" #include "font/NDS1210pt7b.h" #include -struct TextItem -{ - const char *text; - uint16_t color; -}; - -struct IconItem -{ - const unsigned char *icon; - uint16_t color; -}; -struct OnboardingItem -{ - uint16_t app_id; - TextItem screen_name; - TextItem screen_description; - TextItem call_to_action; - IconItem big_icon; - IconItem small_icon; -}; - -class OnboardingApp : public App +class OnboardingApp : public Menu { public: - const app_types type = menu_type; OnboardingApp(TFT_eSprite *spr_); - TFT_eSprite *render(); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); std::pair navigationNext(); - void add_item(uint8_t id, OnboardingItem item); - OnboardingItem find_item(uint8_t id); + TFT_eSprite *render(); private: - std::map items; - uint8_t onboarding_items_count = 0; - uint8_t current_onboarding_position = 0; - - void render_onboarding_screen(OnboardingItem current); }; From 74cc6be6312d896878ad1f2e9f33c782a03a1ba2 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 17:16:49 +0100 Subject: [PATCH 26/29] Changed app_menu to use new reworked "menu app". Broke something in the process... --- firmware/src/apps/app.h | 16 ++- firmware/src/apps/app_menu.cpp | 12 +- firmware/src/apps/app_menu.h | 13 +- firmware/src/apps/apps.cpp | 111 ++++++++++++------ firmware/src/apps/apps.h | 4 +- .../{onboarding.cpp => onboarding_menu.cpp} | 2 +- .../apps/{onboarding.h => onboarding_menu.h} | 0 7 files changed, 98 insertions(+), 60 deletions(-) rename firmware/src/apps/{onboarding.cpp => onboarding_menu.cpp} (99%) rename firmware/src/apps/{onboarding.h => onboarding_menu.h} (100%) diff --git a/firmware/src/apps/app.h b/firmware/src/apps/app.h index b552ec97..e268bc08 100644 --- a/firmware/src/apps/app.h +++ b/firmware/src/apps/app.h @@ -19,16 +19,26 @@ enum app_types menu_type = 1, apps_type = 2 }; + +typedef uint8_t id; class App { + public: + // ID for app + const app_types type = apps_type; + + const unsigned char *small_icon; + const unsigned char *big_icon; + const char *friendly_name; + App(TFT_eSprite *spr_) { this->spr_ = spr_; } virtual ~App() {} - virtual TFT_eSprite *render(); + virtual EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); virtual void updateStateFromSystem(AppState state); @@ -50,9 +60,7 @@ class App return std::make_pair(menu_type, 0); } - const unsigned char *small_icon; - const unsigned char *big_icon; - const char *friendly_name; + virtual TFT_eSprite *render(); protected: /** Full-size sprite used as a framebuffer */ diff --git a/firmware/src/apps/app_menu.cpp b/firmware/src/apps/app_menu.cpp index d41f9998..8e17c55c 100644 --- a/firmware/src/apps/app_menu.cpp +++ b/firmware/src/apps/app_menu.cpp @@ -1,6 +1,6 @@ #include "app_menu.h" -MenuApp::MenuApp(TFT_eSprite *spr_) : App(spr_) +MenuApp::MenuApp(TFT_eSprite *spr_) : Menu(spr_) { sprintf(room, "%s", "Office"); @@ -101,7 +101,7 @@ void MenuApp::add_item(uint8_t id, MenuItem item) void MenuApp::render_menu_screen() { lock(); - uint32_t color_active = current_item->color; + uint32_t color_active = current_item->screen_name.color; uint32_t color_inactive = spr_->color565(150, 150, 150); uint32_t label_color = color_inactive; uint32_t background = spr_->color565(0, 0, 0); @@ -126,17 +126,17 @@ void MenuApp::render_menu_screen() spr_->setFreeFont(&Roboto_Thin_Bold_24); spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); - spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon, icon_size_active, icon_size_active, color_active, background); + spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon.icon, icon_size_active, icon_size_active, color_active, background); // left one - spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon.icon, icon_size_inactive, icon_size_inactive, color_inactive, background); // right one - spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon.icon, icon_size_inactive, icon_size_inactive, color_inactive, background); spr_->setTextColor(color_active); spr_->setFreeFont(&Roboto_Thin_24); - spr_->drawString(current_item->screen_name, center_h, center_v + icon_size_active / 2 + 30, 1); + spr_->drawString(current_item->screen_name.text, center_h, center_v + icon_size_active / 2 + 30, 1); unlock(); }; diff --git a/firmware/src/apps/app_menu.h b/firmware/src/apps/app_menu.h index da503574..d767c60d 100644 --- a/firmware/src/apps/app_menu.h +++ b/firmware/src/apps/app_menu.h @@ -1,5 +1,5 @@ #pragma once -#include "app.h" +#include "menu.h" #include "font/roboto_thin_bold_24.h" #include @@ -7,16 +7,7 @@ const uint8_t SCREEN_NAME_LENGTH = 20; const uint8_t MEX_MENU_ITEMS = 12; -struct MenuItem -{ - const char *screen_name; - uint16_t app_id; - uint32_t color; - const unsigned char *small_icon; - const unsigned char *big_icon; -}; - -class MenuApp : public App +class MenuApp : public Menu { public: MenuApp(TFT_eSprite *spr_); diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 53cbb12f..1622fb8a 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -1,7 +1,7 @@ -#pragma once #include "apps.h" #include "menu.h" -#include "onboarding.h" +#include "app_menu.h" +#include "onboarding_menu.h" #include "settings.h" #include @@ -122,7 +122,7 @@ void Apps::createOnboarding() onboarding_app->add_item( 0, - OnboardingItem{ + MenuItem{ 1, TextItem{ "SMART KNOB", @@ -143,12 +143,11 @@ void Apps::createOnboarding() IconItem{ nullptr, spr_->color565(255, 255, 255), - }, - }); + }}); onboarding_app->add_item( 1, - OnboardingItem{ + MenuItem{ 2, TextItem{ "HOME ASSISTANT", @@ -169,12 +168,11 @@ void Apps::createOnboarding() IconItem{ home_assistant_80, spr_->color565(17, 189, 242), - }, - }); + }}); onboarding_app->add_item( 2, - OnboardingItem{ + MenuItem{ 3, TextItem{ "WIFI", @@ -195,11 +193,10 @@ void Apps::createOnboarding() IconItem{ wifi_conn_80, spr_->color565(255, 255, 255), - }, - }); + }}); onboarding_app->add_item( 3, - OnboardingItem{ + MenuItem{ 4, TextItem{ "DEMO MODE", @@ -220,11 +217,10 @@ void Apps::createOnboarding() IconItem{ nullptr, spr_->color565(255, 255, 255), - }, - }); + }}); onboarding_app->add_item( 4, - OnboardingItem{ + MenuItem{ 5, TextItem{ "FIRMWARE 0.1b", @@ -245,9 +241,7 @@ void Apps::createOnboarding() IconItem{ nullptr, spr_->color565(255, 255, 255), - }, - - }); + }}); add(menu_type, 0, onboarding_app); @@ -266,20 +260,35 @@ void Apps::createOnboarding() menu_app->add_item( 0, MenuItem{ - "SETTINGS", 4, - spr_->color565(0, 255, 200), - settings_40, - settings_80, - }); + TextItem{ + "SETTINGS", + spr_->color565(0, 255, 200), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, + IconItem{ + settings_80, + spr_->color565(255, 255, 255), + }, + IconItem{ + settings_40, + spr_->color565(0, 255, 200), + }}); std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; cJSON *json_root = cJSON_Parse(apps_config.c_str()); cJSON *json_app = NULL; - uint16_t app_position = 5; - uint16_t menu_position = 1; + uint8_t app_position = 5; + uint8_t menu_position = 1; cJSON_ArrayForEach(json_app, json_root) { @@ -292,12 +301,27 @@ void Apps::createOnboarding() menu_app->add_item( menu_position, MenuItem{ - app->friendly_name, app_position, - spr_->color565(0, 255, 200), - app->small_icon, - app->big_icon, - }); + TextItem{ + app->friendly_name, + spr_->color565(0, 255, 200), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, + IconItem{ + app->big_icon, + spr_->color565(0, 255, 200), + }, + IconItem{ + app->small_icon, + spr_->color565(255, 255, 255), + }}); app_position++; menu_position++; @@ -315,7 +339,7 @@ void Apps::updateMenu() std::map>::iterator it; - uint16_t position = 0; + uint8_t position = 0; for (it = apps[apps_type].begin(); it != apps[apps_type].end(); it++) { @@ -324,12 +348,27 @@ void Apps::updateMenu() menu_app->add_item( position, MenuItem{ - it->second->friendly_name, position + 1, //! FIXES BUG WITH SYNC MIGHT CREATE MORE?? - spr_->color565(0, 255, 200), - it->second->small_icon, - it->second->big_icon, - }); + TextItem{ + it->second->friendly_name, + spr_->color565(0, 255, 200), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, + TextItem{ + "", + spr_->color565(255, 255, 255), + }, + IconItem{ + it->second->big_icon, + 0, + }, + IconItem{ + it->second->small_icon, + 0, + }}); position++; } diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index abf5fa51..6cc89886 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -16,8 +16,8 @@ #include "stopwatch.h" // include all "menu" apps -#include "menu.h" -#include "onboarding.h" +#include "app_menu.h" +#include "onboarding_menu.h" // include all "setup" apps #include "onboarding/hass_setup.h" diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding_menu.cpp similarity index 99% rename from firmware/src/apps/onboarding.cpp rename to firmware/src/apps/onboarding_menu.cpp index 42ebd626..2f74ac7b 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding_menu.cpp @@ -1,4 +1,4 @@ -#include "onboarding.h" +#include "onboarding_menu.h" OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : Menu(spr_) { diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding_menu.h similarity index 100% rename from firmware/src/apps/onboarding.h rename to firmware/src/apps/onboarding_menu.h From d7ad55690fde71c8c3e710a1d4ed3205fb7fb932 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 17:37:18 +0100 Subject: [PATCH 27/29] Revert "Changed app_menu to use new reworked "menu app". Broke something in the process..." This reverts commit 74cc6be6312d896878ad1f2e9f33c782a03a1ba2. --- firmware/src/apps/app.h | 16 +-- firmware/src/apps/app_menu.cpp | 12 +- firmware/src/apps/app_menu.h | 13 +- firmware/src/apps/apps.cpp | 111 ++++++------------ firmware/src/apps/apps.h | 4 +- .../{onboarding_menu.cpp => onboarding.cpp} | 2 +- .../apps/{onboarding_menu.h => onboarding.h} | 0 7 files changed, 60 insertions(+), 98 deletions(-) rename firmware/src/apps/{onboarding_menu.cpp => onboarding.cpp} (99%) rename firmware/src/apps/{onboarding_menu.h => onboarding.h} (100%) diff --git a/firmware/src/apps/app.h b/firmware/src/apps/app.h index e268bc08..b552ec97 100644 --- a/firmware/src/apps/app.h +++ b/firmware/src/apps/app.h @@ -19,26 +19,16 @@ enum app_types menu_type = 1, apps_type = 2 }; - -typedef uint8_t id; class App { - public: - // ID for app - const app_types type = apps_type; - - const unsigned char *small_icon; - const unsigned char *big_icon; - const char *friendly_name; - App(TFT_eSprite *spr_) { this->spr_ = spr_; } virtual ~App() {} - + virtual TFT_eSprite *render(); virtual EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); virtual void updateStateFromSystem(AppState state); @@ -60,7 +50,9 @@ class App return std::make_pair(menu_type, 0); } - virtual TFT_eSprite *render(); + const unsigned char *small_icon; + const unsigned char *big_icon; + const char *friendly_name; protected: /** Full-size sprite used as a framebuffer */ diff --git a/firmware/src/apps/app_menu.cpp b/firmware/src/apps/app_menu.cpp index 8e17c55c..d41f9998 100644 --- a/firmware/src/apps/app_menu.cpp +++ b/firmware/src/apps/app_menu.cpp @@ -1,6 +1,6 @@ #include "app_menu.h" -MenuApp::MenuApp(TFT_eSprite *spr_) : Menu(spr_) +MenuApp::MenuApp(TFT_eSprite *spr_) : App(spr_) { sprintf(room, "%s", "Office"); @@ -101,7 +101,7 @@ void MenuApp::add_item(uint8_t id, MenuItem item) void MenuApp::render_menu_screen() { lock(); - uint32_t color_active = current_item->screen_name.color; + uint32_t color_active = current_item->color; uint32_t color_inactive = spr_->color565(150, 150, 150); uint32_t label_color = color_inactive; uint32_t background = spr_->color565(0, 0, 0); @@ -126,17 +126,17 @@ void MenuApp::render_menu_screen() spr_->setFreeFont(&Roboto_Thin_Bold_24); spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1); - spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon.icon, icon_size_active, icon_size_active, color_active, background); + spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon, icon_size_active, icon_size_active, color_active, background); // left one - spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon.icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); // right one - spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon.icon, icon_size_inactive, icon_size_inactive, color_inactive, background); + spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background); spr_->setTextColor(color_active); spr_->setFreeFont(&Roboto_Thin_24); - spr_->drawString(current_item->screen_name.text, center_h, center_v + icon_size_active / 2 + 30, 1); + spr_->drawString(current_item->screen_name, center_h, center_v + icon_size_active / 2 + 30, 1); unlock(); }; diff --git a/firmware/src/apps/app_menu.h b/firmware/src/apps/app_menu.h index d767c60d..da503574 100644 --- a/firmware/src/apps/app_menu.h +++ b/firmware/src/apps/app_menu.h @@ -1,5 +1,5 @@ #pragma once -#include "menu.h" +#include "app.h" #include "font/roboto_thin_bold_24.h" #include @@ -7,7 +7,16 @@ const uint8_t SCREEN_NAME_LENGTH = 20; const uint8_t MEX_MENU_ITEMS = 12; -class MenuApp : public Menu +struct MenuItem +{ + const char *screen_name; + uint16_t app_id; + uint32_t color; + const unsigned char *small_icon; + const unsigned char *big_icon; +}; + +class MenuApp : public App { public: MenuApp(TFT_eSprite *spr_); diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 1622fb8a..53cbb12f 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -1,7 +1,7 @@ +#pragma once #include "apps.h" #include "menu.h" -#include "app_menu.h" -#include "onboarding_menu.h" +#include "onboarding.h" #include "settings.h" #include @@ -122,7 +122,7 @@ void Apps::createOnboarding() onboarding_app->add_item( 0, - MenuItem{ + OnboardingItem{ 1, TextItem{ "SMART KNOB", @@ -143,11 +143,12 @@ void Apps::createOnboarding() IconItem{ nullptr, spr_->color565(255, 255, 255), - }}); + }, + }); onboarding_app->add_item( 1, - MenuItem{ + OnboardingItem{ 2, TextItem{ "HOME ASSISTANT", @@ -168,11 +169,12 @@ void Apps::createOnboarding() IconItem{ home_assistant_80, spr_->color565(17, 189, 242), - }}); + }, + }); onboarding_app->add_item( 2, - MenuItem{ + OnboardingItem{ 3, TextItem{ "WIFI", @@ -193,10 +195,11 @@ void Apps::createOnboarding() IconItem{ wifi_conn_80, spr_->color565(255, 255, 255), - }}); + }, + }); onboarding_app->add_item( 3, - MenuItem{ + OnboardingItem{ 4, TextItem{ "DEMO MODE", @@ -217,10 +220,11 @@ void Apps::createOnboarding() IconItem{ nullptr, spr_->color565(255, 255, 255), - }}); + }, + }); onboarding_app->add_item( 4, - MenuItem{ + OnboardingItem{ 5, TextItem{ "FIRMWARE 0.1b", @@ -241,7 +245,9 @@ void Apps::createOnboarding() IconItem{ nullptr, spr_->color565(255, 255, 255), - }}); + }, + + }); add(menu_type, 0, onboarding_app); @@ -260,35 +266,20 @@ void Apps::createOnboarding() menu_app->add_item( 0, MenuItem{ + "SETTINGS", 4, - TextItem{ - "SETTINGS", - spr_->color565(0, 255, 200), - }, - TextItem{ - "", - spr_->color565(255, 255, 255), - }, - TextItem{ - "", - spr_->color565(255, 255, 255), - }, - IconItem{ - settings_80, - spr_->color565(255, 255, 255), - }, - IconItem{ - settings_40, - spr_->color565(0, 255, 200), - }}); + spr_->color565(0, 255, 200), + settings_40, + settings_80, + }); std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]"; cJSON *json_root = cJSON_Parse(apps_config.c_str()); cJSON *json_app = NULL; - uint8_t app_position = 5; - uint8_t menu_position = 1; + uint16_t app_position = 5; + uint16_t menu_position = 1; cJSON_ArrayForEach(json_app, json_root) { @@ -301,27 +292,12 @@ void Apps::createOnboarding() menu_app->add_item( menu_position, MenuItem{ + app->friendly_name, app_position, - TextItem{ - app->friendly_name, - spr_->color565(0, 255, 200), - }, - TextItem{ - "", - spr_->color565(255, 255, 255), - }, - TextItem{ - "", - spr_->color565(255, 255, 255), - }, - IconItem{ - app->big_icon, - spr_->color565(0, 255, 200), - }, - IconItem{ - app->small_icon, - spr_->color565(255, 255, 255), - }}); + spr_->color565(0, 255, 200), + app->small_icon, + app->big_icon, + }); app_position++; menu_position++; @@ -339,7 +315,7 @@ void Apps::updateMenu() std::map>::iterator it; - uint8_t position = 0; + uint16_t position = 0; for (it = apps[apps_type].begin(); it != apps[apps_type].end(); it++) { @@ -348,27 +324,12 @@ void Apps::updateMenu() menu_app->add_item( position, MenuItem{ + it->second->friendly_name, position + 1, //! FIXES BUG WITH SYNC MIGHT CREATE MORE?? - TextItem{ - it->second->friendly_name, - spr_->color565(0, 255, 200), - }, - TextItem{ - "", - spr_->color565(255, 255, 255), - }, - TextItem{ - "", - spr_->color565(255, 255, 255), - }, - IconItem{ - it->second->big_icon, - 0, - }, - IconItem{ - it->second->small_icon, - 0, - }}); + spr_->color565(0, 255, 200), + it->second->small_icon, + it->second->big_icon, + }); position++; } diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index 6cc89886..abf5fa51 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -16,8 +16,8 @@ #include "stopwatch.h" // include all "menu" apps -#include "app_menu.h" -#include "onboarding_menu.h" +#include "menu.h" +#include "onboarding.h" // include all "setup" apps #include "onboarding/hass_setup.h" diff --git a/firmware/src/apps/onboarding_menu.cpp b/firmware/src/apps/onboarding.cpp similarity index 99% rename from firmware/src/apps/onboarding_menu.cpp rename to firmware/src/apps/onboarding.cpp index 2f74ac7b..42ebd626 100644 --- a/firmware/src/apps/onboarding_menu.cpp +++ b/firmware/src/apps/onboarding.cpp @@ -1,4 +1,4 @@ -#include "onboarding_menu.h" +#include "onboarding.h" OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : Menu(spr_) { diff --git a/firmware/src/apps/onboarding_menu.h b/firmware/src/apps/onboarding.h similarity index 100% rename from firmware/src/apps/onboarding_menu.h rename to firmware/src/apps/onboarding.h From aa7ec5d21c64c78a8130778aa3e606ac9adbd368 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 20:13:00 +0100 Subject: [PATCH 28/29] Fixed!!! --- firmware/src/apps/app.h | 6 ++-- firmware/src/apps/app_menu.cpp | 4 +-- firmware/src/apps/app_menu.h | 14 ++++---- firmware/src/apps/apps.cpp | 35 ++++++++++--------- firmware/src/apps/apps.h | 5 +-- firmware/src/apps/menu.h | 5 ++- .../{onboarding.cpp => onboarding_menu.cpp} | 12 +++---- .../apps/{onboarding.h => onboarding_menu.h} | 4 +-- 8 files changed, 44 insertions(+), 41 deletions(-) rename firmware/src/apps/{onboarding.cpp => onboarding_menu.cpp} (94%) rename firmware/src/apps/{onboarding.h => onboarding_menu.h} (80%) diff --git a/firmware/src/apps/app.h b/firmware/src/apps/app.h index b552ec97..22cdb5c2 100644 --- a/firmware/src/apps/app.h +++ b/firmware/src/apps/app.h @@ -19,6 +19,8 @@ enum app_types menu_type = 1, apps_type = 2 }; + +typedef uint8_t id; class App { public: @@ -26,8 +28,8 @@ class App App(TFT_eSprite *spr_) { this->spr_ = spr_; - } - virtual ~App() {} + }; + virtual ~App(){}; virtual TFT_eSprite *render(); virtual EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); virtual void updateStateFromSystem(AppState state); diff --git a/firmware/src/apps/app_menu.cpp b/firmware/src/apps/app_menu.cpp index d41f9998..24624f6a 100644 --- a/firmware/src/apps/app_menu.cpp +++ b/firmware/src/apps/app_menu.cpp @@ -87,13 +87,13 @@ std::string MenuApp::getClassName() } // TODO: add protection, could cause panic -MenuItem *MenuApp::find_item(uint8_t id) +MenuItemOld *MenuApp::find_item(uint8_t id) { return &(*items.find(id)).second; } // TODO: add protection of overwriting same items -void MenuApp::add_item(uint8_t id, MenuItem item) +void MenuApp::add_item(uint8_t id, MenuItemOld item) { items.insert(std::make_pair(id, item)); } diff --git a/firmware/src/apps/app_menu.h b/firmware/src/apps/app_menu.h index da503574..c2f455e9 100644 --- a/firmware/src/apps/app_menu.h +++ b/firmware/src/apps/app_menu.h @@ -7,7 +7,7 @@ const uint8_t SCREEN_NAME_LENGTH = 20; const uint8_t MEX_MENU_ITEMS = 12; -struct MenuItem +struct MenuItemOld { const char *screen_name; uint16_t app_id; @@ -24,8 +24,8 @@ class MenuApp : public App EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); - void add_item(uint8_t id, MenuItem item); - MenuItem *find_item(uint8_t id); + void add_item(uint8_t id, MenuItemOld item); + MenuItemOld *find_item(uint8_t id); std::string getClassName(); std::pair navigationNext(); @@ -34,15 +34,15 @@ class MenuApp : public App private: uint8_t menu_items_count = 0; uint8_t current_menu_position = 0; - std::map items; + std::map items; char room[12]; void render_menu_screen(); SemaphoreHandle_t mutex; - MenuItem *current_item; - MenuItem *prev_item; - MenuItem *next_item; + MenuItemOld *current_item; + MenuItemOld *prev_item; + MenuItemOld *next_item; void unlock(); }; \ No newline at end of file diff --git a/firmware/src/apps/apps.cpp b/firmware/src/apps/apps.cpp index 53cbb12f..2d7f311d 100644 --- a/firmware/src/apps/apps.cpp +++ b/firmware/src/apps/apps.cpp @@ -1,7 +1,8 @@ #pragma once #include "apps.h" #include "menu.h" -#include "onboarding.h" +#include "onboarding_menu.h" +#include "app_menu.h" #include "settings.h" #include @@ -118,11 +119,11 @@ void Apps::createOnboarding() { clear(); - OnboardingApp *onboarding_app = new OnboardingApp(this->spr_); + OnboardingMenu *onboarding_menu = new OnboardingMenu(this->spr_); - onboarding_app->add_item( + onboarding_menu->add_item( 0, - OnboardingItem{ + MenuItem{ 1, TextItem{ "SMART KNOB", @@ -146,9 +147,9 @@ void Apps::createOnboarding() }, }); - onboarding_app->add_item( + onboarding_menu->add_item( 1, - OnboardingItem{ + MenuItem{ 2, TextItem{ "HOME ASSISTANT", @@ -172,9 +173,9 @@ void Apps::createOnboarding() }, }); - onboarding_app->add_item( + onboarding_menu->add_item( 2, - OnboardingItem{ + MenuItem{ 3, TextItem{ "WIFI", @@ -197,9 +198,9 @@ void Apps::createOnboarding() spr_->color565(255, 255, 255), }, }); - onboarding_app->add_item( + onboarding_menu->add_item( 3, - OnboardingItem{ + MenuItem{ 4, TextItem{ "DEMO MODE", @@ -222,9 +223,9 @@ void Apps::createOnboarding() spr_->color565(255, 255, 255), }, }); - onboarding_app->add_item( + onboarding_menu->add_item( 4, - OnboardingItem{ + MenuItem{ 5, TextItem{ "FIRMWARE 0.1b", @@ -249,7 +250,7 @@ void Apps::createOnboarding() }); - add(menu_type, 0, onboarding_app); + add(menu_type, 0, onboarding_menu); // APPS FOR OTHER ONBOARDING SCREENS HassSetupApp *hass_setup_app = new HassSetupApp(spr_); @@ -265,7 +266,7 @@ void Apps::createOnboarding() menu_app->add_item( 0, - MenuItem{ + MenuItemOld{ "SETTINGS", 4, spr_->color565(0, 255, 200), @@ -291,7 +292,7 @@ void Apps::createOnboarding() menu_app->add_item( menu_position, - MenuItem{ + MenuItemOld{ app->friendly_name, app_position, spr_->color565(0, 255, 200), @@ -323,9 +324,9 @@ void Apps::updateMenu() menu_app->add_item( position, - MenuItem{ + MenuItemOld{ it->second->friendly_name, - position + 1, //! FIXES BUG WITH SYNC MIGHT CREATE MORE?? + position, //! adding + 1 FIXES BUG WITH SYNC MIGHT CREATE MORE?? spr_->color565(0, 255, 200), it->second->small_icon, it->second->big_icon, diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index abf5fa51..cb6b875c 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -3,6 +3,7 @@ #include #include "app.h" +#include "menu.h" #include "../app_config.h" // include all apps @@ -16,8 +17,8 @@ #include "stopwatch.h" // include all "menu" apps -#include "menu.h" -#include "onboarding.h" +#include "app_menu.h" +#include "onboarding_menu.h" // include all "setup" apps #include "onboarding/hass_setup.h" diff --git a/firmware/src/apps/menu.h b/firmware/src/apps/menu.h index c945a70a..1ff90578 100644 --- a/firmware/src/apps/menu.h +++ b/firmware/src/apps/menu.h @@ -32,12 +32,11 @@ class Menu : public App public: const app_types type = menu_type; - Menu(TFT_eSprite *spr_) : App(spr_) {} - virtual ~Menu() {} - TFT_eSprite *render(); + Menu(TFT_eSprite *spr_) : App(spr_){}; EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); std::pair navigationNext(); + TFT_eSprite *render(); void add_item(uint8_t id, MenuItem item) { diff --git a/firmware/src/apps/onboarding.cpp b/firmware/src/apps/onboarding_menu.cpp similarity index 94% rename from firmware/src/apps/onboarding.cpp rename to firmware/src/apps/onboarding_menu.cpp index 42ebd626..d4bdb323 100644 --- a/firmware/src/apps/onboarding.cpp +++ b/firmware/src/apps/onboarding_menu.cpp @@ -1,6 +1,6 @@ -#include "onboarding.h" +#include "onboarding_menu.h" -OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : Menu(spr_) +OnboardingMenu::OnboardingMenu(TFT_eSprite *spr_) : Menu(spr_) { motor_config = PB_SmartKnobConfig{ @@ -21,7 +21,7 @@ OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : Menu(spr_) }; } -EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) +EntityStateUpdate OnboardingMenu::updateStateFromKnob(PB_SmartKnobState state) { // TODO: cache menu size int32_t position_for_onboarding_calc = state.current_position; @@ -35,9 +35,9 @@ EntityStateUpdate OnboardingApp::updateStateFromKnob(PB_SmartKnobState state) return EntityStateUpdate{}; } -void OnboardingApp::updateStateFromSystem(AppState state) {} +void OnboardingMenu::updateStateFromSystem(AppState state) {} -std::pair OnboardingApp::navigationNext() +std::pair OnboardingMenu::navigationNext() { uint8_t current_onboarding_position = get_menu_position(); // Makes sure only apps 1 - 3 have a "second depth" of navigation @@ -53,7 +53,7 @@ std::pair OnboardingApp::navigationNext() return std::make_pair(type, 0); } -TFT_eSprite *OnboardingApp::render() +TFT_eSprite *OnboardingMenu::render() { MenuItem item = find_item(get_menu_position()); diff --git a/firmware/src/apps/onboarding.h b/firmware/src/apps/onboarding_menu.h similarity index 80% rename from firmware/src/apps/onboarding.h rename to firmware/src/apps/onboarding_menu.h index 978b8417..4bf561b3 100644 --- a/firmware/src/apps/onboarding.h +++ b/firmware/src/apps/onboarding_menu.h @@ -5,11 +5,11 @@ #include -class OnboardingApp : public Menu +class OnboardingMenu : public Menu { public: - OnboardingApp(TFT_eSprite *spr_); + OnboardingMenu(TFT_eSprite *spr_); EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); void updateStateFromSystem(AppState state); std::pair navigationNext(); From 83c6fa9418a444c48eeb58b4cde3dde518e478d8 Mon Sep 17 00:00:00 2001 From: carlhampuswall Date: Fri, 19 Jan 2024 21:02:31 +0100 Subject: [PATCH 29/29] Removed destructor causing vtable for menu error. --- firmware/src/apps/app.h | 1 - firmware/src/apps/apps.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/src/apps/app.h b/firmware/src/apps/app.h index 22cdb5c2..b70f81d1 100644 --- a/firmware/src/apps/app.h +++ b/firmware/src/apps/app.h @@ -29,7 +29,6 @@ class App { this->spr_ = spr_; }; - virtual ~App(){}; virtual TFT_eSprite *render(); virtual EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state); virtual void updateStateFromSystem(AppState state); diff --git a/firmware/src/apps/apps.h b/firmware/src/apps/apps.h index cb6b875c..07569cd7 100644 --- a/firmware/src/apps/apps.h +++ b/firmware/src/apps/apps.h @@ -47,6 +47,7 @@ class Apps private: QueueHandle_t mutex; std::map>> apps; + uint8_t active_id = 0; TFT_eSprite *spr_ = nullptr;