/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: 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

24
24
#define _BUTTON_H_
25
25
 
26
26
 
 
27
#include <map>
 
28
 
 
29
 
27
30
class Button
28
31
{
29
32
public:
36
39
        Button( int pin );
37
40
 
38
41
        /**
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
 
         * Update internal state (call as regularly sa possible!)
47
 
         */
48
 
        void update();
49
 
 
50
 
        /**
51
 
         * Get the first pending event.
52
 
         *
53
 
         * @return event id, 0 if there isn't any
54
 
         */
55
 
        int get_event();
 
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();
56
61
 
57
62
protected:
58
63
 
69
74
         * triggering events) since current state began */
70
75
        unsigned long _state_duration;
71
76
 
72
 
        /** pointer to event times */
73
 
        int *_event_times;
 
77
        /** triggered event */
 
78
        int _event_id;
74
79
 
75
 
        /** pending event */
76
 
        int _pending_event;
 
80
        /** press events durations -> event ids */
 
81
        std::map< int, int > _press_events;
77
82
 
78
83
};
79
84