2020-05-19 11:41:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-06-28 21:43:20 +02:00
|
|
|
// system includes
|
2020-05-19 11:41:35 +02:00
|
|
|
#include <functional>
|
|
|
|
|
2021-06-28 21:43:20 +02:00
|
|
|
// Arduino includes
|
|
|
|
#ifdef FEATURE_SERIAL
|
|
|
|
#include <HardwareSerial.h>
|
|
|
|
#endif
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-06-28 21:43:20 +02:00
|
|
|
// 3rdparty lib includes
|
|
|
|
#include <espchrono.h>
|
2022-01-03 01:31:48 +01:00
|
|
|
#include <configwrapper.h>
|
2021-05-21 01:05:41 +02:00
|
|
|
|
2021-06-28 21:43:20 +02:00
|
|
|
// local includes
|
|
|
|
#include "bobbycar-common.h"
|
|
|
|
#include "bobbycar-serial.h"
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2020-05-19 11:41:35 +02:00
|
|
|
#include "feedbackparser.h"
|
2021-05-16 21:51:31 +02:00
|
|
|
#endif
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-06-28 21:43:20 +02:00
|
|
|
// forward declares
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2020-05-19 11:41:35 +02:00
|
|
|
class HardwareSerial;
|
2021-05-16 21:51:31 +02:00
|
|
|
#endif
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-11-01 20:44:57 +01:00
|
|
|
struct Controller
|
|
|
|
{
|
2021-05-16 21:51:31 +02:00
|
|
|
Controller(
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2021-05-16 21:51:31 +02:00
|
|
|
HardwareSerial &serial,
|
|
|
|
#endif
|
2021-10-13 13:46:19 +02:00
|
|
|
bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight,
|
2022-01-03 01:31:48 +01:00
|
|
|
espconfig::ConfigWrapper<int16_t> &voltageCalib30V, espconfig::ConfigWrapper<int16_t> &voltageCalib50V);
|
2020-06-07 22:28:27 +02:00
|
|
|
// Controller(const Controller &) = delete;
|
|
|
|
// Controller &operator=(const Controller &) = delete;
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2020-05-19 11:41:35 +02:00
|
|
|
std::reference_wrapper<HardwareSerial> serial;
|
2021-05-16 21:51:31 +02:00
|
|
|
#endif
|
2020-05-19 11:41:35 +02:00
|
|
|
bool &enableLeft, &enableRight, &invertLeft, &invertRight;
|
2022-01-03 01:31:48 +01:00
|
|
|
espconfig::ConfigWrapper<int16_t> &voltageCalib30V, &voltageCalib50V;
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-06-28 10:55:50 +02:00
|
|
|
bobbycar::protocol::serial::Command command{};
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-05-21 01:05:41 +02:00
|
|
|
#ifdef FEATURE_CAN
|
2021-06-28 21:43:20 +02:00
|
|
|
espchrono::millis_clock::time_point lastCanFeedback{};
|
2021-05-21 01:05:41 +02:00
|
|
|
#endif
|
2020-05-19 11:41:35 +02:00
|
|
|
bool feedbackValid{};
|
2021-06-28 10:55:50 +02:00
|
|
|
bobbycar::protocol::serial::Feedback feedback{};
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-10-12 16:55:42 +02:00
|
|
|
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2020-05-19 11:41:35 +02:00
|
|
|
FeedbackParser parser{serial, feedbackValid, feedback};
|
2021-05-16 21:51:31 +02:00
|
|
|
#endif
|
2021-10-13 10:13:40 +02:00
|
|
|
|
2021-11-02 01:43:58 +01:00
|
|
|
float getCalibratedVoltage() const;
|
2020-05-19 11:41:35 +02:00
|
|
|
};
|