I've been playing with the Atreus firmware trying to change layers by hold,
click or double-click the 'fn' key.
Implementing the logic by hand with 'ifs', 'elses' and state variables was
prone to errors and strange behaviours.
Then I tried with Ragel, a state machine compiler. And It worked!
I've been able to expand the previous logic, like going to 'Hold' layer
from any previous state, without any problem.
The firmware has several customizations, it came from a fork with logic to
use LEDs as layer indicators. All the Ragel logic is in the
You can see the code in