CAN implementation started
This commit is contained in:
@ -162,6 +162,7 @@ build_flags =
|
|||||||
; -DDEFAULT_GAMETRAKDISTMIN=0
|
; -DDEFAULT_GAMETRAKDISTMIN=0
|
||||||
; -DDEFAULT_GAMETRAKDISTMAX=4095
|
; -DDEFAULT_GAMETRAKDISTMAX=4095
|
||||||
-DFEATURE_CLOUD
|
-DFEATURE_CLOUD
|
||||||
|
-DFEATURE_CAN
|
||||||
|
|
||||||
[env:feedc0de_usb]
|
[env:feedc0de_usb]
|
||||||
platform = ${feedc0de.platform}
|
platform = ${feedc0de.platform}
|
||||||
|
@ -4,20 +4,33 @@
|
|||||||
|
|
||||||
#include "bobbycar-protocol/protocol.h"
|
#include "bobbycar-protocol/protocol.h"
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
#include "feedbackparser.h"
|
#include "feedbackparser.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
class HardwareSerial;
|
class HardwareSerial;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct Controller {
|
struct Controller {
|
||||||
Controller(HardwareSerial &serial, bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight) :
|
Controller(
|
||||||
serial{serial}, enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight}
|
#ifndef FEATURE_CAN
|
||||||
|
HardwareSerial &serial,
|
||||||
|
#endif
|
||||||
|
bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight) :
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
|
serial{serial},
|
||||||
|
#endif
|
||||||
|
enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
// Controller(const Controller &) = delete;
|
// Controller(const Controller &) = delete;
|
||||||
// Controller &operator=(const Controller &) = delete;
|
// Controller &operator=(const Controller &) = delete;
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
std::reference_wrapper<HardwareSerial> serial;
|
std::reference_wrapper<HardwareSerial> serial;
|
||||||
|
#endif
|
||||||
bool &enableLeft, &enableRight, &invertLeft, &invertRight;
|
bool &enableLeft, &enableRight, &invertLeft, &invertRight;
|
||||||
|
|
||||||
Command command{};
|
Command command{};
|
||||||
@ -25,6 +38,8 @@ struct Controller {
|
|||||||
bool feedbackValid{};
|
bool feedbackValid{};
|
||||||
Feedback feedback{};
|
Feedback feedback{};
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
FeedbackParser parser{serial, feedbackValid, feedback};
|
FeedbackParser parser{serial, feedbackValid, feedback};
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,9 @@ public:
|
|||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_WHEELDIAMETERMM>, SwitchScreenAction<WheelDiameterMmChangeScreen>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_WHEELDIAMETERMM>, SwitchScreenAction<WheelDiameterMmChangeScreen>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_WHEELDIAMETERINCH>, SwitchScreenAction<WheelDiameterInchChangeScreen>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_WHEELDIAMETERINCH>, SwitchScreenAction<WheelDiameterInchChangeScreen>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NUMMAGNETPOLES>, SwitchScreenAction<NumMagnetPolesChangeScreen>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NUMMAGNETPOLES>, SwitchScreenAction<NumMagnetPolesChangeScreen>>>();
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SWAPFRONTBACK>, ToggleBoolAction, CheckboxIcon, SwapFrontBackAccessor>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SWAPFRONTBACK>, ToggleBoolAction, CheckboxIcon, SwapFrontBackAccessor>>();
|
||||||
|
#endif
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -41,8 +41,18 @@ class Controllers : public std::array<Controller, 2>
|
|||||||
public:
|
public:
|
||||||
explicit Controllers() :
|
explicit Controllers() :
|
||||||
std::array<Controller, 2>{{
|
std::array<Controller, 2>{{
|
||||||
Controller{Serial1, settings.controllerHardware.enableFrontLeft, settings.controllerHardware.enableFrontRight, settings.controllerHardware.invertFrontLeft, settings.controllerHardware.invertFrontRight},
|
Controller {
|
||||||
Controller{Serial2, settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight}
|
#ifndef FEATURE_CAN
|
||||||
|
Serial1,
|
||||||
|
#endif
|
||||||
|
settings.controllerHardware.enableFrontLeft, settings.controllerHardware.enableFrontRight, settings.controllerHardware.invertFrontLeft, settings.controllerHardware.invertFrontRight
|
||||||
|
},
|
||||||
|
Controller {
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
|
Serial2,
|
||||||
|
#endif
|
||||||
|
settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -233,9 +233,11 @@ void setup()
|
|||||||
}
|
}
|
||||||
printMemoryStats("loadSettings()");
|
printMemoryStats("loadSettings()");
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
bootLabel.redraw("swap front back");
|
bootLabel.redraw("swap front back");
|
||||||
updateSwapFrontBack();
|
updateSwapFrontBack();
|
||||||
printMemoryStats("swapFronBack()");
|
printMemoryStats("swapFronBack()");
|
||||||
|
#endif
|
||||||
|
|
||||||
bootLabel.redraw("deviceName");
|
bootLabel.redraw("deviceName");
|
||||||
{
|
{
|
||||||
@ -295,11 +297,13 @@ void setup()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
bootLabel.redraw("front Serial begin");
|
bootLabel.redraw("front Serial begin");
|
||||||
controllers.front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1);
|
controllers.front.serial.get().begin(38400, SERIAL_8N1, PINS_RX1, PINS_TX1);
|
||||||
|
|
||||||
bootLabel.redraw("back Serial begin");
|
bootLabel.redraw("back Serial begin");
|
||||||
controllers.back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2);
|
controllers.back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2);
|
||||||
|
#endif
|
||||||
|
|
||||||
raw_gas = 0;
|
raw_gas = 0;
|
||||||
raw_brems = 0;
|
raw_brems = 0;
|
||||||
@ -418,8 +422,10 @@ void loop()
|
|||||||
performance.lastTime = now;
|
performance.lastTime = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
for (Controller &controller : controllers)
|
for (Controller &controller : controllers)
|
||||||
controller.parser.update();
|
controller.parser.update();
|
||||||
|
#endif
|
||||||
|
|
||||||
handleSerial();
|
handleSerial();
|
||||||
|
|
||||||
|
@ -32,7 +32,9 @@ constexpr Settings::ControllerHardware defaultControllerHardware {
|
|||||||
|
|
||||||
.wheelDiameter = DEFAULT_WHEELDIAMETER,
|
.wheelDiameter = DEFAULT_WHEELDIAMETER,
|
||||||
.numMagnetPoles = 15,
|
.numMagnetPoles = 15,
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
.swapFrontBack = false
|
.swapFrontBack = false
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
|
constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
|
||||||
@ -48,7 +50,9 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
|
|||||||
|
|
||||||
.wheelDiameter = 165,
|
.wheelDiameter = 165,
|
||||||
.numMagnetPoles = 15,
|
.numMagnetPoles = 15,
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
.swapFrontBack = false
|
.swapFrontBack = false
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Settings::WifiSettings defaultWifiSettings {
|
constexpr Settings::WifiSettings defaultWifiSettings {
|
||||||
@ -75,7 +79,9 @@ constexpr Settings::ControllerHardware spinnerControllerHardware {
|
|||||||
|
|
||||||
.wheelDiameter = 165,
|
.wheelDiameter = 165,
|
||||||
.numMagnetPoles = 15,
|
.numMagnetPoles = 15,
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
.swapFrontBack = false
|
.swapFrontBack = false
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings {
|
constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings {
|
||||||
|
@ -51,7 +51,9 @@ struct Settings
|
|||||||
|
|
||||||
int16_t wheelDiameter; // in mm
|
int16_t wheelDiameter; // in mm
|
||||||
int16_t numMagnetPoles; // virtual RPM per one real RPM
|
int16_t numMagnetPoles; // virtual RPM per one real RPM
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
bool swapFrontBack;
|
bool swapFrontBack;
|
||||||
|
#endif
|
||||||
} controllerHardware;
|
} controllerHardware;
|
||||||
|
|
||||||
struct BoardcomputerHardware {
|
struct BoardcomputerHardware {
|
||||||
@ -142,7 +144,9 @@ void Settings::executeForEverySetting(T &&callable)
|
|||||||
|
|
||||||
callable("wheelDiameter", controllerHardware.wheelDiameter);
|
callable("wheelDiameter", controllerHardware.wheelDiameter);
|
||||||
callable("numMagnetPoles", controllerHardware.numMagnetPoles);
|
callable("numMagnetPoles", controllerHardware.numMagnetPoles);
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
callable("swapFrontBack", controllerHardware.swapFrontBack);
|
callable("swapFrontBack", controllerHardware.swapFrontBack);
|
||||||
|
#endif
|
||||||
|
|
||||||
callable("sampleCount", boardcomputerHardware.sampleCount);
|
callable("sampleCount", boardcomputerHardware.sampleCount);
|
||||||
callable("gasMin", boardcomputerHardware.gasMin);
|
callable("gasMin", boardcomputerHardware.gasMin);
|
||||||
|
@ -56,10 +56,12 @@ struct WheelDiameterInchAccessor : public virtual AccessorInterface<float>
|
|||||||
void setValue(float value) override { settings.controllerHardware.wheelDiameter = convertFromInch(value); saveSettings(); }
|
void setValue(float value) override { settings.controllerHardware.wheelDiameter = convertFromInch(value); saveSettings(); }
|
||||||
};
|
};
|
||||||
struct NumMagnetPolesAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.numMagnetPoles; } };
|
struct NumMagnetPolesAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.numMagnetPoles; } };
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
struct SwapFrontBackAccessor : public RefAccessorSaveSettings<bool> {
|
struct SwapFrontBackAccessor : public RefAccessorSaveSettings<bool> {
|
||||||
bool &getRef() const override { return settings.controllerHardware.swapFrontBack; }
|
bool &getRef() const override { return settings.controllerHardware.swapFrontBack; }
|
||||||
void setValue(bool value) override { RefAccessorSaveSettings<bool>::setValue(value); updateSwapFrontBack(); };
|
void setValue(bool value) override { RefAccessorSaveSettings<bool>::setValue(value); updateSwapFrontBack(); };
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct SampleCountAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.sampleCount; } };
|
struct SampleCountAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.sampleCount; } };
|
||||||
struct GasMinAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.gasMin; } };
|
struct GasMinAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.gasMin; } };
|
||||||
|
@ -251,18 +251,22 @@ void sendCommands()
|
|||||||
{
|
{
|
||||||
controller.command.start = Command::VALID_HEADER;
|
controller.command.start = Command::VALID_HEADER;
|
||||||
controller.command.checksum = calculateChecksum(controller.command);
|
controller.command.checksum = calculateChecksum(controller.command);
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
controller.serial.get().write((uint8_t *) &controller.command, sizeof(controller.command));
|
controller.serial.get().write((uint8_t *) &controller.command, sizeof(controller.command));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
void switchScreen(Args&&... args);
|
void switchScreen(Args&&... args);
|
||||||
|
|
||||||
|
#ifndef FEATURE_CAN
|
||||||
void updateSwapFrontBack()
|
void updateSwapFrontBack()
|
||||||
{
|
{
|
||||||
controllers.front.serial = settings.controllerHardware.swapFrontBack ? Serial2 : Serial1;
|
controllers.front.serial = settings.controllerHardware.swapFrontBack ? Serial2 : Serial1;
|
||||||
controllers.back.serial = settings.controllerHardware.swapFrontBack ? Serial1 : Serial2;
|
controllers.back.serial = settings.controllerHardware.swapFrontBack ? Serial1 : Serial2;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void loadSettings()
|
void loadSettings()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user