Replaced Arduino Strings with std::string

This commit is contained in:
2021-06-28 09:59:32 +02:00
parent b0e96933ec
commit 7805059bdf
29 changed files with 211 additions and 210 deletions

View File

@@ -19,21 +19,21 @@ using BluetoothHasClientText = BluetoothStatusTextHelper<TEXT_BLUETOOTHHASCLIENT
//using BluetoothConnectedText = BluetoothStatusTextHelper<TEXT_BLUETOOTHCONNECTED, bool, &BluetoothSerial::connected>; //using BluetoothConnectedText = BluetoothStatusTextHelper<TEXT_BLUETOOTHCONNECTED, bool, &BluetoothSerial::connected>;
struct BluetoothConnectedText : public virtual TextInterface { struct BluetoothConnectedText : public virtual TextInterface {
public: public:
String text() const override { return String{"connected: "} + toString(bluetoothSerial.connected()); } std::string text() const override { return std::string{"connected: "} + to_string(bluetoothSerial.connected()); }
}; };
//constexpr char TEXT_BLUETOOTHISREADY[] = "Is ready: "; //constexpr char TEXT_BLUETOOTHISREADY[] = "Is ready: ";
//using BluetoothIsReadyText = BluetoothStatusTextHelper<TEXT_BLUETOOTHISREADY, bool, &BluetoothSerial::isReady>; //using BluetoothIsReadyText = BluetoothStatusTextHelper<TEXT_BLUETOOTHISREADY, bool, &BluetoothSerial::isReady>;
struct BluetoothIsReadyText : public virtual TextInterface { struct BluetoothIsReadyText : public virtual TextInterface {
public: public:
String text() const override { return String{"isReady: "} + toString(bluetoothSerial.isReady()); } std::string text() const override { return std::string{"isReady: "} + to_string(bluetoothSerial.isReady()); }
}; };
//constexpr char TEXT_BLUETOOTHISREADYMASTER[] = "Is ready (M): "; //constexpr char TEXT_BLUETOOTHISREADYMASTER[] = "Is ready (M): ";
//using BluetoothIsReadyMasterText = BluetoothStatusTextHelper<TEXT_BLUETOOTHISREADYMASTER, bool, &BluetoothSerial::isReady>; //using BluetoothIsReadyMasterText = BluetoothStatusTextHelper<TEXT_BLUETOOTHISREADYMASTER, bool, &BluetoothSerial::isReady>;
class BluetoothIsReadyMasterText : public virtual TextInterface { class BluetoothIsReadyMasterText : public virtual TextInterface {
public: public:
String text() const override { return String{"isReady (M): "} + toString(bluetoothSerial.isReady(true)); } std::string text() const override { return std::string{"isReady (M): "} + to_string(bluetoothSerial.isReady(true)); }
}; };
#endif #endif
} }

View File

@@ -106,7 +106,7 @@ void initWebserver()
else if (const auto *changeValueDisplay = constCurrentDisplay->asChangeValueDisplayInterface()) else if (const auto *changeValueDisplay = constCurrentDisplay->asChangeValueDisplayInterface())
{ {
response->print("<form action=\"/setValue\" method=\"GET\">"); response->print("<form action=\"/setValue\" method=\"GET\">");
response->print("<input type=\"number\" name=\"value\" value=\"" + String{changeValueDisplay->shownValue()} + "\" />"); response->print("<input type=\"number\" name=\"value\" value=\"" + std::to_string(changeValueDisplay->shownValue()) + "\" />");
response->print("<button type=\"submit\">Update</button>"); response->print("<button type=\"submit\">Update</button>");
response->print("</form>"); response->print("</form>");
} }
@@ -276,7 +276,7 @@ void initWebserver()
if (!Update.begin(size, command)) if (!Update.begin(size, command))
Update.printError(Serial); Update.printError(Serial);
String type; std::string type;
if (ArduinoOTA.getCommand() == U_FLASH) if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch"; type = "sketch";
else if (ArduinoOTA.getCommand() == U_SPIFFS) // U_SPIFFS else if (ArduinoOTA.getCommand() == U_SPIFFS) // U_SPIFFS

View File

@@ -119,7 +119,7 @@ void ChangeValueDisplay<Tvalue>::redraw()
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextFont(7); tft.setTextFont(7);
m_valueLabel.redraw(String{m_value}); m_valueLabel.redraw(std::to_string(m_value));
} }
template<typename Tvalue> template<typename Tvalue>

View File

