Button class with auto repeat function.
Diff: Button.h
- Revision:
- 3:03aea89f2a5c
- Parent:
- 2:97ef12e06605
- Child:
- 4:d54859273629
--- a/Button.h Thu Mar 16 13:49:03 2017 +0000 +++ b/Button.h Sat May 13 18:15:11 2017 +0000 @@ -1,3 +1,23 @@ +/** +* @file Button.h +* @brief Button library +* @author Mark Peter Vargha, vmp@varghamarkpeter.hu +* +* Copyright (c) 2017 +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + #ifndef BUTTON_H_INCLUDED #define BUTTON_H_INCLUDED @@ -11,7 +31,7 @@ class Button { public: - 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) + Button(PinName pinName, PinMode pinMode, int activeState, Callback<void(ButtonEvent, PinName)> onButtonEvent = 0, uint16_t autoRepeatTime = 0, uint16_t longPressTime = 600, uint16_t shortPressTime = 30) : _pinName(pinName) , _in(pinName) , _shortPressTime(shortPressTime) @@ -66,13 +86,13 @@ { return _longPressTime; }; - void attach(void(*onButtonEvent)(ButtonEvent event, PinName pinName)) + void attach(Callback<void(ButtonEvent, PinName)> onButtonEvent) { _onButtonEvent = onButtonEvent; }; void detach() { - _onButtonEvent = NULL; + _onButtonEvent = 0; }; private: PinName _pinName; @@ -86,7 +106,7 @@ int _activeState; int _prevState; bool _fireUpDown; - void(*_onButtonEvent)(ButtonEvent event, PinName pinName); + Callback<void(ButtonEvent, PinName)> _onButtonEvent; void isrFall(void); void isrRise(void); void onPress(void);