/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.cc

  • Committer: edam
  • Date: 2012-05-18 12:11:01 UTC
  • Revision ID: tim@ed.am-20120518121101-0wik922hyvjkcjdi
switched back to using classes for modes

Show diffs side-by-side

added added

removed removed

1
 
/* -*- mode: c++; compile-command: "make"; -*- */
 
1
/* -*- mode: c++; compile-command: "BOARD=pro5v make"; -*- */
2
2
/*
3
3
 * propeller-clock.ino
4
4
 *
116
116
// current major mode
117
117
static int _mode = 0;
118
118
 
119
 
// interupt handler's "ignore every other" flag
120
 
static bool _pulse_ignore = true;
121
 
 
122
119
//_____________________________________________________________________________
123
120
//                                                                         code
124
121
 
144
141
                        if( !_modes[ ++_mode ] ) _mode = 0;
145
142
                        _modes[ _mode ]->activate();
146
143
                        break;
147
 
                case 4:
148
 
                        // switch display upside-down
149
 
                        _pulse_ignore = !_pulse_ignore;
150
 
                        break;
151
144
                }
152
145
        }
153
146
}
157
150
void draw_next_segment( bool reset )
158
151
{
159
152
        // keep track of segment
160
 
        static int segment = 0;
161
153
#if CLOCK_FORWARD
 
154
        static int segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
162
155
        if( reset ) segment = ( NUM_SEGMENTS - CLOCK_SHIFT ) % NUM_SEGMENTS;
163
156
#else
 
157
        static int segment = NUM_SEGMENTS - 1 - CLOCK_SHIFT;
164
158
        if( reset ) segment = NUM_SEGMENTS - 1 - CLOCK_SHIFT;
165
159
#endif
166
160
 
178
172
        // draw
179
173
        _modes[ _mode ]->draw( segment );
180
174
 
181
 
        // draw text
182
 
        Text::draw( segment );
 
175
        // TODO: remove this hack
 
176
        Text::post_draw();
183
177
 
184
178
        // draw text rednerer's buffer
185
179
        TextRenderer::output_buffer();
243
237
        // may not be exactly evenly distributed around the rotation, so
244
238
        // we can't recalculate times on every pulse. Instead, we ignore
245
239
        // every other pulse so timings are based on a complete rotation.
246
 
        _pulse_ignore = !_pulse_ignore;
247
 
        if( !_pulse_ignore )
 
240
        static bool ignore = true;
 
241
        ignore = !ignore;
 
242
        if( !ignore )
248
243
        {
249
244
                // set a new pulse time
250
245
                _new_pulse_at = micros();
266
261
        // set up mode-switch button on pin 3
267
262
        pinMode( 3, INPUT );
268
263
        digitalWrite( 3, HIGH );
269
 
        static int event_times[] = { 10, 500, 2000, 4000, 0 };
 
264
        static int event_times[] = { 5, 500, 4000, 0 };
270
265
        _button.set_event_times( event_times );
271
266
 
272
267
        // initialise RTC
273
 
        Time::load_time();
 
268
        Time::init();
274
269
 
275
270
        // init text renderer
276
271
        TextRenderer::init();
280
275
        leds_off();
281
276
 
282
277
        static SwitcherMajorMode switcher;
283
 
        static SettingsMajorMode settings( _button );
 
278
        static SettingsMajorMode settings;
284
279
 
285
280
        // add major modes
286
281
        int mode = 0;