Skip to content

Commit

Permalink
Fix remaining issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cziter15 committed Sep 19, 2024
1 parent 771db6a commit f33e8f0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
12 changes: 6 additions & 6 deletions src/ksf/comp/ksDevicePortal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ namespace ksf::comps
{
case WIFI_SCAN_FAILED:
{
#if ESP32
#if defined(ESP32)
WiFi.scanNetworks(true, false, true);
#elif ESP8266
#elif defined(ESP8266)
WiFi.scanNetworks(true, true);
#else
#error Platform not implemented.
Expand Down Expand Up @@ -511,10 +511,10 @@ namespace ksf::comps
auto& upload{webServer->upload()};
if (upload.status == UPLOAD_FILE_START)
{
#if ESP8266
#if defined(ESP8266)
Update.runAsync(true);
auto maxSketchSpace{(ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000};
#elif ESP32
#elif defined(ESP32)
auto maxSketchSpace{UPDATE_SIZE_UNKNOWN};
#else
#error Platform not implemented.
Expand Down Expand Up @@ -584,12 +584,12 @@ namespace ksf::comps
webServer->onNotFound(std::bind(&ksDevicePortal::onRequest_notFound, this));

/* Setup index page handler. */
webServer->on(FPSTR("/"), HTTP_GET,
webServer->on(FPSTR("/"), HTTP_GET,
std::bind(&ksDevicePortal::onRequest_index, this)
);

/* Setup OTA update request handler. */
webServer->on("/api/flash", HTTP_POST,
webServer->on("/api/flash", HTTP_POST,
std::bind(&ksDevicePortal::onRequest_otaFinish, this), // Upload file part
std::bind(&ksDevicePortal::onRequest_otaChunk, this) // Upload file end
);
Expand Down
4 changes: 2 additions & 2 deletions src/ksf/comp/ksMqttConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ namespace ksf::comps
});
#endif

#if ESP32
#if defined(ESP32)
/* If host is an IP Address, use it. Otherwise use domain name. */
if (IPAddress serverIP; serverIP.fromString(this->broker.c_str()))
netClientUq->connect(serverIP, portNumber, KSF_MQTT_TIMEOUT_MS);
else
netClientUq->connect(this->broker.c_str(), portNumber, KSF_MQTT_TIMEOUT_MS);
#elif ESP8266
#elif defined(ESP8266)
/* If host is an IP Address, use it. Otherwise use domain name. */
if (IPAddress serverIP; serverIP.fromString(this->broker.c_str()))
netClientUq->connect(serverIP, portNumber);
Expand Down
2 changes: 1 addition & 1 deletion src/ksf/comp/ksMqttConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "../evt/ksEvent.h"
#include "../ksSimpleTimer.h"

#if (ESP32 && ESP_ARDUINO_VERSION_MAJOR >= 3)
#if (defined(ESP32) && ESP_ARDUINO_VERSION_MAJOR >= 3)
#define ksMqttConnectorNetClient_t NetworkClient
#define ksMqttConnectorNetClientSecure_t NetworkClientSecure
#else
Expand Down
7 changes: 4 additions & 3 deletions src/ksf/comp/ksWifiConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ namespace ksf::comps
ksWifiConfigurator(PSTR("KSFDevice"));
}


ksWifiConfigurator::ksWifiConfigurator(std::string devicePrefixName)
// As the device name is our field, we are able to move, it's better to do so than using const ref
: deviceName(std::move(devicePrefixName))
{
deviceName += '-';
#if ESP32
#if defined(ESP32)
deviceName += std::to_string(ESP.getEfuseMac());
#elif ESP8266
#elif defined(ESP8266)
deviceName += std::to_string(ESP.getChipId());
#else
#else
#error Platform not implemented.
#endif
}
Expand Down
48 changes: 24 additions & 24 deletions src/ksf/ksConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ namespace ksf

void initializeFramework()
{
#if ESP32
#if (ESP_ARDUINO_VERSION_MAJOR >= 3)
esp_task_wdt_config_t twdt_config = {
.timeout_ms = KSF_WATCHDOG_TIMEOUT_SECS * 1000,
.idle_core_mask = (1 << CONFIG_SOC_CPU_CORES_NUM) - 1,
.trigger_panic = false,
};
esp_task_wdt_reconfigure(&twdt_config);
#else
esp_task_wdt_init(KSF_WATCHDOG_TIMEOUT_SECS * 1000, false);
#endif
#if defined(ESP32)
#if (ESP_ARDUINO_VERSION_MAJOR >= 3)
esp_task_wdt_config_t twdt_config = {
.timeout_ms = KSF_WATCHDOG_TIMEOUT_SECS * 1000,
.idle_core_mask = (1 << CONFIG_SOC_CPU_CORES_NUM) - 1,
.trigger_panic = false,
};
esp_task_wdt_reconfigure(&twdt_config);
#else
esp_task_wdt_init(KSF_WATCHDOG_TIMEOUT_SECS * 1000, false);
#endif
/* Initialize filesystem. */
LittleFS.begin(true);
#endif

#if ESP8266
#if defined(ESP8266)
/* Setup watchdog. */
ESP.wdtEnable(KSF_WATCHDOG_TIMEOUT_SECS * 1000);

Expand Down Expand Up @@ -93,11 +93,11 @@ namespace ksf
return false;
for (auto entry{dir.openNextFile()}; entry; entry = dir.openNextFile())
{
#if ESP8266
std::string path{entry.fullName()};
#else
std::string path{entry.path()};
#endif
#if defined(ESP8266)
std::string path{entry.fullName()};
#else
std::string path{entry.path()};
#endif

bool isDirectory{entry.isDirectory()};
entry.close();
Expand All @@ -121,11 +121,11 @@ namespace ksf
{
bool success{removeDirectory(getNvsDirectory())};

#if ESP8266
success &= !ESP.eraseConfig();
#elif ESP32
success &= nvs_flash_erase() != ESP_OK;
#endif
#if defined(ESP8266)
success &= !ESP.eraseConfig();
#elif defined(ESP32)
success &= nvs_flash_erase() != ESP_OK;
#endif

return success;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace ksf
const std::string getResetReason()
{
auto otaBootType{getOtaBootType()};
#if ESP32
#if defined(ESP32)
switch (esp_reset_reason())
{
case ESP_RST_POWERON:
Expand All @@ -212,7 +212,7 @@ namespace ksf
default:
return PSTR("Unknown");
}
#elif ESP8266
#elif defined(ESP8266)
if (otaBootType != EOTAType::NO_OTA && ESP.getResetInfoPtr()->reason == REASON_SOFT_RESTART)
return otaTypeToString(otaBootType);

Expand Down

0 comments on commit f33e8f0

Please sign in to comment.