Example #1
0
def just_passed_break_time():
    global isPastBreakTime
    if isPastBreakTime:
        return

    leff.start(leff.PAST_BREAK)
    isPastBreakTime = True
Example #2
0
def entering_overtime():
    global inOverTime
    if inOverTime:
        return

    leff.start(leff.ENTERING_OVERTIME)
    inOverTime = True
Example #3
0
def start_sprint(sprintLength, buttonTimeHeld):
    global inSprint, startTimes, objectiveTimes
    if inSprint and not inInterruption:
        end_sprint()

    if not inSession:
        if buttonTimeHeld > (c.FLICKERING_TOLERANCE +
                             c.START_SESSION_TOLERANCE):
            start_session()
        else:
            return  # no E&M interference starting midnight sessions lol

    if inBreak:
        end_break()

    inSprint = True

    if inInterruption:
        end_interruption()
    else:
        time.sleep(0.0085)  # in case thread taking time to boot
        startTimes[SPRINT] = time.time()
        objectiveTimes[SPRINT] = startTimes[SPRINT] + sprintLength

    leff.start(leff.START_SPRINT)
Example #4
0
def woke_up():
    global hasWokeUp, isDisplayingWakeUp
    if hasWokeUp:
        return
    hasWokeUp = True
    isDisplayingWakeUp = False
    now = get_localized_time()
    dt = get_localized_time() - wakeTimeTomorrow
    alarmlessWakeTime = wakeTimeTomorrow + timedelta(
        seconds=c.MORNING_FORGOT_TO_HIT_BUTTON_GRACE_PERIOD)
    displayFunction = None
    funcInput = None
    if now < alarmlessWakeTime:
        displayFunction = oc.display_int
        funcInput = 100
    else:
        displayFunction = oc.display_and_format_seconds
        funcInput = dt.seconds

    if now < wakeTimeTomorrow + c.MORNING_WAKE_EFFECT_LENGTH:
        leff.start(leff.MORNING_CONGRATULATIONS_BIG)
    else:
        leff.start(leff.MORNING_CONGRATULATIONS)

    t = threading.Thread(target=__woke_up_thread,
                         args=(displayFunction, funcInput))
    t.start()
def debug_press(channel):
    global currEffect
    print(f'Current Effect: {int(round(currEffect))}')
    leff.start(int(round(currEffect)))
    currEffect += 0.5
    if currEffect == leff.DEMO_MODE:
        currEffect = 0
    time.sleep(0.5)
Example #6
0
def activate_bedtime_siren_protocol():
    global isBedtimeSirenProtocolEnabled
    dt = get_localized_time() - bedtimeTonight
    oc.display_and_format_seconds_into_minutes(dt.seconds)

    if isBedtimeSirenProtocolEnabled:
        return
    isBedtimeSirenProtocolEnabled = True
    leff.start(leff.PAST_BEDTIME)
Example #7
0
def activate_bedtime_countdown():
    global isDisplayingBedtimeCountdown
    dt = bedtimeTonight - get_localized_time()
    oc.display_and_format_seconds(dt.seconds)

    if isDisplayingBedtimeCountdown:
        return
    isDisplayingBedtimeCountdown = True
    leff.start(leff.BEDTIME_COUNTDOWN)
Example #8
0
def abort_bedtime_protocol():
    global recordedAbortTime, abortBedtimeDate
    global isDisplayingBedtime, isDisplayingBedtimeCountdown, isBedtimeSirenProtocolEnabled
    isDisplayingBedtime = isDisplayingBedtimeCountdown = isBedtimeSirenProtocolEnabled = False
    recordedAbortTime = get_localized_time()

    abortBedtimeDate = bedtimeTonight.date()

    leff.start(leff.ABORT_BEDTIME_PROTOCOL)
    oc.clear_clock()
    oc.set_clock_brightness(c.CLOCK_BRIGHTNESS)
Example #9
0
def bedtime():
    global recordedBedtime, bedtimeDate
    global isDisplayingBedtime, isDisplayingBedtimeCountdown, isBedtimeSirenProtocolEnabled
    isDisplayingBedtime = isDisplayingBedtimeCountdown = isBedtimeSirenProtocolEnabled = False
    recordedBedtime = get_localized_time()

    bedtimeDate = bedtimeTonight.date()

    leff.start(leff.BEDTIME)
    t = threading.Thread(target=flash_bedtime_then_sleep, args=[])
    t.start()
