-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.h
More file actions
124 lines (105 loc) · 3.06 KB
/
structs.h
File metadata and controls
124 lines (105 loc) · 3.06 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
121
122
123
124
#include <utility>
#include "AudioTools/CoreAudio/AudioBasic/Str.h"
#include <sys/_stdint.h>
#ifndef STRUCTS_H
#define STRUCTS_H
#include <vector>
#include <map>
#include "config.h"
#include <Arduino.h>
#include <U8g2lib.h>
//very important structure. Basically, together with MENU, it handles all menu navigation.
struct MENUITEM
{
String title; // item title
void (*action)(void * ptr); // function to execute
void *param; // parameter for function to execute
struct MENU *subMenu; // submenu for this menu item to open
const unsigned char *icon; //it is a pointer, so it can point to the array making it dynamic declaration ;)
const uint8_t icon_size[2]; //dimensions of the icons
};
//very important structure. Basically, together with MENUITEM, it handles all menu navigation.
struct MENU
{
String title; // menu title
std::vector<MENUITEM>* items; // menu items
int numItems; // number of menu items
struct MENU *parentMenu; // parent menu of this menu
uint8_t style;
};
//pointers to subMenu and parentMenu in those structs allow to navigate through menus without the need to track on which menu we are right now
//type for the int variables that will be needed to be changed later (ex. volume)
struct INT_VARIABLE{
String name;
int value;
int min_value;
int max_value;
uint8_t step;
};
//struct made to make menaging wifi networks easier
struct WIFI_INFO{
String SSID;
String PASS;
bool is_pass;
int strength;
};
//class made to make managing many scrolling texts easier
class ScrollableText{
public:
ScrollableText(String text,uint8_t y, U8G2 &display, const uint8_t *font, uint8_t step = 5)
: u8g2(display), text(text), y(y), step(step), font(font) // Initialize all the values here
{
this->SetText(text);
}
void process(){
u8g2.setFont(font);
if(scrolling){
x+=step;
if(x>x_diff)
x = 0;
u8g2.drawStr(-x,y,text.c_str());
}
else{
uint8_t display_x = u8g2.getDisplayWidth();
uint8_t str_x = u8g2.getStrWidth(text.c_str());
u8g2.drawStr( (display_x-str_x)/2 , y, text.c_str() );
}
}
void SetText(String NewText){
u8g2.setFont(font);
text = NewText;
x = 0;
x_diff = -min( (u8g2.getDisplayWidth() - u8g2.getStrWidth(text.c_str())) , 0);
if(x_diff == 0){
scrolling = false;
}
else{
scrolling = true;
text = " " + text + " ";
x_diff += u8g2.getStrWidth(" ");
}
}
private:
bool scrolling;
const uint8_t *font;
U8G2 &u8g2;
//how much px text is too long to fit
uint x_diff = 0;
//current scrolling position
uint x = 0;
uint8_t y = 0;
//text to be showed
String text = "";
//how many pixels to move the text
uint8_t step = 5;
};
//metadata storage (in char arrays)
struct {
String Title;
String Album;
String Artist;
bool changed;
}Meta;
std::map<String,String>Radio_stations;
//std::vector<String[2]>Radio_stations;
#endif