diff --git a/src/main.c b/src/main.c index 255f441..756b25f 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,6 @@ #include "mgos.h" #include "mgos_pwm.h" #include "mongoose-touch.h" -#include "fonts/FreeMonoBold9pt7b.h" struct screen_t *screen = NULL; @@ -52,7 +51,6 @@ void tft_demo(void) mgos_stmpe610_set_handler(touch_handler); mgos_stmpe610_set_dimensions(320, 240); - mgos_ili9341_set_font(&FreeMonoBold9pt7b); mgos_ili9341_set_fgcolor(0,0,0); mgos_ili9341_fillScreen(); diff --git a/src/widget_battery.c b/src/widget_battery.c index 0da7aa1..bd6298d 100644 --- a/src/widget_battery.c +++ b/src/widget_battery.c @@ -27,7 +27,7 @@ static void widget_battery_render(struct widget_t *w, void *ev_data) { if (!w) return; - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); mvolts=widget_battery_getvoltage(); color=ILI9341_RED; diff --git a/src/widget_default.c b/src/widget_default.c index 13d1741..ea79239 100644 --- a/src/widget_default.c +++ b/src/widget_default.c @@ -4,7 +4,7 @@ static void widget_default_draw(struct widget_t *w, uint16_t color) { if (!w) return; - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); mgos_ili9341_set_fgcolor565(color); mgos_ili9341_drawRoundRect(0, 0, w->w, w->h, 8); diff --git a/src/widget_name.c b/src/widget_name.c index d3ec939..30b1c8d 100644 --- a/src/widget_name.c +++ b/src/widget_name.c @@ -3,6 +3,7 @@ #include "mgos_wifi.h" #include "mgos_net.h" #include "mongoose-touch.h" +#include "fonts/FreeMonoBold9pt7b.h" #define WIDGET_NAME_NAME 0 #define WIDGET_NAME_IPADDR 1 @@ -16,6 +17,7 @@ extern struct screen_t *screen; static void widget_name_render(struct widget_t *w, void *ev_data) { char namestring[21]; char *p = NULL; + int16_t text_height; if (!w) @@ -54,11 +56,14 @@ static void widget_name_render(struct widget_t *w, void *ev_data) { sprintf(namestring, "%-20s",mgos_sys_config_get_app_hostname()); } - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); mgos_ili9341_set_fgcolor565(ILI9341_BLACK); mgos_ili9341_fillRect(0, 0, w->w, w->h); + + mgos_ili9341_set_font(&FreeMonoBold9pt7b); mgos_ili9341_set_fgcolor565(ILI9341_GREEN); - mgos_ili9341_print(2, 4, namestring); + text_height=mgos_ili9341_getStringHeight(namestring); + mgos_ili9341_print(2, text_height>w->h?0:(w->h-text_height)/2, namestring); (void) ev_data; } diff --git a/src/widget_network.c b/src/widget_network.c index 37f6a1e..66f0c29 100644 --- a/src/widget_network.c +++ b/src/widget_network.c @@ -7,7 +7,7 @@ static mgos_timer_id recv_timer = 0; static struct widget_t *widget_network = NULL; static void widget_network_render(struct widget_t *w, void *ev_data) { - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); // Send mgos_ili9341_set_fgcolor565(send_timer?ILI9341_YELLOW:ILI9341_DARKGREY); mgos_ili9341_fillTriangle(2, 10, 10, 10, 6, 2); diff --git a/src/widget_time.c b/src/widget_time.c index c4da124..3aaeb07 100644 --- a/src/widget_time.c +++ b/src/widget_time.c @@ -1,8 +1,10 @@ #include "mgos.h" #include "mongoose-touch.h" +#include "fonts/FreeSerifBold9pt7b.h" static void widget_time_render(struct widget_t *w, void *ev_data) { char tmp_buff[32]; + int16_t text_width, text_height; time_t now = 3600 + time(0); // TZ=GMT+1 struct tm* tm_info = gmtime(&now); @@ -11,9 +13,14 @@ static void widget_time_render(struct widget_t *w, void *ev_data) { return; mgos_ili9341_set_fgcolor565(ILI9341_YELLOW); - sprintf(tmp_buff, " %02d:%02d", tm_info->tm_hour, tm_info->tm_min); - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); - mgos_ili9341_print(2, 4, tmp_buff); + sprintf(tmp_buff, " %02d:%02d:%02d", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); + mgos_ili9341_set_font(&FreeSerifBold9pt7b); + + text_width=mgos_ili9341_getStringWidth(tmp_buff); + text_height=mgos_ili9341_getStringHeight(tmp_buff); + + mgos_ili9341_print(text_width>w->w?0:(w->w-text_width)/2, text_height>w->h?0:(w->h-text_height)/2, tmp_buff); (void) ev_data; } diff --git a/src/widget_topbar.c b/src/widget_topbar.c index 9edcf52..bcf29e5 100644 --- a/src/widget_topbar.c +++ b/src/widget_topbar.c @@ -5,7 +5,7 @@ static void widget_topbar_render(struct widget_t *w, void *ev_data) { if (!w) return; - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); mgos_ili9341_set_fgcolor565(ILI9341_WHITE); mgos_ili9341_fillRect(0, 0, w->w, w->h); diff --git a/src/widget_wifi.c b/src/widget_wifi.c index b771774..b23d737 100644 --- a/src/widget_wifi.c +++ b/src/widget_wifi.c @@ -24,7 +24,7 @@ static uint8_t widget_wifi_signal() { static void widget_wifi_render(struct widget_t *w, void *ev_data) { uint8_t x, signal; - mgos_ili9341_set_window(w->x, w->y, w->x+w->w, w->y+w->h); + mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1); mgos_ili9341_set_fgcolor565(ILI9341_DARKGREY); mgos_ili9341_fillTriangle(2, 18, 18, 18, 18, 2);