Skip to content

Commit

Permalink
Switched to std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Nov 14, 2024
1 parent cc998f6 commit 6d9ca5d
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 208 deletions.
2 changes: 2 additions & 0 deletions lib/DimmableLight/src/hw_timer_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "hw_timer_esp32.h"

#include <esp32-hal-timer.h>

const static int TIMER_ID = 0;

static hw_timer_t* timer = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion lib/DimmableLight/src/hw_timer_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef HW_TIMER_ESP32_H
#define HW_TIMER_ESP32_H

#include <Arduino.h>
#include <stdint.h>

void timerInit(void (*callback)());

Expand Down
4 changes: 3 additions & 1 deletion lib/DimmableLight/src/thyristor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
******************************************************************************/
#include "thyristor.h"

#include <Arduino.h>
#include <MycilaCircularBuffer.h>
#include <HardwareSerial.h>

#include <esp32-hal-gpio.h>

#if defined(ARDUINO_ARCH_ESP8266)
#include "hw_timer_esp8266.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/DimmableLight/src/thyristor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef THYRISTOR_H
#define THYRISTOR_H

#include <Arduino.h>
#include <stdint.h>

/**
* These defines affect the declaration of this class and the relative wrappers.
Expand Down
12 changes: 7 additions & 5 deletions lib/MycilaAppInfo/MycilaAppInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <MycilaString.h>
#include <MycilaSystem.h>

#include <string>

#ifndef APP_NAME
#define APP_NAME "YaSolR"
#endif
Expand Down Expand Up @@ -40,15 +42,15 @@ Mycila::AppInfoClass::AppInfoClass() : id(Mycila::System::getChipIDStr().c_str()
nameModel(name + " " + model),
nameModelVersion(name + " " + model + " " + version),
manufacturer(APP_MANUFACTURER),
firmware(String(APP_NAME) + (isdigit(version.charAt(0)) ? "-v" : "-") + (version.indexOf("_") >= 0 ? version.substring(0, version.indexOf("_")) : version) + "-" + __COMPILED_BUILD_NAME__ + ".bin"),
firmware(std::string(APP_NAME) + (std::isdigit(version[0]) ? "-v" : "-") + version.substr(0, version.find("_")) + "-" + __COMPILED_BUILD_NAME__ + ".bin"),
buildBranch(__COMPILED_BUILD_BRANCH__),
buildHash(__COMPILED_BUILD_HASH__),
buildDate(__COMPILED_BUILD_TIMESTAMP__),
defaultHostname(Mycila::Str::lowerCaseCopy(name + "-" + id)),
defaultMqttClientId(Mycila::Str::lowerCaseCopy(name + "_" + id)),
defaultHostname(Mycila::string::toLowerCase(name + "-" + id)),
defaultMqttClientId(Mycila::string::toLowerCase(name + "_" + id)),
defaultSSID(name + "-" + id),
debug(firmware.indexOf("debug") >= 0),
trial(firmware.indexOf("trial") >= 0) {}
debug(firmware.find("debug") != std::string::npos),
trial(firmware.find("trial") != std::string::npos) {}

void Mycila::AppInfoClass::toJson(const JsonObject& root) const {
root["build_date"] = buildDate;
Expand Down
31 changes: 16 additions & 15 deletions lib/MycilaAppInfo/MycilaAppInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#pragma once

#include <ArduinoJson.h>
#include <WString.h>

#include <string>

namespace Mycila {
class AppInfoClass {
Expand All @@ -15,20 +16,20 @@ namespace Mycila {
void toJson(const JsonObject& root) const;

public:
const String id;
const String name;
const String model;
const String version;
const String nameModel;
const String nameModelVersion;
const String manufacturer;
const String firmware;
const String buildBranch;
const String buildHash;
const String buildDate;
const String defaultHostname;
const String defaultMqttClientId;
const String defaultSSID;
const std::string id;
const std::string name;
const std::string model;
const std::string version;
const std::string nameModel;
const std::string nameModelVersion;
const std::string manufacturer;
const std::string firmware;
const std::string buildBranch;
const std::string buildHash;
const std::string buildDate;
const std::string defaultHostname;
const std::string defaultMqttClientId;
const std::string defaultSSID;
const bool debug;
const bool trial;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/MycilaRouter/MycilaRouterOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void Mycila::RouterOutput::applyAutoBypass() {
return;
}
const char* wday = DaysOfWeek[timeInfo.tm_wday];
if (config.weekDays.indexOf(wday) >= 0) {
if (config.weekDays.find(wday) != std::string::npos) {
LOGI(TAG, "Time within %s-%s on %s: starting Auto Bypass '%s' at %.02f °C", config.autoStartTime.c_str(), config.autoStopTime.c_str(), wday, _name, _temperature.orElse(0));
_setBypass(true);
_autoBypassEnabled = _bypassEnabled;
Expand Down
8 changes: 5 additions & 3 deletions lib/MycilaRouter/MycilaRouterOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <ArduinoJson.h>
#endif

#include <string>

namespace Mycila {
class RouterOutput {
public:
Expand Down Expand Up @@ -48,9 +50,9 @@ namespace Mycila {
bool autoBypass = false;
uint8_t autoStartTemperature = 0;
uint8_t autoStopTemperature = 0;
String autoStartTime;
String autoStopTime;
String weekDays;
std::string autoStartTime;
std::string autoStopTime;
std::string weekDays;
float reservedExcessPowerRatio = 1;
} Config;

Expand Down
20 changes: 10 additions & 10 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ lib_deps =
mathieucarbou/AsyncTCP @ 3.2.14
; https://github.com/mathieucarbou/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip
mathieucarbou/ESPAsyncWebServer @ 3.3.22
mathieucarbou/MycilaConfig @ 6.0.3
mathieucarbou/MycilaDS18 @ 4.1.0
mathieucarbou/MycilaConfig @ 6.0.4
mathieucarbou/MycilaDS18 @ 4.1.1
mathieucarbou/MycilaESPConnect @ 7.0.0
mathieucarbou/MycilaEasyDisplay @ 3.0.2
mathieucarbou/MycilaHADiscovery @ 6.0.0
mathieucarbou/MycilaJSY @ 11.1.3
mathieucarbou/MycilaLogger @ 3.2.0
mathieucarbou/MycilaMQTT @ 4.2.3
mathieucarbou/MycilaNTP @ 6.0.2
mathieucarbou/MycilaJSY @ 11.1.4
mathieucarbou/MycilaLogger @ 3.2.1
mathieucarbou/MycilaMQTT @ 5.0.1
mathieucarbou/MycilaNTP @ 6.0.3
mathieucarbou/MycilaPulseAnalyzer @ 2.5.0
mathieucarbou/MycilaPZEM004Tv3 @ 5.0.0
mathieucarbou/MycilaRelay @ 4.0.1
mathieucarbou/MycilaSystem @ 4.0.0
mathieucarbou/MycilaTaskManager @ 3.1.2
mathieucarbou/MycilaTaskMonitor @ 3.0.1
mathieucarbou/MycilaTaskManager @ 3.1.3
mathieucarbou/MycilaTaskMonitor @ 3.0.2
mathieucarbou/MycilaTrafficLight @ 2.0.0
mathieucarbou/MycilaUtilities @ 2.0.0
mathieucarbou/MycilaUtilities @ 3.1.0
lib_ignore =
; AsyncTCP
; mathieucarbou/AsyncTCP
Expand Down Expand Up @@ -158,7 +158,7 @@ build_unflags =
[oss]
build_flags = -D APP_MODEL_OSS
lib_deps =
mathieucarbou/MycilaWebSerial @ 7.0.0
mathieucarbou/MycilaWebSerial @ 7.0.1
ayushsharma82/ESP-DASH @ 4.0.8
lib_ignore =
ESPDASHPro
Expand Down
75 changes: 38 additions & 37 deletions src/Website.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void YaSolR::WebsiteClass::initLayout() {
config.set(KEY_OUTPUT2_DIMMER_LIMIT, "100", false);

router.beginCalibration([]() {
config.set(KEY_OUTPUT1_RESISTANCE, String(router.getOutputs()[0]->config.calibratedResistance).c_str());
config.set(KEY_OUTPUT2_RESISTANCE, String(router.getOutputs()[1]->config.calibratedResistance).c_str());
config.set(KEY_OUTPUT1_RESISTANCE, Mycila::string::to_string(router.getOutputs()[0]->config.calibratedResistance, 2).c_str());
config.set(KEY_OUTPUT2_RESISTANCE, Mycila::string::to_string(router.getOutputs()[1]->config.calibratedResistance, 2).c_str());
});

YaSolR::Website.initCards();
Expand Down Expand Up @@ -231,9 +231,10 @@ void YaSolR::WebsiteClass::initLayout() {
_textConfig(_dnsServer, KEY_NET_DNS);

_ntpSync.attachCallback([](const char* value) {
const String str = String(value);
const size_t len = str.length();
const timeval tv = {str.substring(0, len - 3).toInt(), str.substring(len - 3).toInt()};
const size_t len = strlen(value);
timeval tv;
tv.tv_sec = std::stoul(std::string(value, len - 3));
tv.tv_usec = atol(value + len - 3);
Mycila::NTP.sync(tv);
});

Expand Down Expand Up @@ -391,7 +392,7 @@ void YaSolR::WebsiteClass::initLayout() {
_output1DimmerMapper.attachCallback([this](const char* value) {
const char* comma = strchr(value, ',');
if (comma != nullptr) {
config.set(KEY_OUTPUT1_DIMMER_MIN, String(value).substring(0, comma - value).c_str());
config.set(KEY_OUTPUT1_DIMMER_MIN, std::string(value, comma - value).c_str());
config.set(KEY_OUTPUT1_DIMMER_MAX, comma + 1);
}
_output1DimmerMapper.update(value);
Expand All @@ -400,7 +401,7 @@ void YaSolR::WebsiteClass::initLayout() {
_output2DimmerMapper.attachCallback([this](const char* value) {
const char* comma = strchr(value, ',');
if (comma != nullptr) {
config.set(KEY_OUTPUT2_DIMMER_MIN, String(value).substring(0, comma - value).c_str());
config.set(KEY_OUTPUT2_DIMMER_MIN, std::string(value, comma - value).c_str());
config.set(KEY_OUTPUT2_DIMMER_MAX, comma + 1);
}
_output2DimmerMapper.update(value);
Expand Down Expand Up @@ -456,11 +457,11 @@ void YaSolR::WebsiteClass::initCards() {
_appModel.set((Mycila::AppInfo.model.c_str()));
_appName.set((Mycila::AppInfo.name.c_str()));
_appVersion.set(Mycila::AppInfo.version.c_str());
_deviceBootCount.set(String(Mycila::System::getBootCount()).c_str());
_deviceBootCount.set(std::to_string(Mycila::System::getBootCount()).c_str());
_deviceBootReason.set(Mycila::System::getLastRebootReason());
_deviceCores.set(String(ESP.getChipCores()).c_str());
_deviceCores.set(std::to_string(ESP.getChipCores()).c_str());
_deviceModel.set(ESP.getChipModel());
_deviceRev.set(String(ESP.getChipRevision()).c_str());
_deviceRev.set(std::to_string(ESP.getChipRevision()).c_str());
_deviceID.set(Mycila::AppInfo.id.c_str());
_firmwareBuildHash.set(Mycila::AppInfo.buildHash.c_str());
_firmwareBuildTimestamp.set(Mycila::AppInfo.buildDate.c_str());
Expand Down Expand Up @@ -669,7 +670,7 @@ void YaSolR::WebsiteClass::initCards() {

_displayType.update(config.get(KEY_DISPLAY_TYPE), "SH1106,SH1107,SSD1306");
_displaySpeed.update(config.getInt(KEY_DISPLAY_SPEED));
_displayRotation.update((String(config.get(KEY_DISPLAY_ROTATION))) + "°", "0°,90°,180°,270°");
_displayRotation.update((std::string(config.get(KEY_DISPLAY_ROTATION)) + "°").c_str(), "0°,90°,180°,270°");
_output1RelayType.update(config.get(KEY_OUTPUT1_RELAY_TYPE), "NO,NC");
_output2RelayType.update(config.get(KEY_OUTPUT2_RELAY_TYPE), "NO,NC");
_relay1Type.update(config.get(KEY_RELAY1_TYPE), "NO,NC");
Expand All @@ -678,8 +679,8 @@ void YaSolR::WebsiteClass::initCards() {
_relay2Load.update(load2);
_output1ResistanceInput.update(config.get(KEY_OUTPUT1_RESISTANCE), config.getFloat(KEY_OUTPUT1_RESISTANCE) == 0 ? DASH_STATUS_DANGER : DASH_STATUS_SUCCESS);
_output2ResistanceInput.update(config.get(KEY_OUTPUT2_RESISTANCE), config.getFloat(KEY_OUTPUT2_RESISTANCE) == 0 ? DASH_STATUS_DANGER : DASH_STATUS_SUCCESS);
_output1DimmerMapper.update(String(config.get(KEY_OUTPUT1_DIMMER_MIN)) + "," + config.get(KEY_OUTPUT1_DIMMER_MAX));
_output2DimmerMapper.update(String(config.get(KEY_OUTPUT2_DIMMER_MIN)) + "," + config.get(KEY_OUTPUT2_DIMMER_MAX));
_output1DimmerMapper.update((std::string(config.get(KEY_OUTPUT1_DIMMER_MIN)) + "," + config.get(KEY_OUTPUT1_DIMMER_MAX)).c_str());
_output2DimmerMapper.update((std::string(config.get(KEY_OUTPUT2_DIMMER_MIN)) + "," + config.get(KEY_OUTPUT2_DIMMER_MAX)).c_str());

_displayType.setDisplay(config.getBool(KEY_ENABLE_DISPLAY));
_displaySpeed.setDisplay(config.getBool(KEY_ENABLE_DISPLAY));
Expand Down Expand Up @@ -778,24 +779,24 @@ void YaSolR::WebsiteClass::updateCards() {
Mycila::System::Memory memory;
Mycila::System::getMemory(memory);
Mycila::ESPConnect::Mode mode = espConnect.getMode();
_output1RelaySwitchCount.set(String(bypassRelayO1.getSwitchCount()).c_str());
_output2RelaySwitchCount.set(String(bypassRelayO2.getSwitchCount()).c_str());
_deviceHeapTotal.set((String(memory.total) + " bytes").c_str());
_deviceHeapUsed.set((String(memory.used) + " bytes").c_str());
_deviceHeapUsage.set((String(memory.usage) + " %").c_str());
_gridEnergy.set((String(gridMetrics.energy, 3) + " kWh").c_str());
_gridEnergyReturned.set((String(gridMetrics.energyReturned, 3) + " kWh").c_str());
_gridFrequency.set((String(detectGridFrequency(), 0) + " Hz").c_str());
_output1RelaySwitchCount.set(std::to_string(bypassRelayO1.getSwitchCount()).c_str());
_output2RelaySwitchCount.set(std::to_string(bypassRelayO2.getSwitchCount()).c_str());
_deviceHeapTotal.set((std::to_string(memory.total) + " bytes").c_str());
_deviceHeapUsed.set((std::to_string(memory.used) + " bytes").c_str());
_deviceHeapUsage.set((Mycila::string::to_string(memory.usage, 2) + " %").c_str());
_gridEnergy.set((Mycila::string::to_string(gridMetrics.energy, 3) + " kWh").c_str());
_gridEnergyReturned.set((Mycila::string::to_string(gridMetrics.energyReturned, 3) + " kWh").c_str());
_gridFrequency.set((Mycila::string::to_string(detectGridFrequency(), 0) + " Hz").c_str());
_networkAPIP.set(espConnect.getIPAddress(Mycila::ESPConnect::Mode::AP).toString().c_str());
_networkEthIP.set(espConnect.getIPAddress(Mycila::ESPConnect::Mode::ETH).toString().c_str());
_networkInterface.set(mode == Mycila::ESPConnect::Mode::AP ? "AP" : (mode == Mycila::ESPConnect::Mode::STA ? "WiFi" : (mode == Mycila::ESPConnect::Mode::ETH ? "Ethernet" : "")));
_networkWiFiIP.set(espConnect.getIPAddress(Mycila::ESPConnect::Mode::STA).toString().c_str());
_networkWiFiRSSI.set((String(espConnect.getWiFiRSSI()) + " dBm").c_str());
_networkWiFiSignal.set((String(espConnect.getWiFiSignalQuality()) + " %").c_str());
_networkWiFiRSSI.set((std::to_string(espConnect.getWiFiRSSI()) + " dBm").c_str());
_networkWiFiSignal.set((std::to_string(espConnect.getWiFiSignalQuality()) + " %").c_str());
_networkWiFiSSID.set(espConnect.getWiFiSSID().c_str());
_relay1SwitchCount.set(String(relay1.getSwitchCount()).c_str());
_relay2SwitchCount.set(String(relay2.getSwitchCount()).c_str());
_udpMessageRateBuffer.set((String(udpMessageRateBuffer.rate()) + " msg/s").c_str());
_relay1SwitchCount.set(std::to_string(relay1.getSwitchCount()).c_str());
_relay2SwitchCount.set(std::to_string(relay2.getSwitchCount()).c_str());
_udpMessageRateBuffer.set((Mycila::string::to_string(udpMessageRateBuffer.rate(), 2) + " msg/s").c_str());
_time.set(Mycila::Time::getLocalStr().c_str());
_uptime.set(Mycila::Time::toDHHMMSS(Mycila::System::getUptime()).c_str());
#ifdef APP_MODEL_TRIAL
Expand Down Expand Up @@ -989,15 +990,15 @@ void YaSolR::WebsiteClass::resetPID() {

void YaSolR::WebsiteClass::_sliderConfig(Card& card, const char* key) {
card.attachCallback([key, &card](int value) {
config.set(key, String(value).c_str());
config.set(key, std::to_string(value).c_str());
card.update(config.getInt(key));
dashboard.refreshCard(&card);
});
}

void YaSolR::WebsiteClass::_percentageSlider(Card& card, const char* key) {
card.attachCallback([key, &card](int value) {
config.set(key, String(value).c_str());
config.set(key, std::to_string(value).c_str());
card.update(value);
dashboard.refreshCard(&card);
});
Expand All @@ -1021,7 +1022,7 @@ void YaSolR::WebsiteClass::_numConfig(Card& card, const char* key) {
#ifdef APP_MODEL_PRO
card.attachCallback([key, &card](const char* value) {
if (value[0]) {
config.set(key, String(strtol(value, nullptr, 10)).c_str());
config.set(key, std::to_string(strtol(value, nullptr, 10)).c_str());
} else {
config.unset(key);
}
Expand All @@ -1035,7 +1036,7 @@ void YaSolR::WebsiteClass::_pinConfig(Card& card, const char* key) {
#ifdef APP_MODEL_PRO
card.attachCallback([key, &card, this](const char* value) {
if (value[0]) {
config.set(key, String(strtol(value, nullptr, 10)).c_str());
config.set(key, std::to_string(strtol(value, nullptr, 10)).c_str());
} else {
config.unset(key);
}
Expand Down Expand Up @@ -1144,7 +1145,7 @@ void YaSolR::WebsiteClass::_status(Card& card, const char* key, bool enabled, bo
else if (!enabled)
card.update(config.getBool(key), DASH_STATUS_DANGER "," YASOLR_LBL_124);
else if (!active)
card.update(config.getBool(key), (String(DASH_STATUS_WARNING) + "," + err).c_str());
card.update(config.getBool(key), (std::string(DASH_STATUS_WARNING) + "," + err).c_str());
else
card.update(config.getBool(key), DASH_STATUS_SUCCESS "," YASOLR_LBL_130);
}
Expand All @@ -1153,18 +1154,18 @@ void YaSolR::WebsiteClass::_pinout(Card& card, int32_t pin, std::unordered_map<i
if (pin == GPIO_NUM_NC) {
card.update(YASOLR_LBL_115, DASH_STATUS_IDLE);
} else if (pinout.find(pin) != pinout.end()) {
String v = String(pin) + " (" YASOLR_LBL_153 ")";
pinout[pin]->update(v, DASH_STATUS_DANGER);
card.update(v, DASH_STATUS_DANGER);
std::string v = std::to_string(pin) + " (" YASOLR_LBL_153 ")";
pinout[pin]->update(v.c_str(), DASH_STATUS_DANGER);
card.update(v.c_str(), DASH_STATUS_DANGER);
} else if (!GPIO_IS_VALID_GPIO(pin)) {
pinout[pin] = &card;
card.update(String(pin) + " (" YASOLR_LBL_154 ")", DASH_STATUS_DANGER);
card.update((std::to_string(pin) + " (" YASOLR_LBL_154 ")").c_str(), DASH_STATUS_DANGER);
} else if (!GPIO_IS_VALID_OUTPUT_GPIO(pin)) {
pinout[pin] = &card;
card.update(String(pin) + " (" YASOLR_LBL_155 ")", DASH_STATUS_WARNING);
card.update((std::to_string(pin) + " (" YASOLR_LBL_155 ")").c_str(), DASH_STATUS_WARNING);
} else {
pinout[pin] = &card;
card.update(String(pin) + " (" YASOLR_LBL_156 ")", DASH_STATUS_SUCCESS);
card.update((std::to_string(pin) + " (" YASOLR_LBL_156 ")").c_str(), DASH_STATUS_SUCCESS);
}
}

Expand Down
Loading

0 comments on commit 6d9ca5d

Please sign in to comment.