~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/spaghetti-monster.txt

merged recent fsm branch updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
        entering the state.  When 'arg' exceeds 65535, it wraps around 
113
113
        to 32768.
114
114
 
 
115
      - EV_sleep_tick: This happens every 0.5s during standby, if 
 
116
        enabled at compile time.  The 'arg' is the number of ticks since 
 
117
        entering the state.  When 'arg' exceeds 65535, it wraps around 
 
118
        to 32768.
 
119
 
115
120
    LVP and thermal regulation:
116
121
 
117
122
      - EV_voltage_low: Sent whenever the input power drops below the 
130
135
 
131
136
    Button presses:
132
137
 
133
 
      - EV_1click: The user clicked the e-switch, released it, and 
134
 
        enough time passed that no more clicks were detected.
135
 
 
136
 
      - EV_2clicks: The user clicked and released the e-switch twice, then 
137
 
        enough time passed that no more clicks were detected.
138
 
 
139
 
      - EV_3clicks: The user clicked and released the e-switch three 
140
 
        times, then enough time passed that no more clicks were detected.
141
 
 
142
 
      - EV_4clicks: The user clicked and released the e-switch four times, 
143
 
        then enough time passed that no more clicks were detected.
144
 
 
145
 
      - EV_click1_hold: The user pressed the button and is still holding 
146
 
        it.  The 'arg' indicates how many clock ticks since the "hold" 
147
 
        state started.
148
 
 
149
 
      - EV_click1_hold_release: The user pressed the button, held it for a 
150
 
        while, and then released it.  No timeout is attempted after this.
151
 
 
152
 
      - EV_click2_hold: The user clicked once, then pressed the button and 
153
 
        is still holding it.  The 'arg' indicates how many clock ticks 
154
 
        since the "hold" state started.
155
 
 
156
 
      - EV_click2_hold_release: The user clicked once, then pressed the 
157
 
        button, held it for a while, and released it.  No timeout is 
158
 
        attempted after this.
159
 
 
160
 
      - EV_click1_press: The user pressed the button and it's still down.  
161
 
        No time has yet passed.
162
 
 
163
 
      - EV_click1_release: The user quickly pressed and released the 
164
 
        button.  The click timeout has not yet expired, so they might 
165
 
        still click again.
166
 
 
167
 
      - EV_click2_press: The user pressed the button, released it, pressed 
168
 
        again, and it's still down.  No time has yet passed since then.
169
 
 
170
 
      - EV_click2_release: The quickly pressed and released the button 
171
 
        twice.  The click timeout has not yet expired, so they might still 
172
 
        click again.
 
138
      Button events can be referred to either by pre-defined symbols, or 
 
139
      by teasing out the flags manually.  The structure of a button 
 
140
      event is as follows:
 
141
 
 
142
        - Bit 7: 1 for button events, 0 otherwise.
 
143
 
 
144
        - Bit 6: 1 for a "timeout" event (signals the end of a 
 
145
          sequence), or 0 otherwise.
 
146
 
 
147
        - Bit 5: 1 for a "hold" event, 0 otherwise.  This flag is only 
 
148
          necessary because, without it, it would be impossible to 
 
149
          distinguish between "click, click, timeout" and "click, hold, 
 
150
          release".
 
151
 
 
152
        - Bit 4: 1 if button is currently pressed, 0 otherwise.  Button 
 
153
          release events look just like button press events, except this 
 
154
          is not set.
 
155
 
 
156
        - Bits 0,1,2,3: Counter for how many clicks there have been.  
 
157
          The first click is 1, second is 2, and it goes up to 15 clicks 
 
158
          in a row.  Clicks after 15 are coded as 15.
 
159
 
 
160
      The pre-defined button event symbols are like the following:
 
161
 
 
162
        - EV_click1_press: The user pressed the button, but no time has 
 
163
          passed since then.
 
164
 
 
165
        - EV_click1_release: The user pressed and released the button, 
 
166
          but no time has passed since then.
 
167
 
 
168
        - EV_click1_complete: The user clicked the e-switch, released 
 
169
          it, and enough time passed that no more clicks were detected.
 
170
          (a.k.a. EV_1click)
 
171
 
 
172
        - EV_click1_hold: The user pressed the button, and continued 
 
173
          holding it long enough to count as a "hold" event.  This event 
 
174
          is sent once per timer tick as long as the button is held, and 
 
175
          the 'arg' value indicates how many timer ticks since the 
 
176
          button state went from 'press' to 'hold'. 
 
177
 
 
178
        - EV_click1_hold_release: The button was released at the end of 
 
179
          a "hold" event.  This is the end of the input sequence, 
 
180
          because no timeout period is used after a hold.
 
181
 
 
182
          It's worth noting that a "hold" event can only happen at the 
 
183
          end of an input sequence, and the sequence will reset to empty 
 
184
          after the hold is released.
 
185
 
 
186
      If the user pressed the button more than once, events follow the 
 
187
      same pattern.  These are the same as above, except with a full 
 
188
      short-press and release first.
 
189
 
 
190
        - EV_click2_press
 
191
        - EV_click2_release
 
192
        - EV_click2_complete (a.k.a. EV_2clicks)
 
193
        - EV_click2_hold
 
194
        - EV_click2_hold_release
 
195
 
 
196
      Each of the above patterns continues up to 15 clicks.
 
197
 
 
198
      To match entire categories of events, use the bitmasks provided.  
 
199
      For example, to match button events where the button is down or 
 
200
      the button is up, the code would look like this:
 
201
 
 
202
        if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) {
 
203
          // button is down (can be a press event or a hold event)
 
204
        }
 
205
        else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
 
206
          // button was just released
 
207
        }
173
208
 
174
209
  In theory, you could also define your own arbitrary event types, and 
175
210
  emit() them as necessary, and handle them in State functions the same 
176
211
  as any other event.
177
212
 
178
 
  One thing to note if you create your own Event types:  The copy which 
179
 
  gets sent to States must be in the 'event_sequences' array, meaning 
180
 
  the State gets a const PROGMEM version of the Event.  It cannot simply 
181
 
  send the dynamic 'current_event' object, because it has probably 
182
 
  already changed by the time the callback happens.
183
 
 
184
213
 
185
214
Cooperative multitasking:
186
215
 
287
316
      becomes a "click" event?  Basically, the maximum time between 
288
317
      clicks in a double-click or triple-click.
289
318
 
290
 
    - MAX_CLICKS N: Convenience define to limit the size of the 
291
 
      recognized Event arrays.  Click sequences longer than N won't be 
292
 
      recognized or sent to State functions.
293
 
 
294
319
    - USE_BATTCHECK: Enable the battcheck function.  Also define one of 
295
320
      the following to select a display style:
296
321