diff --git a/platformio.ini b/platformio.ini index b34cd60..474d435 100644 --- a/platformio.ini +++ b/platformio.ini @@ -63,6 +63,7 @@ build_flags = -DTFT_RST=2 -DSPI_FREQUENCY=27000000 -DDEFAULT_SWAPSCREENBYTES=false + -DFEATURE_SERIAL -DPINS_RX1=4 -DPINS_TX1=5 -DPINS_RX2=25 @@ -115,6 +116,8 @@ build_flags = -DTFT_RST=2 -DSPI_FREQUENCY=27000000 -DDEFAULT_SWAPSCREENBYTES=false + -DFEATURE_CAN +; -DFEATURE_SERIAL ; -DPINS_RX1=4 ; -DPINS_TX1=5 ; -DPINS_RX2=22 @@ -163,7 +166,6 @@ build_flags = ; -DDEFAULT_GAMETRAKDISTMIN=0 ; -DDEFAULT_GAMETRAKDISTMAX=4095 ; -DFEATURE_CLOUD - -DFEATURE_CAN [env:feedc0de_usb] platform = ${feedc0de.platform} @@ -332,6 +334,7 @@ build_flags = ${default_wheels_inverted.build_flags} -DDEFAULT_WHEELDIAMETER=165 ; TODO: actually assign pins + -DFEATURE_SERIAL -DPINS_RX1=22 -DPINS_TX1=25 -DPINS_RX2=23 @@ -421,6 +424,7 @@ build_flags = -DTFT_RST=2 -DSPI_FREQUENCY=27000000 -DDEFAULT_SWAPSCREENBYTES=false + -DFEATURE_SERIAL -DPINS_RX1=4 -DPINS_TX1=5 -DPINS_RX2=25 diff --git a/src/controller.h b/src/controller.h index 8a27cb3..a177977 100644 --- a/src/controller.h +++ b/src/controller.h @@ -7,22 +7,22 @@ #include "types.h" -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL #include "feedbackparser.h" #endif -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL class HardwareSerial; #endif namespace { struct Controller { Controller( -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL HardwareSerial &serial, #endif bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight) : -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL serial{serial}, #endif enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight} @@ -31,7 +31,7 @@ struct Controller { // Controller(const Controller &) = delete; // Controller &operator=(const Controller &) = delete; -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL std::reference_wrapper serial; #endif bool &enableLeft, &enableRight, &invertLeft, &invertRight; @@ -44,7 +44,7 @@ struct Controller { bool feedbackValid{}; bobbycar::protocol::serial::Feedback feedback{}; -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL FeedbackParser parser{serial, feedbackValid, feedback}; #endif }; diff --git a/src/displays/menus/controllerhardwaresettingsmenu.h b/src/displays/menus/controllerhardwaresettingsmenu.h index caaf32b..df6c851 100644 --- a/src/displays/menus/controllerhardwaresettingsmenu.h +++ b/src/displays/menus/controllerhardwaresettingsmenu.h @@ -60,7 +60,7 @@ public: constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL constructMenuItem, ToggleBoolAction, CheckboxIcon, SwapFrontBackAccessor>>(); #endif constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); diff --git a/src/globals.h b/src/globals.h index 81615c6..8c0c2f4 100644 --- a/src/globals.h +++ b/src/globals.h @@ -42,13 +42,13 @@ public: explicit Controllers() : std::array{{ Controller { -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL Serial1, #endif settings.controllerHardware.enableFrontLeft, settings.controllerHardware.enableFrontRight, settings.controllerHardware.invertFrontLeft, settings.controllerHardware.invertFrontRight }, Controller { -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL Serial2, #endif settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight diff --git a/src/main.cpp b/src/main.cpp index 75d91c1..bc30dbe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -243,7 +243,7 @@ void setup() } printMemoryStats("loadSettings()"); -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL bootLabel.redraw("swap front back"); updateSwapFrontBack(); printMemoryStats("swapFronBack()"); @@ -309,7 +309,9 @@ void setup() #ifdef FEATURE_CAN initCan(); -#else +#endif + +#ifdef FEATURE_SERIAL bootLabel.redraw("front Serial begin"); controllers.front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1); @@ -440,7 +442,9 @@ void loop() for (int i = 0; i < 4; i++) if (!parseCanInput()) break; -#else +#endif + +#ifdef FEATURE_SERIAL for (Controller &controller : controllers) controller.parser.update(); #endif diff --git a/src/presets.h b/src/presets.h index 1f8a4e0..86897f9 100644 --- a/src/presets.h +++ b/src/presets.h @@ -32,7 +32,7 @@ constexpr Settings::ControllerHardware defaultControllerHardware { .wheelDiameter = DEFAULT_WHEELDIAMETER, .numMagnetPoles = 15, -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL .swapFrontBack = false #endif }; @@ -50,7 +50,7 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware { .wheelDiameter = 165, .numMagnetPoles = 15, -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL .swapFrontBack = false #endif }; @@ -79,7 +79,7 @@ constexpr Settings::ControllerHardware spinnerControllerHardware { .wheelDiameter = 165, .numMagnetPoles = 15, -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL .swapFrontBack = false #endif }; diff --git a/src/settings.h b/src/settings.h index 0d6e967..570b1aa 100644 --- a/src/settings.h +++ b/src/settings.h @@ -51,7 +51,7 @@ struct Settings int16_t wheelDiameter; // in mm int16_t numMagnetPoles; // virtual RPM per one real RPM -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL bool swapFrontBack; #endif } controllerHardware; @@ -144,7 +144,7 @@ void Settings::executeForEverySetting(T &&callable) callable("wheelDiameter", controllerHardware.wheelDiameter); callable("numMagnetPoles", controllerHardware.numMagnetPoles); -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL callable("swapFrontBack", controllerHardware.swapFrontBack); #endif diff --git a/src/settingsaccessors.h b/src/settingsaccessors.h index 8c82d5d..bc1377a 100644 --- a/src/settingsaccessors.h +++ b/src/settingsaccessors.h @@ -56,7 +56,7 @@ struct WheelDiameterInchAccessor : public virtual AccessorInterface void setValue(float value) override { settings.controllerHardware.wheelDiameter = convertFromInch(value); saveSettings(); } }; struct NumMagnetPolesAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.controllerHardware.numMagnetPoles; } }; -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL struct SwapFrontBackAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.swapFrontBack; } void setValue(bool value) override { RefAccessorSaveSettings::setValue(value); updateSwapFrontBack(); }; diff --git a/src/utils.h b/src/utils.h index 7b79d32..88eb8e8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -256,14 +256,15 @@ void fixCommonParams() void sendCommands() { -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL for (Controller &controller : controllers) { controller.command.start = Command::VALID_HEADER; controller.command.checksum = calculateChecksum(controller.command); controller.serial.get().write((uint8_t *) &controller.command, sizeof(controller.command)); } -#else +#endif +#ifdef FEATURE_CAN sendCanCommands(); #endif } @@ -271,7 +272,7 @@ void sendCommands() template void switchScreen(Args&&... args); -#ifndef FEATURE_CAN +#ifdef FEATURE_SERIAL void updateSwapFrontBack() { controllers.front.serial = settings.controllerHardware.swapFrontBack ? Serial2 : Serial1;