#include <time.h>
+#include <math.h>
#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"
const uart_port_t uart_num = UART_NUM_1;
+
+void lcd_clock_draw_face(gl_display_t *);
+void lcd_clock_draw_hand(gl_display_t *, uint16_t, uint16_t, uint8_t);
+
+
int write_tx(const void *data, size_t sz) {
return uart_write_bytes(uart_num, data, sz);
}
gl_gfx_Cls(disp);
/* draw straps */
- for (uint8_t r = 0; r <= LCD_HEIGHT; r+= 5) {
+ for (uint8_t r = 0; r <= LCD_HEIGHT; r+= 4) {
gl_gfx_RectangleFilled(disp,
LCD_WIDTH / 2 - BOOT_STRAP_WIDTH / 2 - BOOT_CIRCL_OFFSET,
LCD_HEIGHT / 2 - r / 2,
void lcd_clock_loop(gl_display_t *disp) {
- gl_txt_FGcolour(disp, GREEN);
- gl_txt_BGcolour(disp, BLACK);
- gl_txt_MoveCursor(disp, 0, 0);
- gl_putstr(disp, (uint8_t *) "Debug Clock Mode");
+ gl_gfx_Cls(disp);
+ gl_gfx_BGcolour(disp, BLACK);
+ lcd_clock_draw_face(disp);
while (1) {
time_t tm = time(NULL);
char txt[10];
snprintf(txt, 10, "%lld", (long long) tm);
- gl_txt_MoveCursor(disp, 1, 0);
- gl_putstr(disp, (uint8_t *) txt);
+ // gl_txt_MoveCursor(disp, 1, 0);
+ // gl_putstr(disp, (uint8_t *) txt);
+ lcd_clock_draw_hand(disp, tm % 60, 60, CLOCKSCR_TIMEHDSE);
+ lcd_clock_draw_hand(disp, tm % (60 * 60), (60 * 60), CLOCKSCR_TIMEHDMN);
+ lcd_clock_draw_hand(disp, tm % (60 * 60 * 12),
+ (60 * 60 * 12), CLOCKSCR_TIMEHDHR);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
for (uint8_t i = 0; i < APPSCR_RCNUM; ++i) {
for (uint8_t j = 0; j < APPSCR_RCNUM; ++j) {
+ /*
printf("adding %d, %d [%d|%d|%d|%d]\n",
i + 1, j + 1,
APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1),
APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0),
APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0),
WHITE);
+ */
}
}
}
+
+
+void lcd_clock_draw_face(gl_display_t *disp) {
+ /* draw the circle */
+ gl_gfx_CircleFilled(disp, LCD_WIDTH / 2, LCD_HEIGHT / 2, CLOCKSCR_CIRCRAD,
+ ALICEBLUE);
+
+ for (double angle = 0; angle < 2 * M_PI; angle += (2 * M_PI) / 12) {
+ /* draw hour ticks */
+
+ /* full 'x' tick start length */
+ int8_t fxs = cos(angle) * (CLOCKSCR_CIRCRAD - (CLOCKSCR_TIMEMKHR / 2));
+ /* full 'y' tick start length */
+ int8_t fys = sin(angle) * (CLOCKSCR_CIRCRAD - (CLOCKSCR_TIMEMKHR / 2));
+
+ /* full 'x' tick end length */
+ int8_t fxe = cos(angle) * (CLOCKSCR_CIRCRAD + (CLOCKSCR_TIMEMKHR / 2));
+ /* full 'y' tick end length */
+ int8_t fye = sin(angle) * (CLOCKSCR_CIRCRAD + (CLOCKSCR_TIMEMKHR / 2));
+
+ /* plot the line. remember this is with respect to the origin so we
+ * need to correct for that by adding LCD_WIDTH / 2 or the ht.
+ */
+
+ gl_gfx_Line(disp,
+ fxs + (LCD_WIDTH / 2),
+ fys + (LCD_HEIGHT / 2),
+ fxe + (LCD_WIDTH / 2),
+ fye + (LCD_HEIGHT / 2), RED);
+ }
+}
+
+
+void lcd_clock_draw_hand(gl_display_t *disp, uint16_t x, uint16_t n, uint8_t l) {
+ /* x = current (minute/second etc., n = total, l = length of hand */
+
+ double angle = (double) x * M_PI * 2 / n;
+
+ /* full 'x' tick end length */
+ int8_t fxe = cos(angle) * l;
+ /* full 'y' tick end length */
+ int8_t fye = sin(angle) * l;
+
+ gl_gfx_Line(disp,
+ 0 + (LCD_WIDTH / 2),
+ 0 + (LCD_HEIGHT / 2),
+ fxe + (LCD_WIDTH / 2),
+ fye + (LCD_HEIGHT / 2), BLACK);
+}
#define APPSCR_TOPCALCW(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCW(0))
#define APPSCR_TOPCALCH(x) ((x) * APPSCR_PAD) + (((x) - 1) * APPSCR_PADCALCH(0))
+/* v stands for variale */
+#define APPSCR_PADCALCVW(n, pad) (LCD_WIDTH - (n) * (pad))
+#define APPSCR_PADCALCVH(n, pad) (LCD_HEIGHT - (n) * (pad))
+#define APPSCR_TOPCALCVW(n, pad, x) ((x) * (pad)) + \
+ (((x) - 1) * APPSCR_PADCALCVW(n, pad))
+#define APPSCR_TOPCALCVH(n, pad, x) ((x) * (pad)) + \
+ (((x) - 1) * APPSCR_PADCALCVH(n, pad))
+
+#define CLOCKSCR_CIRCRAD 50
+/* time markers (hour) length */
+#define CLOCKSCR_TIMEMKHR 6
+
+/* time hand (hour) length */
+#define CLOCKSCR_TIMEHDHR 20
+/* time hand (min) length */
+#define CLOCKSCR_TIMEHDMN 30
+/* time hand (sec) length */
+#define CLOCKSCR_TIMEHDSE 45
+
typedef struct {
uint8_t width;
uint8_t height;