static inline void hslToRgb(double h, double s, double l, double *r, double *g, double *b) { double m1, m2; // TODO h2rgb( h, r, g, b ); h *= 6.0; if ( l <= 0.5 ) m2 = l * ( 1.0 + s ); else m2 = l + s * ( 1.0 - l ); m1 = 2.0 * l - m2; *r = h2c( h + 2.0, m1, m2 ); *g = h2c( h, m1, m2 ); *b = h2c( h - 2.0, m1, m2 ); }
// time output debug function void sprint_time(tstruct *t, char *tstr) { uint8_t ptr = 0; switch (t->dayow) { case 0: tstr[ptr++]='P'; tstr[ptr++]='o'; break; case 1: tstr[ptr++]='U'; tstr[ptr++]='t'; break; case 2: tstr[ptr++]='S'; tstr[ptr++]='t'; break; case 3: tstr[ptr++]='C'; tstr[ptr++]='t'; break; case 4: tstr[ptr++]='P'; tstr[ptr++]='a'; break; case 5: tstr[ptr++]='S'; tstr[ptr++]='o'; break; case 6: tstr[ptr++]='N'; tstr[ptr++]='e'; break; default: tstr[ptr++]='-'; tstr[ptr++]='-'; break; } tstr[ptr++]=' '; tstr[ptr++]=h2c(t->hour/10); tstr[ptr++]=h2c(t->hour%10); tstr[ptr++]=':'; tstr[ptr++]=h2c(t->minute/10); tstr[ptr++]=h2c(t->minute%10); tstr[ptr++]=':'; tstr[ptr++]=h2c(t->second/10); tstr[ptr++]=h2c(t->second%10); tstr[ptr++]='\0'; }
// main program body int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT board_init(); // init dco and leds lcm_init(); // lcd rtc_timer_init(); // init 32kHz timer uart_init(); // init uart (communication) //buttons_init(); // buttons dcf77_init(); // dcf77 receiver #if DCF77_DEBUG lcm_goto(0,0); lcm_prints("DCF"); #endif while(1) { __bis_SR_register(CPUOFF + GIE); // enter sleep mode (leave on rtc second event) tstruct tnow; rtc_get_time(&tnow); char tstr[16]; sprint_time(&tnow,tstr); lcm_goto(1,0); lcm_prints(tstr); str_add_lineend(tstr,16); uart_puts(tstr); uint8_t b=get_button(); if (b) { /*lcm_goto(0,3); tstr[0]='0'+b; tstr[1]='\0'; lcm_prints(tstr);*/ if (b==3) // test rtc set function { tnow.second = 0; tnow.minute = 33; tnow.hour = 22; tnow.dayow = 2; rtc_set_time(&tnow); } } #if DCF77_DEBUG // dcf if (symbol_ready) { int ci=0; lcm_goto(0,3); tstr[ci++]=h2c(tunestatus); tstr[ci++]=' '; tstr[ci++]=h2c(last_symbol); tstr[ci++]=' '; tstr[ci++]=h2c((int)last_Q/100%10); tstr[ci++]=h2c((int)last_Q/10%10); tstr[ci++]=h2c((int)last_Q%10); tstr[ci++]=' '; tstr[ci++]=h2c((int)(finetune>>12)); tstr[ci++]=h2c((int)(finetune>>8)&0x0F); tstr[ci++]=h2c((int)(finetune>>4)&0x0F); tstr[ci++]=h2c((int)(finetune&0x0F)); tstr[ci++]='\0'; lcm_prints(tstr); symbol_ready = false; } #endif } return -1; }