/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: 2012-05-17 22:49:11 UTC
  • Revision ID: tim@ed.am-20120517224911-dbd9dtcpl14xlhi0
rewrote/fixed button event triggering code

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();
61
63
 
62
64
protected:
63
65
 
64
66
        /** pin */
65
67
        int _pin;
66
68
 
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;
 
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;
82
92
 
83
93
};
84
94