-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.cpp
More file actions
120 lines (95 loc) · 2.76 KB
/
config.cpp
File metadata and controls
120 lines (95 loc) · 2.76 KB
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
#ifndef _config
#define _config
#include <stdint.h>
#include <EEPROM.h>
// Color and brightness
#define DEFAULT_BRIGHTNESS_MODE 0
#define DEFAULT_COLOR_FORWARD_MODE 0
#define DEFAULT_COLOR_BACKWARD_MODE 5
// Battery
#define DEFAULT_IDLE_DISPLAY_MODE 1
#define DEFAULT_BATTERY_SERIES_COUNT 20
// LEDs
#define DEFAULT_LED_COUNT 7
#define DEFAULT_LED_TYPE 0
// Options
#define BRIGHTNESS_MODES 4
#define COLOR_MODES 7
#define IDLE_MODES 4
#define LED_TYPES 2
class Config {
private:
public:
uint8_t brightnessState;
uint8_t forwardColorState;
uint8_t backwardColorState;
uint8_t idleDisplayState;
uint8_t batterySeriesState;
unsigned int ledCountState;
uint8_t ledTypeState;
uint8_t pressCount;
uint8_t longPressCount;
void setup(){
brightnessState = EEPROM.read(0);
if(brightnessState > BRIGHTNESS_MODES - 1){
brightnessState = DEFAULT_BRIGHTNESS_MODE;
}
forwardColorState = EEPROM.read(1);
if(forwardColorState > COLOR_MODES - 1){
forwardColorState = DEFAULT_COLOR_FORWARD_MODE;
}
backwardColorState = EEPROM.read(2);
if(backwardColorState > COLOR_MODES - 1){
backwardColorState = DEFAULT_COLOR_BACKWARD_MODE;
}
idleDisplayState = EEPROM.read(3);
if(idleDisplayState > 2){
idleDisplayState = DEFAULT_IDLE_DISPLAY_MODE;
}
batterySeriesState = EEPROM.read(4);
if(batterySeriesState > 40){
batterySeriesState = DEFAULT_BATTERY_SERIES_COUNT;
}
ledCountState = EEPROM.read(5);
if(ledCountState > 40 || ledCountState < 7){
ledCountState = DEFAULT_LED_COUNT;
}
ledTypeState = EEPROM.read(6);
if(ledTypeState > LED_TYPES){
ledTypeState = DEFAULT_LED_TYPE;
}
}
void loop(){
}
void toggleBrightness(){
brightnessState = (brightnessState + 1) % BRIGHTNESS_MODES;
EEPROM.write(0, brightnessState);
}
void toggleForwardColor(){
forwardColorState = (forwardColorState + 1) % COLOR_MODES;
EEPROM.write(1, forwardColorState);
}
void toggleBackwardsColor(){
backwardColorState = (backwardColorState + 1) % COLOR_MODES;
EEPROM.write(2, backwardColorState);
}
void toggleIdle(){
idleDisplayState = (idleDisplayState + 1) % IDLE_MODES;
EEPROM.write(3, idleDisplayState);
}
void setBatterySeries(int newValue){
batterySeriesState = newValue % 41;
EEPROM.write(4, batterySeriesState);
}
void setLedCount(int newValue){
ledCountState = newValue % 41;
if(ledCountState > 7){
EEPROM.write(5, ledCountState);
}
}
void toggleLedType(){
ledTypeState = (ledTypeState + 1) % LED_TYPES;
EEPROM.write(6, ledTypeState);
}
};
#endif