I don’t know if something already exists, but simply reading your spec shows a accidental case that may be problematic: asserting that the initial state of the user input must be off.
Otherwise, you could have: (OFF), >=5 seconds ON, momentary OFF, >=5 seconds ON.
This could happen if something falls against the switch, then is momentarily jostled away before falling back to the switch.
Detecting the following sequence would be safer:
0. (OFF state initial)
= 3 seconds OFF
1-3 seconds ON.
1-3 seconds OFF.
1-3 seconds ON.
However, this has the downside that your system needs to poll the switch while the system is in the off state.
Transform the sequence slightly instead to make it easier to detect:
(OFF state initial)
1-3 seconds ON. [released too early resets back to step 1]
1-3 seconds OFF. [any press in this time resets the sequence back to start of step 2]
1-3 seconds ON. [released too early resets back to step 1]
1-3 seconds OFF. [any press in this time resets the sequence back to start of step 2]
I do wonder there are better solutions by changing how the switch is physically operated (within constraints imposed by accessibility requirements, this switch behavior could already pose challenges w/ physical accessibility).
The applications is a safety push button switch to replace conventional push button.
The accessibility requirement is to prevent a distracted, clumsy or challenged person from tuning on a machine by its push button by accident.
A company which makes heavy equipment reached out to me, because it can be very dangerous turning on heavy equipment by accident. It will take a sequence to turn the machine off and a single press to turn it off.
If I am building it I will not poll. I will use state timers. This can be constructed of logic gates for the states and an analog timer.
(OFF state initial) Switch state is OFF and Machine is OFF
1-3 seconds ON. [released too early resets back to step 1]
1-3 seconds OFF. [any press in this time resets the sequence back to start of step 1]
1-3 seconds ON. [released too early resets back to step 1]
The switch state if OFF and the Machine is ON
5) OFF [any press in this time resets the sequence back to step 1]
It is also an extension of the accessibility workshop last weekend.
Or alternatively (and more commonly), e-stop buttons made for machinery locks in an off state, and require the user to physically turn the button before it pops back up to close the circuit.
Your proposal of:
1. (OFF state initial) Switch state is OFF and Machine is OFF
2. 1-3 seconds ON. [released too early resets back to step 1]
3. 1-3 seconds OFF. [any press in this time resets the sequence back to start of step 1]
4. 1-3 seconds ON. [released too early resets back to step 1]
Still has the same problem as before: how do you ensure that the initial state was NOT a momentary state? This is why I transformed the OFF/ON/OFF/ON detecting ON/OFF/ON/OFF.
Also meant to say that you need to detect the ON states not being held for more than the 3 seconds in your reset.