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>
|
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
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
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
|
|
|
|
|
bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight) :
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2021-05-16 21:51:31 +02:00
|
|
|
serial{serial},
|
|
|
|
|
#endif
|
|
|
|
|
enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight}
|
2020-05-19 11:41:35 +02:00
|
|
|
{
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
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-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
|
2020-05-19 11:41:35 +02:00
|
|
|
};
|
|
|
|
|
}
|