You can use multiple clicks event with one button. This library supports follow events, Single click, Double click, over 3 times click, Long press.

Dependents:   multiclick_test

Files at this revision

API Documentation at this revision

Comitter:
ohtsuka
Date:
Thu Jun 16 01:29:43 2016 +0000
Parent:
6:7f1142cc196a
Commit message:
add file header(MIT License)

Changed in this revision

MultiClick.cpp Show annotated file Show diff for this revision Revisions of this file
MultiClick.h Show annotated file Show diff for this revision Revisions of this file
diff -r 7f1142cc196a -r 7d56935ba84d MultiClick.cpp
--- a/MultiClick.cpp	Wed Jun 15 10:21:28 2016 +0000
+++ b/MultiClick.cpp	Thu Jun 16 01:29:43 2016 +0000
@@ -1,3 +1,35 @@
+/*
+MultiClick.cpp:
+  For one button operation.
+  This library suports these events,
+    * Single click
+    * Double click
+    * N times click (over 3 times click)
+    * Long press
+
+The MIT License (MIT)
+
+Copyright (c) 2016 Uematsu Electric Co.,Ltd. Toru OHTSUKA <t-ohtsuka@jupiter.ocn.ne.jp>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
 #include "MultiClick.h"
 
 MultiClick::MultiClick(PinName p, PinMode m)
@@ -17,8 +49,6 @@
     
     _click_detect_timeout = new Timeout();
     _press_check = new Ticker();
-    _t = new Timer();
-    _t->start();
 
     _press_check_interval_us = 25*1000;
     _shortpress_num = 1;
@@ -38,14 +68,12 @@
         DBG_PRINT("_[%d]", _pressed_count);
         press_check_func();
     } else { // 通常時
-
-    // プレス判定処理開始
-    _pressed_count = 0;
-    _press_check->detach();
-    _press_check->attach_us(this, &MultiClick::press_check_func, _press_check_interval_us );
-    
-    _longpressed = false;
-
+        // プレス判定処理開始
+        _pressed_count = 0;
+        _press_check->detach();
+        _press_check->attach_us(this, &MultiClick::press_check_func, _press_check_interval_us );
+        
+        _longpressed = false;
     }
 }
 
diff -r 7f1142cc196a -r 7d56935ba84d MultiClick.h
--- a/MultiClick.h	Wed Jun 15 10:21:28 2016 +0000
+++ b/MultiClick.h	Thu Jun 16 01:29:43 2016 +0000
@@ -1,3 +1,35 @@
+/*
+MultiClick.h:
+  For one button operation.
+  This library suports these events,
+    * Single click
+    * Double click
+    * N times click (over 3 times click)
+    * Long press
+
+The MIT License (MIT)
+
+Copyright (c) 2016 Uematsu Electric Co.,Ltd. Toru OHTSUKA <t-ohtsuka@jupiter.ocn.ne.jp>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
 #include "mbed.h"
 
 //#define DEBUG
@@ -23,11 +55,11 @@
     void click_detect_timeout( void );
     void press_check_func( void );
 
-    Timer *_t;
+    InterruptIn *_iin;
+    PinMode _mode;
+
     Ticker *_press_check;
     Timeout *_click_detect_timeout;
-    InterruptIn *_iin;
-    PinMode _mode;
     
     int _shortpress_num;
     int _longpress_num;