//============================================================================= void lcd_option(void) { unsigned char h, m, s; unsigned char d, ms, y, dw; LCD_goto(0, 0); LCD_puts(optionmenu[o_menu]); if (o_menu == OM_SETTIME) { RTC_get_time(&h, &m, &s); LCD_goto(0, 1); print_dec(h,2,'0'); LCD_dat(':'); print_dec(m,2,'0'); LCD_dat(':'); print_dec(s,2,'0'); LCD_puts(" "); } else if (o_menu == OM_SETDATE) { RTC_get_date(&dw, &d, &ms, &y); dw = RTC_day_of_week(d, ms, y); LCD_goto(0, 1); print_dec(d,2,'0'); LCD_dat('-'); print_dec(ms,2,'0'); LCD_dat('-'); print_dec(2000 + y,4,'0'); LCD_dat(' '); LCD_dat('['); LCD_puts(den_dw[dw]); LCD_dat(']'); LCD_dat(' '); } else if (o_menu == OM_SETALARM) { LCD_goto(0, 1); print_dec(a_hour,2,'0'); LCD_dat(':'); print_dec(a_min,2,'0'); LCD_dat(':'); print_dec(a_sec,2,'0'); LCD_dat(' '); LCD_dat('-'); LCD_dat(' '); LCD_dat('['); if (a_onoff == 1) LCD_puts(" ON"); else LCD_puts("OFF"); LCD_dat(']'); } else if (o_menu == OM_SETFM) { } }
void anemo_start_count(void) { //use interrupt 4 for speed1 measurement logger.measureAverage.count_speed1 = 0; EICRA |= _BV(ISC01); // detect interrupt on INT4 on rising edge EIMSK |= _BV(INT0); // enable the interrupt on INT4 // use the timer4 to measure the frequency on TIMER1 and 3. For these timers, the input clock is use. // clear TIMER1 and 3 registers //TCNT5 = 0; //TCNT3 = 0; TCNT0 = 0; TCCR0B |= (1 << CS02) | (1 << CS00); // CCS4[2:0] use 1024 prescaler (1 << WGM42) | //TCCR5B |= _BV(CS52) | _BV(CS51) | _BV(CS50); //_BV(ICNC5) | _BV(ICES5) | // // synchronise timers // GTCCR = (1 << TSM); // GTCCR = (1 << PSRSYNC); // GTCCR = 0; // enable TIMER1, 3 and 4 interrupt //TIMSK5 |= (1 << TOIE5); // permit input clock counter, if overflow, problem // TIMSK3 |= (1 << TOIE3); // permit input clock counter, if overflow, problem TIMSK0 |= (1 << TOIE0); // start to count for TNCT4 time TCNT0_tmp = TCNT0; // use to filter the frequency in isr #ifdef DEBUG_SENSORS RTC_get_date(ptrTime); debug_printl("sensors", "anemo start",ptrTime->timestamp,1); #endif }
void anemo_read_value(Measure *_measure) { double speed; speed = adc_value(logger.inPinanemo); // map the value from 0-847 to 0-359 0,423848878394 = 359/847 to map value to change by degree factor speed = speed * 77.1667 / 1058.75; _measure->speed1 = speed ; _measure->speed1 += speed/logger.meas_max; /// return the wind speed's value #ifdef DEBUG_SENSORS RTC_get_date(ptrTime); debug_printl("sensors", "anemo read",ptrTime->timestamp,1); #endif }
//============================================================================= void run_option(unsigned char event) { switch(event) { case EVENT_TIMER_SECOND: lcd_option(); break; case EVENT_KEY_LEFT: BEEP_beep(); if (o_menu > 0) { o_menu--; } else { o_menu = OMENU_MAX; } lcd_option(); break; case EVENT_KEY_RIGHT: BEEP_beep(); if (o_menu < OMENU_MAX) { o_menu++; } else { o_menu = 0; } lcd_option(); break; case EVENT_KEY_SET: if (o_menu == OM_SETTIME) { n_edit_time = 0; RTC_get_time(&hour, &min, &sec); SET_STATE(edit_time); lcd_edit_time(); } else if (o_menu == OM_SETDATE) { n_edit_date = 0; RTC_get_date(&wday, &day, &mes, &year); wday = RTC_day_of_week(day, mes, year); SET_STATE(edit_date); lcd_edit_date(); } else if (o_menu == OM_SETALARM) { n_edit_alarm = 0; // RTC_get_alarm(&a_hour, &a_min, &a_sec); SET_STATE(edit_alarm); lcd_edit_alarm(); } else if (o_menu == OM_SETFM) { SET_STATE(edit_fmstation); lcd_edit_fmstation(); } break; case EVENT_KEY_SET_LONG: LCD_clear(); SET_STATE(run_main); RTOS_setTask(EVENT_TIMER_SECOND, 0, 0); break; } }