diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index be850e6..5362672 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -7,6 +7,8 @@ substitutions: + notification_line_length_limit: "39" + ##### DON'T CHANGE THIS ##### version: "4.0" ############################# @@ -226,14 +228,42 @@ api: label: string text: string then: - - logger.log: "Service: notification_show" - lambda: |- + ESP_LOGV("service.notification_show", "Starting"); + ESP_LOGV("service.notification_show", "label: %s", label.c_str()); + ESP_LOGV("service.notification_show", "text: %s", text.c_str()); + ESP_LOGV("service.notification_show", "text length: %i", text.length()); + id(disp1).send_command_printf("is_notification=1"); id(disp1).send_command_printf("page notification"); id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str()); - id(disp1).set_component_text_printf("notification.notifi_text01", "%s", text.c_str()); + + int maxChars = ${notification_line_length_limit}; + int startPos = 0; + int endPos = 0; + std::string wrappedText = ""; + while (startPos < text.length()) { + while (text[startPos] == ' ' and startPos < text.length()) { startPos++; } + int endPos = startPos + maxChars; + if (endPos >= text.length()) endPos = text.length(); + else + { + while (endPos > startPos && text[endPos] != ' ') { endPos--; } + if (endPos == startPos) endPos = startPos + maxChars; // Handle case of long word + } + wrappedText += text.substr(startPos, endPos-startPos); + if (endPos < text.length()) + { + while (text[endPos] == ' ') { endPos--; } + if (endPos >= startPos) wrappedText += "\\r"; + } + startPos = endPos + 1; // Skip the space + while (text[startPos] == ' ' and startPos < text.length()) { startPos++; } + } + ESP_LOGV("service.notification_show", "text (new): %s", wrappedText.c_str()); + id(disp1).set_component_text_printf("notification.notifi_text01", "%s", wrappedText.c_str()); id(notification_label).publish_state(label.c_str()); - id(notification_text).publish_state(text.c_str()); + id(notification_text).publish_state(wrappedText.c_str()); - switch.turn_on: notification_unread - if: condition: diff --git a/nspanel_eu.HMI b/nspanel_eu.HMI index d284a9a..b1ccafa 100644 Binary files a/nspanel_eu.HMI and b/nspanel_eu.HMI differ diff --git a/nspanel_eu.tft b/nspanel_eu.tft index a36d361..3623500 100644 Binary files a/nspanel_eu.tft and b/nspanel_eu.tft differ diff --git a/nspanel_eu_code/notification.txt b/nspanel_eu_code/notification.txt index 5abee5f..5708896 100644 --- a/nspanel_eu_code/notification.txt +++ b/nspanel_eu_code/notification.txt @@ -57,7 +57,7 @@ Text notifi_text01 Send Component ID : disabled Associated Keyboard: none Text : - Max. Text Size : 100 + Max. Text Size : 250 Text notifi_label Attributes diff --git a/nspanel_us.HMI b/nspanel_us.HMI index cccc67f..d455080 100644 Binary files a/nspanel_us.HMI and b/nspanel_us.HMI differ diff --git a/nspanel_us.tft b/nspanel_us.tft index 9b27efb..632e18b 100644 Binary files a/nspanel_us.tft and b/nspanel_us.tft differ diff --git a/nspanel_us_code/notification.txt b/nspanel_us_code/notification.txt index 7a4d767..c372ed9 100644 --- a/nspanel_us_code/notification.txt +++ b/nspanel_us_code/notification.txt @@ -57,7 +57,7 @@ Text notifi_text01 Send Component ID : disabled Associated Keyboard: none Text : - Max. Text Size : 100 + Max. Text Size : 250 Text notifi_label Attributes diff --git a/nspanel_us_land.HMI b/nspanel_us_land.HMI index 7abc63f..d3b75a0 100644 Binary files a/nspanel_us_land.HMI and b/nspanel_us_land.HMI differ diff --git a/nspanel_us_land.tft b/nspanel_us_land.tft index 669dfde..803c58d 100644 Binary files a/nspanel_us_land.tft and b/nspanel_us_land.tft differ diff --git a/nspanel_us_land_code/notification.txt b/nspanel_us_land_code/notification.txt index 5abee5f..5708896 100644 --- a/nspanel_us_land_code/notification.txt +++ b/nspanel_us_land_code/notification.txt @@ -57,7 +57,7 @@ Text notifi_text01 Send Component ID : disabled Associated Keyboard: none Text : - Max. Text Size : 100 + Max. Text Size : 250 Text notifi_label Attributes