Windows can be moved, minimized and maximized with the mouse; with the keyboard, Tab moves the focus and the arrow keys move the sliders.
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#include "esp_system.h"
31
32#include "speech.h"
33#include "loop.h"
34#include "mario.h"
35
36
40
41
42void setup()
43{
44
45 PS2Controller.
begin(PS2Preset::KeyboardPort0_MousePort1, KbdMode::GenerateVirtualKeys);
46
47 DisplayController.
begin();
49
50
51
52
53}
54
55
56class ChannelFrame :
public uiFrame {
57
67
68 uiLabel * volumeLabel, * frequencyLabel;
69 uiSlider * volumeSlider, * frequencySlider;
72
73public:
74
75 ChannelFrame(uiWindow * parent)
77 {
78 static int channel_ = 0;
79 static int y = 4, x = 4;
80 static int startingFreq = 150;
81
82 app()->moveWindow(this, x, y);
83 y += size().height + 4;
84 if (y + size().height > parent->size().height) {
85 x += 25;
86 y = x;
87 }
88
89 frameProps().resizeable = false;
90 frameProps().hasCloseButton = false;
91
92 setTitleFmt("Channel %d", ++channel_);
93
94
96 volumeSlider =
new uiSlider(
this,
Point(72, 19),
Size(150, 17), uiOrientation::Horizontal);
99 if (curGen)
101 };
102 volumeSlider->
setup(0, 127, 16);
104
105
110 genComboBox->
items().append(
"Sine Wave");
111 genComboBox->
items().append(
"Square Wave");
112 genComboBox->
items().append(
"Triangle Wave");
113 genComboBox->
items().append(
"Sawtooth Wave");
114 genComboBox->
items().append(
"Noise");
115 genComboBox->
items().append(
"Loop");
116 genComboBox->
items().append(
"Speech");
117 genComboBox->
items().append(
"Mario");
121 };
122
123
124 frequencyLabel =
new uiLabel(
this,
"", Point(5, 39));
125 frequencySlider =
new uiSlider(
this, Point(72, 38), Size(330, 17), uiOrientation::Horizontal);
128 if (curGen)
130 };
131 frequencySlider->
setup(0, 8000, 500);
133 startingFreq += 50;
134
135
137 enableCheck =
new uiCheckBox(
this, Point(77, 75-17), Size(17, 17));
139 if (curGen)
141 };
142
143
144 setGenerator(0);
145 }
146
147 void setGenerator(int index) {
148 soundGenerator.
detach(curGen);
149 switch (index) {
150 case 0:
151 curGen = &sine;
152 break;
153 case 1:
154 curGen = □
155 break;
156 case 2:
157 curGen = ▵
158 break;
159 case 3:
160 curGen = &sawtooth;
161 break;
162 case 4:
163 curGen = &noise;
164 break;
165 case 5:
166 curGen = &loop;
167 break;
168 case 6:
169 curGen = &speech;
170 break;
171 case 7:
172 curGen = &mario;
173 break;
174 }
175 soundGenerator.
attach(curGen);
178 }
179};
180
181
182class CommandsFrame :
public uiFrame {
183
184public:
185 CommandsFrame(uiWindow * parent)
186 : uiFrame(parent, "Main Controls", Point(500, 4), Size(133, 200))
187 {
188 frameStyle().titleFont = &fabgl::FONT_std_12;
189 frameProps().resizeable = false;
190 frameProps().hasMaximizeButton = false;
191 frameProps().hasMinimizeButton = false;
192 frameProps().hasCloseButton = false;
193
194 auto addChannelBtn =
new uiButton(
this,
"Add Channel", Point(7, 22), Size(80, 16));
195 addChannelBtn->onClick = [=, this]() {
196 if (heap_caps_get_free_size(MALLOC_CAP_8BIT) < 5000)
197 app()->messageBox("Out of memory!", "I'm sorry, there is no more memory available!", "OK");
198 else
199 new ChannelFrame(parent);
200 };
201
202 auto resetBtn =
new uiButton(
this,
"Reset", Point(7, 45), Size(80, 16));
203 resetBtn->onClick = [=, this]() {
204 if (app()->messageBox("Reset ESP32", "Are you sure?", "Yes", "No", nullptr, uiMessageBoxIcon::Question) == uiMessageBoxResult::Button1)
205 esp_restart();
206 };
207
208
210 auto enableCheck =
new uiCheckBox(
this, Point(48, 68), Size(17, 17));
214 };
215
216
217 auto volumeLabel =
new uiLabel(
this,
"", Point(90, 182));
218 auto volumeSlider =
new uiSlider(
this, Point(100, 20), Size(17, 160), uiOrientation::Vertical);
222 };
223 volumeSlider->
setup(0, 127, 16);
225
226
227 }
228
229};
230
231
232class MyApp :
public uiApp {
233
234 void init() {
235
236 rootWindow()->frameStyle().backgroundColor = RGB888(0, 0, 64);
237
238 new ChannelFrame(rootWindow());
239 new ChannelFrame(rootWindow());
240 new ChannelFrame(rootWindow());
241 new ChannelFrame(rootWindow());
242
243 new CommandsFrame(rootWindow());
244
245 soundGenerator.
play(
true);
246
247 }
248} app;
249
250
251void loop()
252{
253 app.run(&DisplayController);
254}
255
256
257extern "C" void app_main()
258{
259 setup();
260 while (true)
261 loop();
262}
void attach(WaveformGenerator *value)
Attaches a waveform generator.
void detach(WaveformGenerator *value)
Detaches a waveform generator.
void setVolume(int value)
Sets the overall volume.
bool play(bool value)
Starts or stops playing.
SoundGenerator handles audio output.
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes the PS/2 device controller.
VGA bitmapped display controller with 16 colors.
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
Initializer for 8 colors (5 GPIOs).
Delegate onChange
Change event delegate.
uiListBoxStyle & listBoxStyle()
Sets or gets listbox style.
int selectedItem()
Represents currently selected item.
void selectItem(int index)
Selects an item.
Represents the whole application base class.
void setChecked(bool value)
Sets current checkbox or radiobutton checked status.
bool checked()
Determines whether the checkbox or radiobutton is checked.
Delegate onChange
Change event delegate.
uiCheckBox(uiWindow *parent, const Point &pos, const Size &size, uiCheckBoxKind kind=uiCheckBoxKind::CheckBox, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
Represents a checkbox or a radiobutton.
StringList & items()
A list of strings representing items of the combobox.
uiTextEditStyle & textEditStyle()
Sets or gets text edit style.
uiComboBox(uiWindow *parent, const Point &pos, const Size &size, int listHeight, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
This is a combination of a listbox and a single-line editable textbox.
A frame is a window with a title bar, maximize/minimize/close buttons and that is resizable or movabl...
void setTextFmt(const char *format,...)
Sets label formatted text.
uiLabel(uiWindow *parent, char const *text, const Point &pos, const Size &size=Size(0, 0), bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
A label is a static text UI element.
void setup(int min, int max, int ticksFrequency)
Sets the minimum and maximum positions and the tick frequency.
void setPosition(int value)
Sets the slider position.
Delegate onChange
Slider changed event delegate.
uiSlider(uiWindow *parent, const Point &pos, const Size &size, uiOrientation orientation, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
int position()
Determines slider position.
A slider or track bar is a graphical control element with which a user may set a value by moving an i...
uiStaticLabel(uiWindow *parent, char const *text, const Point &pos, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
Single include file of the FabGL library.
This file contains all classes related to FabGL Graphical User Interface.
Represents the coordinates of a point.
Represents a two-dimensional size.
FontInfo const * textFont
FontInfo const * textFont