Introduced types.h and millis_t

This commit is contained in:
2020-06-06 23:09:22 +02:00
parent 6fd97d2ff1
commit 8a61f2a803
12 changed files with 33 additions and 17 deletions

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "globals.h" #include "globals.h"
#include "types.h"
namespace { namespace {
#ifdef FEATURE_BMS #ifdef FEATURE_BMS
@ -8,8 +9,8 @@ namespace bms {
constexpr auto autoReconnect = false; // causes hangs when not available constexpr auto autoReconnect = false; // causes hangs when not available
bool lastConnected; bool lastConnected;
unsigned long lastSend; millis_t lastSend;
unsigned long lastReceive; millis_t lastReceive;
float voltage; float voltage;
float current; float current;

View File

@ -14,6 +14,7 @@
#include "checkboxicon.h" #include "checkboxicon.h"
#include "icons/back.h" #include "icons/back.h"
#include "texts.h" #include "texts.h"
#include "types.h"
namespace { namespace {
class DebugMenu; class DebugMenu;
@ -36,7 +37,7 @@ public:
} }
private: private:
mutable unsigned long m_nextUpdate{}; mutable millis_t m_nextUpdate{};
mutable String m_title; mutable String m_title;
}; };
@ -57,7 +58,7 @@ public:
} }
private: private:
mutable unsigned long m_nextUpdate{}; mutable millis_t m_nextUpdate{};
mutable int m_color; mutable int m_color;
}; };
@ -77,7 +78,7 @@ public:
} }
private: private:
mutable unsigned long m_nextUpdate{}; mutable millis_t m_nextUpdate{};
mutable int m_font; mutable int m_font;
}; };
@ -100,7 +101,7 @@ public:
} }
private: private:
mutable unsigned long m_nextUpdate{}; mutable millis_t m_nextUpdate{};
mutable const Icon<24, 24> *m_icon; mutable const Icon<24, 24> *m_icon;
}; };

View File

@ -9,6 +9,7 @@
#include "checkboxicon.h" #include "checkboxicon.h"
#include "icons/back.h" #include "icons/back.h"
#include "texts.h" #include "texts.h"
#include "types.h"
namespace { namespace {
class MainMenu; class MainMenu;

View File

@ -12,6 +12,7 @@
#include "actions/dummyaction.h" #include "actions/dummyaction.h"
#include "icons/back.h" #include "icons/back.h"
#include "texts.h" #include "texts.h"
#include "types.h"
namespace { namespace {
class WifiSettingsMenu; class WifiSettingsMenu;
@ -48,7 +49,7 @@ private:
std::vector<makeComponent<MenuItem, ChangeableText, DummyAction>> vec; std::vector<makeComponent<MenuItem, ChangeableText, DummyAction>> vec;
unsigned long m_lastScanComplete; millis_t m_lastScanComplete;
}; };
String WifiScanMenu::text() const String WifiScanMenu::text() const

View File

@ -5,6 +5,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "globals.h" #include "globals.h"
#include "types.h"
namespace { namespace {
namespace dpad namespace dpad

View File

@ -5,6 +5,7 @@
#include "globals.h" #include "globals.h"
#include "dpad.h" #include "dpad.h"
#include "types.h"
namespace { namespace {
namespace dpad3wire namespace dpad3wire

View File

@ -7,6 +7,8 @@
#include "bobbycar-protocol/protocol.h" #include "bobbycar-protocol/protocol.h"
#include "types.h"
namespace { namespace {
class FeedbackParser class FeedbackParser
{ {
@ -78,7 +80,7 @@ private:
uint8_t m_incomingByte{}; uint8_t m_incomingByte{};
uint8_t m_incomingBytePrev{}; uint8_t m_incomingBytePrev{};
unsigned long m_lastFeedback{millis()}; millis_t m_lastFeedback{millis()};
const std::reference_wrapper<HardwareSerial> &m_serial; const std::reference_wrapper<HardwareSerial> &m_serial;
bool &m_feedbackValid; bool &m_feedbackValid;
Feedback &m_feedback, m_newFeedback; Feedback &m_feedback, m_newFeedback;

View File

@ -12,10 +12,9 @@
#include "modeinterface.h" #include "modeinterface.h"
#include "settings.h" #include "settings.h"
#include "settingssaver.h" #include "settingssaver.h"
#include "types.h"
namespace { namespace {
using pin_t = int;
int16_t raw_gas, raw_brems; int16_t raw_gas, raw_brems;
float gas, brems; float gas, brems;
#ifdef FEATURE_GAMETRAK #ifdef FEATURE_GAMETRAK
@ -33,7 +32,7 @@ Controller front{Serial1, settings.controllerHardware.enableFrontLeft, settings.
Controller back{Serial2, settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight}; Controller back{Serial2, settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight};
struct { struct {
unsigned long lastTime = millis(); millis_t lastTime = millis();
int current{0}; int current{0};
int last{0}; int last{0};
} performance; } performance;
@ -63,7 +62,7 @@ public:
static void confirmButton(bool pressed) static void confirmButton(bool pressed)
{ {
static unsigned long pressBegin = 0; static millis_t pressBegin = 0;
const auto now = millis(); const auto now = millis();
@ -86,7 +85,7 @@ public:
static void backButton(bool pressed) static void backButton(bool pressed)
{ {
static unsigned long pressBegin = 0; static millis_t pressBegin = 0;
const auto now = millis(); const auto now = millis();

View File

@ -22,12 +22,13 @@
#include "actions/bluetoothbeginmasteraction.h" #include "actions/bluetoothbeginmasteraction.h"
#include "actions/bluetoothconnectbmsaction.h" #include "actions/bluetoothconnectbmsaction.h"
#include "bobby_webserver.h" #include "bobby_webserver.h"
#include "types.h"
namespace { namespace {
ModeInterface *lastMode{}; ModeInterface *lastMode{};
unsigned long lastModeUpdate{}; millis_t lastModeUpdate{};
unsigned long lastStatsUpdate{}; millis_t lastStatsUpdate{};
unsigned long lastDisplayRedraw{}; millis_t lastDisplayRedraw{};
constexpr auto modeUpdateRate = 50; constexpr auto modeUpdateRate = 50;
constexpr auto statsUpdateRate = 50; constexpr auto statsUpdateRate = 50;

View File

@ -7,6 +7,7 @@
#include "modeinterface.h" #include "modeinterface.h"
#include "globals.h" #include "globals.h"
#include "utils.h" #include "utils.h"
#include "types.h"
namespace { namespace {
class DefaultMode : public ModeInterface class DefaultMode : public ModeInterface
@ -20,7 +21,7 @@ public:
bool waitForBremsLoslass{false}; bool waitForBremsLoslass{false};
private: private:
unsigned long lastTime{millis()}; millis_t lastTime{millis()};
float lastPwm{0}; float lastPwm{0};
}; };

View File

@ -3,6 +3,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "globals.h" #include "globals.h"
#include "types.h"
namespace { namespace {
template<typename HANDLER, pin_t CLK, pin_t DT, pin_t SW> template<typename HANDLER, pin_t CLK, pin_t DT, pin_t SW>

6
src/types.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
namespace {
using pin_t = int;
using millis_t = unsigned long;
}