+/EE445L

embedded systems

git clone https://git.julia.blue/+/EE445L

Joseph RyanChange draw order to remove artifactsef2ae2d

master
3.3 KiB103 linesraw
1#include "display.h"
2#include "LED.h"
3#include "ST7735.h"
4#include "graphics.h"
5#include <math.h>
6
7const float PI = 3.141592653589793238462643383;
8
9void display_init() {
10    Output_Init();
11    draw_circle(64, 96, 63, ST7735_Color565(255, 255, 255));
12}
13
14int hours(int t) {
15    return (t / 3600) % 24;
16}
17
18int minutes(int t) {
19    return (t / 60) % 60;
20}
21
22int seconds(int t) {
23    return t % 60;
24}
25
26char* time_str(uint32_t t) {
27    static char buf[9];
28    buf[0] = hours(t) / 10 + '0';
29    buf[1] = hours(t) % 10 + '0';
30    buf[2] = ':';
31    buf[3] = minutes(t) / 10 + '0';
32    buf[4] = minutes(t) % 10 + '0';
33    buf[5] = ':';
34    buf[6] = seconds(t) / 10 + '0';
35    buf[7] = seconds(t) % 10 + '0';
36    return buf;
37}
38
39char* time_str_nosec(uint32_t t) {
40    static char buf[9];
41    buf[0] = hours(t) / 10 + '0';
42    buf[1] = hours(t) % 10 + '0';
43    buf[2] = ':';
44    buf[3] = minutes(t) / 10 + '0';
45    buf[4] = minutes(t) % 10 + '0';
46
47    return buf;
48}
49
50void render_alarm(uint32_t a, int enabled) {
51    ST7735_DrawString(7, 1, time_str_nosec(a), ST7735_RED);
52    if (enabled)
53        ST7735_DrawString(15, 1, "on ", ST7735_RED);
54    else
55        ST7735_DrawString(15, 1, "off", ST7735_Color565(200, 123, 123));
56}
57
58void render_time(uint32_t t) {
59    static int old_secx, old_secy, old_minx, old_miny, old_hourx, old_houry;
60    LED_RedToggle();
61    LED_RedToggle();
62
63    uint32_t sec_hand_color = ST7735_Color565(255, 0, 0);
64    uint32_t min_hand_color = ST7735_Color565(123, 234, 15);
65    uint32_t hour_hand_color = ST7735_Color565(180, 170, 160);
66
67    int sec_hand_len = 57;
68    int min_hand_len = 51;
69    int hour_hand_len = 38;
70
71    int secx = cosf(-PI / 2 + (2 * PI / 60) * seconds(t)) * sec_hand_len;
72    int secy = sinf(-PI / 2 + (2 * PI / 60) * seconds(t)) * sec_hand_len;
73    int minx = cosf(-PI / 2 + (2 * PI / 60) * minutes(t)) * min_hand_len;
74    int miny = sinf(-PI / 2 + (2 * PI / 60) * minutes(t)) * min_hand_len;
75    int hourx = cosf(-PI / 2 + (2 * PI / 24) * hours(t)) * hour_hand_len;
76    int houry = sinf(-PI / 2 + (2 * PI / 24) * hours(t)) * hour_hand_len;
77    ST7735_SetTextColor(ST7735_YELLOW);
78    ST7735_SetCursor(7, 0);
79    ST7735_OutString(time_str(t));
80    draw_line(64, 96, 64 + old_secx, 96 + old_secy, 0);
81    draw_line(64, 96, 64 + old_minx, 96 + old_miny, 0);
82    draw_line(63, 96, 63 + old_hourx, 96 + old_houry, 0);
83    draw_line(65, 96, 65 + old_hourx, 96 + old_houry, 0);
84    draw_line(64, 95, 64 + old_hourx, 95 + old_houry, 0);
85    draw_line(64, 97, 64 + old_hourx, 97 + old_houry, 0);
86    draw_line(64, 96, 64 + old_hourx, 96 + old_houry, 0);
87    ST7735_DrawString(10, 4, "12", ST7735_YELLOW);
88    ST7735_DrawString(10, 14, "6", ST7735_YELLOW);
89    ST7735_DrawString(1, 9, "9", ST7735_YELLOW);
90    ST7735_DrawString(19, 9, "3", ST7735_YELLOW);
91    draw_line(64, 96, 64 + hourx, 96 + houry, hour_hand_color);
92    draw_line(63, 96, 63 + hourx, 96 + houry, hour_hand_color);
93    draw_line(65, 96, 65 + hourx, 96 + houry, hour_hand_color);
94    draw_line(64, 95, 64 + hourx, 95 + houry, hour_hand_color);
95    draw_line(64, 97, 64 + hourx, 97 + houry, hour_hand_color);
96    draw_line(64, 96, 64 + minx, 96 + miny, min_hand_color);
97    draw_line(64, 96, 64 + secx, 96 + secy, sec_hand_color);
98    old_secx = secx, old_secy = secy;
99    old_minx = minx, old_miny = miny;
100    old_hourx = hourx, old_houry = houry;
101
102    LED_RedToggle();
103}