Example #10
0
def end_interruption():
    global inInterruption, interruptionDelay
    inInterruption = False
    interruptionDelay += time.time() - startTimes[INTERRUPTION]

    if isPastBreakTime:
        leff.start(leff.PAST_BREAK)
    elif inBreak:
        oc.override_light_calib_rgba(c.BREAK_L_B)
    elif inOverTime:
        leff.start(leff.ENTERING_OVERTIME)
    elif inSprint:
        oc.override_light_calib_rgba(c.SPRINT_L_B)
    else:
        oc.override_light_calib_rgba((0, 0, 0, 0))
Example #11
0
def __end_session_thread():
    global inSession
    leff.start(leff.END_SESSION)
    time.sleep(2.5)
    if not isDislayingStats:
        oc.clear_clock()
    time.sleep(5.5)

    if inSprint or inBreak:
        return  # a new one was started during shutdown lol

    inSession = False

    bp.isDisplayingBedtime = False
    bp.isDisplayingBedtimeCountdown = False
    bp.isBedtimeSirenProtocolEnabled = False
def update_button_logic():
    global isButtonHoldsEnabled, inDemoMode

    if not bl.isGreenPressed and not bl.isYellowPressed and not bl.isRedPressed:
        isButtonHoldsEnabled = True

    if isButtonHoldsEnabled:

        if bl.greenTimeHeld > c.QUICK_SPRINT_HOLD_TIME and bl.isOneButtonPressed(
        ):
            sm.start_sprint(c.QUICK_SPRINT_LENGTH)
            disable_all_button_holds_until_all_released()

        if sm.inSession:

            if bl.yellowTimeHeld > c.LONG_BREAK_HOLD_TIME and bl.isOneButtonPressed(
            ):
                sm.start_break(c.LONG_BREAK_LENGTH)
                disable_all_button_holds_until_all_released()

            if bl.greenTimeHeld > c.END_SESSION_HOLD_TIME and bl.yellowTimeHeld > c.END_SESSION_HOLD_TIME:
                sm.end_session()
                disable_all_button_holds_until_all_released()

        else:

            if bl.yellowTimeHeld > c.BEDTIME_SHUTDOWN_HOLD_TIME and bl.isOneButtonPressed(
            ):
                bp.bedtime()
                disable_all_button_holds_until_all_released()

            if bl.redTimeHeld > c.ABORT_BEDTIME_PROTOCOL_HOLD_TIME and bl.isOneButtonPressed(
            ):
                bp.abort_bedtime_protocol()
                disable_all_button_holds_until_all_released()

            if bl.greenTimeHeld > c.DEMO_MODE_HOLD_TIME and bl.yellowTimeHeld > c.DEMO_MODE_HOLD_TIME and bl.redTimeHeld > c.DEMO_MODE_HOLD_TIME:
                leff.start(leff.DEMO_MODE)
                inDemoMode = True
                print("DEMO MODE")
                disable_all_button_holds_until_all_released()
Example #13
0
def start_break(breakLength):
    global inBreak, startTimes, objectiveTimes
    statsCorrection = 0
    if inBreak and not inInterruption:
        end_break()
        statsCorrection = c.END_STATS_DISPLAY_LENGTH
        # if a new break is started, then no need for the
        # extra time to show end sprint stats
    inBreak = True

    if inSprint:
        end_sprint()

    if inInterruption:
        end_interruption()
    else:
        startTimes[BREAK] = time.time()
        objectiveTimes[
            BREAK] = startTimes[BREAK] + breakLength - statsCorrection

    leff.start(leff.START_BREAK)
Example #14
0
def start_interruption():
    global inInterruption, startTimes
    inInterruption = True
    startTimes[INTERRUPTION] = time.time()
    leff.start(leff.START_INTERRUPTION)
import datetime

logging.basicConfig(filename='app.log',
                    filemode='w',
                    format='%(name)s - %(levelname)s - %(message)s')

light_effects.turnOff()

# on boot safety in case I reboot at 11:30 lol
bedtime_protocol.calculate_sunrise_of_tomorrow_and_bedtime()
bedtime_protocol.update_bedtime_protocol()

if c.TZ.localize(datetime.datetime.now()) > bedtime_protocol.bedtimeTonight:
    bedtime_protocol.abort_bedtime_protocol()
else:
    light_effects.start(light_effects.END_SESSION)  # boot colors


def main():
    print("started successfully!")

    while (True):
        startTime = time.time()

        button_listener.listen_to_the_buttons()
        button_logic.update_button_logic()

        session_manager.update_session_manager()
        bedtime_protocol.update_bedtime_protocol()

        light_effects.update_light_effects()