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