/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/button.h

  • Committer: Tim Marston
  • Date: 2013-03-31 17:07:36 UTC
  • Revision ID: tim@ed.am-20130331170736-hphm2hg0y6l7w6z1
made rtc-test's DS1307 library a symlink to the main one in src/util

Show diffs side-by-side

added added

removed removed

24
24
#define _BUTTON_H_
25
25
 
26
26
 
27
 
#include <map>
28
 
 
29
 
 
30
27
class Button
31
28
{
32
29
public:
39
36
        Button( int pin );
40
37
 
41
38
        /**
42
 
         * Add a duration at which the specified event id should be triggered.
43
 
         *
44
 
         * @oaram duration the time at which the event should be triggered
45
 
         * @param event_id a unique identifier for the event (not 0)
46
 
         */
47
 
        void add_event_at( int duration, int event_id );
48
 
 
49
 
        /**
50
 
         * Update internal state
51
 
         */
52
 
        int update();
53
 
 
54
 
        /**
55
 
         * Retrieve the event id of the event that was triggered at the last
56
 
         * update, if there was one.
57
 
         *
58
 
         * @return event id, or 0
59
 
         */
60
 
        int get_triggered_event();
 
39
         * Set event times.
 
40
         *
 
41
         * @oaram pointer to ordered, zero-terminated array of event times
 
42
         */
 
43
        void set_event_times( int *event_times );
 
44
 
 
45
        /**
 
46
         * Set button press mode
 
47
         *
 
48
         * @param send_interim send interim presses during a long press?
 
49
         */
 
50
        void set_press_mode( bool send_interim );
 
51
 
 
52
        /**
 
53
         * Update internal state (call as regularly sa possible!)
 
54
         */
 
55
        void update();
 
56
 
 
57
        /**
 
58
         * Get the first pending event.
 
59
         *
 
60
         * @return event id, 0 if there isn't any
 
61
         */
 
62
        int get_event();
 
63
 
 
64
        /**
 
65
         * Get the current button state.
 
66
         *
 
67
         * @return true if the button is pressed
 
68
         */
 
69
        bool get_state();
61
70
 
62
71
protected:
63
72
 
64
73
        /** pin */
65
74
        int _pin;
66
75
 
67
 
        /** current state */
 
76
        /** last real state */
 
77
        bool _last_real_state;
 
78
 
 
79
        /** time when the real state began */
 
80
        unsigned long _millis_real_state;
 
81
 
 
82
        /** accepted state */
68
83
        bool _state;
69
84
 
70
 
        /** time when current state began */
71
 
        unsigned long _state_millis;
72
 
 
73
 
        /** milliseconds that have been accountred for (in terms of
74
 
         * triggering events) since current state began */
75
 
        unsigned long _state_duration;
76
 
 
77
 
        /** triggered event */
78
 
        int _event_id;
79
 
 
80
 
        /** press events durations -> event ids */
81
 
        std::map< int, int > _press_events;
82
 
 
 
85
        /** time when the accepted state began */
 
86
        unsigned long _millis_state;
 
87
 
 
88
        /** amount of time that we've already triggered events for this press */
 
89
        unsigned long _millis_done;
 
90
 
 
91
        /** pointer to event times */
 
92
        int *_event_times;
 
93
 
 
94
        /** pending event */
 
95
        int _pending_event;
83
96
};
84
97
 
85
98