76
76
******************************************************************************/
80
78
#include "config.h"
82
#include "mode_switcher.h"
82
#include "switcher_major_mode.h"
83
83
#include "drawer.h"
85
86
//_____________________________________________________________________________
101
102
static unsigned long segment_step_sub_step = 0;
102
103
static unsigned long segment_step_sub = 0;
104
// flag to indicate that the drawing mode should be cycled to the next one
105
static bool inc_draw_mode = false;
107
// a bounce-managed button
108
106
static Button button( 3 );
109
static int major_mode = 0;
111
#define MAX_MAJOR_MODES 5
114
static MajorMode *major_modes[ MAX_MAJOR_MODES ] = { 0 };
110
116
//_____________________________________________________________________________
114
// check for button presses
120
// perform button events
121
void doButtonEvents()
118
int event = button.update();
123
inc_draw_mode = true;
123
// loop through pending events
124
while( int event = button.get_event() )
130
major_modes[ major_mode ]->press();
135
major_modes[ major_mode ]->long_press();
139
// looooong press (change major mode)
141
if( ++major_mode >= MAX_MAJOR_MODES )
143
} while( major_modes[ major_mode ] == NULL );
144
major_modes[ major_mode ]->activate();
129
// turn an led on/off
130
void ledOn( int num, bool on )
132
if( num < 0 || num > 9 ) return;
134
// convert to pin no.
137
// pin 4 needs to be inverted (it's driving a PNP)
138
if( num == 4 ) on = !on;
140
digitalWrite( num, on? HIGH : LOW );
144
152
// draw a display segment
145
153
void drawNextSegment( bool reset )
147
static ModeSwitcher mode_switcher;
148
static bool init = false;
152
mode_switcher.activate();
155
155
// keep track of segment
156
156
#if CLOCK_FORWARD
157
157
static int segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
249
249
// set up mode-switch button on pin 3
250
250
pinMode( 3, INPUT );
251
251
digitalWrite( 3, HIGH );
252
button.add_event_at( 5, 1 );
253
button.add_event_at( 1000, 2 );
254
button.add_event_at( 4000, 3 );
252
static int event_times[] = { 5, 500, 4000, 0 };
253
button.set_event_times( event_times );
257
Serial.begin( 9600 );
255
// set up major modes
256
static SwitcherMajorMode switcher_major_mode;
258
major_modes[ mode++ ] = &switcher_major_mode;
259
major_modes[ 0 ]->activate();
264
266
// if there has been a new pulse, we'll be resetting the display
265
267
bool reset = new_pulse_at? true : false;
267
272
// only do this stuff at the start of a display cycle, to ensure
268
273
// that no state changes mid-display
276
// calculate segment times
277
calculateSegmentTimes();
274
279
// keep track of time
275
280
Time &time = Time::get_instance();
283
// perform button events
279
287
// draw this segment
280
288
drawNextSegment( reset );
282
// do we need to recalculate segment times?
284
calculateSegmentTimes();
286
290
// wait till it's time to draw the next segment
287
waitTillNextSegment( reset );
291
waitTillEndOfSegment( reset );