2020-05-19 11:41:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-08-10 03:37:14 +02:00
|
|
|
// system includes
|
2020-05-19 11:41:35 +02:00
|
|
|
#include <algorithm>
|
2020-06-28 04:28:54 +02:00
|
|
|
#include <utility>
|
2021-06-28 09:59:32 +02:00
|
|
|
#include <string>
|
2021-05-20 21:29:07 +02:00
|
|
|
|
2021-08-10 03:37:14 +02:00
|
|
|
// Arduino includes
|
2021-06-28 21:43:20 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
|
|
|
#include <HardwareSerial.h>
|
|
|
|
#endif
|
|
|
|
|
2021-08-10 03:37:14 +02:00
|
|
|
// 3rdparty lib includes
|
2021-06-28 21:43:20 +02:00
|
|
|
#include <espchrono.h>
|
2021-08-20 13:20:02 +02:00
|
|
|
#include <cpputils.h>
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2021-08-10 03:37:14 +02:00
|
|
|
// local includes
|
2021-06-28 14:38:03 +02:00
|
|
|
#ifdef FEATURE_CAN
|
2021-06-28 21:43:20 +02:00
|
|
|
#include "bobbycar-can.h"
|
2021-06-28 14:38:03 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_SERIAL
|
2021-06-28 21:43:20 +02:00
|
|
|
#include "bobbycar-serial.h"
|
2021-06-28 14:38:03 +02:00
|
|
|
#endif
|
2021-05-20 21:29:07 +02:00
|
|
|
|
2020-05-19 11:41:35 +02:00
|
|
|
#include "display.h"
|
|
|
|
#include "globals.h"
|
2021-05-21 01:05:41 +02:00
|
|
|
#ifdef FEATURE_CAN
|
|
|
|
#include "can.h"
|
|
|
|
#endif
|
2020-05-19 11:41:35 +02:00
|
|
|
|
2022-06-12 20:15:31 +02:00
|
|
|
#ifdef FEATURE_DPAD
|
|
|
|
#include "dpad.h"
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_3WIRESW
|
|
|
|
#include "dpad3wire.h"
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_5WIRESW
|
|
|
|
#include "dpad5wire.h"
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_5WIRESW_2OUT
|
|
|
|
#include "dpad5wire_2out.h"
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_6WIRESW
|
|
|
|
#include "dpad6wire.h"
|
|
|
|
#endif
|
|
|
|
#ifdef DPAD_BOARDCOMPUTER_V2
|
|
|
|
#include "dpad_boardcomputer_v2.h"
|
|
|
|
#endif
|
2022-10-13 22:00:16 +02:00
|
|
|
#include "setup.h"
|
2022-06-12 20:15:31 +02:00
|
|
|
|
2021-11-01 20:44:57 +01:00
|
|
|
extern bool currentlyReverseBeeping;
|
|
|
|
extern bool reverseBeepToggle;
|
|
|
|
extern espchrono::millis_clock::time_point lastReverseBeepToggle;
|
|
|
|
|
|
|
|
float convertToKmh(float val);
|
|
|
|
float convertFromKmh(float val);
|
|
|
|
float convertToInch(float val);
|
|
|
|
float convertFromInch(float val);
|
|
|
|
float fixCurrent(int16_t value);
|
|
|
|
float fixBoardTemp(int16_t value);
|
|
|
|
std::string hallString(const bobbycar::protocol::serial::MotorFeedback &motor);
|
|
|
|
std::string to_string(bobbycar::protocol::ControlType value);
|
|
|
|
std::string to_string(bobbycar::protocol::ControlMode value);
|
|
|
|
std::array<std::reference_wrapper<bobbycar::protocol::serial::MotorState>, 2> motorsInController(Controller &controller);
|
|
|
|
std::array<std::reference_wrapper<const bobbycar::protocol::serial::MotorState>, 2> motorsInController(const Controller &controller);
|
|
|
|
std::array<std::reference_wrapper<bobbycar::protocol::serial::MotorFeedback>, 2> motorFeedbacksInController(Controller &controller);
|
|
|
|
std::array<std::reference_wrapper<const bobbycar::protocol::serial::MotorFeedback>, 2> motorFeedbacksInController(const Controller &controller);
|
|
|
|
std::array<std::reference_wrapper<bobbycar::protocol::serial::MotorState>, 4> motors();
|
|
|
|
void fixCommonParams();
|
|
|
|
void sendCommands();
|
2021-06-28 10:57:39 +02:00
|
|
|
#ifdef FEATURE_SERIAL
|
2021-11-01 20:44:57 +01:00
|
|
|
void updateSwapFrontBack();
|
2020-05-25 21:27:44 +02:00
|
|
|
#endif
|
2022-01-03 17:13:45 +01:00
|
|
|
bool loadProfileSettings();
|
|
|
|
bool saveProfileSettings();
|
2021-11-01 20:44:57 +01:00
|
|
|
void updateAccumulators();
|
|
|
|
void readPotis();
|
2021-11-05 20:12:18 +01:00
|
|
|
float wattToAmpere(float watt);
|
|
|
|
float wattToMotorCurrent(float watt);
|
2021-11-21 02:16:37 +01:00
|
|
|
uint8_t time_to_percent(espchrono::milliseconds32 repeat, espchrono::milliseconds32 riseTime, espchrono::milliseconds32 fullTime, size_t numLeds, bool invert);
|
2021-12-13 22:13:39 +01:00
|
|
|
std::string local_clock_string();
|
2022-04-08 20:54:02 +02:00
|
|
|
int16_t map_analog_stick(uint16_t middle, uint16_t start, uint16_t end, uint16_t deadband, uint16_t raw);
|
2022-01-17 17:39:50 +01:00
|
|
|
|
|
|
|
inline uint32_t CRGB_TO_UINT32(CRGB crgb)
|
|
|
|
{
|
|
|
|
return crgb.raw[0]<<16 | crgb.raw[1]<<8 | crgb.raw[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline CRGB UINT32_TO_CRGB(uint32_t color)
|
|
|
|
{
|
|
|
|
CRGB crgb;
|
|
|
|
|
|
|
|
crgb.raw[0]=color>>16 & 0xFF;
|
|
|
|
crgb.raw[1]=color>>8 & 0xFF;
|
|
|
|
crgb.raw[2]=color & 0xFF;
|
|
|
|
|
|
|
|
return crgb;
|
|
|
|
}
|
2022-02-26 14:58:41 +01:00
|
|
|
|
|
|
|
std::string get_wifi_security_string(wifi_auth_mode_t authMode);
|
2022-03-03 22:41:39 +01:00
|
|
|
float float_map(float x, float in_min, float in_max, float out_min, float out_max);
|
2022-03-26 17:03:12 +01:00
|
|
|
bool is_valid_timestamp(espchrono::utc_clock::time_point timestamp);
|
2022-06-12 20:15:31 +02:00
|
|
|
|
2022-10-06 11:22:21 +02:00
|
|
|
std::string toString(esp_chip_model_t esp_chip_model);
|
2022-10-06 22:37:31 +02:00
|
|
|
std::optional<SetupStep> checkIfInCalibration();
|
2022-10-13 22:00:16 +02:00
|
|
|
void drawLargeText(const std::string&& text);
|
2022-10-06 11:22:21 +02:00
|
|
|
|
2022-06-12 20:15:31 +02:00
|
|
|
namespace bobbydpad {
|
|
|
|
#ifdef FEATURE_DPAD
|
|
|
|
static constexpr const auto ButtonCount = dpad::BUTTON_COUNT;
|
|
|
|
static constexpr const auto &dpad_init = dpad::init;
|
|
|
|
static constexpr const auto &dpad_update = dpad::update;
|
|
|
|
static constexpr const char * const dpad_name = "dpad";
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_3WIRESW
|
|
|
|
static constexpr const auto ButtonCount = dpad3wire::BUTTON_COUNT;
|
|
|
|
static constexpr const auto &dpad_init = dpad3wire::init;
|
|
|
|
static constexpr const auto &dpad_update = dpad3wire::update;
|
|
|
|
static constexpr const char * const dpad_name = "dpad3wire";
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_5WIRESW
|
|
|
|
static constexpr const auto ButtonCount = dpad5wire::BUTTON_COUNT;
|
|
|
|
static constexpr const auto &dpad_init = dpad5wire::init;
|
|
|
|
static constexpr const auto &dpad_update = dpad5wire::update;
|
|
|
|
static constexpr const char * const dpad_name = "dpad5wire";
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_5WIRESW_2OUT
|
|
|
|
static constexpr const auto ButtonCount = dpad5wire_2out::BUTTON_COUNT;
|
|
|
|
static constexpr const auto &dpad_init = dpad5wire_2out::init;
|
|
|
|
static constexpr const auto &dpad_update = dpad5wire_2out::update;
|
|
|
|
static constexpr const char * const dpad_name = "dpad5wire_2out";
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_DPAD_6WIRESW
|
|
|
|
static constexpr const auto ButtonCount = dpad6wire::BUTTON_COUNT;
|
|
|
|
static constexpr const auto &dpad_init = dpad6wire::init;
|
|
|
|
static constexpr const auto &dpad_update = dpad6wire::update;
|
|
|
|
static constexpr const char * const dpad_name = "dpad6wire";
|
|
|
|
#endif
|
|
|
|
#ifdef DPAD_BOARDCOMPUTER_V2
|
|
|
|
static constexpr const auto ButtonCount = dpad_boardcomputer_v2::BUTTON_COUNT;
|
|
|
|
static constexpr const auto &dpad_init = dpad_boardcomputer_v2::init;
|
|
|
|
static constexpr const auto &dpad_update = dpad_boardcomputer_v2::update;
|
|
|
|
static constexpr const char * const dpad_name = "dpad_boardcomputer_v2";
|
|
|
|
#endif
|
2022-06-12 21:05:06 +02:00
|
|
|
#if !defined(FEATURE_DPAD) && !defined(FEATURE_DPAD_3WIRESW) && !defined(FEATURE_DPAD_5WIRESW) && !defined(FEATURE_DPAD_5WIRESW_2OUT) && !defined(FEATURE_DPAD_6WIRESW) && !defined(DPAD_BOARDCOMPUTER_V2)
|
|
|
|
static constexpr const auto ButtonCount = 0;
|
|
|
|
static constexpr const auto &dpad_init = nullptr;
|
|
|
|
static constexpr const auto &dpad_update = nullptr;
|
|
|
|
static constexpr const char * const dpad_name = "";
|
|
|
|
#endif
|
2022-06-12 20:15:31 +02:00
|
|
|
} // namespace bobbydpad
|