#include "display.h" #include "LED.h" #include "ST7735.h" #include "graphics.h" #include const float PI = 3.141592653589793238462643383; void display_init() { Output_Init(); draw_circle(64, 96, 63, ST7735_Color565(255, 255, 255)); } int hours(int t) { return (t / 3600) % 24; } int minutes(int t) { return (t / 60) % 60; } int seconds(int t) { return t % 60; } char* time_str(uint32_t t) { static char buf[9]; buf[0] = hours(t) / 10 + '0'; buf[1] = hours(t) % 10 + '0'; buf[2] = ':'; buf[3] = minutes(t) / 10 + '0'; buf[4] = minutes(t) % 10 + '0'; buf[5] = ':'; buf[6] = seconds(t) / 10 + '0'; buf[7] = seconds(t) % 10 + '0'; return buf; } char* time_str_nosec(uint32_t t) { static char buf[9]; buf[0] = hours(t) / 10 + '0'; buf[1] = hours(t) % 10 + '0'; buf[2] = ':'; buf[3] = minutes(t) / 10 + '0'; buf[4] = minutes(t) % 10 + '0'; return buf; } void render_alarm(uint32_t a, int enabled) { ST7735_DrawString(7, 1, time_str_nosec(a), ST7735_RED); if (enabled) ST7735_DrawString(15, 1, "on ", ST7735_RED); else ST7735_DrawString(15, 1, "off", ST7735_Color565(200, 123, 123)); } void render_time(uint32_t t) { static int old_secx, old_secy, old_minx, old_miny, old_hourx, old_houry; LED_RedToggle(); LED_RedToggle(); uint32_t sec_hand_color = ST7735_Color565(255, 0, 0); uint32_t min_hand_color = ST7735_Color565(123, 234, 15); uint32_t hour_hand_color = ST7735_Color565(180, 170, 160); int sec_hand_len = 57; int min_hand_len = 51; int hour_hand_len = 38; int secx = cosf(-PI / 2 + (2 * PI / 60) * seconds(t)) * sec_hand_len; int secy = sinf(-PI / 2 + (2 * PI / 60) * seconds(t)) * sec_hand_len; int minx = cosf(-PI / 2 + (2 * PI / 60) * minutes(t)) * min_hand_len; int miny = sinf(-PI / 2 + (2 * PI / 60) * minutes(t)) * min_hand_len; int hourx = cosf(-PI / 2 + (2 * PI / 24) * hours(t)) * hour_hand_len; int houry = sinf(-PI / 2 + (2 * PI / 24) * hours(t)) * hour_hand_len; ST7735_SetTextColor(ST7735_YELLOW); ST7735_SetCursor(7, 0); ST7735_OutString(time_str(t)); draw_line(64, 96, 64 + old_secx, 96 + old_secy, 0); draw_line(64, 96, 64 + old_minx, 96 + old_miny, 0); draw_line(63, 96, 63 + old_hourx, 96 + old_houry, 0); draw_line(65, 96, 65 + old_hourx, 96 + old_houry, 0); draw_line(64, 95, 64 + old_hourx, 95 + old_houry, 0); draw_line(64, 97, 64 + old_hourx, 97 + old_houry, 0); draw_line(64, 96, 64 + old_hourx, 96 + old_houry, 0); ST7735_DrawString(10, 4, "12", ST7735_YELLOW); ST7735_DrawString(10, 14, "6", ST7735_YELLOW); ST7735_DrawString(1, 9, "9", ST7735_YELLOW); ST7735_DrawString(19, 9, "3", ST7735_YELLOW); draw_line(64, 96, 64 + hourx, 96 + houry, hour_hand_color); draw_line(63, 96, 63 + hourx, 96 + houry, hour_hand_color); draw_line(65, 96, 65 + hourx, 96 + houry, hour_hand_color); draw_line(64, 95, 64 + hourx, 95 + houry, hour_hand_color); draw_line(64, 97, 64 + hourx, 97 + houry, hour_hand_color); draw_line(64, 96, 64 + minx, 96 + miny, min_hand_color); draw_line(64, 96, 64 + secx, 96 + secy, sec_hand_color); old_secx = secx, old_secy = secy; old_minx = minx, old_miny = miny; old_hourx = hourx, old_houry = houry; LED_RedToggle(); }