-
Notifications
You must be signed in to change notification settings - Fork 1
/
M5DropMenuSample.ino
212 lines (191 loc) · 6.64 KB
/
M5DropMenuSample.ino
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <vector>
#include <SD.h>
#include <M5Stack.h>
#include "GroveJoystick.h"
#include "FACESGameBoy.h"
#include "PLUSEncoder.h"
#include "ButtonDrawer.h"
#include "MenuContainer.h"
#include "MenuItemSD.h"
#include "MenuItemBLE.h"
#include "MenuItem/MenuItemBoolean.h"
#include "MenuItem/MenuItemNumeric.h"
#include "Demo/SystemInfo.h"
#include "Demo/I2CScanner.h"
#include "Demo/AD34FFTTaskDemo.h"
#include "Demo/ADInputDemo.h"
#include "Demo/DHT12Demo.h"
#include "Demo/MPU9250Demo.h"
#include "Demo/BLEDemo.h"
#include "Demo/ScrollDemo.h"
#include "VroomCtrlDemo.h"
MenuContainer _menu;
void CallBackMenuItem(MenuItem* sender)
{
M5.Lcd.fillRect(0,0,320,8,0);
M5.Lcd.setTextColor(0xffff,0);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(15, 0);
M5.Lcd.print("CallbackSample : ");
M5.Lcd.print(sender->title);
}
template <typename T>
void CallBackExec(MenuItem* sender)
{
T menu;
menu(sender);
}
void setup() {
M5.begin();
typedef std::vector<MenuItem*> submenu;
_menu.callback = CallBackMenuItem;
_menu.SetSubItems(submenu
{ new MenuItem("tree sample", submenu
{ new MenuItem("sub 1", submenu
{ new MenuItem("sub 1-1")
, new MenuItem("sub 1-2")
, new MenuItem("sub 1-3")
} )
, new MenuItem("sub 2")
, new MenuItem("sub 3", submenu
{ new MenuItem("sub 3-1", submenu
{ new MenuItem("sub 3-1-1")
, new MenuItem("sub 3-1-2")
, new MenuItem("sub 3-1-3")
} )
, new MenuItem("sub 3-2")
, new MenuItem("sub 3-3", submenu
{ new MenuItem("sub 3-3-1", submenu
{ new MenuItem("sub 3-3-1-1")
, new MenuItem("sub 3-3-1-2")
, new MenuItem("sub 3-3-1-3")
} )
, new MenuItem("sub 3-1-2")
, new MenuItem("sub 3-1-3")
} )
} )
} )
, new MenuItem("Demo", submenu
{ new MenuItem("System Information", CallBackExec<SystemInfo> )
, new MenuItem("I2C Scanner", CallBackExec<I2CScanner> )
, new MenuItem("FIRE/GO AD34Mic FFT MultiTask", CallBackExec<AD34FFTTaskDemo> )
, new MenuItem("AD35 AD36 Input", CallBackExec<ADInputDemo> )
, new MenuItem("DHT12" , CallBackExec<DHT12Demo> )
, new MenuItem("MPU9250", CallBackExec<MPU9250Demo> )
, new MenuItem("Scroll Demo", CallBackExec<ScrollDemo>)
, new MenuItem("BLE Vroom Controller", CallBackExec<VroomCtrlDemo> )
} )
, new MenuItemNumeric("Brightness",1,15,5,CallBackBrightness)
, new MenuItem("GPIO switch", CallBackGPIOtest, submenu
{ new MenuItemBoolean("GPIO16",16)
, new MenuItemBoolean("GPIO17",17)
, new MenuItemBoolean("GPIO 2", 2)
, new MenuItemBoolean("GPIO 5", 5)
, new MenuItemNumeric("GPIO25",0,255,0,25,CallBackDACtest)
, new MenuItemNumeric("GPIO26",0,255,0,26,CallBackDACtest)
} )
, new MenuItemBLE("BLE" , BLEDemo() )
, new MenuItemSD("SD card", CallBackSDtest)
}
);
_menu.begin();
Wire.begin();
ButtonDrawer::getInstance()->setTitle("Back","Next","Ok");
}
uint32_t msecRepeatStart = 250;
bool moving;
void loop() {
M5.update();
if (M5.BtnA.wasPressed()) { _menu.moveUp(); }
if (M5.BtnB.wasPressed()) { _menu.moveNext(); }
if (M5.BtnC.wasPressed()) { _menu.selectItem(); }
if (!moving) {
if (M5.BtnA.pressedFor(msecRepeatStart)) { _menu.moveUp(); }
if (M5.BtnB.pressedFor(msecRepeatStart)) { _menu.moveNext(); }
}
#ifdef _GroveJoystick_H_
JoyStick.Rotate = 0;
if (JoyStick.update()) {
if (JoyStick.wasLeft()) _menu.moveUp();
if (JoyStick.wasDown()) _menu.moveNext();
if (JoyStick.wasUp()) _menu.movePrev();
if (JoyStick.wasRight()
|| JoyStick.wasPressed()) _menu.selectItem();
}
#endif
#ifdef _FACESGameBoy_H_
if (FacesGameBoy.update()) {
if (FacesGameBoy.wasLeft()
|| FacesGameBoy.wasPressedB()) _menu.moveUp();
if (FacesGameBoy.wasDown()) _menu.moveNext();
if (FacesGameBoy.wasUp()) _menu.movePrev();
if (FacesGameBoy.wasRight()
|| FacesGameBoy.wasPressedA()) _menu.selectItem();
if (!moving) {
if (FacesGameBoy.pressedLeftFor(msecRepeatStart)) _menu.moveUp();
if (FacesGameBoy.pressedDownFor(msecRepeatStart)) _menu.moveNext();
if (FacesGameBoy.pressedUpFor(msecRepeatStart)) _menu.movePrev();
}
}
#endif
#ifdef _PLUSEncoder_H_
if (PlusEncoder.update()) {
if (PlusEncoder.isLongClick()) _menu.moveUp();
if (PlusEncoder.wasDown()) _menu.moveNext();
if (PlusEncoder.wasUp()) _menu.movePrev();
if (PlusEncoder.isClick()) _menu.selectItem();
}
#endif
ButtonDrawer::getInstance()->draw();
moving = _menu.loop();
if (!moving) { delay(1); }
}
void CallBackGPIOtest(MenuItem* sender)
{
MenuItemBoolean* mi = static_cast<MenuItemBoolean*>(sender);
if (!mi) return;
pinMode(mi->tag, OUTPUT);
digitalWrite(mi->tag, mi->value);
}
void CallBackDACtest(MenuItem* sender)
{
MenuItemNumeric* mi = static_cast<MenuItemNumeric*>(sender);
if (!mi) return;
pinMode(mi->tag, OUTPUT);
dacWrite(mi->tag, mi->value);
}
void CallBackBrightness(MenuItem* sender)
{
MenuItemNumeric* mi = static_cast<MenuItemNumeric*>(sender);
if (!mi) return;
M5.Lcd.setBrightness(mi->value*16);
}
void CallBackSDtest(MenuItem* sender)
{
MenuItemSD* mi = static_cast<MenuItemSD*>(sender);
if (!mi) return;
SD.begin();
File file = SD.open(mi->path, FILE_READ);
if (!file.isDirectory()) {
FileView(file);
}
file.close();
M5.Lcd.fillScreen(0);
}
void FileView(File ff){
M5.Lcd.clear(0);
M5.Lcd.setTextColor(0xffff,0);
M5.Lcd.setCursor(0,0);
size_t len = ff.size();
uint8_t buf[256];
if (ff.read(buf, len)) {
ButtonDrawer btnDrawer("Back","","");
for(int i=0; i<len; ++i){
M5.Lcd.write(buf[i]);
}
btnDrawer.draw();
while (!M5.BtnA.isPressed()) {
M5.update();
}
}
}