Conversation
|
Q1: when this is useful? you have an example? Q2: this is the only place where the magic state number used as a value, but setting it to I think it would better test for |
|
Thanks for taking a look at this and asking the questions. Is this useful? Do I have an example?I am using it in this code here. This is part of an application released here. It runs on hardware with six buttons. Three are on/off keys (k1, k2, k3) and three are rotating encoders (e1, e2, e3). The application allows the user to record music, stop, play and move the record/play head backwards and forwards. It is ideal for a finite state machine. One scenario for this application is that the user may be recording, realise they've made a mistake, and want to restart the recording immediately. I want them to be able to do this by simply hitting "record" again, not by having to hit "stop" first. Then if they do go from the record state to the record state (which I want to allow) the application has to tidy up from their first recording (a call to the Can we do better than using a magic state
|
s:record -> e:k2_long_press -> s:restart_record -> e:restart -> s:record
|
I don't know if you're still maintaining this, but I have found this addition useful. It does not change any existing defined behaviour, and it adds (what I think is) useful behaviour.
This change allows the user to define an event from and to the same state, while also ensuring all the callbacks get called. It preserves the existing behaviour of an event which has a
fromstate but notostate, which returns aNO_TRANSITION.