This repository was archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMenuItem.h
124 lines (103 loc) · 3.21 KB
/
MenuItem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* A class that handles menu navigation and actions.
*/
#ifndef MenuItem_h
#define MenuItem_h
#include <Arduino.h>
#include <DS1302.h>
#include "PixelAnimator.h"
#include "RPMMeasure.h"
#include "ButtonSet.h"
#include "Config.h"
#include <TM1637Display.h>
#include "_menuHelpers.h"
class MenuItem {
public:
static void update(void);
static void onButtonSetEvent(buttonSetEvent_t event);
static void setConfig(Config* config);
static void setRPMMeasure(RPMMeasure* rpm);
static void setButtonSet(ButtonSet* buttons);
static void setDisplay(TM1637Display* display);
static void setAnimator(PixelAnimator* animator);
static void setRTCClock(DS1302* rtcClock);
static void enter(MenuItem* item);
static void enter(uint8_t itemIndex);
static void mainMenuNext(uint8_t currentIndex);
static void mainMenuPrev(uint8_t currentIndex);
static void colorMenuNext(uint8_t currentIndex);
static void colorMenuPrev(uint8_t currentIndex);
static void profileMenuNext(uint8_t currentIndex);
static void profileMenuPrev(uint8_t currentIndex);
virtual void onEnter(){}
virtual void onButtonEvent(buttonSetEvent_t event){}
virtual void onUpdate(){}
virtual void onLeave(){}
protected:
static Config* CONFIG;
static Profile* PROFILE;
static RPMMeasure* rpm;
static ButtonSet* buttons;
static TM1637Display* display;
static PixelAnimator* animator;
static MenuItem* activeMenuItem;
static DS1302* rtcClock;
static uint8_t prevMenuItemIndex;
};
class EditingMenuItem : public MenuItem {
public:
virtual void onEnter(){
editing = false;
didEdit = false;
}
virtual void onButtonEvent(buttonSetEvent_t event){
if(event == Right){
editing = !editing;
if(editing){ didEdit = true; }
}
}
protected:
bool editing;
bool didEdit;
};
class RPMEditingMenuItem : public EditingMenuItem {
public:
virtual void onButtonEvent(buttonSetEvent_t event){
EditingMenuItem::onButtonEvent(event);
if(!editing) return;
switch(event){
case Up: onValueChange(100); break;
case Down: onValueChange(-100); break;
case HoldUp: onValueChange(1000); break;
case HoldDown: onValueChange(-1000); break;
}
}
protected:
virtual void onValueChange(int difference);
};
class ColorEditingMenuItem : public EditingMenuItem {
public:
virtual void onEnter(){
EditingMenuItem::onEnter();
color = ColorPicker::at(colorIndex, allowBlack);
}
virtual void onButtonEvent(buttonSetEvent_t event){
EditingMenuItem::onButtonEvent(event);
if(!editing) return;
switch(event){
case Up: color = ColorPicker::prev(colorIndex, allowBlack); break;
case Down: color = ColorPicker::next(colorIndex, allowBlack); break;
case Left: animator->setFill(CRGB::Black); animator->show(); break;
}
}
void onUpdate(){
animator->setFill(editing ? color : CRGB::Black);
animator->setEdges(editing && millis() / ANIM_FAST % 2 ? CRGB::White : CRGB::Black);
animator->show();
}
protected:
uint8_t colorIndex;
CRGB color;
bool allowBlack;
};
#endif