diff --git a/avdweb_Switch.cpp b/avdweb_Switch.cpp index c5fd143..0764fe5 100644 --- a/avdweb_Switch.cpp +++ b/avdweb_Switch.cpp @@ -112,12 +112,11 @@ WEBSITE: http://www.avdweb.nl/arduino/hardware-interfacing/simple-switch-debounc #include "Arduino.h" #include "avdweb_Switch.h" -switchCallback_t Switch::_beepAllCallback; // definition static function pointer with typedef -//void (*Switch::_beepAllCallback)(void*); // definition static function pointer without typedef -void* Switch::_beepAllCallbackParam; // without = +switchCallback_t Switch::_beepAllCallback = nullptr; // definition static function pointer with typedef +void* Switch::_beepAllCallbackParam = nullptr; -Switch::Switch(byte _pin, byte PinMode, bool polarity, int debouncePeriod, int longPressPeriod, int doubleClickPeriod, int deglitchPeriod): -pin(_pin), polarity(polarity), deglitchPeriod(deglitchPeriod), debouncePeriod(debouncePeriod), longPressPeriod(longPressPeriod), doubleClickPeriod(doubleClickPeriod) +Switch::Switch(byte _pin, byte PinMode, bool polarity, unsigned long debouncePeriod, unsigned long longPressPeriod, unsigned long doubleClickPeriod, unsigned long deglitchPeriod): +deglitchPeriod(deglitchPeriod), debouncePeriod(debouncePeriod), longPressPeriod(longPressPeriod), doubleClickPeriod(doubleClickPeriod), pin(_pin), polarity(polarity) { pinMode(pin, PinMode); switchedTime = millis(); debounced = digitalRead(pin); diff --git a/avdweb_Switch.h b/avdweb_Switch.h index 42eb267..9c21f74 100644 --- a/avdweb_Switch.h +++ b/avdweb_Switch.h @@ -18,7 +18,7 @@ typedef void (*switchCallback_t)(void*); class Switch { public: - Switch(byte _pin, byte PinMode=INPUT_PULLUP, bool polarity=LOW, int debouncePeriod=50, int longPressPeriod=300, int doubleClickPeriod=250, int deglitchPeriod=10); + Switch(byte _pin, byte PinMode=INPUT_PULLUP, bool polarity=LOW, unsigned long debouncePeriod=50, unsigned long longPressPeriod=300, unsigned long doubleClickPeriod=250, unsigned long deglitchPeriod=10); bool poll(); // Returns 1 if switched bool switched(); // will be refreshed by poll() bool on(); @@ -36,7 +36,7 @@ class Switch void setSingleClickCallback(switchCallback_t cb, void* param = nullptr); void setBeepAllCallback(switchCallback_t cb, void* param = nullptr); - int deglitchPeriod, debouncePeriod, longPressPeriod, doubleClickPeriod; + unsigned long deglitchPeriod, debouncePeriod, longPressPeriod, doubleClickPeriod; protected: bool process(); // not inline, used in child class @@ -58,14 +58,13 @@ class Switch switchCallback_t _longPressCallback = nullptr; switchCallback_t _doubleClickCallback = nullptr; switchCallback_t _singleClickCallback = nullptr; - static switchCallback_t _beepAllCallback = nullptr; // static function pointer, can be used by all objects - //static void(*_beepAllCallback)(void*) = nullptr; // static function pointer without typedef + static switchCallback_t _beepAllCallback; // static function pointer, can be used by all objects void* _pushedCallbackParam = nullptr; void* _releasedCallbackParam = nullptr; void* _longPressCallbackParam = nullptr; void* _doubleClickCallbackParam = nullptr; void* _singleClickCallbackParam = nullptr; - static void* _beepAllCallbackParam = nullptr; // can be used by all objects + static void* _beepAllCallbackParam; // can be used by all objects }; #endif