Button class with auto repeat function.

Revision:
1:3385a1ea4a7d
Parent:
0:a39041955963
Child:
2:97ef12e06605
--- a/Button.h	Tue Feb 14 13:00:47 2017 +0000
+++ b/Button.h	Tue Feb 14 13:22:07 2017 +0000
@@ -11,7 +11,7 @@
 class Button
 {
 public:
-    Button(PinName pinName, PinMode pinMode, int activeState, void(*onButtonEvent)(ButtonEvent event, PinName pinName), float autoRepeatTime = 0, uint16_t longPressTime = 600, uint16_t shortPressTime = 30)
+    Button(PinName pinName, PinMode pinMode, int activeState, void(*onButtonEvent)(ButtonEvent event, PinName pinName) = NULL, uint16_t autoRepeatTime = 0, uint16_t longPressTime = 600, uint16_t shortPressTime = 30)
     : _pinName(pinName)
     , _in(pinName)
     , _shortPressTime(shortPressTime)
@@ -26,11 +26,11 @@
         _in.rise(Callback<void()>(this, &Button::isrRise));
         _in.fall(Callback<void()>(this, &Button::isrFall));
     };
-    inline void setAutoRepeat(float autoRepeatTime)
+    inline void setAutoRepeatTime_ms(uint16_t autoRepeatTime)
     {
         _autoRepeatTime = autoRepeatTime;
     };
-    inline float getAutoRepeat() const
+    inline uint16_t getAutoRepeatTime_ms() const
     {
         return _autoRepeatTime;
     }
@@ -46,6 +46,34 @@
     {
         _fireUpDown = fire;
     };
+    inline bool isFireUpDown() const
+    {
+        return _fireUpDown;
+    };
+    void setShortPressTime_ms(uint16_t time_ms)
+    {
+        _shortPressTime = time_ms;
+    };
+    inline uint16_t getShortPressTime_ms() const
+    {
+        return _shortPressTime;
+    };
+    void setLongPressTime_ms(uint16_t time_ms)
+    {
+        _longPressTime = time_ms;
+    };
+    inline uint16_t getLongPressTime_ms() const
+    {
+        return _longPressTime;
+    };
+    void attach(void(*onButtonEvent)(ButtonEvent event, PinName pinName))
+    {
+        _onButtonEvent = onButtonEvent;
+    };
+    void detach()
+    {
+        _onButtonEvent = NULL;
+    };
 private:
     PinName _pinName;
     InterruptIn _in;
@@ -54,7 +82,7 @@
     Timeout _autoRepeatStarter;
     uint16_t _shortPressTime;
     uint16_t _longPressTime;
-    float _autoRepeatTime;
+    uint16_t _autoRepeatTime;
     int _activeState;
     int _prevState;
     bool _fireUpDown;