Modified version to work with EventQueue (outside of ISR)
Diff: MultiClick.cpp
- Revision:
- 7:7d56935ba84d
- Parent:
- 6:7f1142cc196a
- Child:
- 8:633350efee38
--- 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; } }