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

  • Committer: edam
  • Date: 2012-02-28 16:50:26 UTC
  • Revision ID: edam@waxworlds.org-20120228165026-pwnwo300xx2e2kg6
removed ulibc, fixed button, added text rendering

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * mode_switcher.cc
 
2
 * switcher_major_mode.cc
3
3
 *
4
4
 * Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston.
5
5
 *
20
20
 * You should have received a copy of the GNU Lesser General Public License
21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
 
#include "mode_switcher.h"
 
23
#include "switcher_major_mode.h"
24
24
#include "test_mode.h"
25
25
#include "analogue_clock_mode.h"
26
 
 
27
 
 
28
 
ModeSwitcher::ModeSwitcher()
 
26
#include "digital_clock_mode.h"
 
27
#include "Arduino.h"
 
28
 
 
29
 
 
30
SwitcherMajorMode::SwitcherMajorMode()
29
31
{
 
32
        for( int a = 0; a < MAX_MINOR_MODES; a++ )
 
33
                _modes[ a ] = NULL;
 
34
 
30
35
        static TestMode test_mode;
31
36
        static AnalogueClockMode analogue_clock_mode;
32
 
 
33
 
        _modes.push_back( &test_mode );
34
 
        _modes.push_back( &analogue_clock_mode );
35
 
}
36
 
 
37
 
 
38
 
void ModeSwitcher::short_press()
39
 
{
40
 
        _modes[ _mode ]->next_flavour();
41
 
}
42
 
 
43
 
 
44
 
void ModeSwitcher::long_press()
45
 
{
46
 
        if( ++_mode >= (signed)_modes.size() )
47
 
                _mode = 0;
 
37
        static DigitalClockMode digital_clock_mode;
 
38
 
 
39
        int mode = 0;
 
40
        _modes[ mode++ ] = &digital_clock_mode;
 
41
        _modes[ mode++ ] = &test_mode;
 
42
        _modes[ mode++ ] = &analogue_clock_mode;
 
43
}
 
44
 
 
45
 
 
46
void SwitcherMajorMode::press()
 
47
{
 
48
        _modes[ _mode ]->press();
 
49
}
 
50
 
 
51
 
 
52
void SwitcherMajorMode::long_press()
 
53
{
 
54
        do {
 
55
                if( ++_mode >= MAX_MINOR_MODES )
 
56
                        _mode = 0;
 
57
        } while( _modes[ _mode ] == NULL );
48
58
        _modes[ _mode ]->activate();
49
59
}
50
60
 
51
61
 
52
 
void ModeSwitcher::activate()
 
62
void SwitcherMajorMode::activate()
53
63
{
54
64
        _mode = 0;
55
65
        _modes[ _mode ]->activate();
56
66
}
57
67
 
58
68
 
59
 
Drawer &ModeSwitcher::get_drawer()
 
69
Drawer &SwitcherMajorMode::get_drawer()
60
70
{
61
71
        return *_modes[ _mode ];
62
72
}