/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 01:31:43 UTC
  • Revision ID: tim@ed.am-20120225013143-9fet2y2d3fjlrwez
added ulibc

Show diffs side-by-side

added added

removed removed

75
75
 
76
76
******************************************************************************/
77
77
 
78
 
#include "button.h"
 
78
 
 
79
#include <button.h>
79
80
#include "config.h"
80
81
#include "time.h"
81
82
#include "mode_switcher.h"
100
101
static unsigned long segment_step_sub_step = 0;
101
102
static unsigned long segment_step_sub = 0;
102
103
 
103
 
// the button
 
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
104
108
static Button button( 3 );
105
109
 
106
 
// major mode
107
 
static int major_mode = 0;
108
 
 
109
 
// major modes
110
 
static std::vector< MajorMode * > major_modes;
111
 
 
112
110
//_____________________________________________________________________________
113
111
//                                                                         code
114
112
 
122
120
        // handle any events
123
121
        switch( event ) {
124
122
        case 1:
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();
 
123
                inc_draw_mode = true;
134
124
                break;
135
125
        }
136
126
}
137
127
 
138
128
 
 
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
 
139
144
// draw a display segment
140
145
void drawNextSegment( bool reset )
141
146
{
 
147
        static ModeSwitcher mode_switcher;
 
148
        static bool init = false;
 
149
 
 
150
        if( !init ) {
 
151
                init = true;
 
152
                mode_switcher.activate();
 
153
        }
 
154
 
142
155
        // keep track of segment
143
156
#if CLOCK_FORWARD
144
157
        static int segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
149
162
#endif
150
163
 
151
164
        // draw
152
 
        Drawer &drawer = major_modes[ major_mode ]->get_drawer();
 
165
        Drawer &drawer = mode_switcher.get_drawer();
153
166
        if( reset ) drawer.draw_reset();
154
167
        drawer.draw( segment );
155
168
 
242
255
 
243
256
        // serial comms
244
257
        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();
250
258
}
251
259
 
252
260