~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-events.c

  • Committer: Selene Scriven
  • Date: 2020-07-06 20:24:28 UTC
  • mfrom: (188.1.294 fsm)
  • Revision ID: bzr@toykeeper.net-20200706202428-7pyen2ow9q2rtd9p
merged nearly a year of updates from the fsm branch, including the new product map

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef FSM_EVENTS_C
21
21
#define FSM_EVENTS_C
22
22
 
 
23
#include <util/delay_basic.h>
 
24
 
23
25
 
24
26
void empty_event_sequence() {
25
27
    current_event = EV_none;
42
44
        // set press flag
43
45
        current_event |= B_PRESS;
44
46
        // increase click counter
45
 
        if ((current_event & B_COUNT) < (B_COUNT-1)) {
 
47
        if ((current_event & B_COUNT) < (B_COUNT)) {
46
48
            current_event ++;
47
49
        }
48
50
        return 1;  // event pushed, even if max clicks already reached
108
110
    /*  // delay_zero() implementation
109
111
    if (ms == 0) {
110
112
        CLKPR = 1<<CLKPCE; CLKPR = 0;  // full speed
111
 
        _delay_loop_2(BOGOMIPS*98/100/3);
 
113
        _delay_loop_2(BOGOMIPS*95/100/3);
112
114
        return 1;
113
115
    }
114
116
    */
118
120
        uint8_t level = actual_level;  // volatile, avoid repeat access
119
121
        if (level < QUARTERSPEED_LEVEL) {
120
122
            clock_prescale_set(clock_div_4);
121
 
            _delay_loop_2(BOGOMIPS*98/100/4);
 
123
            _delay_loop_2(BOGOMIPS*90/100/4);
122
124
        }
123
125
        //else if (level < HALFSPEED_LEVEL) {
124
126
        //    clock_prescale_set(clock_div_2);
125
 
        //    _delay_loop_2(BOGOMIPS*98/100/2);
 
127
        //    _delay_loop_2(BOGOMIPS*95/100/2);
126
128
        //}
127
129
        else {
128
130
            clock_prescale_set(clock_div_1);
129
 
            _delay_loop_2(BOGOMIPS*98/100);
 
131
            _delay_loop_2(BOGOMIPS*90/100);
130
132
        }
131
133
        // restore regular clock speed
132
134
        clock_prescale_set(clock_div_1);
134
136
        // underclock MCU to save power
135
137
        clock_prescale_set(clock_div_4);
136
138
        // wait
137
 
        _delay_loop_2(BOGOMIPS*98/100/4);
 
139
        _delay_loop_2(BOGOMIPS*90/100/4);
138
140
        // restore regular clock speed
139
141
        clock_prescale_set(clock_div_1);
140
142
        #endif  // ifdef USE_RAMPING
141
143
        #else
142
144
        // wait
143
 
        _delay_loop_2(BOGOMIPS*98/100);
 
145
        _delay_loop_2(BOGOMIPS*90/100);
144
146
        #endif  // ifdef USE_DYNAMIC_UNDERCLOCKING
145
147
 
 
148
        // run pending system processes while we wait
 
149
        handle_deferred_interrupts();
 
150
 
146
151
        if ((nice_delay_interrupt) || (old_state != current_state)) {
147
152
            return 0;  // state changed; abort
148
153
        }