emanuelen5 / kitchen-timer

0 stars 0 forks source link

Create button library #44

Closed nperozzi closed 4 weeks ago

nperozzi commented 3 months ago

Yeah, it would have to be put into its own file. A file that just contains the functionality for pressing the button (not anything relating to the rotation). The button can be described as a state machine, and I think that would make it a lot easier to avoid the sneaky edge conditions :)

But either way, I think we should do this in a follow-up PR. This is definitely good enough for now!

I started a sketch on the state diagram, but it became a mess. I'll have to get back to it. Leaving it here for now:

stateDiagram-v2
    state if_state1 <<choice>>
    state if_state2 <<choice>>

    [*] --> EvaluateSinglePress: PRESS
    EvaluateSinglePress --> SinglePress: [time_since_init < 500 ms] DEPRESS
    EvaluateSinglePress --> LongPress: [time of state > 2000 ms]

    state EvaluateSinglePress {
        [*] --> S1_Wait: [time_since_init <= 500 ms] DEPRESS
    }
    EvaluateSinglePress --> if_state1
    if_state1 --> SinglePress: [time_since_init > 500ms]
    if_state1 --> EvaluateDoublePress: [time_since_init <= 500ms]

    state EvaluateDoublePress {
        [*] --> S2_Wait1: [time_since_init <= 500ms] PRESS
        S2_Wait1 --> S2_Wait2: [time_since_init <= 500ms] DEPRESS
    }
    EvaluateDoublePress --> if_state2 
    if_state2 --> DoublePress: [time_since_init <= 500ms] PRESS
    if_state2 --> SinglePress: [time_since_init > 500 ms] PRESS
    if_state2 --> [*]: [time_since_init > 500 ms] DEPRESS

    SinglePress --> [*]
    DoublePress --> [*]
    LongPress --> [*]

_Originally posted by @emanuelen5 in https://github.com/emanuelen5/kitchen-timer/pull/41#discussion_r1678366517_