diff --git a/config_feedc0de.cmake b/config_feedc0de.cmake index c870494..862a880 100644 --- a/config_feedc0de.cmake +++ b/config_feedc0de.cmake @@ -9,7 +9,6 @@ add_definitions( -DFEATURE_ADC_IN -DPINS_GAS=34 -DPINS_BREMS=35 -# -DPINS_LED=23 -DILI9341_DRIVER=1 -DTFT_MOSI=13 -DTFT_SCLK=15 @@ -75,4 +74,7 @@ add_definitions( # -DDEFAULT_GAMETRAKDISTMIN=0 # -DDEFAULT_GAMETRAKDISTMAX=4095 # -DFEATURE_CLOUD + -DFEATURE_LEDBACKLIGHT + -DPINS_LEDBACKLIGHT=23 + -DLEDBACKLIGHT_INVERTED ) diff --git a/export.sh b/export.sh index a8099b5..f027abd 100644 --- a/export.sh +++ b/export.sh @@ -1,4 +1,4 @@ -if [[ $_ == $0 ]] +if [[ $_ == $0 ]] && [[ "$1" != "--skip-source-check" ]] then echo "export.sh has to be sourced, not run in a subshell" echo ". export.sh" diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index 5f38cb9..cd9466f 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -62,6 +62,10 @@ struct SwapFrontBackAccessor : public RefAccessorSaveSettings { void setValue(bool value) override { RefAccessorSaveSettings::setValue(value); updateSwapFrontBack(); }; #endif }; +#ifdef FEATURE_CAN +struct SendFrontCanCmdAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.sendFrontCanCmd; } }; +struct SendBackCanCmdAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.sendBackCanCmd; } }; +#endif struct SampleCountAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.boardcomputerHardware.sampleCount; } }; struct GasMinAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.boardcomputerHardware.gasMin; } }; diff --git a/main/can.h b/main/can.h index 47927d0..4671552 100644 --- a/main/can.h +++ b/main/can.h @@ -5,6 +5,7 @@ #include #include +#include #include @@ -219,11 +220,11 @@ bool parseBoardcomputerCanMessage(const twai_message_t &message) bool tryParseCanInput() { twai_message_t message; - if (const auto result = twai_receive(&message, pdMS_TO_TICKS(50)); result != ESP_OK) + if (const auto result = twai_receive(&message, pdMS_TO_TICKS(10)); result != ESP_OK) { if (result != ESP_ERR_TIMEOUT) { - //Serial.printf("CAN err twai_receive() failed with %s\r\n", esp_err_to_name(result)); + ESP_LOGE(TAG, "CAN err twai_receive() failed with %s", esp_err_to_name(result)); } if (espchrono::millis_clock::now() - controllers.front.lastCanFeedback > 100ms) @@ -293,20 +294,27 @@ void sendCanCommands() const auto result = twai_transmit(&message, pdMS_TO_TICKS(200)); if (result != ESP_OK && result != ESP_ERR_TIMEOUT) { - //Serial.printf("ERROR: twai_transmit() failed with %s\r\n", esp_err_to_name(result)); + ESP_LOGE(TAG, "ERROR: twai_transmit() failed with %s", esp_err_to_name(result)); } return result; }; - const Controller &front = settings.controllerHardware.swapFrontBack ? controllers.back : controllers.front; - const Controller &back = settings.controllerHardware.swapFrontBack ? controllers.front : controllers.back; + const bool swap = settings.controllerHardware.swapFrontBack; + const Controller *front = + (swap ? settings.controllerHardware.sendBackCanCmd : settings.controllerHardware.sendFrontCanCmd ) ? + (swap ? &controllers.back : &controllers.front) : + nullptr; + const Controller *back = + (swap ? settings.controllerHardware.sendFrontCanCmd : settings.controllerHardware.sendBackCanCmd ) ? + (swap ? &controllers.front : &controllers.back) : + nullptr; using namespace bobbycar::protocol::can; - send(MotorController::Command::InpTgt, front.command.left.pwm); - send(MotorController::Command::InpTgt, front.command.right.pwm); - send(MotorController::Command::InpTgt, back.command.left.pwm); - send(MotorController::Command::InpTgt, back.command.right.pwm); + if (front) send(MotorController::Command::InpTgt, front->command.left.pwm); + if (front) send(MotorController::Command::InpTgt, front->command.right.pwm); + if (back) send(MotorController::Command::InpTgt, back->command.left.pwm); + if (back) send(MotorController::Command::InpTgt, back->command.right.pwm); uint16_t buttonLeds{}; if (const auto index = settingsPersister.currentlyOpenProfileIndex()) @@ -328,10 +336,10 @@ void sendCanCommands() static int i{}; - if (front.command.buzzer.freq != lastValues.front.freq || - front.command.buzzer.pattern != lastValues.front.pattern || - back.command.buzzer.freq != lastValues.back.freq || - back.command.buzzer.pattern != lastValues.back.pattern) + if ((front && front->command.buzzer.freq != lastValues.front.freq ) || + (front && front->command.buzzer.pattern != lastValues.front.pattern ) || + (back && back->command.buzzer.freq != lastValues.back.freq) || + (back && back->command.buzzer.pattern != lastValues.back.pattern)) i = 10; else if (buttonLeds != lastValues.buttonLeds) i = 12; @@ -339,92 +347,92 @@ void sendCanCommands() switch (i++) { case 0: - send(MotorController::Command::Enable, front.command.left.enable); - send(MotorController::Command::Enable, front.command.right.enable); - send(MotorController::Command::Enable, back.command.left.enable); - send(MotorController::Command::Enable, back.command.right.enable); + if (front) send(MotorController::Command::Enable, front->command.left.enable); + if (front) send(MotorController::Command::Enable, front->command.right.enable); + if (back) send(MotorController::Command::Enable, back->command.left.enable); + if (back) send(MotorController::Command::Enable, back->command.right.enable); break; case 1: - send(MotorController::Command::CtrlTyp, front.command.left.ctrlTyp); - send(MotorController::Command::CtrlTyp, front.command.right.ctrlTyp); - send(MotorController::Command::CtrlTyp, back.command.left.ctrlTyp); - send(MotorController::Command::CtrlTyp, back.command.right.ctrlTyp); + if (front) send(MotorController::Command::CtrlTyp, front->command.left.ctrlTyp); + if (front) send(MotorController::Command::CtrlTyp, front->command.right.ctrlTyp); + if (back) send(MotorController::Command::CtrlTyp, back->command.left.ctrlTyp); + if (back) send(MotorController::Command::CtrlTyp, back->command.right.ctrlTyp); break; case 2: - send(MotorController::Command::CtrlMod, front.command.left.ctrlMod); - send(MotorController::Command::CtrlMod, front.command.right.ctrlMod); - send(MotorController::Command::CtrlMod, back.command.left.ctrlMod); - send(MotorController::Command::CtrlMod, back.command.right.ctrlMod); + if (front) send(MotorController::Command::CtrlMod, front->command.left.ctrlMod); + if (front) send(MotorController::Command::CtrlMod, front->command.right.ctrlMod); + if (back) send(MotorController::Command::CtrlMod, back->command.left.ctrlMod); + if (back) send(MotorController::Command::CtrlMod, back->command.right.ctrlMod); break; case 3: - send(MotorController::Command::IMotMax, front.command.left.iMotMax); - send(MotorController::Command::IMotMax, front.command.right.iMotMax); - send(MotorController::Command::IMotMax, back.command.left.iMotMax); - send(MotorController::Command::IMotMax, back.command.right.iMotMax); + if (front) send(MotorController::Command::IMotMax, front->command.left.iMotMax); + if (front) send(MotorController::Command::IMotMax, front->command.right.iMotMax); + if (back) send(MotorController::Command::IMotMax, back->command.left.iMotMax); + if (back) send(MotorController::Command::IMotMax, back->command.right.iMotMax); break; case 4: - send(MotorController::Command::IDcMax, front.command.left.iDcMax); - send(MotorController::Command::IDcMax, front.command.right.iDcMax); - send(MotorController::Command::IDcMax, back.command.left.iDcMax); - send(MotorController::Command::IDcMax, back.command.right.iDcMax); + if (front) send(MotorController::Command::IDcMax, front->command.left.iDcMax); + if (front) send(MotorController::Command::IDcMax, front->command.right.iDcMax); + if (back) send(MotorController::Command::IDcMax, back->command.left.iDcMax); + if (back) send(MotorController::Command::IDcMax, back->command.right.iDcMax); break; case 5: - send(MotorController::Command::NMotMax, front.command.left.nMotMax); - send(MotorController::Command::NMotMax, front.command.right.nMotMax); - send(MotorController::Command::NMotMax, back.command.left.nMotMax); - send(MotorController::Command::NMotMax, back.command.right.nMotMax); + if (front) send(MotorController::Command::NMotMax, front->command.left.nMotMax); + if (front) send(MotorController::Command::NMotMax, front->command.right.nMotMax); + if (back) send(MotorController::Command::NMotMax, back->command.left.nMotMax); + if (back) send(MotorController::Command::NMotMax, back->command.right.nMotMax); break; case 6: - send(MotorController::Command::FieldWeakMax, front.command.left.fieldWeakMax); - send(MotorController::Command::FieldWeakMax, front.command.right.fieldWeakMax); - send(MotorController::Command::FieldWeakMax, back.command.left.fieldWeakMax); - send(MotorController::Command::FieldWeakMax, back.command.right.fieldWeakMax); + if (front) send(MotorController::Command::FieldWeakMax, front->command.left.fieldWeakMax); + if (front) send(MotorController::Command::FieldWeakMax, front->command.right.fieldWeakMax); + if (back) send(MotorController::Command::FieldWeakMax, back->command.left.fieldWeakMax); + if (back) send(MotorController::Command::FieldWeakMax, back->command.right.fieldWeakMax); break; case 7: - send(MotorController::Command::PhaseAdvMax, front.command.left.phaseAdvMax); - send(MotorController::Command::PhaseAdvMax, front.command.right.phaseAdvMax); - send(MotorController::Command::PhaseAdvMax, back.command.left.phaseAdvMax); - send(MotorController::Command::PhaseAdvMax, back.command.right.phaseAdvMax); + if (front) send(MotorController::Command::PhaseAdvMax, front->command.left.phaseAdvMax); + if (front) send(MotorController::Command::PhaseAdvMax, front->command.right.phaseAdvMax); + if (back) send(MotorController::Command::PhaseAdvMax, back->command.left.phaseAdvMax); + if (back) send(MotorController::Command::PhaseAdvMax, back->command.right.phaseAdvMax); break; case 8: - send(MotorController::Command::CruiseCtrlEna, front.command.left.cruiseCtrlEna); - send(MotorController::Command::CruiseCtrlEna, front.command.right.cruiseCtrlEna); - send(MotorController::Command::CruiseCtrlEna, back.command.left.cruiseCtrlEna); - send(MotorController::Command::CruiseCtrlEna, back.command.right.cruiseCtrlEna); + if (front) send(MotorController::Command::CruiseCtrlEna, front->command.left.cruiseCtrlEna); + if (front) send(MotorController::Command::CruiseCtrlEna, front->command.right.cruiseCtrlEna); + if (back) send(MotorController::Command::CruiseCtrlEna, back->command.left.cruiseCtrlEna); + if (back) send(MotorController::Command::CruiseCtrlEna, back->command.right.cruiseCtrlEna); break; case 9: - send(MotorController::Command::CruiseMotTgt, front.command.left.nCruiseMotTgt); - send(MotorController::Command::CruiseMotTgt, front.command.right.nCruiseMotTgt); - send(MotorController::Command::CruiseMotTgt, back.command.left.nCruiseMotTgt); - send(MotorController::Command::CruiseMotTgt, back.command.right.nCruiseMotTgt); + if (front) send(MotorController::Command::CruiseMotTgt, front->command.left.nCruiseMotTgt); + if (front) send(MotorController::Command::CruiseMotTgt, front->command.right.nCruiseMotTgt); + if (back) send(MotorController::Command::CruiseMotTgt, back->command.left.nCruiseMotTgt); + if (back) send(MotorController::Command::CruiseMotTgt, back->command.right.nCruiseMotTgt); break; case 10: - if (send(MotorController::Command::BuzzerFreq, front.command.buzzer.freq) == ESP_OK) - lastValues.front.freq = front.command.buzzer.freq; -// if (send(MotorController::Command::BuzzerFreq, front.command.buzzer.freq) == ESP_OK) -// lastValues.front.freq = front.command.buzzer.freq; - if (send(MotorController::Command::BuzzerFreq, back.command.buzzer.freq) == ESP_OK) - lastValues.back.freq = back.command.buzzer.freq; -// if (send(MotorController::Command::BuzzerFreq, back.command.buzzer.freq) == ESP_OK) -// lastValues.back.freq = back.command.buzzer.freq; - if (send(MotorController::Command::BuzzerPattern, front.command.buzzer.pattern) == ESP_OK) - lastValues.front.pattern = front.command.buzzer.pattern; -// if (send(MotorController::Command::BuzzerPattern, front.command.buzzer.pattern) == ESP_OK) -// lastValues.front.pattern = front.command.buzzer.pattern; - if (send(MotorController::Command::BuzzerPattern, back.command.buzzer.pattern) == ESP_OK) - lastValues.back.pattern = back.command.buzzer.pattern; -// if (send(MotorController::Command::BuzzerPattern, back.command.buzzer.pattern) == ESP_OK) -// lastValues.back.pattern = back.command.buzzer.pattern; + if (front && send(MotorController::Command::BuzzerFreq, front->command.buzzer.freq) == ESP_OK) + lastValues.front.freq = front->command.buzzer.freq; +// if (front && send(MotorController::Command::BuzzerFreq, front->command.buzzer.freq) == ESP_OK) +// lastValues.front.freq = front->command.buzzer.freq; + if (back && send(MotorController::Command::BuzzerFreq, back->command.buzzer.freq) == ESP_OK) + lastValues.back.freq = back->command.buzzer.freq; +// if (back && send(MotorController::Command::BuzzerFreq, back->command.buzzer.freq) == ESP_OK) +// lastValues.back.freq = back->command.buzzer.freq; + if (front && send(MotorController::Command::BuzzerPattern, front->command.buzzer.pattern) == ESP_OK) + lastValues.front.pattern = front->command.buzzer.pattern; +// if (front && send(MotorController::Command::BuzzerPattern, front->command.buzzer.pattern) == ESP_OK) +// lastValues.front.pattern = front->command.buzzer.pattern; + if (back && send(MotorController::Command::BuzzerPattern, back->command.buzzer.pattern) == ESP_OK) + lastValues.back.pattern = back->command.buzzer.pattern; +// if (back && send(MotorController::Command::BuzzerPattern, back->command.buzzer.pattern) == ESP_OK) +// lastValues.back.pattern = back->command.buzzer.pattern; break; case 11: - send(MotorController::Command::Led, front.command.led); - //send(MotorController::Command::Led, front.command.led); - send(MotorController::Command::Led, back.command.led); - //send(MotorController::Command::Led, back.command.led); - send(MotorController::Command::Poweroff, front.command.poweroff); - //send(MotorController::Command::Poweroff, front.command.poweroff); - send(MotorController::Command::Poweroff, back.command.poweroff); - //send(MotorController::Command::Poweroff, back.command.poweroff); + if (front) send(MotorController::Command::Led, front->command.led); + //if (front) send(MotorController::Command::Led, front->command.led); + if (back) send(MotorController::Command::Led, back->command.led); + //if (back) send(MotorController::Command::Led, back->command.led); + if (front) send(MotorController::Command::Poweroff, front->command.poweroff); + //if (front) send(MotorController::Command::Poweroff, front->command.poweroff); + if (back) send(MotorController::Command::Poweroff, back->command.poweroff); + //if (back) send(MotorController::Command::Poweroff, back->command.poweroff); break; case 12: if (send(Boardcomputer::Feedback::ButtonLeds, buttonLeds) == ESP_OK) diff --git a/main/displays/menus/controllerhardwaresettingsmenu.h b/main/displays/menus/controllerhardwaresettingsmenu.h index 2781639..c2f573a 100644 --- a/main/displays/menus/controllerhardwaresettingsmenu.h +++ b/main/displays/menus/controllerhardwaresettingsmenu.h @@ -61,6 +61,10 @@ public: constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, ToggleBoolAction, CheckboxIcon, SwapFrontBackAccessor>>(); +#ifdef FEATURE_CAN + constructMenuItem, ToggleBoolAction, CheckboxIcon, SendFrontCanCmdAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, SendBackCanCmdAccessor>>(); +#endif constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } }; diff --git a/main/displays/menus/settingsmenu.h b/main/displays/menus/settingsmenu.h index 7a3157c..2731954 100644 --- a/main/displays/menus/settingsmenu.h +++ b/main/displays/menus/settingsmenu.h @@ -32,6 +32,13 @@ class MainMenu; } namespace { +#ifdef FEATURE_LEDBACKLIGHT +struct BacklightAccessor : public virtual AccessorInterface +{ + bool getValue() const override { return digitalRead(PINS_LEDBACKLIGHT) != ledBacklightInverted; } + void setValue(bool value) override { digitalWrite(PINS_LEDBACKLIGHT, value != ledBacklightInverted); } +}; +#endif struct FrontLedAccessor : public RefAccessor { bool &getRef() const override { return controllers.front.command.led; } }; struct BackLedAccessor : public RefAccessor { bool &getRef() const override { return controllers.back.command.led; } }; @@ -43,6 +50,9 @@ class SettingsMenu : public: SettingsMenu() { +#ifdef FEATURE_LEDBACKLIGHT + constructMenuItem, ToggleBoolAction, CheckboxIcon, BacklightAccessor>>(); +#endif constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::wifi>>>(); #ifdef FEATURE_BLUETOOTH diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index 1b6a709..cea0e61 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -1,7 +1,11 @@ #pragma once +// system includes +#include + // 3rdparty lib includes #include +#include // local includes #include "display.h" @@ -103,6 +107,15 @@ private: Label m_labelProfile{205, bottomLines[3]}; // 35, 15 static const constexpr int bottomLines[4] { 251, 266, 281, 296 }; + + struct CachedString + { + std::string text; + espchrono::millis_clock::time_point timestamp = espchrono::millis_clock::now(); + }; + + std::optional m_cachedWifiStatus; + std::optional m_cachedWifiIP; }; void StatusDisplay::initScreen() @@ -141,6 +154,9 @@ void StatusDisplay::initScreen() m_labelProfile.start(); tft.setTextColor(TFT_WHITE, TFT_BLACK); + + m_cachedWifiStatus = std::nullopt; + m_cachedWifiIP = std::nullopt; } void StatusDisplay::redraw() @@ -157,13 +173,38 @@ void StatusDisplay::redraw() m_backStatus.redraw(controllers.back); tft.setTextFont(2); - m_labelWifiStatus.redraw(wifi_stack::toString(wifi_stack::get_sta_status())); - m_labelLimit0.redraw(std::to_string(controllers.front.command.left.iMotMax) + "A"); + + if (!m_cachedWifiStatus || espchrono::ago(m_cachedWifiStatus->timestamp) >= 500ms) + { + const auto staStatus = wifi_stack::get_sta_status(); + if (staStatus == wifi_stack::WiFiStaStatus::WL_CONNECTED) + { + if (const auto result = wifi_stack::get_sta_ap_info(); result) + { + m_cachedWifiStatus = CachedString{ .text = std::string{reinterpret_cast(result->ssid)} }; + } + else + { + ESP_LOGW("BOBBY", "get_sta_ap_info() failed with %.*s", result.error().size(), result.error().data()); + goto showStaStatus; + } + } + else + { +showStaStatus: + m_cachedWifiStatus = CachedString{ .text = wifi_stack::toString(staStatus) }; + } + } + + assert(m_cachedWifiStatus); + m_labelWifiStatus.redraw(m_cachedWifiStatus->text); + + m_labelLimit0.redraw(fmt::format("{}A", controllers.front.command.left.iMotMax)); if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA)) m_labelIpAddress.redraw(wifi_stack::toString(result->ip)); else m_labelIpAddress.clear(); - m_labelLimit1.redraw(std::to_string(controllers.front.command.left.iDcMax) + "A"); + m_labelLimit1.redraw(fmt::format("{}A", controllers.front.command.left.iDcMax)); m_labelPerformance.redraw(std::to_string(performance.last)); m_labelMode.redraw(currentMode->displayName()); m_labelName.redraw(deviceName); diff --git a/main/globals.h b/main/globals.h index 13cd279..67230f5 100644 --- a/main/globals.h +++ b/main/globals.h @@ -90,4 +90,14 @@ ModeInterface *lastMode{}; ModeInterface *currentMode{}; std::unique_ptr currentDisplay; + +#ifdef FEATURE_LEDBACKLIGHT +constexpr const bool ledBacklightInverted = +#ifdef LEDBACKLIGHT_INVERTED + true +#else + false +#endif +; +#endif } diff --git a/main/main.cpp b/main/main.cpp index 2c24110..479c147 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -102,11 +102,15 @@ using namespace std::chrono_literals; #include "wifi_bobbycar.h" namespace { +std::optional lastWifiUpdate; std::optional lastPotiRead; std::optional lastModeUpdate; std::optional lastStatsUpdate; std::optional lastDisplayUpdate; std::optional lastDisplayRedraw; +#ifdef FEATURE_CAN +std::optional lastCanParse; +#endif #ifdef FEATURE_BLE std::optional lastBleUpdate; #endif @@ -126,9 +130,9 @@ extern "C" void app_main() //Serial.setDebugOutput(true); //Serial.println("setup()"); -#ifdef PINS_LED - pinMode(PINS_LED, OUTPUT); - digitalWrite(PINS_LED, LOW); +#ifdef FEATURE_LEDBACKLIGHT + pinMode(PINS_LEDBACKLIGHT, OUTPUT); + digitalWrite(PINS_LEDBACKLIGHT, ledBacklightInverted ? LOW : HIGH); #endif printMemoryStats("setup()"); @@ -268,18 +272,22 @@ extern "C" void app_main() printMemoryStats("readPotis()"); #ifdef FEATURE_CLOUD + bootLabel.redraw("startCloud"); startCloud(); + printMemoryStats("readPotis()"); #endif + bootLabel.redraw("switchScreen"); + #if defined(FEATURE_DPAD_5WIRESW) && defined(DPAD_5WIRESW_DEBUG) switchScreen(); - return; -#endif +#else if (!gas || !brems || *gas > 200.f || *brems > 200.f) switchScreen(true); else switchScreen(); +#endif printMemoryStats("switchScreen()"); @@ -290,7 +298,12 @@ extern "C" void app_main() const auto now = espchrono::millis_clock::now(); - wifi_update(); + if (!lastWifiUpdate || now - *lastWifiUpdate >= 100ms) + { + wifi_update(); + + lastWifiUpdate = now; + } #ifdef FEATURE_DPAD dpad::update(); @@ -359,7 +372,12 @@ extern "C" void app_main() } #ifdef FEATURE_CAN - can::parseCanInput(); + if (!lastCanParse || now - *lastCanParse >= 50ms) + { + can::parseCanInput(); + + lastCanParse = now; + } #endif #ifdef FEATURE_SERIAL diff --git a/main/presets.h b/main/presets.h index 351c860..f158a57 100644 --- a/main/presets.h +++ b/main/presets.h @@ -32,7 +32,11 @@ constexpr Settings::ControllerHardware defaultControllerHardware { .wheelDiameter = DEFAULT_WHEELDIAMETER, .numMagnetPoles = 15, - .swapFrontBack = false + .swapFrontBack = false, +#ifdef FEATURE_CAN + .sendFrontCanCmd = true, + .sendBackCanCmd = true, +#endif }; constexpr Settings::ControllerHardware mosfetsOffControllerHardware { @@ -48,7 +52,11 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware { .wheelDiameter = 165, .numMagnetPoles = 15, - .swapFrontBack = false + .swapFrontBack = false, +#ifdef FEATURE_CAN + .sendFrontCanCmd = true, + .sendBackCanCmd = true, +#endif }; constexpr Settings::WifiSettings defaultWifiSettings { @@ -75,7 +83,11 @@ constexpr Settings::ControllerHardware spinnerControllerHardware { .wheelDiameter = 165, .numMagnetPoles = 15, - .swapFrontBack = false + .swapFrontBack = false, +#ifdef FEATURE_CAN + .sendFrontCanCmd = true, + .sendBackCanCmd = true, +#endif }; constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings { @@ -87,7 +99,7 @@ constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings }; constexpr Settings::BoardcomputerHardware defaultBoardcomputerHardware { - .sampleCount = 100, + .sampleCount = 50, .gasMin = DEFAULT_GASMIN, .gasMax = DEFAULT_GASMAX, .bremsMin = DEFAULT_BREMSMIN, diff --git a/main/settings.h b/main/settings.h index 2462419..f2665b0 100644 --- a/main/settings.h +++ b/main/settings.h @@ -51,7 +51,13 @@ struct Settings int16_t wheelDiameter; // in mm int16_t numMagnetPoles; // virtual RPM per one real RPM + bool swapFrontBack; + +#ifdef FEATURE_CAN + bool sendFrontCanCmd; + bool sendBackCanCmd; +#endif } controllerHardware; struct BoardcomputerHardware { @@ -143,6 +149,10 @@ void Settings::executeForEverySetting(T &&callable) callable("wheelDiameter", controllerHardware.wheelDiameter); callable("numMagnetPoles", controllerHardware.numMagnetPoles); callable("swapFrontBack", controllerHardware.swapFrontBack); +#ifdef FEATURE_CAN + callable("sendFrontCanCmd", controllerHardware.sendFrontCanCmd); + callable("sendBackCanCmd", controllerHardware.sendBackCanCmd); +#endif callable("sampleCount", boardcomputerHardware.sampleCount); callable("gasMin", boardcomputerHardware.gasMin); @@ -161,6 +171,7 @@ void Settings::executeForEverySetting(T &&callable) callable("gametrakDistMax", boardcomputerHardware.gametrakDistMax); #endif callable("swapScreenBytes", boardcomputerHardware.swapScreenBytes); + callable("potiReadRate", boardcomputerHardware.timersSettings.potiReadRate); callable("modeUpdateRate", boardcomputerHardware.timersSettings.modeUpdateRate); callable("statsUpdateRate", boardcomputerHardware.timersSettings.statsUpdateRate); diff --git a/main/texts.h b/main/texts.h index 2cee1d2..8b0ee58 100644 --- a/main/texts.h +++ b/main/texts.h @@ -74,6 +74,7 @@ constexpr char TEXT_DEBUG[] = "Debug"; //SettingsMenu //constexpr char TEXT_SETTINGS[] = "Settings"; +constexpr char TEXT_BACKLIGHT[] = "Backlight"; constexpr char TEXT_LIMITSSETTINGS[] = "Limits settings"; constexpr char TEXT_WIFISETTINGS[] = "WiFi settings"; //constexpr char TEXT_BLUETOOTHSETTINGS[] = "Bluetooth settings"; @@ -95,6 +96,10 @@ constexpr char TEXT_NUMMAGNETPOLES[] = "Num magnet poles"; constexpr char TEXT_SETENABLED[] = "Set enabled"; constexpr char TEXT_SETINVERTED[] = "Set inverted"; constexpr char TEXT_SWAPFRONTBACK[] = "Swap front/back"; +#ifdef FEATURE_CAN +constexpr char TEXT_FRONTSENDCAN[] = "Front send CAN"; +constexpr char TEXT_BACKSENDCAN[] = "Back send CAN"; +#endif //constexpr char TEXT_BACK[] = "Back"; //StationWifiSettingsMenu diff --git a/main/utils.h b/main/utils.h index 5cce7a0..78b9a8c 100644 --- a/main/utils.h +++ b/main/utils.h @@ -4,8 +4,6 @@ #include #include -#include - #ifdef FEATURE_SERIAL #include #endif diff --git a/main/widgets/label.h b/main/widgets/label.h index e41c1cb..0010d3f 100644 --- a/main/widgets/label.h +++ b/main/widgets/label.h @@ -14,7 +14,7 @@ public: int y() const { return m_y; }; void start(); - void redraw(const std::string &str, bool forceRedraw = false); + void redraw(std::string_view str, bool forceRedraw = false); void clear(); private: @@ -45,7 +45,7 @@ void Label::start() m_lastHeight = 0; } -void Label::redraw(const std::string &str, bool forceRedraw) +void Label::redraw(std::string_view str, bool forceRedraw) { if (m_lastStr == str && m_lastFont == tft.textfont && @@ -53,7 +53,7 @@ void Label::redraw(const std::string &str, bool forceRedraw) !forceRedraw) return; - const auto renderedWidth = tft.drawString(str.c_str(), m_x, m_y); + const auto renderedWidth = tft.drawString(str.data(), m_x, m_y); const auto renderedHeight = tft.fontHeight(); if (renderedWidth < m_lastWidth) diff --git a/main/wifi_bobbycar.h b/main/wifi_bobbycar.h index 6030203..4a70003 100644 --- a/main/wifi_bobbycar.h +++ b/main/wifi_bobbycar.h @@ -9,14 +9,14 @@ namespace { wifi_stack::config wifi_create_config() { - return wifi_stack::config { + static wifi_stack::config config { .wifiEnabled = true, .hostname = deviceName, .sta = { .wifis = std::array { wifi_stack::wifi_entry { .ssid = "realraum", .key = "r3alraum" }, wifi_stack::wifi_entry { .ssid = "McDonalds Free WiFi", .key = "Passwort_123" }, - wifi_stack::wifi_entry { .ssid = "***REMOVED***", .key = "***REMOVED***" }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, wifi_stack::wifi_entry { .ssid = {}, .key = {} }, wifi_stack::wifi_entry { .ssid = {}, .key = {} }, wifi_stack::wifi_entry { .ssid = {}, .key = {} }, @@ -42,6 +42,8 @@ wifi_stack::config wifi_create_config() .beacon_interval = 100 } }; + + return config; } void wifi_begin() diff --git a/open_ide.sh b/open_ide.sh new file mode 100755 index 0000000..f1940c5 --- /dev/null +++ b/open_ide.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [[ -z "$IDF_PATH" ]] +then + source export.sh --skip-source-check +fi + +qtcreator "bobbycar-boardcomputer-firmware" 2>&1 >/dev/null &