bzr branch
http://bzr.ed.am/elec/propeller-clock
56
by edam
updated software to include drawing abstraction infrastructure |
1 |
#include "analogue_clock_mode.h" |
2 |
#include "config.h" |
|
3 |
#include "time.h" |
|
4 |
||
5 |
||
6 |
AnalogueClockMode::AnalogueClockMode() |
|
7 |
: |
|
8 |
MinorMode( 1 ) |
|
9 |
{ |
|
10 |
} |
|
11 |
||
12 |
||
13 |
void AnalogueClockMode::draw( int segment ) |
|
14 |
{ |
|
15 |
Time &time = Time::get_instance(); |
|
16 |
||
17 |
int second = segment / NUM_SECOND_SEGMENTS; |
|
18 |
int second_segment = segment % NUM_SECOND_SEGMENTS; |
|
19 |
||
20 |
// what needs to be drawn? |
|
21 |
bool draw_tick = ( !second_segment && second % 5 == 0 && second ) || |
|
22 |
( second == 0 && second_segment == 1 ) || |
|
23 |
( second == 59 && second_segment == NUM_SECOND_SEGMENTS - 1 ); |
|
24 |
bool draw_second = !second_segment && second == time.get_seconds(); |
|
25 |
bool draw_minute = !second_segment && second == time.get_minutes(); |
|
26 |
bool draw_hour = segment == time.get_hours() * 5 * NUM_SECOND_SEGMENTS + |
|
27 |
( 5 * NUM_SECOND_SEGMENTS * time.get_minutes() / 60 ); |
|
28 |
||
29 |
// set the LEDs |
|
30 |
led_on( 9, true ); |
|
31 |
led_on( 8, draw_tick || draw_second ); |
|
32 |
for( int a = 6; a <= 7; a++ ) |
|
33 |
led_on( a, draw_minute || draw_second ); |
|
34 |
for( int a = 0; a <= 5; a++ ) |
|
35 |
led_on( a, draw_minute || draw_second || draw_hour ); |
|
36 |
} |