diff --git a/configs/config_comred_new.cmake b/configs/config_comred_new.cmake index b158210..5b94571 100644 --- a/configs/config_comred_new.cmake +++ b/configs/config_comred_new.cmake @@ -25,7 +25,7 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_SERIAL # -DFEATURE_MOSFETS # -DFEATURE_BLUETOOTH -# -DFEATURE_BMS + -DFEATURE_BMS # -DFEATURE_GAMETRAK # -DFEATURE_POWERSUPPLY -DFEATURE_LEDBACKLIGHT diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index d019917..0efe6cd 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -6,16 +6,6 @@ set(BOBBY_HEADERS accessors/wifiapconfigaccessors.h accessors/wifistaconfigaccessors.h actions/assertaction.h - actions/bluetoothbeginaction.h - actions/bluetoothbeginmasteraction.h - actions/bluetoothconnectbmsaction.h - actions/bluetoothdisconnectaction.h - actions/bluetoothendaction.h - actions/bluetoothflushaction.h - actions/bmsturnoffchargeaction.h - actions/bmsturnoffdischargeaction.h - actions/bmsturnonchargeaction.h - actions/bmsturnondischargeaction.h actions/dividebyzeroaction.h actions/erasenvsaction.h actions/ledstripanimationactions.h @@ -34,8 +24,6 @@ set(BOBBY_HEADERS actions/wifistascanclearaction.h battery.h ble_bobby.h - bluetooth_bobby.h - bluetoothmode.h bmsutils.h bobbyblinker.h bobbybuttons.h @@ -45,7 +33,6 @@ set(BOBBY_HEADERS bobbytypesafeenum.h buildserver.h can.h - changevaluedisplay_bluetoothmode.h changevaluedisplay_bobbyquickactions.h changevaluedisplay_controlmode.h changevaluedisplay_controltype.h @@ -140,9 +127,6 @@ set(BOBBY_HEADERS screens/batteryinfodisplay.h screens/batterymenu.h screens/blesettingsmenu.h - screens/bluetoothsettingsmenu.h - screens/bmsdisplay.h - screens/bmsmenu.h screens/boardcomputerhardwaresettingsmenu.h screens/buzzermenu.h screens/calibratevoltagedisplay.h @@ -244,7 +228,6 @@ set(BOBBY_HEADERS taskmanager.h tempomat.h texthelpers/bletexthelpers.h - texthelpers/bluetoothtexthelpers.h texthelpers/cloudtexthelpers.h texthelpers/debugtexthelpers.h texthelpers/esptexthelpers.h @@ -283,7 +266,7 @@ set(BOBBY_SOURCES actions/wifistascanclearaction.cpp battery.cpp ble_bobby.cpp - bluetooth_bobby.cpp + bmsutils.cpp bobbyblinker.cpp bobbybuttons.cpp bobbyhupe.cpp @@ -373,8 +356,6 @@ set(BOBBY_SOURCES screens/batteryinfodisplay.cpp screens/batterymenu.cpp screens/blesettingsmenu.cpp - screens/bmsdisplay.cpp - screens/bmsmenu.cpp screens/boardcomputerhardwaresettingsmenu.cpp screens/buzzermenu.cpp screens/calibratevoltagedisplay.cpp diff --git a/main/actions/bluetoothbeginaction.cpp b/main/actions/bluetoothbeginaction.cpp deleted file mode 100644 index 6705a48..0000000 --- a/main/actions/bluetoothbeginaction.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "bluetoothbeginaction.h" - -// local includes -#include "globals.h" -#include "newsettings.h" - -#ifdef FEATURE_BLUETOOTH -void BluetoothBeginAction::triggered() -{ - if (!bluetoothSerial.begin(configs.bluetoothName.value.c_str())) - { - //Serial.println("Could not begin bluetooth"); - // TODO: better error handling - } -} -#endif diff --git a/main/actions/bluetoothbeginaction.h b/main/actions/bluetoothbeginaction.h deleted file mode 100644 index 1485973..0000000 --- a/main/actions/bluetoothbeginaction.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -// 3rdparty lib includes -#include - -#ifdef FEATURE_BLUETOOTH -class BluetoothBeginAction : public virtual espgui::ActionInterface -{ -public: - void triggered() override; -}; -#endif diff --git a/main/actions/bluetoothbeginmasteraction.h b/main/actions/bluetoothbeginmasteraction.h deleted file mode 100644 index 5d50824..0000000 --- a/main/actions/bluetoothbeginmasteraction.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "globals.h" -#include "newsettings.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BLUETOOTH -class BluetoothBeginMasterAction : public virtual ActionInterface -{ -public: - void triggered() override - { - if (!bluetoothSerial.begin(configs.bluetoothName.value.c_str(), true)) - { - //Serial.println("Could not begin bluetooth master"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/actions/bluetoothconnectbmsaction.h b/main/actions/bluetoothconnectbmsaction.h deleted file mode 100644 index ef0f6c5..0000000 --- a/main/actions/bluetoothconnectbmsaction.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "globals.h" - -using namespace espgui; - -namespace { -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) -class BluetoothConnectBmsAction : public virtual ActionInterface -{ -public: - void triggered() override - { - uint8_t remoteAddress[ESP_BD_ADDR_LEN] = {0xAA, 0xBB, 0xCC, 0xA1, 0x23, 0x45}; - if (!bluetoothSerial.connect(remoteAddress)) - { - //Serial.println("Could not connect bluetooth to bms"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/actions/bluetoothdisconnectaction.h b/main/actions/bluetoothdisconnectaction.h deleted file mode 100644 index 82d778f..0000000 --- a/main/actions/bluetoothdisconnectaction.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "globals.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BLUETOOTH -class BluetoothDisconnectAction : public virtual ActionInterface -{ -public: - void triggered() override - { - if (!bluetoothSerial.disconnect()) - { - //Serial.println("Could not disconnect bluetooth"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/actions/bluetoothendaction.h b/main/actions/bluetoothendaction.h deleted file mode 100644 index 8a1ed67..0000000 --- a/main/actions/bluetoothendaction.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "globals.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BLUETOOTH -class BluetoothEndAction : public virtual ActionInterface -{ -public: - void triggered() override - { - bluetoothSerial.end(); - } -}; -#endif -} diff --git a/main/actions/bluetoothflushaction.h b/main/actions/bluetoothflushaction.h deleted file mode 100644 index 527e1b7..0000000 --- a/main/actions/bluetoothflushaction.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "globals.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BLUETOOTH -class BluetoothFlushAction : public virtual ActionInterface -{ -public: - void triggered() override - { - bluetoothSerial.flush(); - } -}; -#endif -} diff --git a/main/actions/bmsturnoffchargeaction.h b/main/actions/bmsturnoffchargeaction.h deleted file mode 100644 index 719d84a..0000000 --- a/main/actions/bmsturnoffchargeaction.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "bmsutils.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BMS -class BmsTurnOffChargeAction : public virtual ActionInterface -{ -public: - void triggered() override - { - if (!bms::send6Bit(42405, 250, 0)) - { - //Serial.println("Could not turn off charge mosfet"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/actions/bmsturnoffdischargeaction.h b/main/actions/bmsturnoffdischargeaction.h deleted file mode 100644 index 6f123ca..0000000 --- a/main/actions/bmsturnoffdischargeaction.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "bmsutils.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BMS -class BmsTurnOffDischargeAction : public virtual ActionInterface -{ -public: - void triggered() override - { - if (!bms::send6Bit(42405, 249, 0)) - { - //Serial.println("Could not turn off discharge mosfet"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/actions/bmsturnonchargeaction.h b/main/actions/bmsturnonchargeaction.h deleted file mode 100644 index 712c568..0000000 --- a/main/actions/bmsturnonchargeaction.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "bmsutils.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BMS -class BmsTurnOnChargeAction : public virtual ActionInterface -{ -public: - void triggered() override - { - if (!bms::send6Bit(42405, 250, 1)) - { - //Serial.println("Could not turn on charge mosfet"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/actions/bmsturnondischargeaction.h b/main/actions/bmsturnondischargeaction.h deleted file mode 100644 index 585a5ab..0000000 --- a/main/actions/bmsturnondischargeaction.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "actioninterface.h" -#include "bmsutils.h" - -using namespace espgui; - -namespace { -#ifdef FEATURE_BMS -class BmsTurnOnDischargeAction : public virtual ActionInterface -{ -public: - void triggered() override - { - if (!bms::send6Bit(42405, 249, 1)) - { - //Serial.println("Could not turn on discharge mosfet"); - // TODO: better error handling - } - } -}; -#endif -} diff --git a/main/bluetooth_bobby.cpp b/main/bluetooth_bobby.cpp deleted file mode 100644 index 3f1de46..0000000 --- a/main/bluetooth_bobby.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "bluetooth_bobby.h" - -// compilation will be broken as there is no config parameter - -// local includes -#ifdef FEATURE_BLUETOOTH -#include "actions/bluetoothbeginaction.h" -#include "actions/bluetoothbeginmasteraction.h" -#ifdef FEATURE_BMS -#include "actions/bluetoothconnectbmsaction.h" -#endif -#include "bluetoothmode.h" -#endif - -#ifdef FEATURE_BLUETOOTH -void bluetooth_init() -{ - if (configs.bluetooth.autoBluetoothMode.value == BluetoothMode::Master) - { - bootLabel.redraw("bluetooth begin master"); - BluetoothBeginMasterAction{}.triggered(); -#ifdef FEATURE_BMS - if (configs.autoConnectBms.value) - { - bootLabel.redraw("connect BMS"); - BluetoothConnectBmsAction{}.triggered(); - } -#endif - } - else if (configs.bluetooth.autoBluetoothMode.value == BluetoothMode::Slave) - { - bootLabel.redraw("bluetooth begin"); - BluetoothBeginAction{}.triggered(); - } -} - -void bluetooth_update() -{ -} -#endif diff --git a/main/bluetooth_bobby.h b/main/bluetooth_bobby.h deleted file mode 100644 index 2bc4634..0000000 --- a/main/bluetooth_bobby.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#ifdef FEATURE_BLUETOOTH -void bluetooth_init(); -void bluetooth_update(); -#endif diff --git a/main/bluetoothmode.h b/main/bluetoothmode.h deleted file mode 100644 index 71ddc35..0000000 --- a/main/bluetoothmode.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include -enum class BluetoothMode : uint8_t -{ - Off, - Master, - Slave -}; diff --git a/main/bmsutils.cpp b/main/bmsutils.cpp new file mode 100644 index 0000000..8c04356 --- /dev/null +++ b/main/bmsutils.cpp @@ -0,0 +1,4 @@ +#include "bmsutils.h" + +namespace bms { +} // namespace bms diff --git a/main/bmsutils.h b/main/bmsutils.h index 52af5ae..478fa10 100644 --- a/main/bmsutils.h +++ b/main/bmsutils.h @@ -1,141 +1,4 @@ #pragma once -#include - -#include "globals.h" - -namespace { -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) namespace bms { -constexpr auto autoReconnect = false; // causes hangs when not available - -bool lastConnected; -espchrono::millis_clock::time_point lastSend; -espchrono::millis_clock::time_point lastReceive; - -float voltage; -float current; -float capacity; -int8_t soc; -float cycle; -int16_t power; -float batt[12]; - -bool send6Bit(int zhen_tou, int address, int data) -{ - uint8_t buffer[6]; - buffer[0] = (char)((zhen_tou>>8)&255); - buffer[1] = (char)(zhen_tou&255); - buffer[2] = (char)(address&255); - buffer[3] = (char)((data>>8)&255); - buffer[4] = (char)(data&255); - buffer[5] = (char)(buffer[2]+buffer[3]+buffer[4]); - - const auto sent = bluetoothSerial.write(buffer, 6); - if (sent != 6) - { - //Serial.printf("send: %u\r\n", sent); - } - return sent == 6; -} - -void init() -{ - -} - -void update() -{ - const auto now = espchrono::millis_clock::now(); - - if (bluetoothSerial.hasClient() != lastConnected) - { - lastSend = 0; - lastConnected = bluetoothSerial.hasClient(); - } - - if (bluetoothSerial.hasClient()) - { - if (bluetoothSerial.available() >= 140) - { - uint8_t buffer[140]; - const auto read = bluetoothSerial.readBytes(buffer, 140); - if (read != 140) - { - //Serial.printf("bms read buffer too short %u\r\n", read); - - for (int i = 0; i < read; i++) - { - //Serial.printf("%i ", buffer[i]); - } - //Serial.println(); - - goto after_read; - } - - if (buffer[0] != 170 || - buffer[1] != 85 || - buffer[2] != 170 || - buffer[3] != 255) - { - //Serial.println("bms read buffer wrong sequence"); - - for (const auto &x : buffer) - { - //Serial.printf("%i ", x); - } - //Serial.println(); - - goto after_read; - } - - lastReceive = now; - - voltage = static_cast((buffer[4] << 8) | buffer[5]) / 10.f; - current = static_cast((buffer[72] << 8) | buffer[73]) / 10.f; - capacity = static_cast((((((buffer[79] << 8) | buffer[80]) << 8) | buffer[81]) << 8) | buffer[82]) / 1000.f; - soc = buffer[74]; - cycle = static_cast((((((buffer[83] << 8) | buffer[84]) << 8) | buffer[85]) << 8) | buffer[86]) / 1000.f; - power = (buffer[113] << 8) | buffer[114]; - - for (int i = 0; i < 12; i++) - batt[i] = ((buffer[(i*2)+6] * 256) + buffer[(i*2)+7]) / 1000.f; - } -// else if (bluetoothSerial.available()) -// { -// //Serial.printf("available() = %i\r\n", bluetoothSerial.available()); -// while (bluetoothSerial.available()) -// { -// //Serial.printf("%i ", bluetoothSerial.read()); -// } -// //Serial.println(); -// } - - after_read: - - if (!lastSend || now-lastSend >= 1000) - { - //Serial.println("requresting bms live values"); - if (!send6Bit(56283, 0, 0)) - { - //Serial.println("could not request bms live values"); - } - lastSend = now; - } - } - else if (autoReconnect) - { - if (!lastSend || now-lastSend >= 500) - { - uint8_t remoteAddress[ESP_BD_ADDR_LEN] = {0xAA, 0xBB, 0xCC, 0xA1, 0x23, 0x45}; - //Serial.println("connect()"); - const auto result = bluetoothSerial.connect(remoteAddress); - //Serial.printf("connect() returned %s\r\n", result?"true":"false"); - - lastSend = now; - } - } -} -} -#endif -} +} // namespace bms diff --git a/main/changevaluedisplay_bluetoothmode.h b/main/changevaluedisplay_bluetoothmode.h deleted file mode 100644 index 303ca7f..0000000 --- a/main/changevaluedisplay_bluetoothmode.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -// local includes -#include "changevaluedisplay.h" -#include "menudisplay.h" -#include "utils.h" -#include "actions/setvalueaction.h" -#include "actions/backproxyaction.h" -#include "icons/back.h" -#ifdef FEATURE_BLUETOOTH -#include "bluetoothmode.h" -#endif - -namespace espgui { -#ifdef FEATURE_BLUETOOTH -template<> -class ChangeValueDisplay : - public MenuDisplay, - public virtual AccessorInterface, - public virtual ActionInterface -{ - using Base = MenuDisplay; - -public: - ChangeValueDisplay(); - - void start() override; -}; - -ChangeValueDisplay::ChangeValueDisplay() -{ - constructMenuItem, StaticText>>(BluetoothMode::Off, *this, *this); - constructMenuItem, StaticText>>(BluetoothMode::Master, *this, *this); - constructMenuItem, StaticText>>(BluetoothMode::Slave, *this, *this); - constructMenuItem, StaticMenuItemIcon<&bobbyicons::back>>>(*this); -} - -void ChangeValueDisplay::start() -{ - Base::start(); - - switch (const auto value = getValue()) - { - case BluetoothMode::Off: setSelectedIndex(0); break; - case BluetoothMode::Master: setSelectedIndex(1); break; - case BluetoothMode::Slave: setSelectedIndex(2); break; - default: - //Serial.printf("Unknown BluetoothMode: %i\r\n", int(value)); - setSelectedIndex(4); - } -} -#endif -} // namespace espgui diff --git a/main/globals.cpp b/main/globals.cpp index 279e2b9..40f962b 100644 --- a/main/globals.cpp +++ b/main/globals.cpp @@ -48,10 +48,5 @@ std::atomic buttonRequest; bool initScreenRequest{false}; Controllers controllers; - -#ifdef FEATURE_BLUETOOTH -BluetoothSerial bluetoothSerial; -#endif - ModeInterface *lastMode{}; ModeInterface *currentMode{}; diff --git a/main/globals.h b/main/globals.h index 98a5e1b..7f6057f 100644 --- a/main/globals.h +++ b/main/globals.h @@ -7,9 +7,6 @@ #include // Arduino includes -#ifdef FEATURE_BLUETOOTH -#include -#endif #ifdef FEATURE_SERIAL #include #endif @@ -123,10 +120,6 @@ extern Controllers controllers; struct FrontControllerGetter { static Controller &get() { return controllers.front; }}; struct BackControllerGetter { static Controller &get() { return controllers.back; }}; -#ifdef FEATURE_BLUETOOTH -extern BluetoothSerial bluetoothSerial; -#endif - extern ModeInterface *lastMode; extern ModeInterface *currentMode; diff --git a/main/screens/bluetoothsettingsmenu.h b/main/screens/bluetoothsettingsmenu.h deleted file mode 100644 index 1fffdb8..0000000 --- a/main/screens/bluetoothsettingsmenu.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -// compilation will be broken as there is no config parameter - -// local includes -#include "changevaluedisplay.h" -#ifdef FEATURE_BLUETOOTH -#include "changevaluedisplay_bluetoothmode.h" -#endif -#include "guihelpers/bobbymenudisplay.h" -#include "menuitem.h" -#include "actions/dummyaction.h" -#ifdef FEATURE_BLUETOOTH -#include "actions/bluetoothbeginaction.h" -#include "actions/bluetoothbeginmasteraction.h" -#include "actions/bluetoothflushaction.h" -#include "actions/bluetoothendaction.h" -#include "actions/bluetoothdisconnectaction.h" -#endif -#include "actions/switchscreenaction.h" -#include "texthelpers/bluetoothtexthelpers.h" -#include "accessors/settingsaccessors.h" -#include "icons/back.h" - -using namespace espgui; -using namespace bluetoothtexthelpers; - -namespace { -#ifdef FEATURE_BLUETOOTH -class BluetoothSettingsMenu; - -//using AutoBluetoothModeChangeDisplay = makeComponent< -// ChangeValueDisplay, -// StaticText, -// AutoBluetoothModeAccessor, -// BackActionInterface>, -// SwitchScreenAction -//>; - -class BluetoothSettingsMenu : - public BobbyMenuDisplay, - public StaticText, - public BackActionInterface> -{ -public: - BluetoothSettingsMenu() - { - constructMenuItem>(); - constructMenuItem>(); -// constructMenuItem>(); // crashes - constructMenuItem>(); - constructMenuItem>(); - constructMenuItem, BluetoothBeginAction>>(); - constructMenuItem, BluetoothBeginMasterAction>>(); - constructMenuItem, BluetoothFlushAction>>(); - constructMenuItem, BluetoothEndAction>>(); - constructMenuItem, BluetoothDisconnectAction>>(); -// constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::back>>>(); - } -}; -#endif -} // namespace diff --git a/main/screens/bmsdisplay.cpp b/main/screens/bmsdisplay.cpp deleted file mode 100644 index af05531..0000000 --- a/main/screens/bmsdisplay.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "bmsdisplay.h" - -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) -#include "screens/mainmenu.h" -#include "screens/speedinfodisplay.h" -#include "screens/statusdisplay.h" -#include "screenmanager.h" -#include "guihelpers/bobbymenudisplay.h" - -using namespace espgui; - -void BmsDisplay::initScreen() -{ - Base::initScreen(); - - tft.fillScreen(TFT_BLACK); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - - tft.setTextFont(2); - m_statusLabel.start(); - m_statusLabel.redraw("init"); - - tft.setTextFont(4); - tft.drawString("Voltage:", 0, m_voltageLabel.y()); - m_voltageLabel.start(); - tft.drawString("Capacity:", 0, m_capacityLabel.y()); - m_capacityLabel.start(); - tft.drawString("SOC:", 0, m_socLabel.y()); - m_socLabel.start(); - tft.drawString("Power:", 0, m_powerLabel.y()); - m_powerLabel.start(); - tft.drawString("Current:", 0, m_currentLabel.y()); - m_currentLabel.start(); - tft.drawString("Speed:", 0, m_speedLabel.y()); - m_speedLabel.start(); - tft.drawString("PpS:", 0, m_powerPerSpeedLabel.y()); - m_powerPerSpeedLabel.start(); - - for (auto &label : m_battLabels) - label.start(); - - tft.drawString("Cycle:", 0, m_cycleLabel.y()); - m_cycleLabel.start(); -} - -void BmsDisplay::redraw() -{ - Base::redraw(); - - if (bluetoothSerial.hasClient()) - tft.setTextColor(TFT_GREEN, TFT_BLACK); - else - { - tft.setTextColor(TFT_RED, TFT_BLACK); - tft.setTextFont(2); - } - - m_statusLabel.redraw(bluetoothSerial.hasClient() ? "OK" : "FAIL"); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); - if (!bluetoothSerial.hasClient()) - tft.setTextFont(4); - - if (bluetoothSerial.hasClient()) - { - m_voltageLabel.redraw(fmt::format("{:.02f}V", bms::voltage)); - m_capacityLabel.redraw(fmt::format("{:.02f} mAh", bms::capacity)); - m_socLabel.redraw(fmt::format("{:.02f}%", bms::soc)); - m_powerLabel.redraw(fmt::format("{:.02f}W", bms::power)); - m_currentLabel.redraw(fmt::format("{:.02f}A", bms::current)); - } - else - { - m_voltageLabel.clear(); - m_capacityLabel.clear(); - m_socLabel.clear(); - m_powerLabel.clear(); - m_currentLabel.clear(); - } - - m_speedLabel.redraw(fmt::format("{:.02f}kmh", avgSpeedKmh)); - - if (bluetoothSerial.hasClient()) - m_powerPerSpeedLabel.redraw(fmt::format("{:.02f}W/kmh", avgSpeedKmh < 1 ? 0 : bms::power / avgSpeedKmh)); - else - m_powerPerSpeedLabel.clear(); - - for (int i = 0; i < 12; i++) - m_battLabels[i].redraw(fmt::format("{:.02f}", bms::batt[i])); - - if (bluetoothSerial.hasClient()) - m_cycleLabel.redraw(fmt::format("{:.02f}AH", bms::cycle)); - else - m_cycleLabel.clear(); -} - -void BmsDisplay::buttonPressed(espgui::Button button) -{ - Base::buttonPressed(button); - - switch (button) - { - using espgui::Button; - case Button::Right: pushScreen(); break; - case Button::Up: switchScreen(); break; - case Button::Down: switchScreen(); break; - default:; - } -} -#endif diff --git a/main/screens/bmsdisplay.h b/main/screens/bmsdisplay.h deleted file mode 100644 index fd2243f..0000000 --- a/main/screens/bmsdisplay.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) -// 3rdparty lib includes -#include -#include -#include - -// local includes -#include "globals.h" -#include "bmsutils.h" -#include "bobbydisplay.h" - -class BmsDisplay : - public BobbyDisplay, - public espgui::DummyBack -{ - using Base = BobbyDisplay; - -public: - void initScreen() override; - void redraw() override; - - void buttonPressed(espgui::Button button) override; - - espgui::Label m_statusLabel{200, 0}; - - espgui::Label m_voltageLabel{107, 0}; - espgui::Label m_capacityLabel{107, 25}; - espgui::Label m_socLabel{107, 50}; - espgui::Label m_powerLabel{107, 75}; - espgui::Label m_currentLabel{107, 100}; - espgui::Label m_speedLabel{107, 125}; - espgui::Label m_powerPerSpeedLabel{107, 150}; - - std::array m_battLabels{{ - espgui::Label{0, 225}, espgui::Label{60, 225}, espgui::Label{120, 225}, espgui::Label{180, 225}, - espgui::Label{0, 250}, espgui::Label{60, 250}, espgui::Label{120, 250}, espgui::Label{180, 250}, - espgui::Label{0, 275}, espgui::Label{60, 275}, espgui::Label{120, 275}, espgui::Label{180, 275} - }}; - - espgui::Label m_cycleLabel{105, 300}; -}; -#endif diff --git a/main/screens/bmsmenu.cpp b/main/screens/bmsmenu.cpp deleted file mode 100644 index 927499e..0000000 --- a/main/screens/bmsmenu.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "bmsmenu.h" - -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) -// local includes -#include "menuitem.h" -#include "actions/bluetoothconnectbmsaction.h" -#include "actions/bluetoothdisconnectaction.h" -#include "actions/dummyaction.h" -#include "actions/bmsturnonchargeaction.h" -#include "actions/bmsturnoffchargeaction.h" -#include "actions/bmsturnondischargeaction.h" -#include "actions/bmsturnoffdischargeaction.h" -#include "actions/popscreenaction.h" -#include "bluetoothtexthelpers.h" -#include "icons/back.h" - -using namespace espgui; -using namespace bluetoothtexthelpers; - -BmsMenu::BmsMenu() -{ - constructMenuItem, BluetoothConnectBmsAction>>(); - constructMenuItem, BluetoothDisconnectAction>>(); - constructMenuItem>(); - constructMenuItem, BmsTurnOnChargeAction>>(); - constructMenuItem, BmsTurnOffChargeAction>>(); - constructMenuItem, BmsTurnOnDischargeAction>>(); - constructMenuItem, BmsTurnOffDischargeAction>>(); - constructMenuItem, PopScreenAction, StaticMenuItemIcon<&bobbyicons::back>>>(); -} - -void BmsMenu::back() -{ - popSreen(); -} -#endif diff --git a/main/screens/bmsmenu.h b/main/screens/bmsmenu.h deleted file mode 100644 index d6e300a..0000000 --- a/main/screens/bmsmenu.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) -// local includes -#include "guihelpers/bobbymenudisplay.h" - -class BmsMenu : public BobbyMenuDisplay -{ -public: - BmsMenu(); - - std::string text() const override { return TEXT_BMS; } - void back() override; -}; -#endif diff --git a/main/screens/graphsmenu.cpp b/main/screens/graphsmenu.cpp index 4eb3c08..f4920cb 100644 --- a/main/screens/graphsmenu.cpp +++ b/main/screens/graphsmenu.cpp @@ -27,10 +27,6 @@ constexpr char TEXT_SUMCURRENT[] = "Sum current"; constexpr char TEXT_FRONTVOLTAGE[] = "Front voltage"; constexpr char TEXT_BACKVOLTAGE[] = "Back voltage"; constexpr char TEXT_VOLTAGES[] = "Voltages"; -constexpr char TEXT_BMSVOLTAGE[] = "BMS voltage"; -constexpr char TEXT_BMSCURRENT[] = "BMS current"; -constexpr char TEXT_BMSPOWER[] = "BMS power"; -constexpr char TEXT_SUMCURRENTSCOMPARISON[] = "Sum currents comparison"; constexpr char TEXT_MOTORCURRENTS[] = "Motor currents"; constexpr char TEXT_RSSI[] = "RSSI"; constexpr char TEXT_BACK[] = "Back"; @@ -132,37 +128,6 @@ using VoltagesSplitGraphDisplay = espgui::makeComponent< espgui::BackActionInterface >; -#ifdef FEATURE_BMS -using BmsVoltageGraphDisplay = espgui::makeComponent< - BobbyGraphDisplay<1>, - espgui::StaticText, - espgui::SingleGraphAccessor, - espgui::ConfirmActionInterface, - espgui::BackActionInterface ->; -using BmsCurrentGraphDisplay = espgui::makeComponent< - BobbyGraphDisplay<1>, - espgui::StaticText, - espgui::SingleGraphAccessor, - espgui::ConfirmActionInterface, - espgui::BackActionInterface ->; -using BmsPowerGraphDisplay = espgui::makeComponent< - BobbyGraphDisplay<1>, - espgui::StaticText, - espgui::SingleGraphAccessor, - espgui::ConfirmActionInterface, - espgui::BackActionInterface ->; -using SumCurrentsComparisonGraphDisplay = espgui::makeComponent< - BobbyGraphDisplay<2>, - espgui::StaticText, - DualGraphAccessor, - espgui::ConfirmActionInterface, - espgui::BackActionInterface ->; -#endif - class MotorCurrentsStatistics : public virtual espgui::GraphAccessorInterface<4> { std::array, 4> getBuffers() const override @@ -203,12 +168,6 @@ GraphsMenu::GraphsMenu() constructMenuItem, PushScreenAction>>(); constructMenuItem, PushScreenAction>>(); constructMenuItem, PushScreenAction>>(); -#ifdef FEATURE_BMS - constructMenuItem, PushScreenAction>>(); - constructMenuItem, PushScreenAction>>(); - constructMenuItem, PushScreenAction>>(); - constructMenuItem, PushScreenAction>>(); -#endif constructMenuItem, PushScreenAction>>(); constructMenuItem, PushScreenAction>>(); constructMenuItem, PopScreenAction, StaticMenuItemIcon<&bobbyicons::back>>>(); diff --git a/main/screens/mainmenu.cpp b/main/screens/mainmenu.cpp index 0ba66df..d3462ad 100644 --- a/main/screens/mainmenu.cpp +++ b/main/screens/mainmenu.cpp @@ -13,7 +13,6 @@ #include "screens/graphsmenu.h" #include "screens/batterymenu.h" #include "screens/powersupplydisplay.h" -#include "screens/bmsmenu.h" #include "screens/settingsmenu.h" #include "screens/manageprofilesmenu.h" #include "screens/mosfetsmenu.h" @@ -31,9 +30,6 @@ #include "icons/modes.h" #include "icons/presets.h" #include "icons/graph.h" -#ifdef FEATURE_BMS -#include "icons/bms.h" -#endif #include "icons/settings.h" #include "icons/lock.h" #include "icons/demos.h" @@ -59,11 +55,9 @@ constexpr char TEXT_LEDSTRIP[] = "Ledstrip"; constexpr char TEXT_STATISTICSMENU[] = "Statistics"; constexpr char TEXT_SELECTMODE[] = "Select mode"; constexpr char TEXT_MODESETTINGS[] = "Mode settings"; -constexpr char TEXT_PRESETS[] = "Presets"; constexpr char TEXT_PROFILES[] = "Profiles"; constexpr char TEXT_GRAPHS[] = "Graphs"; constexpr char TEXT_POWERSUPPLY[] = "Powersupply"; -constexpr char TEXT_BMS[] = "BMS"; constexpr char TEXT_SETTINGS[] = "Settings"; constexpr char TEXT_GREENPASS[] = "Green Pass"; constexpr char TEXT_LOCKVEHICLE[] = "Lock vehicle"; @@ -111,9 +105,6 @@ MainMenu::MainMenu() #endif #ifdef FEATURE_MOSFETS constructMenuItem, PushScreenAction>>(); -#endif -#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) - constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::bms>>>(); #endif constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::demos>>>(); if (SHOWITEM) { constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::presets>>>(); } diff --git a/main/screens/settingsmenu.cpp b/main/screens/settingsmenu.cpp index 795981a..51c6817 100644 --- a/main/screens/settingsmenu.cpp +++ b/main/screens/settingsmenu.cpp @@ -24,7 +24,6 @@ #include "icons/wifi.h" #include "screens/aboutmenu.h" #include "screens/blesettingsmenu.h" -#include "screens/bluetoothsettingsmenu.h" #include "screens/boardcomputerhardwaresettingsmenu.h" #include "screens/buzzermenu.h" #include "screens/cloudsettingsmenu.h" @@ -48,7 +47,6 @@ constexpr char TEXT_BACKLIGHT[] = "Backlight"; constexpr char TEXT_LIMITSSETTINGS[] = "Limits settings"; constexpr char TEXT_NETWORKSETTINGS[] = "Network settings"; constexpr char TEXT_ESPNOW[] = "ESPNOW settings"; -constexpr char TEXT_BLUETOOTHSETTINGS[] = "Bluetooth settings"; constexpr char TEXT_BLESETTINGS[] = "BLE settings"; constexpr char TEXT_CLOUDSETTINGS[] = "Cloud settings"; constexpr char TEXT_UDPCLOUDSETTINGS[] = "UDP Cloud settings"; @@ -60,7 +58,6 @@ constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W setting constexpr char TEXT_FEATUREFLAGS[] = "Feature flags"; constexpr char TEXT_USERNAME[] = "Username"; // ota-name constexpr char TEXT_ANHAENGER_ID[] = "Anhaenger ID"; -constexpr char TEXT_AUTOCONNECTBMS[] = "Auto connect BMS"; constexpr char TEXT_BUZZER[] = "Buzzer"; constexpr char TEXT_FRONTLED[] = "Front LED"; constexpr char TEXT_BACKLED[] = "Back LED"; @@ -109,9 +106,6 @@ SettingsMenu::SettingsMenu() constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::wifi>>>(); if (configs.feature.esp_now.isEnabled.value()) constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::wifi>>>(); -#ifdef FEATURE_BLUETOOTH - constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::bluetooth>>>(); -#endif if (configs.feature.ble.isEnabled.value()) constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::bluetooth>>>(); if (configs.feature.cloud.isEnabled.value()) @@ -130,9 +124,6 @@ SettingsMenu::SettingsMenu() constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::demos>>>(); constructMenuItem, PushScreenAction>>(); constructMenuItem, PushScreenAction>>(); -//#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS) -// constructMenuItem, BobbyCheckbox, AutoConnectBmsAccessor>>(); -//#endif constructMenuItem, PushScreenAction, StaticMenuItemIcon<&bobbyicons::buzzer>>>(); constructMenuItem, BobbyCheckbox, FrontLedAccessor>>(); constructMenuItem, BobbyCheckbox, BackLedAccessor>>(); diff --git a/main/screens/speedinfodisplay.cpp b/main/screens/speedinfodisplay.cpp index 78bc2bb..50cff60 100644 --- a/main/screens/speedinfodisplay.cpp +++ b/main/screens/speedinfodisplay.cpp @@ -85,11 +85,7 @@ void SpeedInfoDisplay::buttonPressed(espgui::Button button) espgui::switchScreen(); break; case Button::Down: -#ifdef FEATURE_BMS - espgui::switchScreen(); -#else espgui::switchScreen(); -#endif break; default:; } diff --git a/main/screens/statusdisplay.cpp b/main/screens/statusdisplay.cpp index 6bc6b4e..093ef93 100644 --- a/main/screens/statusdisplay.cpp +++ b/main/screens/statusdisplay.cpp @@ -10,16 +10,13 @@ #include // local includes -#include "screens/batteryinfodisplay.h" -#include "screens/speedinfodisplay.h" -#ifdef FEATURE_BMS -#include "screens/bmsdisplay.h" -#endif -#include "screens/mainmenu.h" -#include "screens/metersdisplay.h" #include "drivingstatistics.h" #include "modes/defaultmode.h" #include "newsettings.h" +#include "screens/batteryinfodisplay.h" +#include "screens/mainmenu.h" +#include "screens/metersdisplay.h" +#include "screens/speedinfodisplay.h" #include "taskmanager.h" #include "udpcloud.h" @@ -217,11 +214,7 @@ void StatusDisplay::buttonPressed(espgui::Button button) case Button::Up: if (simplified) return; -#ifdef FEATURE_BMS - switchScreen(); -#else switchScreen(); -#endif break; case Button::Down: if (simplified) diff --git a/main/settingspersister.cpp b/main/settingspersister.cpp index 59e6628..753469c 100644 --- a/main/settingspersister.cpp +++ b/main/settingspersister.cpp @@ -16,9 +16,6 @@ // local includes #include "profilesettings.h" -#ifdef FEATURE_BLUETOOTH -#include "bluetoothmode.h" -#endif #include "unifiedmodelmode.h" #include "globals.h" @@ -140,16 +137,6 @@ template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_ *out_value = LarsmModeMode(tempValue); return err; }}; -#ifdef FEATURE_BLUETOOTH -template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, BluetoothMode* out_value) -{ - uint8_t tempValue; - esp_err_t err = nvs_get_u8(handle, key, &tempValue); - if (err == ESP_OK) - *out_value = BluetoothMode(tempValue); - return err; -}}; -#endif template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, UnifiedModelMode* out_value) { uint8_t tempValue; @@ -283,12 +270,6 @@ template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_ { return nvs_set_u8(handle, key, uint8_t(value)); }}; -#ifdef FEATURE_BLUETOOTH -template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, BluetoothMode value) -{ - return nvs_set_u8(handle, key, uint8_t(value)); -}}; -#endif template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, UnifiedModelMode value) { return nvs_set_u8(handle, key, uint8_t(value)); diff --git a/main/statistics.cpp b/main/statistics.cpp index c0dc322..5274639 100644 --- a/main/statistics.cpp +++ b/main/statistics.cpp @@ -2,9 +2,6 @@ namespace statistics { ContainerType raw_gas, raw_brems, gas, brems, avgSpeed, avgSpeedKmh, sumCurrent, frontVoltage, backVoltage, frontLeftCurrent, frontRightCurrent, backLeftCurrent, backRightCurrent, -#ifdef FEATURE_BMS - bmsVoltage, bmsCurrent, bmsPower, -#endif rssi; } // namespace statistics @@ -33,11 +30,6 @@ void pushStats() statistics::backLeftCurrent.push_back(fixCurrent(controllers.back.feedback.left.dcLink)); statistics::backRightCurrent.push_back(fixCurrent(controllers.back.feedback.right.dcLink)); } -#ifdef FEATURE_BMS - statistics::bmsVoltage.push_back(bms::voltage); - statistics::bmsCurrent.push_back(bms::current); - statistics::bmsPower.push_back(bms::power); -#endif if (wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::CONNECTED) { if (const auto &result = wifi_stack::get_sta_ap_info(); result) diff --git a/main/statistics.h b/main/statistics.h index 411d776..3579f0d 100644 --- a/main/statistics.h +++ b/main/statistics.h @@ -6,15 +6,11 @@ // local includes #include "globals.h" -#include "bmsutils.h" #include "utils.h" namespace statistics { using ContainerType = ring_buffer; extern ContainerType raw_gas, raw_brems, gas, brems, avgSpeed, avgSpeedKmh, sumCurrent, frontVoltage, backVoltage, frontLeftCurrent, frontRightCurrent, backLeftCurrent, backRightCurrent, -#ifdef FEATURE_BMS - bmsVoltage, bmsCurrent, bmsPower, -#endif rssi; } // namespace statistics @@ -42,11 +38,6 @@ using AvgSpeedKmhStatistics = BufferAccessorImpl; using SumCurrentStatistics = BufferAccessorImpl; using FrontVoltageStatistics = BufferAccessorImpl; using BackVoltageStatistics = BufferAccessorImpl; -#ifdef FEATURE_BMS -using BmsVoltageStatistics = BufferAccessorImpl; -using BmsCurrentStatistics = BufferAccessorImpl; -using BmsPowerStatistics = BufferAccessorImpl; -#endif using FrontLeftCurrentStatistics = BufferAccessorImpl; using FrontRightCurrentStatistics = BufferAccessorImpl; using BackLeftCurrentStatistics = BufferAccessorImpl; diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index 70f8aae..7fef79a 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -18,12 +18,6 @@ #endif #include "time_bobbycar.h" #include "potis.h" -#ifdef FEATURE_BLUETOOTH -#include "bluetooth_bobby.h" -#ifdef FEATURE_BMS -#include "bmsutils.h" -#endif -#endif #ifdef FEATURE_CAN #include "can.h" #endif @@ -65,12 +59,6 @@ BobbySchedulerTask schedulerTasksArr[] { #endif BobbySchedulerTask { "time", initTime, updateTime, 100ms, false }, BobbySchedulerTask { "potis", initPotis, readPotis, 20ms, false }, -#ifdef FEATURE_BLUETOOTH - BobbySchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms, false }, -#ifdef FEATURE_BMS - BobbySchedulerTask { "bms", bms::init, bms::update, 100ms, false }, -#endif -#endif #ifdef FEATURE_CAN BobbySchedulerTask { "can", can::initCan, can::updateCan, 10ms, false }, #endif diff --git a/main/texthelpers/bluetoothtexthelpers.h b/main/texthelpers/bluetoothtexthelpers.h deleted file mode 100644 index c7171ae..0000000 --- a/main/texthelpers/bluetoothtexthelpers.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -// 3rdparty lib includes -#include "fmt/core.h" - -// local includes -#include "textinterface.h" -#include "globals.h" -#include "utils.h" - -namespace bluetoothtexthelpers { -#ifdef FEATURE_BLUETOOTH -template -using BluetoothStatusTextHelper = StatusTextHelper; - -constexpr char TEXT_BLUETOOTHAVAILABLE[] = "Available: "; -using BluetoothAvailableText = BluetoothStatusTextHelper; - -constexpr char TEXT_BLUETOOTHHASCLIENT[] = "Has client: "; -using BluetoothHasClientText = BluetoothStatusTextHelper; - -//constexpr char TEXT_BLUETOOTHCONNECTED[] = "Connected: "; -//using BluetoothConnectedText = BluetoothStatusTextHelper; -struct BluetoothConnectedText : public virtual TextInterface { -public: - std::string text() const override { return fmt::format("{}: {}", TEXT_BLUETOOTHCONNECTED, to_string(bluetoothSerial.connected())); } -}; - -//constexpr char TEXT_BLUETOOTHISREADY[] = "Is ready: "; -//using BluetoothIsReadyText = BluetoothStatusTextHelper; -struct BluetoothIsReadyText : public virtual TextInterface { -public: - std::string text() const override { return fmt::format("{}: {}", TEXT_BLUETOOTHISREADY, to_string(bluetoothSerial.isReady())); } -}; - -//constexpr char TEXT_BLUETOOTHISREADYMASTER[] = "Is ready (M): "; -//using BluetoothIsReadyMasterText = BluetoothStatusTextHelper; -class BluetoothIsReadyMasterText : public virtual TextInterface { -public: - std::string text() const override { return fmt::format("{}: {}", TEXT_BLUETOOTHISREADYMASTER, to_string(bluetoothSerial.isReady(true))); } -}; -#endif -}