From c0e4115482f0c34df82f2c45897ca7d5e2d81dc5 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sat, 31 Oct 2020 11:18:01 +0100 Subject: [PATCH] UI: Add clock to top bar, add rtc.c for Linux --- meson.build | 1 + openrtx/src/main.c | 2 +- openrtx/src/ui.c | 39 ++++++++++++---- platform/mcu/x86_64/drivers/rtc.c | 76 +++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 platform/mcu/x86_64/drivers/rtc.c diff --git a/meson.build b/meson.build index 82e12c19..c1137dd9 100644 --- a/meson.build +++ b/meson.build @@ -106,6 +106,7 @@ linux_src = src + ['platform/drivers/display/display_libSDL.c', 'platform/drivers/keyboard/keyboard_linux.c', 'platform/mcu/x86_64/drivers/gpio.c', 'platform/mcu/x86_64/drivers/delays.c', + 'platform/mcu/x86_64/drivers/rtc.c', 'platform/targets/linux/platform.c', 'openrtx/src/graphics/graphics_rgb565.c', 'rtos/uC-OS3/Ports/POSIX/os_cpu_c.c', diff --git a/openrtx/src/main.c b/openrtx/src/main.c index d0890913..0fc4d8c7 100644 --- a/openrtx/src/main.c +++ b/openrtx/src/main.c @@ -45,7 +45,7 @@ int main(void) gfx_print(splash_origin, splash_buf, FONT_SIZE_4, TEXT_ALIGN_CENTER, color_yellow_fab413); gfx_render(); while(gfx_renderingInProgress()); - OSTimeDlyHMSM(0u, 0u, 0u, 500u, OS_OPT_TIME_HMSM_STRICT, &os_err); + OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); // Clear screen gfx_clearScreen(); diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index b37b9422..dc0d5530 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -28,34 +28,53 @@ * * Below is shown the row height for two common display densities. * - * 160x128 display (MD380) + * 160x128 display (MD380) Recommended font size * ┌─────────────────────────┐ - * │ top_status_bar (16px) │ + * │ top_status_bar (16 px) │ 8 pt font with 4 px vertical padding * ├─────────────────────────┤ - * │ Line 1 (32px) │ + * │ Line 1 (32px) │ 16 pt font with 8 px vertical padding * │ │ - * │ Line 2 (32px) │ + * │ Line 2 (32px) │ 16 pt font with 8 px vertical padding * │ │ - * │ Line 3 (32px) │ + * │ Line 3 (32px) │ 16 pt font with 8 px vertical padding * │ │ * ├─────────────────────────┤ - * │bottom_status_bar (16px) │ + * │bottom_status_bar (16 px)│ 8 pt font with 4 px vertical padding * └─────────────────────────┘ * * 128x64 display (GD77) * ┌─────────────────────────┐ - * │ top_status_bar (8px) │ + * │ top_status_bar (8 px) │ 8 pt font without vertical padding * ├─────────────────────────┤ * │ Line 1 (16px) │ * │ Line 2 (16px) │ * │ Line 3 (16px) │ * ├─────────────────────────┤ - * │ bottom_status_bar (8px) │ + * │ bottom_status_bar (8 px)│ 8 pt font without vertical padding * └─────────────────────────┘ */ #include -#include +#include "ui.h" +#include "graphics.h" +#include "rtc.h" + +color_t color_white = {255, 255, 255}; + +void ui_drawTopBar() +{ + // Print clock on top bar, use 4 px padding + point_t clock_pos = {0, 5}; + char clock_buf[6] = ""; + curTime_t time = rtc_getTime(); + snprintf(clock_buf, sizeof(clock_buf), "%2d:%2d", time.hour, time.minute); + gfx_print(clock_pos, clock_buf, FONT_SIZE_1, TEXT_ALIGN_CENTER, color_white); +} + +void ui_drawMainScreen() +{ + ui_drawTopBar(); +} void ui_init() { @@ -63,6 +82,8 @@ void ui_init() bool ui_update(state_t state, uint32_t keys) { + gfx_clearScreen(); + ui_drawMainScreen(); return true; } diff --git a/platform/mcu/x86_64/drivers/rtc.c b/platform/mcu/x86_64/drivers/rtc.c new file mode 100644 index 00000000..ef1b9e0e --- /dev/null +++ b/platform/mcu/x86_64/drivers/rtc.c @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include "rtc.h" + +void rtc_init() +{ + printf("rtc_init()\n"); +} + +void rtc_shutdown() +{ + printf("rtc_shutdown()\n"); +} + +void rtc_setTime(curTime_t t) +{ + printf("rtc_setTime(t)\n"); +} + +void rtc_setHour(uint8_t hours, uint8_t minutes, uint8_t seconds) +{ + printf("rtc_setHour(%d, %d, %d)\n", hours, minutes, seconds); +} + +void rtc_setDate(uint8_t date, uint8_t month, uint8_t year) +{ + printf("rtc_setDate(%d, %d, %d)\n", date, month, year); +} + +curTime_t rtc_getTime() +{ + curTime_t t; + + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + + t.hour = timeinfo->tm_hour; + t.minute = timeinfo->tm_min; + t.second = timeinfo->tm_sec; + t.year = timeinfo->tm_year + 1900; + t.day = timeinfo->tm_mday; + t.month = timeinfo->tm_mon + 1; + + return t; +} + +void rtc_dstSet() +{ + printf("rtc_dstSet()\n"); +} + +void rtc_dstClear() +{ + printf("rtc_dstClear()\n"); +}