void lcd_clock_draw_face(gl_display_t *);
-void lcd_clock_draw_hand(gl_display_t *, uint16_t, uint16_t, uint8_t);
+void lcd_clock_draw_hand(gl_display_t *, uint16_t, uint16_t, uint8_t, gl_word_t);
+gl_word_t txt_strw(gl_display_t *, char *);
int write_tx(const void *data, size_t sz) {
ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
}
+
+void slower_baud() {
+ uart_config_t uart_config = {
+ .baud_rate = 9600,
+ .data_bits = UART_DATA_8_BITS,
+ .parity = UART_PARITY_DISABLE,
+ .stop_bits = UART_STOP_BITS_1,
+ .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
+ .rx_flow_ctrl_thresh = 10,
+ };
+ // Configure UART parameters
+ ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
+}
+
+/* ================================================================= */
+
void lcd_task(void) {
// Setup UART buffered IO with event queue
const int uart_buffer_size = UART_HW_FIFO_LEN(uart_num) + 4;
gl_txt_FGcolour(disp, BLACK);
gl_txt_BGcolour(disp, WHITE);
gl_txt_MoveCursor(disp, 6, 10);
+ gl_txt_Bold(disp, 1);
gl_putstr(disp, (uint8_t *) "SMART");
gl_txt_MoveCursor(disp, 7, 10);
+ gl_txt_Bold(disp, 1);
gl_putstr(disp, (uint8_t *) "WATCH");
gl_txt_MoveCursor(disp, 8, 10);
- gl_putstr(disp, (uint8_t *) "OS (v1)");
+ gl_txt_Bold(disp, 1);
+ gl_putstr(disp, (uint8_t *) "OS v0.1");
gl_txt_MoveCursor(disp, 10, 10);
gl_putstr(disp, (uint8_t *) "Anish &");
gl_txt_MoveCursor(disp, 11, 10);
void lcd_clock_loop(gl_display_t *disp) {
- gl_gfx_Cls(disp);
gl_gfx_BGcolour(disp, BLACK);
+ gl_gfx_Cls(disp);
lcd_clock_draw_face(disp);
+ gl_txt_FGcolour(disp, DARKGREEN);
+ gl_txt_BGcolour(disp, ALICEBLUE);
while (1) {
time_t tm = time(NULL);
- char txt[10];
- snprintf(txt, 10, "%lld", (long long) tm);
+ char txt[12];
+ // snprintf(txt, 10, "%lld", (long long) tm);
+ snprintf(txt, 12, "%02lld:%02lld %s",
+ tm / (60 * 60) % 12,
+ tm / 60 % 60,
+ (tm / (60 * 60) % 24 > 12) ? "PM" : "AM");
+ gl_txt_Italic(disp, 1);
+ uint16_t chw = txt_strw(disp, txt);
+ gl_gfx_MoveTo(disp, (LCD_WIDTH / 2) - (chw / 2), (LCD_HEIGHT / 2)
+ + (CLOCKSCR_CIRCRAD / 2));
+ gl_putstr(disp, (unsigned char *) 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 - 1) % 60,
+ 60, CLOCKSCR_TIMEHDSE, ALICEBLUE);
+ lcd_clock_draw_hand(disp, (tm + (60 * 60) - 1) % (60 * 60),
+ (60 * 60), CLOCKSCR_TIMEHDMN,
+ ALICEBLUE);
+ lcd_clock_draw_hand(disp, (tm + (60 * 60 * 12) - 1) % (60 * 60 * 12),
+ (60 * 60 * 12), CLOCKSCR_TIMEHDHR, ALICEBLUE);
+ lcd_clock_draw_hand(disp, tm % 60, 60, CLOCKSCR_TIMEHDSE, RED);
+ lcd_clock_draw_hand(disp, tm % (60 * 60), (60 * 60), CLOCKSCR_TIMEHDMN,
+ BLACK);
lcd_clock_draw_hand(disp, tm % (60 * 60 * 12),
- (60 * 60 * 12), CLOCKSCR_TIMEHDHR);
- vTaskDelay(pdMS_TO_TICKS(1000));
+ (60 * 60 * 12), CLOCKSCR_TIMEHDHR, BLACK);
+ vTaskDelay(pdMS_TO_TICKS(500));
}
}
}
-void lcd_clock_draw_hand(gl_display_t *disp, uint16_t x, uint16_t n, uint8_t l) {
+void lcd_clock_draw_hand(gl_display_t *disp, uint16_t x, uint16_t n, uint8_t l,
+ gl_word_t color) {
/* x = current (minute/second etc., n = total, l = length of hand */
- double angle = (double) x * M_PI * 2 / n;
+ /* offset to center of clock */
+ double angle = ((double) x * M_PI * 2 / n) - M_PI_2;
/* full 'x' tick end length */
int8_t fxe = cos(angle) * l;
0 + (LCD_WIDTH / 2),
0 + (LCD_HEIGHT / 2),
fxe + (LCD_WIDTH / 2),
- fye + (LCD_HEIGHT / 2), BLACK);
+ fye + (LCD_HEIGHT / 2), color);
+}
+
+
+gl_word_t txt_strw(gl_display_t *disp, char *str) {
+ gl_word_t pxlw = 0;
+ while (*str) {
+ pxlw += gl_charwidth(disp, (unsigned char) *str);
+ str++;
+ }
+ return pxlw;
}