From eb03d33eddfe46d137c6cda4350a5876251aa356 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:35:06 +0100 Subject: [PATCH] Support to idf v5 --- nspanel_esphome_addon_upload_tft.yaml | 6 ++-- nspanel_esphome_core.yaml | 46 +++++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/nspanel_esphome_addon_upload_tft.yaml b/nspanel_esphome_addon_upload_tft.yaml index e93879d..707bc86 100644 --- a/nspanel_esphome_addon_upload_tft.yaml +++ b/nspanel_esphome_addon_upload_tft.yaml @@ -462,7 +462,7 @@ script: transfer_buffer_size_ = chunk_size; } - ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d", + ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %" PRIu32, url.c_str(), content_length_, transfer_buffer_size_, ESP.getFreeHeap()); int result = 0; @@ -559,7 +559,7 @@ script: result += static_cast(recv_string[j + 1]) << (8 * j); } if (result > 0) { - ESP_LOGI(TAG, "Nextion reported new range %d", result); + ESP_LOGI(TAG, "Nextion reported new range %" PRIu32, result); content_length_ = tft_size_ - result; // Deallocate the buffer when done delete[] buffer; @@ -692,7 +692,7 @@ script: return upload_end_(false); } - ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d, Heap Size %d", + ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d, Heap Size %" PRIu32, url.c_str(), content_length_, esp_get_free_heap_size()); ESP_LOGV(TAG, "Starting transfer by chunks loop"); diff --git a/nspanel_esphome_core.yaml b/nspanel_esphome_core.yaml index 0ef10e9..cee2567 100644 --- a/nspanel_esphome_core.yaml +++ b/nspanel_esphome_core.yaml @@ -383,7 +383,7 @@ api: foreground: int[] background: int[] then: - - lambda: set_component_color->execute(component, foreground, background); + - lambda: set_component_color->execute(component, std::vector(foreground.begin(), foreground.end()), std::vector(background.begin(), background.end())); ##### Service to show a notification-message on the screen ##### - service: notification_show @@ -437,7 +437,7 @@ api: { if ((page_icon != std::string()) and (page_icon != "")) disp1->set_component_text_printf("icon_state", "%s", page_icon.c_str()); - set_component_color->execute("icon_state", page_icon_color, {}); + set_component_color->execute("icon_state", std::vector(page_icon_color.begin(), page_icon_color.end()), {-1}); } # Service to show a QR code on the display (ex. for WiFi password) @@ -494,10 +494,10 @@ api: std::string btnicon = btn_id.c_str() + std::string("icon"); std::string btntext = btn_id.c_str() + std::string("text"); std::string btnbri = btn_id.c_str() + std::string("bri"); - disp1->send_command_printf("%spic.pic=%i", btn_id.c_str(), btn_pic); - set_component_color->execute(btnicon.c_str(), btn_icon_font, btn_bg); - set_component_color->execute(btntext.c_str(), btn_txt_font, btn_bg); - set_component_color->execute(btnbri.c_str(), btn_bri_font, btn_bg); + disp1->send_command_printf("%spic.pic=%" PRIu32, btn_id.c_str(), btn_pic); + set_component_color->execute(btnicon.c_str(), std::vector(btn_icon_font.begin(), btn_icon_font.end()), std::vector(btn_bg.begin(), btn_bg.end())); + set_component_color->execute(btntext.c_str(), std::vector(btn_txt_font.begin(), btn_txt_font.end()), std::vector(btn_bg.begin(), btn_bg.end())); + set_component_color->execute(btnbri.c_str(), std::vector(btn_bri_font.begin(), btn_bri_font.end()), std::vector(btn_bg.begin(), btn_bg.end())); disp1->set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str()); display_wrapped_text->execute(btntext.c_str(), btn_label.c_str(), 10); if (strcmp(btn_bri_txt.c_str(), "0") != 0) @@ -556,19 +556,26 @@ api: // Notification button disp1->send_command_printf("is_notification=%i", (notification_text->state.empty() and notification_label->state.empty()) ? 0 : 1); disp1->set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str()); - set_component_color->execute("home.bt_notific", notification_unread->state ? notification_icon_color_unread : notification_icon_color_normal, {}); + set_component_color->execute("home.bt_notific", notification_unread->state ? + std::vector(notification_icon_color_unread.begin(), notification_icon_color_unread.end()) : + std::vector(notification_icon_color_normal.begin(), notification_icon_color_normal.end()), + {-1}); id(home_notify_icon_color_normal) = notification_icon_color_normal; id(home_notify_icon_color_unread) = notification_icon_color_unread; // QRCode button disp1->send_command_printf("is_qrcode=%i", (qrcode) ? 1 : 0); disp1->set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str()); - set_component_color->execute("home.bt_qrcode", qrcode_icon_color, {}); + //set_component_color->execute("home.bt_qrcode", qrcode_icon_color, {}); + set_component_color->execute("home.bt_entities", std::vector(qrcode_icon_color.begin(), qrcode_icon_color.end()), {-1}); + // Entities pages button disp1->send_command_printf("is_entities=%i", (entities_pages) ? 1 : 0); disp1->set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str()); - set_component_color->execute("home.bt_entities", entities_pages_icon_color, {}); + //set_component_color->execute("home.bt_entities", entities_pages_icon_color, {}); + set_component_color->execute("home.bt_entities", std::vector(entities_pages_icon_color.begin(), entities_pages_icon_color.end()), {-1}); + // Alarm button disp1->send_command_printf("is_alarm=%i", (alarm_state == "" or alarm_state.empty()) ? 0 : 1); @@ -666,7 +673,7 @@ api: if (volume_level != id(last_volume_level)) { id(last_volume_level) = volume_level; - disp1->set_component_text_printf("vol_text", "%i%%", volume_level); + disp1->set_component_text_printf("vol_text", "%" PRIu32 "%%", volume_level); disp1->set_component_value("vol_slider", volume_level); } disp1->show_component("vol_slider"); @@ -835,10 +842,10 @@ globals: initial_value: '65535' - id: home_notify_icon_color_normal - type: std::vector + type: std::vector restore_value: false - id: home_notify_icon_color_unread - type: std::vector + type: std::vector restore_value: false ##### Versions ##### @@ -1214,9 +1221,9 @@ switch: optimistic: true restore_mode: ALWAYS_OFF on_turn_on: - - lambda: set_component_color->execute("home.bt_notific", id(home_notify_icon_color_unread), {}); + - lambda: set_component_color->execute("home.bt_notific", std::vector(id(home_notify_icon_color_unread).begin(), id(home_notify_icon_color_unread).end()), {-1}); on_turn_off: - - lambda: set_component_color->execute("home.bt_notific", id(home_notify_icon_color_normal), {}); + - lambda: set_component_color->execute("home.bt_notific", std::vector(id(home_notify_icon_color_normal).begin(), id(home_notify_icon_color_normal).end()), {-1}); ##### Notification sound ##### - name: ${device_name} Notification sound @@ -1939,13 +1946,15 @@ script: int bg565 = -1; // Foreground - if (foreground.size() == 3) fg565 = ((foreground[0] & 0b11111000) << 8) | ((foreground[1] & 0b11111100) << 3) | (foreground[2] >> 3); + if (foreground.size() == 3 and foreground[0] >= 0 and foreground[1] >= 0 and foreground[2] >= 0) fg565 = ((foreground[0] & 0b11111000) << 8) | ((foreground[1] & 0b11111100) << 3) | (foreground[2] >> 3); else if (foreground.size() == 1) fg565 = foreground[0]; + else fg565 = -1; if (fg565 >= 0) disp1->set_component_font_color(component.c_str(), fg565); // Background - if (background.size() == 3) bg565 = ((background[0] & 0b11111000) << 8) | ((background[1] & 0b11111100) << 3) | (background[2] >> 3); + if (background.size() == 3 and background[0] >= 0 and background[1] >= 0 and background[2] >= 0) bg565 = ((background[0] & 0b11111000) << 8) | ((background[1] & 0b11111100) << 3) | (background[2] >> 3); else if (background.size() == 1) bg565 = background[0]; + else bg565 = -1; if (bg565 >= 0) disp1->set_component_background_color(component.c_str(), bg565); - id: display_wrapped_text @@ -2251,7 +2260,10 @@ script: refresh_relays->execute(); refresh_wifi_icon->execute(); disp1->send_command_printf("is_notification=%i", (notification_text->state.empty() and notification_label->state.empty()) ? 0 : 1); - set_component_color->execute("home.bt_notific", notification_unread->state ? id(home_notify_icon_color_unread) : id(home_notify_icon_color_normal), {}); + set_component_color->execute("home.bt_notific", notification_unread->state ? + std::vector(id(home_notify_icon_color_unread).begin(), id(home_notify_icon_color_unread).end()) : + std::vector(id(home_notify_icon_color_normal).begin(), id(home_notify_icon_color_normal).end()), + {-1}); refresh_datetime->execute(); addon_climate_update_page_home->execute(); }