-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
178 lines (150 loc) · 4.53 KB
/
Copy pathmain.cpp
File metadata and controls
178 lines (150 loc) · 4.53 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
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
/*Using LVGL with Arduino requires some extra steps:
*Be sure to read the docs here: https://docs.lvgl.io/master/get-started/platforms/arduino.html */
#include <all_data.h>
/*To use the built-in examples and demos of LVGL uncomment the includes below respectively.
*You also need to copy `lvgl/examples` to `lvgl/src/examples`. Similarly for the demos `lvgl/demos` to `lvgl/src/demos`.
Note that the `lv_examples` library is for LVGL v7 and you shouldn't install it for this version (since LVGL v8)
as the examples and demos are now part of the main LVGL library. */
/*Change to your screen resolution*/
static const uint16_t screenWidth = 320;
static const uint16_t screenHeight = 240;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[screenWidth * screenHeight / 10];
CST816S touch(3, 18, 8, 46); // sda, scl, rst, irq
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.pushColors((uint16_t *)&color_p->full, w * h, true);
tft.endWrite();
lv_disp_flush_ready(disp_drv);
}
// /*Read the touchpad*/
void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
if (touch.available())
{
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = 320 - touch.data.y;
data->point.y = touch.data.x;
}
else
{
data->state = LV_INDEV_STATE_REL;
}
}
void lvgl_set_init(void)
{
lv_init();
tft.begin(); /* TFT init */
touch.begin();
tft.setRotation(3); /* Landscape orientation, flipped */
lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * screenHeight / 10);
/*Initialize the display*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
/*Initialize the (dummy) input device driver*/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
void lvgl_task(void *pt);
void WiFi_task(void *pt);
void time_task(void *pt);
void music_task(void *pt);
void mic_task(void *pt);
void move_task(void *pt);
void setup()
{
Serial.begin(9600); /* prepare for possible serial debug */
// initWiFi();
initSD();
initmusic();
initmic();
lvgl_set_init();
ui_init();
lv_100ask_2048_simple_test();
init_clear();
xTaskCreatePinnedToCore(lvgl_task, "lvgl_task", 1024 * 15, NULL, 2, NULL, 1);
xTaskCreatePinnedToCore(WiFi_task, "WiFi_task", 1024 * 5, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(time_task, "time_task", 1024 * 5, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(music_task, "music_task", 1024 * 5, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(mic_task, "mic_task", 1024 * 5, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(move_task, "move_task", 1024 * 5, NULL, 1, NULL, 0);
}
// bool flag =1;
void loop()
{
// GPTtest();
// lv_timer_handler();
// delay(5);
}
void lvgl_task(void *pt)
{
while (1)
{
if (Serial.available())
{
String RX = Serial.readStringUntil('\n');
const char *RX_get = RX.c_str();
lv_textarea_add_text(ui_TextSerialRx, RX_get);
}
lv_timer_handler();
vTaskDelay(5);
}
}
void WiFi_task(void *pt)
{
while (1)
{
WiFiUpdate();
vTaskDelay(50);
}
}
void time_task(void *pt)
{
while (1)
{
get_time_weather();
// double val = (double)(analogRead(10)*0.0244);
// lv_bar_set_value(ui_Electricity, (uint32_t)val, LV_ANIM_OFF);
vTaskDelay(1000);
}
}
void music_task(void *pt)
{
while (1)
{
getmusic();
vTaskDelay(5);
}
}
void mic_task(void *pt)
{
while (1)
{
getmic();
vTaskDelay(5);
}
}
void move_task(void *pt)
{
while (1)
{
getmove();
vTaskDelay(5);
}
}