Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added img/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions include/DisplayHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Adafruit_GC9A01A.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <unordered_map>
#include <utility>
#include <vector>

Expand All @@ -19,6 +20,7 @@ enum class FontSize : int
kFontSizeXXXL = 6, // Font size 36x52
};

/// @brief Enum representing different gauge views.
enum class GaugeView : int
{
kDashboard = 0,
Expand All @@ -29,6 +31,11 @@ enum class GaugeView : int
kGaugeMax = kSingleGauge,
};

struct GaugeInfo
{
std::vector<GaugeData> gauges;
};

class DisplayHandler
{
public:
Expand All @@ -39,6 +46,10 @@ class DisplayHandler
void display();
void clearScreen();

void createBackArrow();
void clearBackArrow();

int getCurrentGaugeCursorIndex();
void moveGaugeCursor(int gaugeIndex);
void clearGaugeCursor();

Expand All @@ -48,14 +59,34 @@ class DisplayHandler
void setCurrentView(GaugeView newGauge);
GaugeView getCurrentView();

void setCurrentDashboardGauges(std::vector<GaugeData> gauges);
std::vector<GaugeData> getCurrentDashboardGauges();

void setCurrentQuadGauges(std::vector<GaugeData> gauges);
std::vector<GaugeData> getCurrentQuadGauges();

void setCurrentDualGauges(std::vector<GaugeData> gauges);
std::vector<GaugeData> getCurrentDualGauges();

void setCurrentSingleGauge(GaugeData gauges);
GaugeData getCurrentSingleGauge();

private:
const int _screenHeight;
const int _screenWidth;

Adafruit_GC9A01A _tft;

std::unordered_map<GaugeView, GaugeInfo> _gaugeMap;

GaugeView _currentGaugeView;
bool _gaugeViewUpdated;

std::vector<GaugeData> _currentDashboardGauges;
std::vector<GaugeData> _currentQuadGauges;
std::vector<GaugeData> _currentDualGauges;
GaugeData _currentSingleGauge;

std::vector<std::pair<GaugeData, String>> _currentData;
std::vector<std::pair<GaugeData, String>> _oldData;
bool _dataUpdated;
Expand Down Expand Up @@ -87,4 +118,6 @@ class DisplayHandler
void _highlightQuadGauge(uint16_t textColor, uint16_t backgroundColor);
void _highlightDualGauge(uint16_t textColor, uint16_t backgroundColor);
void _highlightSingleGauge(uint16_t textColor, uint16_t backgroundColor);

void _drawBackArrow(uint16_t arrowColor, uint16_t backgroundColor);
};
15 changes: 10 additions & 5 deletions include/EncoderHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#include <Chrono.h>
#include <EncoderTool.h>

enum Clicks : int
struct Clicks
{
kNoClick = 0,
kSingleClick = 1,
kDoubleClick = 2,
bool singleClick = false;
bool doubleClick = false;
};

class EncoderHandler
Expand All @@ -26,7 +25,10 @@ class EncoderHandler
void setDoubleClickSpeed(int doubleClickSpeed);
int getDoubleClickSpeed();

int buttonPressed();
int getMin();
int getMax();

Clicks buttonPressed();

private:
EncoderTool::Encoder _encoder;
Expand All @@ -35,4 +37,7 @@ class EncoderHandler
Chrono _clickTimer;
Clicks _clicks;
int _doubleClickSpeed;

int _min;
int _max;
};
8 changes: 7 additions & 1 deletion include/ProgramMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ const uint8_t cold_icon[] PROGMEM = {
0x03, 0xC0, 0x00, 0x00, 0x03, 0xFF, 0x00, 0x00, 0x03, 0xFF, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x3F, 0xE3, 0xC7, 0xFC, 0x3F, 0xE3, 0xC7, 0xFC, 0x00, 0x03, 0xC0,
0x00, 0x00, 0x03, 0xC0, 0x00, 0x3F, 0xC7, 0xE3, 0xFC, 0x3F, 0xC7, 0xF3, 0xFC, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x07,
0xF0, 0x00, 0x1F, 0xC7, 0xE7, 0xF8, 0x1F, 0xE1, 0xC7, 0xF8, 0x00, 0x00, 0x00, 0x00};
0xF0, 0x00, 0x1F, 0xC7, 0xE7, 0xF8, 0x1F, 0xE1, 0xC7, 0xF8, 0x00, 0x00, 0x00, 0x00};

const uint8_t back[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0xfc, 0x00,
0x00, 0x01, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xe0, 0x3f, 0xff, 0xff, 0xe0, 0x7f, 0xff,
0xff, 0xe0, 0x1f, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xe0, 0x03, 0xff, 0xff, 0xe0, 0x01, 0xff, 0xff, 0xe0, 0x00,
0x7c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
29 changes: 26 additions & 3 deletions include/StateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "MegaSquirtInfo.h"

#include <DisplayHandler.h>
#include <EncoderHandler.h>

#include <unordered_map>

class CanDataHandler;
class EncoderHandler;
Expand All @@ -19,6 +22,11 @@ enum State : int
kSettingsSelected = 3,
};

struct StateInfo
{
int index = 0;
};

class StateManager
{
public:
Expand All @@ -35,8 +43,23 @@ class StateManager

State _menuState;

void _scrollGauge(int newValue);
void _select(int numClicks);
void _updateEncoder();
GaugeView _currentView;
int _currentGaugeCursorIndex;

std::vector<GaugeData> _currentDashboardGauges;
std::vector<GaugeData> _currentQuadGauges;
std::vector<GaugeData> _currentDualGauges;
GaugeData _currentSingleGauge;

std::unordered_map<State, StateInfo> _stateMap;

void _handleScroll(int newValue);
void _handleItemSelectedScroll(int newValue);
void _handleClick(Clicks clicks);
void _handleIdleClick();
void _handleViewSelectedClick(Clicks clicks);
void _handleItemSelectedClick(Clicks clicks);
void _updateEncoder(int initialValue);
std::vector<std::pair<GaugeData, String>> _loadStateData(GaugeView state);
std::unordered_map<State, StateInfo>::iterator _getCurrentStateInfo(State currentState);
};
8 changes: 7 additions & 1 deletion src/CanDataHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ constexpr uint32_t kBaseID = 1520; // This is set in megasquirt (typically 1520)
MegaCAN_broadcast_message_t CanDataHandler::_bCastMsg = {};
MegaCAN CanDataHandler::_mega_can(kBaseID);

/// @brief Initializes the CAN bus.
/// @param canBaud The baud rate for the CAN bus.
void CanDataHandler::initCan(int canBaud)
{
can.begin();
Expand All @@ -20,11 +22,14 @@ void CanDataHandler::initCan(int canBaud)
can.mailboxStatus();
}

/// @brief Polls the CAN bus for events.
void CanDataHandler::pollCan()
{
can.events();
}

/// @brief Retrieves gauge data based on the provided gauges.
/// @param gauges A vector of GaugeData enums specifying which gauges to retrieve.
std::vector<std::pair<GaugeData, String>> CanDataHandler::getGaugeData(const std::vector<GaugeData>& gauges)
{
std::vector<std::pair<GaugeData, String>> data;
Expand Down Expand Up @@ -67,7 +72,8 @@ std::vector<std::pair<GaugeData, String>> CanDataHandler::getGaugeData(const std
return data;
}

// Routine used by FlexCAN for retrieving the received CAN data.
/// @brief Routine used by FlexCAN for retrieving the received CAN data.
/// @param msg The received CAN message.
void CanDataHandler::canMShandler(const CAN_message_t& msg)
{
if (!msg.flags.extended)
Expand Down
Loading