@@ -497,14 +497,12 @@ void DisplayText(void)
497497 // use disp_xpos, disp_ypos
498498 DisplayDrawStringAt (disp_xpos, disp_ypos, linebuf, fg_color, 0 );
499499 }
500- #ifdef USE_DISPLAY_MODES1TO5
501- } else {
502- DisplayLogBufferAdd (linebuf);
503- }
504- #endif // USE_DISPLAY_MODES1TO5
505500 memset (linebuf, ' ' , sizeof (linebuf));
506501 linebuf[sizeof (linebuf)-1 ] = 0 ;
507502 dp = linebuf;
503+ #ifdef USE_DISPLAY_MODES1TO5
504+ }
505+ #endif // USE_DISPLAY_MODES1TO5
508506 }
509507 } else {
510508 // copy chars
@@ -1236,7 +1234,9 @@ extern FS *ffsp;
12361234 alignright (linebuf);
12371235 }
12381236#ifdef USE_DISPLAY_MODES1TO5
1239- if (!Settings->display_mode ) {
1237+ if (Settings->display_mode ) {
1238+ DisplayLogBufferAdd (linebuf);
1239+ } else
12401240#endif // USE_DISPLAY_MODES1TO5
12411241 if (col > 0 && lin > 0 ) {
12421242 // use col and lin
@@ -1245,11 +1245,6 @@ extern FS *ffsp;
12451245 // use disp_xpos, disp_ypos
12461246 DisplayDrawStringAt (disp_xpos, disp_ypos, linebuf, fg_color, 0 );
12471247 }
1248- #ifdef USE_DISPLAY_MODES1TO5
1249- } else {
1250- DisplayLogBufferAdd (linebuf);
1251- }
1252- #endif // USE_DISPLAY_MODES1TO5
12531248 }
12541249 // draw buffer
12551250 if (auto_draw&1 ) {
@@ -1597,6 +1592,8 @@ void DisplayAllocLogBuffer(void)
15971592 if (disp_log_buffer != nullptr ) {
15981593 disp_log_buffer_cols = Settings->display_cols [0 ] +1 ;
15991594 DisplayClearLogBuffer ();
1595+ DisplayClearScreenBuffer ();
1596+ DisplayClear ();
16001597 }
16011598 }
16021599}
@@ -1818,35 +1815,37 @@ void DisplayAnalyzeJson(char *topic, const char *json)
18181815 }
18191816}
18201817
1821- void DisplayMqttSubscribe (void )
1822- {
1818+ void DisplayMqttSubscribe (void ) {
18231819/* Subscribe to tele messages only
18241820 * Supports the following FullTopic formats
18251821 * - %prefix%/%topic%
18261822 * - home/%prefix%/%topic%
18271823 * - home/level2/%prefix%/%topic% etc.
18281824 */
1825+ char stopic[TOPSZ];
1826+ strlcpy (stopic, SettingsText (SET_MQTT_FULLTOPIC), sizeof (stopic));
1827+ char *tp = strtok (stopic, " /" );
1828+ char ntopic[TOPSZ];
1829+ ntopic[0 ] = ' \0 ' ;
1830+ while (tp != nullptr ) {
1831+ if (!strcmp_P (tp, MQTT_TOKEN_PREFIX)) {
1832+ break ;
1833+ }
1834+ strncat_P (ntopic, PSTR (" +/" ), sizeof (ntopic) - strlen (ntopic) -1 ); // Add single-level wildcards
1835+ tp = strtok (nullptr , " /" );
1836+ }
1837+ strncat (ntopic, SettingsText (SET_MQTTPREFIX3), sizeof (ntopic) - strlen (ntopic) -1 ); // Subscribe to tele messages
1838+ strncat_P (ntopic, PSTR (" /#" ), sizeof (ntopic) - strlen (ntopic) -1 ); // Add multi-level wildcard
18291839 if (Settings->display_model && (Settings->display_mode &0x04 )) {
1830-
1831- char stopic[TOPSZ];
1832- char ntopic[TOPSZ];
1833-
1834- ntopic[0 ] = ' \0 ' ;
1835- strlcpy (stopic, SettingsText (SET_MQTT_FULLTOPIC), sizeof (stopic));
1836- char *tp = strtok (stopic, " /" );
1837- while (tp != nullptr ) {
1838- if (!strcmp_P (tp, MQTT_TOKEN_PREFIX)) {
1839- break ;
1840- }
1841- strncat_P (ntopic, PSTR (" +/" ), sizeof (ntopic) - strlen (ntopic) -1 ); // Add single-level wildcards
1842- tp = strtok (nullptr , " /" );
1840+ if (!disp_subscribed) {
1841+ disp_subscribed = true ;
1842+ MqttSubscribe (ntopic);
18431843 }
1844- strncat (ntopic, SettingsText (SET_MQTTPREFIX3), sizeof (ntopic) - strlen (ntopic) -1 ); // Subscribe to tele messages
1845- strncat_P (ntopic, PSTR (" /#" ), sizeof (ntopic) - strlen (ntopic) -1 ); // Add multi-level wildcard
1846- MqttSubscribe (ntopic);
1847- disp_subscribed = true ;
18481844 } else {
1849- disp_subscribed = false ;
1845+ if (disp_subscribed) {
1846+ disp_subscribed = false ;
1847+ MqttUnsubscribe (ntopic);
1848+ }
18501849 }
18511850}
18521851
@@ -2026,14 +2025,18 @@ void CmndDisplayMode(void) {
20262025 if ((XdrvMailbox.payload >= 0 ) && (XdrvMailbox.payload <= 5 )) {
20272026 uint32_t last_display_mode = Settings->display_mode ;
20282027 Settings->display_mode = XdrvMailbox.payload ;
2029-
2030- if (disp_subscribed != (Settings->display_mode &0x04 )) {
2031- TasmotaGlobal.restart_flag = 2 ; // Restart to Add/Remove MQTT subscribe
2032- } else {
2033- if (Settings->display_mode ) { // Switch to non mode 0
2028+ if (last_display_mode != Settings->display_mode ) { // Switch to different mode
2029+ if ((!last_display_mode && Settings->display_mode ) || // Switch to mode 1, 2, 3 or 4
2030+ (last_display_mode && !Settings->display_mode )) { // Switch to mode 0
2031+ DisplayInit (DISPLAY_INIT_MODE);
2032+ }
2033+ if (1 == Settings->display_mode ) { // Switch to mode 1
2034+ DisplayClear ();
2035+ }
2036+ else if (Settings->display_mode > 1 ) { // Switch to mode 2, 3 or 4
20342037 DisplayLogBufferInit ();
20352038 }
2036- DisplayInit (DISPLAY_INIT_MODE );
2039+ DisplayMqttSubscribe ( );
20372040 }
20382041 }
20392042#endif // USE_DISPLAY_MODES1TO5
0 commit comments