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

  • Committer: Tim Marston
  • Date: 2012-05-18 14:55:12 UTC
  • Revision ID: tim@ed.am-20120518145512-4dg4ble01d47a8z5
moved rount Time a bit, and passed _button to SettingsMajorMode so that it can
come in and out of send_interim mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "Arduino.h"
26
26
#include "time.h"
27
27
#include "common.h"
28
 
#include "text.h"
29
28
 
30
29
 
31
30
void AnalogueClockMode::draw( int segment )
42
41
        bool draw_second = segment == _second_segment;
43
42
 
44
43
        // set the LEDs
45
 
        switch( _flavour )
46
 
        {
47
 
        case 0:
48
 
                led( 9, true );
49
 
                led( 8, draw_tick || draw_second );
50
 
                led( 7, draw_minute || draw_second );
51
 
                led( 6, draw_minute || draw_minute_side || draw_second );
52
 
                led( 5, draw_minute || draw_minute_side ||
53
 
                                          draw_second || draw_hour );
54
 
                for( int a = 0; a <= 4; a++ )
55
 
                        led( a, draw_minute || draw_minute_side ||
56
 
                                                  draw_second || draw_hour || draw_hour_side );
57
 
                break;
58
 
        case 1:
59
 
                led( 9, draw_tick );
60
 
                led( 8, draw_second );
61
 
                led( 7, draw_minute || draw_second );
62
 
                led( 6, draw_minute || draw_minute_side || draw_second );
63
 
                led( 5, draw_minute || draw_minute_side ||
64
 
                                          draw_second || draw_hour );
65
 
                for( int a = 0; a <= 4; a++ )
66
 
                        led( a, draw_minute || draw_minute_side ||
67
 
                                                  draw_second || draw_hour || draw_hour_side );
68
 
                break;
69
 
        case 2:
70
 
                led( 9, segment <= _subsecond_segment );
71
 
                led( 8, draw_tick || draw_second );
72
 
                led( 7, draw_minute || draw_second );
73
 
                led( 6, draw_minute || draw_minute_side || draw_second );
74
 
                led( 5, draw_minute || draw_minute_side ||
75
 
                                          draw_second || draw_hour );
76
 
                for( int a = 0; a <= 4; a++ )
77
 
                        led( a, draw_minute || draw_minute_side ||
78
 
                                                  draw_second || draw_hour || draw_hour_side );
79
 
                break;
80
 
        case 3:
81
 
                led( 9, segment <= ( _second_segment +
82
 
                                NUM_SECOND_SEGMENTS * _subsecond_segment / NUM_SEGMENTS ) );
83
 
                led( 8, draw_tick );
84
 
                led( 7, draw_minute );
85
 
                led( 6, draw_minute || draw_minute_side );
86
 
                led( 5, draw_minute || draw_minute_side || draw_hour );
87
 
                for( int a = 0; a <= 4; a++ )
88
 
                        led( a, draw_minute || draw_minute_side ||
89
 
                                        draw_hour || draw_hour_side );
90
 
                break;
91
 
        }
 
44
        led( 9, _flavour == 0 );
 
45
        led( 8, draw_tick || draw_second );
 
46
        led( 7, draw_minute || draw_second );
 
47
        led( 6, draw_minute || draw_minute_side || draw_second );
 
48
        led( 5, draw_minute || draw_minute_side ||
 
49
                                  draw_second || draw_hour );
 
50
        for( int a = 0; a <= 4; a++ )
 
51
                led( a, draw_minute || draw_minute_side ||
 
52
                                          draw_second || draw_hour || draw_hour_side );
92
53
}
93
54
 
94
55
 
95
56
void AnalogueClockMode::draw_reset()
96
57
{
97
 
        int old_second_segment = _second_segment;
98
 
 
99
58
        // calculate hand locations
100
59
        _hour_segment = ( Time::get_hours() % 12 ) * 5 * NUM_SECOND_SEGMENTS +
101
60
                ( 5 * NUM_SECOND_SEGMENTS * Time::get_minutes() / 60 );
102
61
        _minute_segment = Time::get_minutes() * NUM_SECOND_SEGMENTS +
103
62
                ( NUM_SECOND_SEGMENTS * Time::get_seconds() / 60 );
104
63
        _second_segment = Time::get_seconds() * NUM_SECOND_SEGMENTS;
105
 
 
106
 
        // calculate the subsecond segment
107
 
        if( old_second_segment != _second_segment ) {
108
 
                _second_millis = millis();
109
 
                _subsecond_segment = 0;
110
 
        }
111
 
        else {
112
 
                unsigned long elapsed = ::millis() - _second_millis;
113
 
                _subsecond_segment = elapsed * NUM_SEGMENTS / 1000;
114
 
        }
115
64
}
116
65
 
117
66
 
118
67
void AnalogueClockMode::activate()
119
68
{
120
69
        _flavour = 0;
121
 
        _second_millis = ::millis();
122
 
 
123
 
        Text::reset();
124
70
}
125
71
 
126
72
 
127
73
void AnalogueClockMode::press()
128
74
{
129
 
        if( ++_flavour >= 4 )
 
75
        if( ++_flavour >= 2 )
130
76
                _flavour = 0;
131
77
}