@@ -11,10 +11,10 @@ struct ControllerTexts
ControllerTexts() = delete; ControllerTexts() = delete;
~ControllerTexts() = delete; ~ControllerTexts() = delete;
struct BuzzerFreqText : public virtual TextInterface { public: String text() const override { return String{"buzzerFreq: "} + toString(controller::get().command.buzzer.freq); } }; struct BuzzerFreqText : public virtual TextInterface { public: std::string text() const override { return "buzzerFreq: " + std::to_string(controller::get().command.buzzer.freq); } };
struct BuzzerPatternText : public virtual TextInterface { public: String text() const override { return String{"buzzerPattern: "} + toString(controller::get().command.buzzer.pattern); } }; struct BuzzerPatternText : public virtual TextInterface { public: std::string text() const override { return "buzzerPattern: " + std::to_string(controller::get().command.buzzer.pattern); } };
struct PoweroffText : public virtual TextInterface { public: String text() const override { return String{"poweroff: "} + toString(controller::get().command.poweroff); } }; struct PoweroffText : public virtual TextInterface { public: std::string text() const override { return "poweroff: " + std::to_string(controller::get().command.poweroff); } };
struct LedText : public virtual TextInterface { public: String text() const override { return String{"led: "} + toString(controller::get().command.led); } }; struct LedText : public virtual TextInterface { public: std::string text() const override { return "led: " + std::to_string(controller::get().command.led); } };
private: private:
struct LeftCommandGetter { static const MotorState &get() { return controller::get().command.left; } }; struct LeftCommandGetter { static const MotorState &get() { return controller::get().command.left; } };
@@ -26,26 +26,26 @@ private:
CommandTexts() = delete; CommandTexts() = delete;
~CommandTexts() = delete; ~CommandTexts() = delete;
struct EnableText : public virtual TextInterface { public: String text() const override { return String{"enable: "} + toString(MotorStateGetter::get().enable); } }; struct EnableText : public virtual TextInterface { public: std::string text() const override { return "enable: " + std::to_string(MotorStateGetter::get().enable); } };
struct PwmText : public virtual TextInterface { public: String text() const override { return String{"pwm: "} + toString(MotorStateGetter::get().pwm); } }; struct PwmText : public virtual TextInterface { public: std::string text() const override { return "pwm: " + std::to_string(MotorStateGetter::get().pwm); } };
struct CtrlTypText : public virtual TextInterface { public: String text() const override { return String{"ctrlTyp: "} + toString(MotorStateGetter::get().ctrlTyp); } }; struct CtrlTypText : public virtual TextInterface { public: std::string text() const override { return "ctrlTyp: " + to_string(MotorStateGetter::get().ctrlTyp); } };
struct CtrlModText : public virtual TextInterface { public: String text() const override { return String{"ctrlMod: "} + toString(MotorStateGetter::get().ctrlMod); } }; struct CtrlModText : public virtual TextInterface { public: std::string text() const override { return "ctrlMod: " + to_string(MotorStateGetter::get().ctrlMod); } };
struct IMotMaxText : public virtual TextInterface { public: String text() const override { return String{"iMotMax: "} + toString(MotorStateGetter::get().iMotMax); } }; struct IMotMaxText : public virtual TextInterface { public: std::string text() const override { return "iMotMax: " + std::to_string(MotorStateGetter::get().iMotMax); } };
struct IDcMaxText : public virtual TextInterface { public: String text() const override { return String{"iDcMax: "} + toString(MotorStateGetter::get().iDcMax); } }; struct IDcMaxText : public virtual TextInterface { public: std::string text() const override { return "iDcMax: " + std::to_string(MotorStateGetter::get().iDcMax); } };
struct NMotMaxText : public virtual TextInterface { public: String text() const override { return String{"nMotMax: "} + toString(MotorStateGetter::get().nMotMax); } }; struct NMotMaxText : public virtual TextInterface { public: std::string text() const override { return "nMotMax: " + std::to_string(MotorStateGetter::get().nMotMax); } };
struct FieldWeakMaxText : public virtual TextInterface { public: String text() const override { return String{"fieldWeakMax: "} + toString(MotorStateGetter::get().fieldWeakMax); } }; struct FieldWeakMaxText : public virtual TextInterface { public: std::string text() const override { return "fieldWeakMax: " + std::to_string(MotorStateGetter::get().fieldWeakMax); } };
struct PhaseAdvMaxText : public virtual TextInterface { public: String text() const override { return String{"phaseAdvMax: "} + toString(MotorStateGetter::get().phaseAdvMax); } }; struct PhaseAdvMaxText : public virtual TextInterface { public: std::string text() const override { return "phaseAdvMax: " + std::to_string(MotorStateGetter::get().phaseAdvMax); } };
}; };
public: public:
using LeftCommand = CommandTexts<LeftCommandGetter>; using LeftCommand = CommandTexts<LeftCommandGetter>;
using RightCommand = CommandTexts<LeftCommandGetter>; using RightCommand = CommandTexts<LeftCommandGetter>;
struct BatVoltageText : public virtual TextInterface { public: String text() const override { auto line = String{"batVoltage: "}; if (controller::get().feedbackValid) line += toString(controller::get().feedback.batVoltage); return line; } }; struct BatVoltageText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.batVoltage); return line; } };
struct BatVoltageFixedText : public virtual TextInterface { public: String text() const override { auto line = String{"batVoltage: "}; if (controller::get().feedbackValid) line += toString(fixBatVoltage(controller::get().feedback.batVoltage)) + 'V'; return line; } }; struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += std::to_string(fixBatVoltage(controller::get().feedback.batVoltage)) + 'V'; return line; } };
struct BoardTempText : public virtual TextInterface { public: String text() const override { auto line = String{"boardTemp: "}; if (controller::get().feedbackValid) line += toString(controller::get().feedback.boardTemp); return line; } }; struct BoardTempText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.boardTemp); return line; } };
struct BoardTempFixedText : public virtual TextInterface { public: String text() const override { auto line = String{"boardTemp: "}; if (controller::get().feedbackValid) line += toString(fixBoardTemp(controller::get().feedback.boardTemp)) + 'C'; return line; } }; struct BoardTempFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += std::to_string(fixBoardTemp(controller::get().feedback.boardTemp)) + 'C'; return line; } };
struct TimeoutCntSerialText : public virtual TextInterface { public: String text() const override { auto line = String{"timeoutCntSerial: "}; if (controller::get().feedbackValid) line += toString(controller::get().feedback.timeoutCntSerial); return line; } }; struct TimeoutCntSerialText : public virtual TextInterface { public: std::string text() const override { std::string line{"timeoutCntSerial: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.timeoutCntSerial); return line; } };
private: private:
struct LeftFeedbackGetter { static const MotorFeedback &get() { return controller::get().feedback.left; } }; struct LeftFeedbackGetter { static const MotorFeedback &get() { return controller::get().feedback.left; } };
@@ -57,20 +57,20 @@ private:
FeedbackTexts() = delete; FeedbackTexts() = delete;
~FeedbackTexts() = delete; ~FeedbackTexts() = delete;
struct AngleText : public virtual TextInterface { public: String text() const override { auto line = String{"angle: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().angle); return line; } }; struct AngleText : public virtual TextInterface { public: std::string text() const override { std::string line{"angle: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().angle); return line; } };
struct SpeedText : public virtual TextInterface { public: String text() const override { auto line = String{"speed: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().speed); return line; } }; struct SpeedText : public virtual TextInterface { public: std::string text() const override { std::string line{"speed: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().speed); return line; } };
struct SpeedKmhText : public virtual TextInterface { public: String text() const override { auto line = String{"speed kmh: "}; if (controller::get().feedbackValid) line += toString(convertToKmh(MotorFeedbackGetter::get().speed)); return line; } }; struct SpeedKmhText : public virtual TextInterface { public: std::string text() const override { std::string line{"speed kmh: "}; if (controller::get().feedbackValid) line += std::to_string(convertToKmh(MotorFeedbackGetter::get().speed)); return line; } };
struct ErrorText : public virtual TextInterface { public: String text() const override { auto line = String{"error: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().error); return line; } }; struct ErrorText : public virtual TextInterface { public: std::string text() const override { std::string line{"error: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().error); return line; } };
struct DcLinkText : public virtual TextInterface { public: String text() const override { auto line = String{"dcLink: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().dcLink); return line; } }; struct DcLinkText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcLink: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().dcLink); return line; } };
struct DcLinkFixedText : public virtual TextInterface { public: String text() const override { auto line = String{"dcLink: "}; if (controller::get().feedbackValid) line += toString(fixCurrent(MotorFeedbackGetter::get().dcLink)) + 'A'; return line; } }; struct DcLinkFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcLink: "}; if (controller::get().feedbackValid) line += std::to_string(fixCurrent(MotorFeedbackGetter::get().dcLink)) + 'A'; return line; } };
struct DcPhaAText : public virtual TextInterface { public: String text() const override { auto line = String{"dcPhaA: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().dcPhaA); return line; } }; struct DcPhaAText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcPhaA: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().dcPhaA); return line; } };
struct DcPhaAFixedText : public virtual TextInterface { public: String text() const override { auto line = String{"dcPhaA: "}; if (controller::get().feedbackValid) line += toString(fixCurrent(MotorFeedbackGetter::get().dcPhaA)) + 'A'; return line; } }; struct DcPhaAFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcPhaA: "}; if (controller::get().feedbackValid) line += std::to_string(fixCurrent(MotorFeedbackGetter::get().dcPhaA)) + 'A'; return line; } };
struct DcPhaBText : public virtual TextInterface { public: String text() const override { auto line = String{"dcPhaB: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().dcPhaB); return line; } }; struct DcPhaBText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcPhaB: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().dcPhaB); return line; } };
struct DcPhaBFixedText : public virtual TextInterface { public: String text() const override { auto line = String{"dcPhaB: "}; if (controller::get().feedbackValid) line += toString(fixCurrent(MotorFeedbackGetter::get().dcPhaB)) + 'A'; return line; } }; struct DcPhaBFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcPhaB: "}; if (controller::get().feedbackValid) line += std::to_string(fixCurrent(MotorFeedbackGetter::get().dcPhaB)) + 'A'; return line; } };
struct DcPhaCText : public virtual TextInterface { public: String text() const override { auto line = String{"dcPhaC: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().dcPhaC); return line; } }; struct DcPhaCText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcPhaC: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().dcPhaC); return line; } };
struct DcPhaCFixedText : public virtual TextInterface { public: String text() const override { auto line = String{"dcPhaC: "}; if (controller::get().feedbackValid) line += toString(fixCurrent(MotorFeedbackGetter::get().dcPhaC)) + 'A'; return line; } }; struct DcPhaCFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"dcPhaC: "}; if (controller::get().feedbackValid) line += std::to_string(fixCurrent(MotorFeedbackGetter::get().dcPhaC)) + 'A'; return line; } };
struct ChopsText : public virtual TextInterface { public: String text() const override { auto line = String{"chops: "}; if (controller::get().feedbackValid) line += toString(MotorFeedbackGetter::get().chops); return line; } }; struct ChopsText : public virtual TextInterface { public: std::string text() const override { std::string line{"chops: "}; if (controller::get().feedbackValid) line += std::to_string(MotorFeedbackGetter::get().chops); return line; } };
struct HallText : public virtual TextInterface { public: String text() const override { auto line = String{"hall: "}; if (controller::get().feedbackValid) line += hallString(MotorFeedbackGetter::get()); return line; } }; struct HallText : public virtual TextInterface { public: std::string text() const override { std::string line{"hall: "}; if (controller::get().feedbackValid) line += hallString(MotorFeedbackGetter::get()); return line; } };
}; };
public: public:

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <WString.h> #include <string>
namespace { namespace {
class TextInterface; class TextInterface;

View File

@@ -92,11 +92,11 @@ void BmsDisplay::redraw()
if (bluetoothSerial.hasClient()) if (bluetoothSerial.hasClient())
{ {
m_voltageLabel.redraw(String{bms::voltage} + 'V'); m_voltageLabel.redraw(std::to_string(bms::voltage) + 'V');
m_capacityLabel.redraw(String{int(bms::capacity)} + "mAh"); m_capacityLabel.redraw(std::to_string(int(bms::capacity)) + "mAh");
m_socLabel.redraw(String{bms::soc} + '%'); m_socLabel.redraw(std::to_string(bms::soc) + '%');
m_powerLabel.redraw(String{bms::power} + 'W'); m_powerLabel.redraw(std::to_string(bms::power) + 'W');
m_currentLabel.redraw(String{bms::current} + 'A'); m_currentLabel.redraw(std::to_string(bms::current) + 'A');
} }
else else
{ {
@@ -107,18 +107,18 @@ void BmsDisplay::redraw()
m_currentLabel.clear(); m_currentLabel.clear();
} }
m_speedLabel.redraw(String{avgSpeedKmh} + "kmh"); m_speedLabel.redraw(std::to_string(avgSpeedKmh) + "kmh");
if (bluetoothSerial.hasClient()) if (bluetoothSerial.hasClient())
m_powerPerSpeedLabel.redraw(String{avgSpeedKmh < 1 ? 0 : bms::power / avgSpeedKmh} + "W/kmh"); m_powerPerSpeedLabel.redraw(std::to_string(avgSpeedKmh < 1 ? 0 : bms::power / avgSpeedKmh) + "W/kmh");
else else
m_powerPerSpeedLabel.clear(); m_powerPerSpeedLabel.clear();
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
m_battLabels[i].redraw(String{bms::batt[i]}); m_battLabels[i].redraw(std::to_string(bms::batt[i]));
if (bluetoothSerial.hasClient()) if (bluetoothSerial.hasClient())
m_cycleLabel.redraw(String{bms::cycle} + "AH"); m_cycleLabel.redraw(std::to_string(bms::cycle) + "AH");
else else
m_cycleLabel.clear(); m_cycleLabel.clear();
} }

View File

@@ -1,8 +1,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <string>
#include <WString.h>
#include "display.h" #include "display.h"
#include "actions/switchscreenaction.h" #include "actions/switchscreenaction.h"
@@ -131,31 +130,31 @@ void CalibrateDisplay::update()
void CalibrateDisplay::redraw() void CalibrateDisplay::redraw()
{ {
m_labels[0].redraw(toString(m_gas)); m_labels[0].redraw(std::to_string(m_gas));
m_labels[1].redraw(toString(raw_gas)); m_labels[1].redraw(std::to_string(raw_gas));
if (m_status == Status::GasMin) if (m_status == Status::GasMin)
tft.setTextColor(TFT_RED, TFT_BLACK); tft.setTextColor(TFT_RED, TFT_BLACK);
m_labels[2].redraw(toString(m_gasMin)); m_labels[2].redraw(std::to_string(m_gasMin));
if (m_status == Status::GasMin) if (m_status == Status::GasMin)
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
if (m_status == Status::GasMax) if (m_status == Status::GasMax)
tft.setTextColor(TFT_RED, TFT_BLACK); tft.setTextColor(TFT_RED, TFT_BLACK);
m_labels[3].redraw(toString(m_gasMax)); m_labels[3].redraw(std::to_string(m_gasMax));
if (m_status == Status::GasMax) if (m_status == Status::GasMax)
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
m_progressBars[0].redraw(m_gas); m_progressBars[0].redraw(m_gas);
m_labels[4].redraw(toString(m_brems)); m_labels[4].redraw(std::to_string(m_brems));
m_labels[5].redraw(toString(raw_brems)); m_labels[5].redraw(std::to_string(raw_brems));
if (m_status == Status::BremsMin) if (m_status == Status::BremsMin)
tft.setTextColor(TFT_RED, TFT_BLACK); tft.setTextColor(TFT_RED, TFT_BLACK);
m_labels[6].redraw(toString(m_bremsMin)); m_labels[6].redraw(std::to_string(m_bremsMin));
if (m_status == Status::BremsMin) if (m_status == Status::BremsMin)
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
if (m_status == Status::BremsMax) if (m_status == Status::BremsMax)
tft.setTextColor(TFT_RED, TFT_BLACK); tft.setTextColor(TFT_RED, TFT_BLACK);
m_labels[7].redraw(toString(m_bremsMax)); m_labels[7].redraw(std::to_string(m_bremsMax));
if (m_status == Status::BremsMax) if (m_status == Status::BremsMax)
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);

View File

@@ -65,7 +65,7 @@ void DPad5WireDebugDisplay::initScreen()
void DPad5WireDebugDisplay::redraw() void DPad5WireDebugDisplay::redraw()
{ {
m_labelRaw.redraw(String{} + m_labelRaw.redraw(std::string{} +
(std::get<0>(dpad5wire::lastState) ? '1' : '0') + ' ' + (std::get<0>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<1>(dpad5wire::lastState) ? '1' : '0') + ' ' + (std::get<1>(dpad5wire::lastState) ? '1' : '0') + ' ' +
(std::get<2>(dpad5wire::lastState) ? '1' : '0') + ' ' + (std::get<2>(dpad5wire::lastState) ? '1' : '0') + ' ' +
@@ -83,8 +83,8 @@ void DPad5WireDebugDisplay::redraw()
m_labelProfile1.redraw(std::get<DPAD_5WIRESW_PROFILE1>(dpad5wire::lastState) ? "1" : "0"); m_labelProfile1.redraw(std::get<DPAD_5WIRESW_PROFILE1>(dpad5wire::lastState) ? "1" : "0");
m_labelProfile2.redraw(std::get<DPAD_5WIRESW_PROFILE2>(dpad5wire::lastState) ? "1" : "0"); m_labelProfile2.redraw(std::get<DPAD_5WIRESW_PROFILE2>(dpad5wire::lastState) ? "1" : "0");
m_labelProfile3.redraw(std::get<DPAD_5WIRESW_PROFILE3>(dpad5wire::lastState) ? "1" : "0"); m_labelProfile3.redraw(std::get<DPAD_5WIRESW_PROFILE3>(dpad5wire::lastState) ? "1" : "0");
m_labelGas.redraw(String{raw_gas}); m_labelGas.redraw(std::to_string(raw_gas));
m_labelBrems.redraw(String{raw_brems}); m_labelBrems.redraw(std::to_string(raw_brems));
} }
#endif #endif
} }

View File

@@ -1,8 +1,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <string>
#include <WString.h>
#include "display.h" #include "display.h"
#include "actions/switchscreenaction.h" #include "actions/switchscreenaction.h"
@@ -63,14 +62,14 @@ void GametrakCalibrateDisplay::initScreen()
void GametrakCalibrateDisplay::redraw() void GametrakCalibrateDisplay::redraw()
{ {
m_labels[0].redraw(String{gametrakX}); m_labels[0].redraw(std::to_string(gametrakX));
m_labels[1].redraw(String{raw_gametrakX}); m_labels[1].redraw(std::to_string(raw_gametrakX));
m_labels[2].redraw(String{gametrakY}); m_labels[2].redraw(std::to_string(gametrakY));
m_labels[3].redraw(String{raw_gametrakY}); m_labels[3].redraw(std::to_string(raw_gametrakY));
m_labels[4].redraw(String{gametrakDist}); m_labels[4].redraw(std::to_string(gametrakDist));
m_labels[5].redraw(String{raw_gametrakDist}); m_labels[5].redraw(std::to_string(raw_gametrakDist));
m_progressBars[0].redraw(gametrakX); m_progressBars[0].redraw(gametrakX);
m_progressBars[1].redraw(gametrakY); m_progressBars[1].redraw(gametrakY);

View File

@@ -92,7 +92,7 @@ void Lockscreen::initScreen()
drawRect(0, 1, TFT_YELLOW); drawRect(0, 1, TFT_YELLOW);
drawRect(0, 2, TFT_YELLOW); drawRect(0, 2, TFT_YELLOW);
m_labels[0].redraw(String(m_numbers[0])); m_labels[0].redraw(std::to_string(m_numbers[0]));
} }
void Lockscreen::redraw() void Lockscreen::redraw()
@@ -115,7 +115,7 @@ void Lockscreen::redraw()
std::for_each(std::begin(m_labels) + 1, std::end(m_labels), [](auto &label){ label.redraw({}); }); std::for_each(std::begin(m_labels) + 1, std::end(m_labels), [](auto &label){ label.redraw({}); });
} }
m_labels[m_currentIndex].redraw(String{m_numbers[m_currentIndex]}); m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex]));
drawRect(m_currentIndex, 1, TFT_YELLOW); drawRect(m_currentIndex, 1, TFT_YELLOW);
drawRect(m_currentIndex, 2, TFT_YELLOW); drawRect(m_currentIndex, 2, TFT_YELLOW);
@@ -132,7 +132,7 @@ void Lockscreen::redraw()
else if (m_numbers[m_currentIndex] > 9) else if (m_numbers[m_currentIndex] > 9)
m_numbers[m_currentIndex]-=10; m_numbers[m_currentIndex]-=10;
m_labels[m_currentIndex].redraw(String(m_numbers[m_currentIndex])); m_labels[m_currentIndex].redraw(std::to_string(m_numbers[m_currentIndex]));
m_rotated = 0; m_rotated = 0;
} }

View File

@@ -24,11 +24,11 @@ class SettingsMenu;
namespace { namespace {
struct GasText : public virtual TextInterface { struct GasText : public virtual TextInterface {
public: public:
String text() const override { return String{"gas: "} + raw_gas + ": " + gas; } std::string text() const override { return std::string{"gas: "} + std::to_string(raw_gas) + ": " + std::to_string(gas); }
}; };
struct BremsText : public virtual TextInterface { struct BremsText : public virtual TextInterface {
public: public:
String text() const override { return String{"brems: "} + raw_brems + ": " + brems; } std::string text() const override { return std::string{"brems: "} + std::to_string(raw_brems) + ": " + std::to_string(brems); }
}; };
using SampleCountChangeScreen = makeComponent< using SampleCountChangeScreen = makeComponent<
@@ -80,15 +80,15 @@ using DPadDebounceChangeScreen = makeComponent<
#ifdef FEATURE_GAMETRAK #ifdef FEATURE_GAMETRAK
struct GametrakXText : public virtual TextInterface { struct GametrakXText : public virtual TextInterface {
public: public:
String text() const override { return String{"gametrakX: "} + raw_gametrakX + ": " + gametrakX; } std::string text() const override { return std::string{"gametrakX: "} + std::to_string(raw_gametrakX) + ": " + std::to_string(gametrakX); }
}; };
struct GametrakYText : public virtual TextInterface { struct GametrakYText : public virtual TextInterface {
public: public:
String text() const override { return String{"gametrakY: "} + raw_gametrakY + ": " + gametrakY; } std::string text() const override { return std::string{"gametrakY: "} + std::to_string(raw_gametrakY) + ": " + std::to_string(gametrakY); }
}; };
struct GametrakDistText : public virtual TextInterface { struct GametrakDistText : public virtual TextInterface {
public: public:
String text() const override { return String{"gametrakDist: "} + raw_gametrakDist + ": " + gametrakDist; } std::string text() const override { return std::string{"gametrakDist: "} + std::to_string(raw_gametrakDist) + ": " + std::to_string(gametrakDist); }
}; };
using GametrakXMinChangeScreen = makeComponent< using GametrakXMinChangeScreen = makeComponent<

View File

@@ -2,7 +2,7 @@
// Arduino includes // Arduino includes
#include <Arduino.h> #include <Arduino.h>
#include <WString.h> #include <string>
// local includes // local includes
#include "menudisplay.h" #include "menudisplay.h"
@@ -26,12 +26,12 @@ namespace {
class RandomText : public virtual TextInterface class RandomText : public virtual TextInterface
{ {
public: public:
String text() const override std::string text() const override
{ {
const auto now = millis(); const auto now = millis();
if (!m_nextUpdate || now >= m_nextUpdate) if (!m_nextUpdate || now >= m_nextUpdate)
{ {
m_title = String{"Dynamic text: "} + random(0, 100); m_title = std::string{"Dynamic text: "} + std::to_string(random(0, 100));
m_nextUpdate = now + random(0, 1000); m_nextUpdate = now + random(0, 1000);
} }
@@ -40,7 +40,7 @@ public:
private: private:
mutable millis_t m_nextUpdate{}; mutable millis_t m_nextUpdate{};
mutable String m_title; mutable std::string m_title;
}; };
class RandomColor : public virtual ColorInterface class RandomColor : public virtual ColorInterface

View File

@@ -20,7 +20,7 @@ namespace {
template<const char *Tprefix, typename Taccessor> template<const char *Tprefix, typename Taccessor>
struct TextWithValueHelper : public virtual TextInterface struct TextWithValueHelper : public virtual TextInterface
{ {
String text() const override { return Tprefix + (' ' + String{Taccessor{}.getValue()}); } std::string text() const override { return Tprefix + (' ' + std::to_string(Taccessor{}.getValue())); }
}; };
using IMotMaxChangeScreen = makeComponent< using IMotMaxChangeScreen = makeComponent<

View File

@@ -27,7 +27,7 @@ class WifiScanMenu : public MenuDisplay, public BackActionInterface<SwitchScreen
public: public:
WifiScanMenu(); WifiScanMenu();
String text() const override; std::string text() const override;
void start() override; void start() override;
void update() override; void update() override;
@@ -44,9 +44,9 @@ WifiScanMenu::WifiScanMenu()
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<WifiSettingsMenu>, StaticMenuItemIcon<&icons::back>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<WifiSettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
} }
String WifiScanMenu::text() const std::string WifiScanMenu::text() const
{ {
auto text = String{menuItemCount()-1} + " found"; auto text = std::to_string(menuItemCount()-1) + " found";
switch (WiFi.scanComplete()) switch (WiFi.scanComplete())
{ {
case WIFI_SCAN_RUNNING: text += " (scanning)"; break; case WIFI_SCAN_RUNNING: text += " (scanning)"; break;
@@ -76,7 +76,7 @@ void WifiScanMenu::update()
for (std::size_t i = 0; i < n; i++) for (std::size_t i = 0; i < n; i++)
{ {
const auto ssid = WiFi.SSID(i); const auto ssid = to_string(WiFi.SSID(i));
if (menuItemCount() <= i) if (menuItemCount() <= i)
{ {
if (m_reusableItems.empty()) if (m_reusableItems.empty())

View File

@@ -72,7 +72,7 @@ void MetersDisplay::redraw()
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextFont(2); tft.setTextFont(2);
m_sumCurrentLabel.redraw(toString(sumCurrent) + 'A'); m_sumCurrentLabel.redraw(std::to_string(sumCurrent) + 'A');
meters[0].redraw(fixBatVoltage(controllers.front.feedback.batVoltage), 35, 50); meters[0].redraw(fixBatVoltage(controllers.front.feedback.batVoltage), 35, 50);
meters[1].redraw(fixBatVoltage(controllers.back.feedback.batVoltage), 35, 50); meters[1].redraw(fixBatVoltage(controllers.back.feedback.batVoltage), 35, 50);

View File

@@ -43,8 +43,8 @@ void PowerSupplyDisplay::initScreen()
void PowerSupplyDisplay::redraw() void PowerSupplyDisplay::redraw()
{ {
m_voltageLabel.redraw(String{50.4} + 'V'); m_voltageLabel.redraw(std::to_string(50.4) + 'V');
m_currentLabel.redraw(String{15.1} + 'A'); m_currentLabel.redraw(std::to_string(15.1) + 'A');
} }
void PowerSupplyDisplay::confirm() void PowerSupplyDisplay::confirm()

View File

@@ -145,26 +145,26 @@ void StatusDisplay::initScreen()
void StatusDisplay::redraw() void StatusDisplay::redraw()
{ {
tft.setTextFont(2); tft.setTextFont(2);
m_labelRawGas.redraw(String{raw_gas}); m_labelRawGas.redraw(std::to_string(raw_gas));
m_labelGas.redraw(String{gas}); m_labelGas.redraw(std::to_string(gas));
m_progressBarGas.redraw(gas); m_progressBarGas.redraw(gas);
m_labelRawBrems.redraw(String{raw_brems}); m_labelRawBrems.redraw(std::to_string(raw_brems));
m_labelBrems.redraw(String{brems}); m_labelBrems.redraw(std::to_string(brems));
m_progressBarBrems.redraw(brems); m_progressBarBrems.redraw(brems);
m_frontStatus.redraw(controllers.front); m_frontStatus.redraw(controllers.front);
m_backStatus.redraw(controllers.back); m_backStatus.redraw(controllers.back);
tft.setTextFont(2); tft.setTextFont(2);
m_labelWifiStatus.redraw(toString(WiFi.status())); m_labelWifiStatus.redraw(to_string(WiFi.status()));
m_labelLimit0.redraw(String{controllers.front.command.left.iMotMax} + "A"); m_labelLimit0.redraw(std::to_string(controllers.front.command.left.iMotMax) + "A");
m_labelIpAddress.redraw(WiFi.localIP().toString()); m_labelIpAddress.redraw(to_string(WiFi.localIP()));
m_labelLimit1.redraw(String{controllers.front.command.left.iDcMax} + "A"); m_labelLimit1.redraw(std::to_string(controllers.front.command.left.iDcMax) + "A");
m_labelPerformance.redraw(String{performance.last}); m_labelPerformance.redraw(std::to_string(performance.last));
m_labelMode.redraw(currentMode->displayName()); m_labelMode.redraw(currentMode->displayName());
m_labelName.redraw(&deviceName[0]); m_labelName.redraw(&deviceName[0]);
const auto profile = settingsPersister.currentlyOpenProfileIndex(); const auto profile = settingsPersister.currentlyOpenProfileIndex();
m_labelProfile.redraw(profile?String{*profile}:"-"); m_labelProfile.redraw(profile ? std::to_string(*profile) : "-");
} }
void StatusDisplay::rotate(int offset) void StatusDisplay::rotate(int offset)
@@ -192,8 +192,8 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller)
{ {
tft.setTextFont(4); tft.setTextFont(4);
m_labelLeftPwm.redraw(String{controller.command.left.pwm}); m_labelLeftPwm.redraw(std::to_string(controller.command.left.pwm));
m_labelRightPwm.redraw(String{controller.command.right.pwm}); m_labelRightPwm.redraw(std::to_string(controller.command.right.pwm));
if (controller.feedbackValid != m_lastFeedbackValid || m_initialRedraw) if (controller.feedbackValid != m_lastFeedbackValid || m_initialRedraw)
{ {
@@ -231,8 +231,8 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller)
if (controller.feedbackValid) if (controller.feedbackValid)
{ {
m_labelVoltage.redraw(String{fixBatVoltage(controller.feedback.batVoltage)} + 'V'); m_labelVoltage.redraw(std::to_string(fixBatVoltage(controller.feedback.batVoltage)) + 'V');
m_labelTemperature.redraw(String{fixBoardTemp(controller.feedback.boardTemp)} + 'C'); m_labelTemperature.redraw(std::to_string(fixBoardTemp(controller.feedback.boardTemp)) + 'C');
m_leftMotor.redraw(controller.feedback.left); m_leftMotor.redraw(controller.feedback.left);
m_rightMotor.redraw(controller.feedback.right); m_rightMotor.redraw(controller.feedback.right);
} }
@@ -250,11 +250,11 @@ void StatusDisplay::BoardStatus::MotorStatus::redraw(const MotorFeedback &motor)
{ {
tft.setTextFont(4); tft.setTextFont(4);
tft.setTextColor(motor.error?TFT_RED:TFT_GREEN, TFT_BLACK); tft.setTextColor(motor.error?TFT_RED:TFT_GREEN, TFT_BLACK);
m_labelError.redraw(String{motor.error}); m_labelError.redraw(std::to_string(motor.error));
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
m_labelCurrent.redraw(String{fixCurrent(motor.dcLink)} + 'A'); m_labelCurrent.redraw(std::to_string(fixCurrent(motor.dcLink)) + 'A');
m_labelSpeed.redraw(String{convertToKmh(motor.speed)}); m_labelSpeed.redraw(std::to_string(convertToKmh(motor.speed)));
tft.setTextFont(2); tft.setTextFont(2);
m_labelHallSensors.redraw(hallString(motor)); m_labelHallSensors.redraw(hallString(motor));

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <array> #include <array>
#include <string>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <WString.h>
#include "display.h" #include "display.h"
#include "actions/switchscreenaction.h" #include "actions/switchscreenaction.h"
@@ -22,8 +22,8 @@ namespace {
class UpdateDisplay : public Display, public DummyBack class UpdateDisplay : public Display, public DummyBack
{ {
public: public:
UpdateDisplay(const String &title); UpdateDisplay(const std::string &title);
UpdateDisplay(String &&title); UpdateDisplay(std::string &&title);
void start() override; void start() override;
void initScreen() override; void initScreen() override;
@@ -38,18 +38,18 @@ public:
bool m_errorValid; bool m_errorValid;
private: private:
const String m_title; const std::string m_title;
Label m_progressLabel{20, 150}; Label m_progressLabel{20, 150};
ProgressBar m_progressBar{20, 200, 200, 10, 0, 100}; ProgressBar m_progressBar{20, 200, 200, 10, 0, 100};
}; };
UpdateDisplay::UpdateDisplay(const String &title) : UpdateDisplay::UpdateDisplay(const std::string &title) :
m_title{title} m_title{title}
{} {}
UpdateDisplay::UpdateDisplay(String &&title) : UpdateDisplay::UpdateDisplay(std::string &&title) :
m_title{std::move(title)} m_title{std::move(title)}
{} {}
@@ -81,7 +81,7 @@ void UpdateDisplay::initScreen()
void UpdateDisplay::redraw() void UpdateDisplay::redraw()
{ {
m_progressLabel.redraw(String{} + m_progress + '/' + m_total); m_progressLabel.redraw(std::to_string(m_progress) + '/' + std::to_string(m_total));
m_progressBar.redraw(float(m_progress) / m_total * 100.f); m_progressBar.redraw(float(m_progress) / m_total * 100.f);
} }

View File

@@ -10,7 +10,7 @@ void breakLine(AsyncResponseStream &stream)
void label(AsyncResponseStream &stream, const char *name, const char *text) void label(AsyncResponseStream &stream, const char *name, const char *text)
{ {
HtmlTag label(stream, "label", String(" for=\"") + name + "\""); HtmlTag label(stream, "label", std::string(" for=\"") + name + "\"");
stream.print(text); stream.print(text);
} }
@@ -78,7 +78,7 @@ void checkboxInput(AsyncResponseStream &stream, bool value, const char *name, co
void selectOption(AsyncResponseStream &stream, const char *value, const char *text, bool selected) void selectOption(AsyncResponseStream &stream, const char *value, const char *text, bool selected)
{ {
String str{" value=\""}; std::string str{" value=\""};
str += value; str += value;
str += "\""; str += "\"";

View File

@@ -126,35 +126,35 @@ void cloudTask(void*)
{ {
if (esp_websocket_client_is_connected(handle)) if (esp_websocket_client_is_connected(handle))
{ {
String msg = "{" std::string msg = "{"
"\"type\": \"fullStatus\"," "\"type\": \"fullStatus\","
"\"partial\": false, " "\"partial\": false, "
"\"status\": {" "\"status\": {"
"\"millis\":" + String{millis()} + "," "\"millis\":" + std::to_string(millis()) + ","
"\"front.valid\":" + (controllers.front.feedbackValid?"true":"false") + "," "\"front.valid\":" + (controllers.front.feedbackValid?"true":"false") + ","
"\"back.valid\":" + (controllers.back.feedbackValid?"true":"false") + "," "\"back.valid\":" + (controllers.back.feedbackValid?"true":"false") + ","
"\"front.left.pwm\":" + String(controllers.front.command.left.pwm) + "," "\"front.left.pwm\":" + std::to_string(controllers.front.command.left.pwm) + ","
"\"front.right.pwm\":" + String(controllers.front.command.right.pwm) + "," "\"front.right.pwm\":" + std::to_string(controllers.front.command.right.pwm) + ","
"\"back.left.pwm\":" + String(controllers.back.command.left.pwm) + "," "\"back.left.pwm\":" + std::to_string(controllers.back.command.left.pwm) + ","
"\"back.right.pwm\":" + String(controllers.back.command.right.pwm) + "," "\"back.right.pwm\":" + std::to_string(controllers.back.command.right.pwm) + ","
"\"front.volt\":" + String(controllers.front.feedback.batVoltage) + "," "\"front.volt\":" + std::to_string(controllers.front.feedback.batVoltage) + ","
"\"back.volt\":" + String(controllers.back.feedback.batVoltage) + "," "\"back.volt\":" + std::to_string(controllers.back.feedback.batVoltage) + ","
"\"front.temp\":" + String(controllers.front.feedback.boardTemp) + "," "\"front.temp\":" + std::to_string(controllers.front.feedback.boardTemp) + ","
"\"back.temp\":" + String(controllers.back.feedback.boardTemp) + "," "\"back.temp\":" + std::to_string(controllers.back.feedback.boardTemp) + ","
"\"front.bad\":" + String(controllers.front.feedback.timeoutCntSerial) + "," "\"front.bad\":" + std::to_string(controllers.front.feedback.timeoutCntSerial) + ","
"\"back.bad\":" + String(controllers.back.feedback.timeoutCntSerial) + "," "\"back.bad\":" + std::to_string(controllers.back.feedback.timeoutCntSerial) + ","
"\"front.left.speed\":" + String(controllers.front.feedback.left.speed) + "," "\"front.left.speed\":" + std::to_string(controllers.front.feedback.left.speed) + ","
"\"front.right.speed\":" + String(controllers.front.feedback.right.speed) + "," "\"front.right.speed\":" + std::to_string(controllers.front.feedback.right.speed) + ","
"\"back.left.speed\":" + String(controllers.back.feedback.left.speed) + "," "\"back.left.speed\":" + std::to_string(controllers.back.feedback.left.speed) + ","
"\"back.right.speed\":" + String(controllers.back.feedback.right.speed) + "," "\"back.right.speed\":" + std::to_string(controllers.back.feedback.right.speed) + ","
"\"front.left.current\":" + String(controllers.front.feedback.left.current) + "," "\"front.left.current\":" + std::to_string(controllers.front.feedback.left.current) + ","
"\"front.right.current\":" + String(controllers.front.feedback.right.current) + "," "\"front.right.current\":" + std::to_string(controllers.front.feedback.right.current) + ","
"\"back.left.current\":" + String(controllers.back.feedback.left.current) + "," "\"back.left.current\":" + std::to_string(controllers.back.feedback.left.current) + ","
"\"back.right.current\":" + String(controllers.back.feedback.right.current) + "," "\"back.right.current\":" + std::to_string(controllers.back.feedback.right.current) + ","
"\"front.left.error\":" + String(controllers.front.feedback.left.error) + "," "\"front.left.error\":" + std::to_string(controllers.front.feedback.left.error) + ","
"\"front.right.error\":" + String(controllers.front.feedback.right.error) + "," "\"front.right.error\":" + std::to_string(controllers.front.feedback.right.error) + ","
"\"back.left.error\":" + String(controllers.back.feedback.left.error) + "," "\"back.left.error\":" + std::to_string(controllers.back.feedback.left.error) + ","
"\"back.right.error\":" + String(controllers.back.feedback.right.error) + "\"back.right.error\":" + std::to_string(controllers.back.feedback.right.error) +
"}" "}"
"}"; "}";

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <WString.h> #include <string>
namespace { namespace {
class ModeInterface { class ModeInterface {

View File

@@ -14,7 +14,7 @@ void initOta()
{ {
ArduinoOTA ArduinoOTA
.onStart([]() { .onStart([]() {
String type; std::to_string type;
if (ArduinoOTA.getCommand() == U_FLASH) if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch"; type = "sketch";
else if (ArduinoOTA.getCommand() == U_SPIFFS) // U_SPIFFS else if (ArduinoOTA.getCommand() == U_SPIFFS) // U_SPIFFS

View File

@@ -17,7 +17,7 @@ void handleSerial()
if (last_status != status) if (last_status != status)
{ {
Serial.print("Status changed to: "); Serial.print("Status changed to: ");
Serial.println(toString(status)); Serial.println(to_string(status).c_str());
last_status = status; last_status = status;
} }
@@ -25,7 +25,7 @@ void handleSerial()
if (last_ip != ip) if (last_ip != ip)
{ {
Serial.print("IP changed to: "); Serial.print("IP changed to: ");
Serial.println(ip.toString()); Serial.println(to_string(ip).c_str());
last_ip = ip; last_ip = ip;
} }

View File

@@ -78,7 +78,7 @@ bool SettingsPersister::openProfile(uint8_t index)
closeProfile(); closeProfile();
nvs_handle handle; nvs_handle handle;
esp_err_t err = nvs_open((String{"bobbycar"}+index).c_str(), NVS_READWRITE, &handle); esp_err_t err = nvs_open(("bobbycar"+std::to_string(index)).c_str(), NVS_READWRITE, &handle);
if (err != ESP_OK) if (err != ESP_OK)
{ {
Serial.printf("nvs_open() returned: %s\r\n", esp_err_to_name(err)); Serial.printf("nvs_open() returned: %s\r\n", esp_err_to_name(err));

View File

@@ -1,11 +1,13 @@
#pragma once #pragma once
#include <WString.h> #include <string>
#include "utils.h"
namespace { namespace {
class TextInterface { class TextInterface {
public: public:
virtual String text() const = 0; virtual std::string text() const = 0;
}; };
template<const char *Ttext> template<const char *Ttext>
@@ -14,31 +16,32 @@ class StaticText : public virtual TextInterface
public: public:
static constexpr const char *STATIC_TEXT = Ttext; static constexpr const char *STATIC_TEXT = Ttext;
String text() const override { return Ttext; } std::string text() const override { return Ttext; }
}; };
class ChangeableText : public virtual TextInterface class ChangeableText : public virtual TextInterface
{ {
public: public:
String text() const override { return m_title; } std::string text() const override { return m_title; }
void setTitle(const String &title) { m_title = title; } void setTitle(std::string &&title) { m_title = std::move(title); }
void setTitle(const std::string &title) { m_title = title; }
private: private:
String m_title; std::string m_title;
}; };
template<const char *Ttext, typename Ttype, Ttype *Tptr, typename TreturnType, TreturnType (Ttype::*Tmethod)()> template<const char *Ttext, typename Ttype, Ttype *Tptr, typename TreturnType, TreturnType (Ttype::*Tmethod)()>
class StatusTextHelper : public virtual TextInterface class StatusTextHelper : public virtual TextInterface
{ {
public: public:
String text() const override { return String{Ttext} + (Tptr->*Tmethod)(); } std::string text() const override { using std::to_string; using ::to_string; return Ttext + to_string((Tptr->*Tmethod)()); }
}; };
template<typename T> template<typename T>
class CachedText : public virtual T class CachedText : public virtual T
{ {
public: public:
String text() const override std::string text() const override
{ {
if (!m_loaded) if (!m_loaded)
{ {
@@ -51,14 +54,14 @@ public:
private: private:
mutable bool m_loaded{}; mutable bool m_loaded{};
mutable String m_text; mutable std::string m_text;
}; };
template<typename T> template<typename T>
class StaticallyCachedText : public virtual T class StaticallyCachedText : public virtual T
{ {
public: public:
String text() const override std::string text() const override
{ {
static const auto text = T::text(); static const auto text = T::text();
return text; return text;

View File

@@ -2,12 +2,13 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include <string>
#include <driver/can.h> #include <driver/can.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <WString.h>
#include <WiFi.h> #include <WiFi.h>
#include <WString.h>
#include "bobbycar-protocol/bobbycar-can.h" #include "bobbycar-protocol/bobbycar-can.h"
@@ -86,25 +87,17 @@ float fixBoardTemp(int16_t value)
return value/10.; return value/10.;
} }
String hallString(const MotorFeedback &motor) std::string hallString(const MotorFeedback &motor)
{ {
return String{} + (motor.hallA ? '1' : '0') + (motor.hallB ? '1' : '0') + (motor.hallC ? '1' : '0'); return std::string{} + (motor.hallA ? '1' : '0') + (motor.hallB ? '1' : '0') + (motor.hallC ? '1' : '0');
} }
template<typename T> std::string to_string(const String &value)
String toString(T value)
{ {
return String{} + value; return std::string{value.c_str(), value.length()};
} }
template<> std::string to_string(ControlType value)
String toString<bool>(bool value)
{
return value ? "true" : "false";
}
template<>
String toString<ControlType>(ControlType value)
{ {
switch (value) switch (value)
{ {
@@ -112,11 +105,10 @@ String toString<ControlType>(ControlType value)
case ControlType::Sinusoidal: return "Sinusoidal"; case ControlType::Sinusoidal: return "Sinusoidal";
case ControlType::FieldOrientedControl: return "FieldOrientedControl"; case ControlType::FieldOrientedControl: return "FieldOrientedControl";
} }
return String("Unknown: ") + int(value); return "Unknown ControlType(" + std::to_string(int(value)) + ')';
} }
template<> std::string to_string(ControlMode value)
String toString<ControlMode>(ControlMode value)
{ {
switch (value) switch (value)
{ {
@@ -125,11 +117,10 @@ String toString<ControlMode>(ControlMode value)
case ControlMode::Speed: return "Speed"; case ControlMode::Speed: return "Speed";
case ControlMode::Torque: return "Torque"; case ControlMode::Torque: return "Torque";
} }
return String("Unknown: ") + int(value); return "Unknown ControlMode(" + std::to_string(int(value)) + ')';
} }
template<> std::string to_string(wl_status_t value)
String toString<wl_status_t>(wl_status_t value)
{ {
switch (value) switch (value)
{ {
@@ -143,11 +134,10 @@ String toString<wl_status_t>(wl_status_t value)
case WL_DISCONNECTED: return "WL_DISCONNECTED"; case WL_DISCONNECTED: return "WL_DISCONNECTED";
} }
return String("Unknown: ") + int(value); return "Unknown wl_status_t(" + std::to_string(int(value)) + ')';
} }
template<> std::string to_string(ota_error_t value)
String toString<ota_error_t>(ota_error_t value)
{ {
switch (value) switch (value)
{ {
@@ -158,7 +148,17 @@ String toString<ota_error_t>(ota_error_t value)
case OTA_END_ERROR: return "OTA_END_ERROR"; case OTA_END_ERROR: return "OTA_END_ERROR";
} }
return String("Unknown: ") + int(value); return "Unknown ota_error_t(" + std::to_string(int(value)) + ')';
}
std::string to_string(IPAddress value)
{
return to_string(value.toString());
}
std::string to_string(IPv6Address value)
{
return to_string(value.toString());
} }
std::array<std::reference_wrapper<MotorState>, 2> motorsInController(Controller &controller) std::array<std::reference_wrapper<MotorState>, 2> motorsInController(Controller &controller)

View File

@@ -112,7 +112,7 @@ void Graph<LENGTH, COUNT>::render(const Container &buffers, bool delta)
tft.setTextFont(2); tft.setTextFont(2);
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK);
for (auto iter = std::begin(m_labels); iter != std::end(m_labels); iter++) for (auto iter = std::begin(m_labels); iter != std::end(m_labels); iter++)
iter->redraw(String(int(m_max+((m_min-m_max)/(m_labels.size()-1)*std::distance(std::begin(m_labels), iter))))); iter->redraw(std::to_string(int(m_max+((m_min-m_max)/(m_labels.size()-1)*std::distance(std::begin(m_labels), iter)))));
int x{leftMargin}; int x{leftMargin};
for (auto pixelsIter = std::begin(m_lastPixels); pixelsIter!=std::end(m_lastPixels); pixelsIter++) for (auto pixelsIter = std::begin(m_lastPixels); pixelsIter!=std::end(m_lastPixels); pixelsIter++)

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <WString.h> #include <string>
#include "globals.h" #include "globals.h"
@@ -14,14 +14,14 @@ public:
int y() const { return m_y; }; int y() const { return m_y; };
void start(); void start();
void redraw(const String &str, bool forceRedraw = false); void redraw(const std::string &str, bool forceRedraw = false);
void clear(); void clear();
private: private:
const int m_x; const int m_x;
const int m_y; const int m_y;
String m_lastStr; std::string m_lastStr;
int m_lastFont; int m_lastFont;
int m_lastColor; int m_lastColor;
@@ -45,7 +45,7 @@ void Label::start()
m_lastHeight = 0; m_lastHeight = 0;
} }
void Label::redraw(const String &str, bool forceRedraw) void Label::redraw(const std::string &str, bool forceRedraw)
{ {
if (m_lastStr == str && if (m_lastStr == str &&
m_lastFont == tft.textfont && m_lastFont == tft.textfont &&
@@ -53,7 +53,7 @@ void Label::redraw(const String &str, bool forceRedraw)
!forceRedraw) !forceRedraw)
return; return;
const auto renderedWidth = tft.drawString(str, m_x, m_y); const auto renderedWidth = tft.drawString(str.c_str(), m_x, m_y);
const auto renderedHeight = tft.fontHeight(); const auto renderedHeight = tft.fontHeight();
if (renderedWidth < m_lastWidth) if (renderedWidth < m_lastWidth)

View File

@@ -8,110 +8,110 @@
namespace { namespace {
struct WifiStatusBitsText : public virtual TextInterface { struct WifiStatusBitsText : public virtual TextInterface {
public: public:
String text() const override { return String{"statusBits: "} + WiFi.getStatusBits(); } std::string text() const override { return "statusBits: " + std::to_string(WiFi.getStatusBits()); }
}; };
struct WifiChannelText : public virtual TextInterface { struct WifiChannelText : public virtual TextInterface {
public: public:
String text() const override { return String{"channel: "} + WiFi.channel(); } std::string text() const override { return "channel: " + std::to_string(WiFi.channel()); }
}; };
struct WifiIsConnectedText : public virtual TextInterface { struct WifiIsConnectedText : public virtual TextInterface {
public: public:
String text() const override { return String{"isConnected: "} + toString(WiFi.isConnected()); } std::string text() const override { return "isConnected: " + std::to_string(WiFi.isConnected()); }
}; };
struct WifiLocalIpText : public virtual TextInterface { struct WifiLocalIpText : public virtual TextInterface {
public: public:
String text() const override { return String{"localIP: "} + WiFi.localIP().toString(); } std::string text() const override { return "localIP: " + to_string(WiFi.localIP()); }
}; };
struct WifiMacAddressText : public virtual TextInterface { struct WifiMacAddressText : public virtual TextInterface {
public: public:
String text() const override { return String{"macAddress: "} + WiFi.macAddress(); } std::string text() const override { return "macAddress: " + to_string(WiFi.macAddress()); }
}; };
struct WifiSubnetMaskText : public virtual TextInterface { struct WifiSubnetMaskText : public virtual TextInterface {
public: public:
String text() const override { return String{"subnetMask: "} + WiFi.subnetMask().toString(); } std::string text() const override { return "subnetMask: " + to_string(WiFi.subnetMask()); }
}; };
struct WifiGatewayIpText : public virtual TextInterface { struct WifiGatewayIpText : public virtual TextInterface {
public: public:
String text() const override { return String{"gatewayIP: "} + WiFi.gatewayIP().toString(); } std::string text() const override { return "gatewayIP: " + to_string(WiFi.gatewayIP()); }
}; };
struct WifiDnsIpText : public virtual TextInterface { struct WifiDnsIpText : public virtual TextInterface {
public: public:
String text() const override { return String{"dnsIP: "} + WiFi.dnsIP().toString(); } std::string text() const override { return "dnsIP: " + to_string(WiFi.dnsIP()); }
}; };
struct WifiBroadcastIpText : public virtual TextInterface { struct WifiBroadcastIpText : public virtual TextInterface {
public: public:
String text() const override { return String{"broadcastIP: "} + WiFi.broadcastIP().toString(); } std::string text() const override { return "broadcastIP: " + to_string(WiFi.broadcastIP()); }
}; };
struct WifiNetworkIdText : public virtual TextInterface { struct WifiNetworkIdText : public virtual TextInterface {
public: public:
String text() const override { return String{"networkID: "} + WiFi.networkID().toString(); } std::string text() const override { return "networkID: " + to_string(WiFi.networkID()); }
}; };
struct WifiSubnetCIDRText : public virtual TextInterface { struct WifiSubnetCIDRText : public virtual TextInterface {
public: public:
String text() const override { return String{"subnetCIDR: "} + WiFi.subnetCIDR(); } std::string text() const override { return "subnetCIDR: " + to_string(WiFi.subnetCIDR()); }
}; };
struct WifiLocalIpV6Text : public virtual TextInterface { struct WifiLocalIpV6Text : public virtual TextInterface {
public: public:
String text() const override { return String{"localIPv6: "} + WiFi.localIPv6().toString(); } std::string text() const override { return "localIPv6: " + to_string(WiFi.localIPv6()); }
}; };
struct WifiHostnameText : public virtual TextInterface { struct WifiHostnameText : public virtual TextInterface {
public: public:
String text() const override { return String{"hostname: "} + WiFi.getHostname(); } std::string text() const override { return "hostname: " + to_string(WiFi.getHostname()); }
}; };
struct WifiStatusText : public virtual TextInterface { struct WifiStatusText : public virtual TextInterface {
public: public:
String text() const override { return String{"status: "} + toString(WiFi.status()); } std::string text() const override { return "status: " + to_string(WiFi.status()); }
}; };
struct WifiSsidText : public virtual TextInterface { struct WifiSsidText : public virtual TextInterface {
public: public:
String text() const override { return String{"SSID: "} + WiFi.SSID(); } std::string text() const override { return "SSID: " + to_string(WiFi.SSID()); }
}; };
struct WifiPskText : public virtual TextInterface { struct WifiPskText : public virtual TextInterface {
public: public:
String text() const override { return String{"psk: "} + WiFi.psk(); } std::string text() const override { return "psk: " + to_string(WiFi.psk()); }
}; };
struct WifiBssidText : public virtual TextInterface { struct WifiBssidText : public virtual TextInterface {
public: public:
String text() const override { return String{"BSSID: "} + WiFi.BSSIDstr(); } std::string text() const override { return "BSSID: " + to_string(WiFi.BSSIDstr()); }
}; };
struct WifiRssiText : public virtual TextInterface { struct WifiRssiText : public virtual TextInterface {
public: public:
String text() const override { return String{"RSSI: "} + WiFi.RSSI(); } std::string text() const override { return "RSSI: " + to_string(WiFi.RSSI()); }
}; };
class WifiSoftApGetStationNumText : public virtual TextInterface { class WifiSoftApGetStationNumText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPgetStationNum: "} + WiFi.softAPgetStationNum(); } std::string text() const override { return "softAPgetStationNum: " + to_string(WiFi.softAPgetStationNum()); }
}; };
class WifiSoftApIpText : public virtual TextInterface { class WifiSoftApIpText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPIP: "} + WiFi.softAPIP().toString(); } std::string text() const override { return "softAPIP: " + to_string(WiFi.softAPIP()); }
}; };
class WifiSoftApBroadcastIpText : public virtual TextInterface { class WifiSoftApBroadcastIpText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPBroadcastIP: "} + WiFi.softAPBroadcastIP().toString(); } std::string text() const override { return "softAPBroadcastIP: " + to_string(WiFi.softAPBroadcastIP()); }
}; };
class WifiSoftApNetworkIdText : public virtual TextInterface { class WifiSoftApNetworkIdText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPNetworkID: "} + WiFi.softAPNetworkID().toString(); } std::string text() const override { return "softAPNetworkID: " + to_string(WiFi.softAPNetworkID()); }
}; };
class WifiSoftApSubnetCidrText : public virtual TextInterface { class WifiSoftApSubnetCidrText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPSubnetCIDR: "} + WiFi.softAPSubnetCIDR(); } std::string text() const override { return "softAPSubnetCIDR: " + std::to_string(WiFi.softAPSubnetCIDR()); }
}; };
class WifiSoftApIpV6Text : public virtual TextInterface { class WifiSoftApIpV6Text : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPIPv6: "} + WiFi.softAPIPv6().toString(); } std::string text() const override { return "softAPIPv6: " + to_string(WiFi.softAPIPv6()); }
}; };
class WifiSoftApHostnameText : public virtual TextInterface { class WifiSoftApHostnameText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPgetHostname: "} + WiFi.softAPgetHostname(); } std::string text() const override { return "softAPgetHostname: " + to_string(WiFi.softAPgetHostname()); }
}; };
class WifiSoftApMacAddressText : public virtual TextInterface { class WifiSoftApMacAddressText : public virtual TextInterface {
public: public:
String text() const override { return String{"softAPmacAddress: "} + WiFi.softAPmacAddress(); } std::string text() const override { return "softAPmacAddress: " + to_string(WiFi.softAPmacAddress()); }
}; };
} }