Refactor app to use 'screen with widgets' rather than 'widgets'
This commit is contained in:
30
src/main.c
30
src/main.c
@ -6,6 +6,8 @@
|
||||
#include "stmpe610.h"
|
||||
#include "mongoose-touch.h"
|
||||
|
||||
static struct screen_t *screen = NULL;
|
||||
|
||||
static long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
@ -19,7 +21,11 @@ static void touch_handler(struct mgos_stmpe610_event_data *ed) {
|
||||
x = map(ed->x, 0, 4095, 0, _width-1);
|
||||
y = map(ed->y, 0, 4095, 0, _height-1);
|
||||
LOG(LL_INFO, ("Touch %s at (%d,%d) pressure=%d, length=%d", ed->direction==TOUCH_UP?"UP":"DOWN", x, y, ed->z, ed->length));
|
||||
widget = widget_find(x, y);
|
||||
|
||||
widget = screen_widget_find_by_xy(screen, x, y);
|
||||
if (widget) {
|
||||
LOG(LL_INFO, ("Widget '%s' found", widget->name));
|
||||
}
|
||||
|
||||
if (ed->direction==TOUCH_DOWN) {
|
||||
// mgos_ili9341_drawCircle(x, y, ed->length, ILI9341_YELLOW);
|
||||
@ -36,6 +42,8 @@ static void touch_handler(struct mgos_stmpe610_event_data *ed) {
|
||||
|
||||
void tft_demo(void)
|
||||
{
|
||||
struct widget_t *w;
|
||||
|
||||
mgos_ili9341_setRotation(mgos_sys_config_get_tft_orientation());
|
||||
mgos_stmpe610_set_rotation(mgos_sys_config_get_tft_orientation());
|
||||
mgos_ili9341_setGammaCurve(DEFAULT_GAMMA_CURVE);
|
||||
@ -44,11 +52,21 @@ void tft_demo(void)
|
||||
mgos_ili9341_jpg_image(CENTER, CENTER, 1, "mongoose-os.jpg", NULL, 0);
|
||||
// mgos_ili9341_jpg_image(200, 150, 2, "flower.jpg", NULL, 0);
|
||||
|
||||
widget_add(0, 0, 198, 20, 0, widget_name_ev, NULL);
|
||||
widget_add(198, 0, 22, 20, 0, widget_network_ev, NULL);
|
||||
widget_add(220, 0, 20, 20, 5000, widget_wifi_ev, NULL);
|
||||
widget_add(240, 0, 80, 20, 1000, widget_time_ev, NULL);
|
||||
widget_add(0, 21, 320, 2, 0, widget_topbar_ev, NULL);
|
||||
screen = screen_create_from_file("fs/screen_main.json");
|
||||
w = widget_create("name", 0, 0, 198, 20, 0, widget_name_ev, NULL);
|
||||
screen_widget_add(screen, w);
|
||||
|
||||
w = widget_create("network", 198, 0, 22, 20, 0, widget_network_ev, NULL);
|
||||
screen_widget_add(screen, w);
|
||||
|
||||
w = widget_create("wifi", 220, 0, 20, 20, 5000, widget_wifi_ev, NULL);
|
||||
screen_widget_add(screen, w);
|
||||
|
||||
w = widget_create("time", 240, 0, 80, 20, 1000, widget_time_ev, NULL);
|
||||
screen_widget_add(screen, w);
|
||||
|
||||
w = widget_create("topbar", 0, 21, 320, 2, 0, widget_topbar_ev, NULL);
|
||||
screen_widget_add(screen, w);
|
||||
}
|
||||
|
||||
enum mgos_app_init_result mgos_app_init(void)
|
||||
|
Reference in New Issue
Block a user