static void hourBeep() { static beep_state_t beep; static byte beepHour; if((timeData.mins == 0 && timeData.secs == 0) || beep != BEEP_0) { switch(beep) { case BEEP_0: if(beepHour != timeData.hours) { beepHour = timeData.hours; pwrmgr_setState(PWR_ACTIVE_HOURBEEP, PWR_STATE_IDLE); buzzer_buzz(100, TONE_2_5KHZ, VOL_HOUR); beep = BEEP_1; } break; case BEEP_1: if(!buzzer_buzzing()) { buzzer_buzz(100, TONE_3_5KHZ, VOL_HOUR); beep = BEEP_2; } break; case BEEP_2: if(!buzzer_buzzing()) { pwrmgr_setState(PWR_ACTIVE_HOURBEEP, PWR_STATE_NONE); beep = BEEP_0; } break; default: break; } } }
void display_update() { static millis8_t lastDraw; // Time of last draw static byte fpsMs; // Milliseconds to next draw // Limit frame rate millis8_t now = millis(); if((millis8_t)(now - lastDraw) < fpsMs) { pwrmgr_setState(PWR_ACTIVE_DISPLAY, PWR_STATE_IDLE); return; } lastDraw = now; debugPin_draw(HIGH); display_t busy = DISPLAY_DONE; #if COMPILE_ANIMATIONS // Update animations animation_update(); // Draw stuff if(drawFunc != NULL && (crt_anim.active || (!crt_anim.active && !crt_anim.closing))) busy = drawFunc(); // Do CRT animation if(crt_anim.active) crt_animation(); busy = busy || crt_anim.active || animation_active(); #else if(drawFunc != NULL) busy = drawFunc(); #endif if(appConfig.showFPS) { // Work out & draw FPS, add 2ms (actually 2.31ms) for time it takes to send to OLED, clear buffer etc // This is only approximate millis8_t end = millis() + ((byte)(16000000UL / F_CPU)) + 1; char buff[5]; sprintf_P(buff, PSTR("%u"), (uint)(1000 / (millis8_t)(end - now))); draw_string(buff,false,107,56); } // End drawing, send to OLED draw_end(); debugPin_draw(LOW); // Decide framerate if(busy == DISPLAY_DONE) { pwrmgr_setState(PWR_ACTIVE_DISPLAY, PWR_STATE_NONE); fpsMs = FRAME_RATE_LOW_MS; } else { pwrmgr_setState(PWR_ACTIVE_DISPLAY, PWR_STATE_IDLE); fpsMs = FRAME_RATE_MS; } }