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

  • Committer: edam
  • Date: 2012-02-25 14:54:33 UTC
  • Revision ID: edam@waxworlds.org-20120225145433-kih8qs45x05cum46
removed Bounce library and updated/fixed new code

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * switcher_major_mode.cc
 
2
 * mode_switcher.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 "switcher_major_mode.h"
 
23
#include "mode_switcher.h"
24
24
#include "test_mode.h"
25
25
#include "analogue_clock_mode.h"
26
 
#include "digital_clock_mode.h"
27
 
#include "Arduino.h"
28
 
 
29
 
 
30
 
SwitcherMajorMode::SwitcherMajorMode()
 
26
 
 
27
 
 
28
ModeSwitcher::ModeSwitcher()
31
29
{
32
 
        for( int a = 0; a < MAX_MINOR_MODES; a++ )
33
 
                _modes[ a ] = NULL;
34
 
 
35
30
        static TestMode test_mode;
36
31
        static AnalogueClockMode analogue_clock_mode;
37
 
        static DigitalClockMode digital_clock_mode;
38
 
 
39
 
        int mode = 0;
40
 
        _modes[ mode++ ] = &analogue_clock_mode;
41
 
        _modes[ mode++ ] = &digital_clock_mode;
42
 
        _modes[ mode++ ] = &test_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 );
 
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;
58
48
        _modes[ _mode ]->activate();
59
49
}
60
50
 
61
51
 
62
 
void SwitcherMajorMode::activate()
 
52
void ModeSwitcher::activate()
63
53
{
64
54
        _mode = 0;
65
55
        _modes[ _mode ]->activate();
66
56
}
67
57
 
68
58
 
69
 
Drawer &SwitcherMajorMode::get_drawer()
 
59
Drawer &ModeSwitcher::get_drawer()
70
60
{
71
61
        return *_modes[ _mode ];
72
62
}