Skip to content

Commit

Permalink
Save 6k code from ESP32 safeboot
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Nov 11, 2024
1 parent 0536cc8 commit 0744bf7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
4 changes: 3 additions & 1 deletion tasmota/tasmota_support/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,11 @@ char* SettingsText(uint32_t index) {

if (index >= SET_MAX) { // Index above SET_MAX are not stored in Settings
#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
if (SET_BUTTON17 <= index && index <= SET_BUTTON32)
return (char*)GetWebButton(index-SET_BUTTON17+16);
#endif
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER
position += settings_text_size -1; // Setting not supported - internal error - return empty string
} else {
SettingsUpdateFinished();
Expand Down
47 changes: 17 additions & 30 deletions tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,8 @@ const WebServerDispatch_t WebServerDispatch[] PROGMEM = {
{ "dl", HTTP_ANY, HandleBackupConfiguration },
{ "rs", HTTP_ANY, HandleRestoreConfiguration },
{ "rt", HTTP_ANY, HandleResetConfiguration },
{ "in", HTTP_ANY, HandleInformation }
#endif // Not FIRMWARE_MINIMAL
#ifndef FIRMWARE_MINIMAL_ONLY
{ "in", HTTP_ANY, HandleInformation },
#endif // Not FIRMWARE_MINIMAL_ONLY
};

void WebServer_on(const char * prefix, void (*func)(void), uint8_t method = HTTP_ANY) {
Expand Down Expand Up @@ -1521,14 +1519,7 @@ void HandleRoot(void) {

if (HTTP_ADMIN == Web.state) {
#ifdef FIRMWARE_MINIMAL
#ifdef ESP32
#ifndef FIRMWARE_MINIMAL_ONLY
WSContentSpaceButton(BUTTON_INFORMATION);
WSContentButton(BUTTON_FIRMWARE_UPGRADE);
#endif // FIRMWARE_MINIMAL_ONLY
#else // ESP8266
WSContentSpaceButton(BUTTON_FIRMWARE_UPGRADE);
#endif // ESP32
WSContentButton(BUTTON_CONSOLE);
#else // Not FIRMWARE_MINIMAL
WSContentSpaceButton(BUTTON_CONFIGURATION);
Expand Down Expand Up @@ -1912,7 +1903,7 @@ void HandleTemplateConfiguration(void) {
if (!FlashPin(i)) {
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", template_gp.io[i]);
}
#endif
#endif // CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
}
WSContentSend_P(PSTR("}1%d}1%d"), flag, Settings->user_template_base); // FLAG: 1 BASE: 17
WSContentEnd();
Expand Down Expand Up @@ -1966,7 +1957,7 @@ void HandleTemplateConfiguration(void) {
RedPin(i) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? PSTR(" style='width:146px'") : "", i, i);
WSContentSend_P(PSTR("<td style='width:54px'><select id='h%d'></select></td></tr>"), i);
}
#endif
#endif // CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
}
WSContentSend_P(PSTR("</table>"));

Expand Down Expand Up @@ -2202,7 +2193,7 @@ void HandleWifiConfiguration(void) {
WebRestart(3);
#else
HandleRoot();
#endif
#endif // RESTART_AFTER_INITIAL_WIFI_CONFIG
}
}

Expand Down Expand Up @@ -2365,7 +2356,7 @@ void HandleWifiConfiguration(void) {
WSContentSend_P(HTTP_FORM_WIFI_PART2, SettingsTextEscaped(SET_STASSID2).c_str(), WIFI_HOSTNAME, WIFI_HOSTNAME, SettingsTextEscaped(SET_HOSTNAME).c_str(), SettingsTextEscaped(SET_CORS).c_str());
#else
WSContentSend_P(HTTP_FORM_WIFI_PART2, SettingsTextEscaped(SET_STASSID2).c_str(), WIFI_HOSTNAME, WIFI_HOSTNAME, SettingsTextEscaped(SET_HOSTNAME).c_str());
#endif
#endif // USE_CORS
}

WSContentSend_P(HTTP_FORM_END);
Expand Down Expand Up @@ -2400,7 +2391,7 @@ void WifiSaveSettings(void) {
cmnd += AddWebCommand(PSTR(D_CMND_HOSTNAME), PSTR("h"), PSTR("1"));
#ifdef USE_CORS
cmnd += AddWebCommand(PSTR(D_CMND_CORS), PSTR("c"), PSTR("1"));
#endif
#endif // USE_CORS
cmnd += AddWebCommand(PSTR(D_CMND_SSID "1"), PSTR("s1"), PSTR("1"));
cmnd += AddWebCommand(PSTR(D_CMND_SSID "2"), PSTR("s2"), PSTR("1"));
cmnd += AddWebCommand(PSTR(D_CMND_PASSWORD "3"), PSTR("p1"), PSTR("\""));
Expand Down Expand Up @@ -2617,12 +2608,6 @@ void HandleRestoreConfiguration(void)
Web.upload_file_type = UPL_SETTINGS;
}

#endif // Not FIRMWARE_MINIMAL

/*-------------------------------------------------------------------------------------------*/

#ifndef FIRMWARE_MINIMAL_ONLY

void WSContentSeparatorI(uint32_t size) {
WSContentSend_P(PSTR("</td></tr><tr><td colspan=2><hr style='font-size:2px'%s/>"), (1 == size)?" size=1":"");
// WSContentSend_P(PSTR("</td></tr><tr><td colspan=2><hr style='font-size:%dpx'/>"), size);
Expand Down Expand Up @@ -2873,7 +2858,8 @@ void HandleInformation(void) {
WSContentSpaceButton(BUTTON_MAIN);
WSContentStop();
}
#endif // Not FIRMWARE_MINIMAL_ONLY

#endif // Not FIRMWARE_MINIMAL

/*-------------------------------------------------------------------------------------------*/

Expand Down Expand Up @@ -2939,7 +2925,7 @@ void HandleUpgradeFirmware(void) {
}
#else
WSContentSend_P(HTTP_FORM_RST_UPG, PSTR(D_START_UPGRADE));
#endif
#endif // ESP32
WSContentSpaceButton(BUTTON_MAIN);
WSContentStop();

Expand Down Expand Up @@ -3169,7 +3155,7 @@ void HandleUploadLoop(void) {
uint32_t upload_size = (!strlen(tmp)) ? 0 : atoi(tmp);
AddLog(LOG_LEVEL_DEBUG, D_LOG_UPLOAD "Freespace %i Filesize %i", ESP.getFreeSketchSpace(), upload_size);
if (upload_size > ESP.getFreeSketchSpace()) { // TODO revisit this test
#endif
#endif // ESP8266
Web.upload_error = 4; // Program flash size is larger than real flash size
return;
}
Expand Down Expand Up @@ -3565,6 +3551,8 @@ bool CaptivePortal(void)

/*********************************************************************************************/

#ifndef FIRMWARE_MINIMAL

enum {QUERY_DEFAULT=0, QUERY_RUN};
int WebQuery(char *buffer, int query_function);

Expand Down Expand Up @@ -3727,7 +3715,6 @@ int WebQuery(char *buffer, int query_function = 0)
return status;
}


int WebSend(char *buffer)
{
// [tasmota] POWER1 ON --> Sends http://tasmota/cm?cmnd=POWER1 ON
Expand Down Expand Up @@ -3878,7 +3865,6 @@ const char kWebCmndStatus[] PROGMEM = D_JSON_DONE "|" D_JSON_WRONG_PARAMETERS "|

const char kWebCommands[] PROGMEM = "|" // No prefix
D_CMND_WEBLOG "|"
#ifndef FIRMWARE_MINIMAL_ONLY
D_CMND_WEBTIME "|"
#ifdef USE_EMULATION
D_CMND_EMULATION "|"
Expand All @@ -3897,12 +3883,10 @@ const char kWebCommands[] PROGMEM = "|" // No prefix
#ifdef USE_CORS
"|" D_CMND_CORS
#endif
#endif // FIRMWARE_MINIMAL_ONLY
;

void (* const WebCommand[])(void) PROGMEM = {
&CmndWeblog,
#ifndef FIRMWARE_MINIMAL_ONLY
&CmndWebTime,
#ifdef USE_EMULATION
&CmndEmulation,
Expand All @@ -3921,7 +3905,6 @@ void (* const WebCommand[])(void) PROGMEM = {
#ifdef USE_CORS
, &CmndCors
#endif
#endif // FIRMWARE_MINIMAL_ONLY
};

/*********************************************************************************************/
Expand Down Expand Up @@ -4174,7 +4157,9 @@ void CmndCors(void)
}
ResponseCmndChar(SettingsText(SET_CORS));
}
#endif
#endif // USE_CORS

#endif // not FIRMWARE_MINIMAL

/*********************************************************************************************\
* Interface
Expand Down Expand Up @@ -4263,9 +4248,11 @@ bool Xdrv01(uint32_t function)
}
}
break;
#ifndef FIRMWARE_MINIMAL
case FUNC_COMMAND:
result = DecodeCommand(kWebCommands, WebCommand);
break;
#endif // FIRMWARE_MINIMAL
case FUNC_ACTIVE:
result = true;
break;
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_06_snfbridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ void CmndRfTimeout(void) {
}

#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL

void SonoffBridgeAddButton(void) {
WSContentSend_P(HTTP_TABLE100);
Expand Down Expand Up @@ -539,6 +540,7 @@ void SonoffBridgeWebGetArg(void) {
}
}

#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER

/*********************************************************************************************\
Expand All @@ -559,12 +561,14 @@ bool Xdrv06(uint32_t function)
result = DecodeCommand(kSonoffBridgeCommands, SonoffBridgeCommand);
break;
#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
case FUNC_WEB_ADD_MAIN_BUTTON:
SonoffBridgeAddButton();
break;
case FUNC_WEB_GET_ARG:
SonoffBridgeWebGetArg();
break;
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER
case FUNC_INIT:
if (Settings->rf_duplicate_time < 10) {
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ void TuyaSensorsShow(bool json)
}

#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL

#define WEB_HANDLE_TUYA "d16"

Expand Down Expand Up @@ -1646,6 +1647,7 @@ void TuyaWebGetArg(void) {
}
}

#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER

/*********************************************************************************************\
Expand Down Expand Up @@ -1735,6 +1737,7 @@ bool Xdrv16(uint32_t function) {
TuyaSensorsShow(1);
break;
#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
case FUNC_WEB_ADD_MAIN_BUTTON:
TuyaAddButton();
break;
Expand All @@ -1744,6 +1747,7 @@ bool Xdrv16(uint32_t function) {
case FUNC_WEB_SENSOR:
TuyaSensorsShow(0);
break;
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER
case FUNC_ACTIVE:
result = true;
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ void TuyaSensorsShow(bool json)
}

#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL

#define WEB_HANDLE_TUYA "d16"

Expand Down Expand Up @@ -2439,6 +2440,7 @@ void TuyaWebGetArg(void) {
}
}

#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER

/*********************************************************************************************\
Expand Down Expand Up @@ -2570,6 +2572,7 @@ bool Xdrv16(uint32_t function) {
TuyaSensorsShow(1);
break;
#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
case FUNC_WEB_ADD_MAIN_BUTTON:
TuyaAddButton();
break;
Expand All @@ -2579,6 +2582,7 @@ bool Xdrv16(uint32_t function) {
case FUNC_WEB_SENSOR:
TuyaSensorsShow(0);
break;
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER
case FUNC_ACTIVE:
result = true;
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xlgt_light/xlgt_07_lsc_mcsl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ void LscMcModuleSelected(void) {
}

#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
#ifdef USE_LSC_MCSL_GUI

void LscMcAddFuctionButtons(void) {
Expand Down Expand Up @@ -287,6 +288,7 @@ void LscMcWebGetArg(void) {
}

#endif // USE_LSC_MCSL_GUI
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER


Expand All @@ -306,6 +308,7 @@ bool Xlgt07(uint32_t function)
result = LscMcMultiButtonPressed();
break;
#ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
#ifdef USE_LSC_MCSL_GUI
case FUNC_WEB_ADD_MAIN_BUTTON:
LscMcAddFuctionButtons();
Expand All @@ -314,6 +317,7 @@ bool Xlgt07(uint32_t function)
LscMcWebGetArg();
break;
#endif // USE_LSC_MCSL_GUI
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER
case FUNC_MODULE_INIT:
LscMcModuleSelected();
Expand Down

0 comments on commit 0744bf7

Please sign in to comment.