-
Notifications
You must be signed in to change notification settings - Fork 1
/
UI.h
90 lines (71 loc) · 2.19 KB
/
UI.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
#ifndef UI_H
#define UI_H
#include "UIState.h"
#include "SequenceView.h"
#include "PickStepView.h"
#include "StepOptionsView.h"
#include "SequencerOptionsView.h"
#define FPS 60
#define PRINT_FREQUENCY 1 / FPS * 1000
extern UIState uiState;
class UI
{
public:
void begin() {
IView &view = getCurrentView();
view.enable();
previousView = &view;
}
void loop() {
uiState.loop();
IView &view = getCurrentView();
if (&view != previousView) {
view.enable();
}
view.loop();
print();
previousView = &view;
}
void print() {
if ((millis() - lastPrintMillis) <= PRINT_FREQUENCY) {
return;
}
lastPrintMillis = millis();
IView &view = getCurrentView();
display.clearDisplay();
view.print();
// Helper pixels to locale screen edges
#if DEBUG
display.drawPixel(0, 0, SSD1306_WHITE);
display.drawPixel(0, display.height() - 1, SSD1306_WHITE);
display.drawPixel(display.width() - 1, 0, SSD1306_WHITE);
display.drawPixel(display.width() - 1, display.height() - 1, SSD1306_WHITE);
#endif
display.display();
}
private:
long lastPrintMillis = 0;
IView *previousView;
SequenceView view_Sequence;
PickStepView view_PickStep;
StepOptionsView view_StepOptions;
SequencerOptionsView view_SequencerOptions;
IView& getCurrentView() {
switch (uiState.state) {
case UI_STATE_SEQUENCE:
return view_Sequence;
break;
case UI_STATE_PICK_STEP:
return view_PickStep;
break;
case UI_STATE_STEP_OPTIONS:
return view_StepOptions;
break;
break;
case UI_STATE_SEQUENCER_OPTIONS:
return view_SequencerOptions;
break;
}
}
};
#endif