/** Handles up or down button click while in main window. Use this click to start or restart a cycle. */ void pomOnMainWindowUpOrDownClick(ClickRecognizerRef recognizer, void *context) { if (app.timer.state == PomStateReady) { pomSetState(PomStateWorking); } else { pomSetState(PomStateReady); } }
/** Tick handler. Called every second. Also called on the minute for "heartbeat" working reminders. */ void pomOnTick(struct tm *tick_time, TimeUnits units_changed) { if (app.timer.state == PomStateReady) return; app.ticksRemaining--; // check for time up // Note: because this returns, you have an extra second to see the change over. feature, not a bug. if (app.ticksRemaining < 0) { if (app.timer.state == PomStateWorking) { // you finished the pomodoro! congrats! app.timer.completedPoms++; if (app.timer.lastPomHour < 6 && tick_time->tm_hour >= 6) { app.timer.completedPoms = 0; } app.timer.lastPomHour = tick_time->tm_hour; vibes_short_pulse(); light_enable_interaction(); pomSetState(PomStateResting); return; } else if (app.timer.state == PomStateResting) { // time to start another pomodoro. vibes_enqueue_custom_pattern(VIBRATE_DIT_DIT_DAH); light_enable_interaction(); pomSetState(app.settings.autoContinue? PomStateWorking : PomStateReady); return; } } bool isWorking = (app.timer.state == PomStateWorking); // bool isResting = (app.timer.state == PomStateResting); // heartbeat if (isWorking && app.settings.vibrateWhileWorking && (app.ticksRemaining % app.settings.vibrateTicks) == 0) { vibes_enqueue_custom_pattern(VIBRATE_MINIMAL); } // TODO resize inverter /* float pctRemaining = (app.ticksRemaining + 0.0) / app.totalTicks; GRect inverterFrame = GRect(0, 0, windowSize.w, 0); if (isWorking) { inverterFrame.size.h = (1.0 - pctRemaining) * windowSize.h; } else if (isResting) { inverterFrame.size.h = pctRemaining * windowSize.h; } layer_set_frame(inverter_layer_get_layer(app.inverterLayer), inverterFrame); */ // set timer text formatTime(gTimeString, app.ticksRemaining); text_layer_set_text(app.timeTextLayer, gTimeString); // redraw! layer_mark_dirty(window_get_root_layer(app.mainWindow)); }
/** Window unload handler for settings window. */ void pomOnMenuWindowUnload(struct Window *menuWindowRef) { pomSaveCookies(); pomSetState(app.state); //redraw in case language changed }