/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
 
         * 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();
 
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();
63
61
 
64
62
protected:
65
63
 
66
64
        /** pin */
67
65
        int _pin;
68
66
 
69
 
        /** last state */
70
 
        bool _state_last;
71
 
 
72
 
        /** time when this state began */
73
 
        unsigned long _millis_state;
74
 
 
75
 
        /** amount of time that we've already triggered events for this press */
76
 
        unsigned long _millis_done;
77
 
 
78
 
        /** pointer to event times */
79
 
        int *_event_times;
80
 
 
81
 
        /** pending event */
82
 
        int _pending_event;
83
 
 
84
 
        /** an interim event buffer */
85
 
        int _interim_event;
86
 
 
87
 
        /** send interim events? */
88
 
        bool _send_interim;
89
 
 
90
 
        /** when not sending interim events, ignore the next unpress */
91
 
        bool _ignore_next_unpress;
 
67
        /** current state */
 
68
        bool _state;
 
69
 
 
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;
92
82
 
93
83
};
94
84