/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/propeller-clock.ino

  • Committer: edam
  • Date: 2012-02-25 14:54:33 UTC
  • Revision ID: edam@waxworlds.org-20120225145433-kih8qs45x05cum46
removed Bounce library and updated/fixed new code

Show diffs side-by-side

added added

removed removed

75
75
 
76
76
******************************************************************************/
77
77
 
78
 
 
79
 
#include <button.h>
 
78
#include "button.h"
80
79
#include "config.h"
81
80
#include "time.h"
82
81
#include "mode_switcher.h"
101
100
static unsigned long segment_step_sub_step = 0;
102
101
static unsigned long segment_step_sub = 0;
103
102
 
104
 
// flag to indicate that the drawing mode should be cycled to the next one
105
 
static bool inc_draw_mode = false;
106
 
 
107
 
// a bounce-managed button
 
103
// the button
108
104
static Button button( 3 );
109
105
 
 
106
// major mode
 
107
static int major_mode = 0;
 
108
 
 
109
// major modes
 
110
static std::vector< MajorMode * > major_modes;
 
111
 
110
112
//_____________________________________________________________________________
111
113
//                                                                         code
112
114
 
120
122
        // handle any events
121
123
        switch( event ) {
122
124
        case 1:
123
 
                inc_draw_mode = true;
 
125
                major_modes[ major_mode ]->short_press();
 
126
                break;
 
127
        case 2:
 
128
                major_modes[ major_mode ]->long_press();
 
129
                break;
 
130
        case 3:
 
131
                if( ++major_mode >= major_modes.size() )
 
132
                        major_mode = 0;
 
133
                major_modes[ major_mode ]->activate();
124
134
                break;
125
135
        }
126
136
}
127
137
 
128
138
 
129
 
// turn an led on/off
130
 
void ledOn( int num, bool on )
131
 
{
132
 
        if( num < 0 || num > 9 ) return;
133
 
 
134
 
        // convert to pin no.
135
 
        num += 4;
136
 
 
137
 
        // pin 4 needs to be inverted (it's driving a PNP)
138
 
        if( num == 4 ) on = !on;
139
 
 
140
 
        digitalWrite( num, on? HIGH : LOW );
141
 
}
142
 
 
143
 
 
144
139
// draw a display segment
145
140
void drawNextSegment( bool reset )
146
141
{
147
 
        static ModeSwitcher mode_switcher;
148
 
        static bool init = false;
149
 
 
150
 
        if( !init ) {
151
 
                init = true;
152
 
                mode_switcher.activate();
153
 
        }
154
 
 
155
142
        // keep track of segment
156
143
#if CLOCK_FORWARD
157
144
        static int segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
162
149
#endif
163
150
 
164
151
        // draw
165
 
        Drawer &drawer = mode_switcher.get_drawer();
 
152
        Drawer &drawer = major_modes[ major_mode ]->get_drawer();
166
153
        if( reset ) drawer.draw_reset();
167
154
        drawer.draw( segment );
168
155
 
255
242
 
256
243
        // serial comms
257
244
        Serial.begin( 9600 );
 
245
 
 
246
        // set up major modes
 
247
        static ModeSwitcher mode_switcher;
 
248
        major_modes.push_back( &mode_switcher );
 
249
        major_modes[ 0 ]->activate();
258
250
}
259
251
 
260
252