Skip to content

Commit

Permalink
Fixed several compiler warnings.
Browse files Browse the repository at this point in the history
- initialization order of class members
- initialization of static variables
- comparison of signed and unsigned time periods

Issue #17
  • Loading branch information
j9brown committed Jun 4, 2021
1 parent 0edf680 commit 1b69535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions avdweb_Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions avdweb_Switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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

0 comments on commit 1b69535

Please sign in to comment.