Skip to content

Commit 6c9a6ef

Browse files
authored
Merge pull request #18 from j9brown/master
Fixed several compiler warnings.
2 parents f7f6a29 + 16b51ef commit 6c9a6ef

File tree

2 files changed

+77
-78
lines changed

2 files changed

+77
-78
lines changed

avdweb_Switch.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ WEBSITE: http://www.avdweb.nl/arduino/hardware-interfacing/simple-switch-debounc
113113
#include "Arduino.h"
114114
#include "avdweb_Switch.h"
115115

116-
switchCallback_t Switch::_beepAllCallback; // definition static function pointer with typedef
117-
//void (*Switch::_beepAllCallback)(void*); // definition static function pointer without typedef
118-
void* Switch::_beepAllCallbackParam; // without =
116+
switchCallback_t Switch::_beepAllCallback = nullptr; // definition static function pointer with typedef
117+
void* Switch::_beepAllCallbackParam = nullptr;
119118

120-
Switch::Switch(byte _pin, byte PinMode, bool polarity, int debouncePeriod, int longPressPeriod, int doubleClickPeriod, int deglitchPeriod):
121-
pin(_pin), polarity(polarity), deglitchPeriod(deglitchPeriod), debouncePeriod(debouncePeriod), longPressPeriod(longPressPeriod), doubleClickPeriod(doubleClickPeriod)
119+
Switch::Switch(byte _pin, byte PinMode, bool polarity, unsigned long debouncePeriod, unsigned long longPressPeriod, unsigned long doubleClickPeriod, unsigned long deglitchPeriod):
120+
deglitchPeriod(deglitchPeriod), debouncePeriod(debouncePeriod), longPressPeriod(longPressPeriod), doubleClickPeriod(doubleClickPeriod), pin(_pin), polarity(polarity)
122121
{ pinMode(pin, PinMode);
123122
switchedTime = millis();
124123
debounced = digitalRead(pin);

avdweb_Switch.h

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
/*
2-
Switch.cpp
3-
Copyright (C) 2012 Albert van Dalen http://www.avdweb.nl
4-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
5-
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
7-
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.gnu.org/licenses .
8-
9-
AUTHOR: Albert van Dalen
10-
WEBSITE: http://www.avdweb.nl/arduino/hardware-interfacing/simple-switch-debouncer.html
11-
*/
12-
13-
#ifndef AVDWEB_SWITCH_H
14-
#define AVDWEB_SWITCH_H
15-
16-
typedef void (*switchCallback_t)(void*);
17-
18-
class Switch
19-
{
20-
public:
21-
Switch(byte _pin, byte PinMode=INPUT_PULLUP, bool polarity=LOW, int debouncePeriod=50, int longPressPeriod=300, int doubleClickPeriod=250, int deglitchPeriod=10);
22-
bool poll(); // Returns 1 if switched
23-
bool switched(); // will be refreshed by poll()
24-
bool on();
25-
bool pushed(); // will be refreshed by poll()
26-
bool released(); // will be refreshed by poll()
27-
bool longPress(); // will be refreshed by poll()
28-
bool doubleClick(); // will be refreshed by poll()
29-
bool singleClick(); // will be refreshed by poll()
30-
31-
// Set methods for event callbacks
32-
void setPushedCallback(switchCallback_t cb, void* param = nullptr);
33-
void setReleasedCallback(switchCallback_t cb, void* param = nullptr);
34-
void setLongPressCallback(switchCallback_t cb, void* param = nullptr);
35-
void setDoubleClickCallback(switchCallback_t cb, void* param = nullptr);
36-
void setSingleClickCallback(switchCallback_t cb, void* param = nullptr);
37-
void setBeepAllCallback(switchCallback_t cb, void* param = nullptr);
38-
39-
int deglitchPeriod, debouncePeriod, longPressPeriod, doubleClickPeriod;
40-
41-
protected:
42-
bool process(); // not inline, used in child class
43-
void inline deglitch();
44-
void inline debounce();
45-
void inline calcLongPress();
46-
void inline calcDoubleClick();
47-
void inline calcSingleClick();
48-
void triggerCallbacks();
49-
50-
unsigned long deglitchTime, switchedTime, pushedTime, releasedTime, ms;
51-
const byte pin;
52-
const bool polarity;
53-
bool input, lastInput, equal, deglitched, debounced, _switched, _longPress, longPressDisable, _doubleClick, _singleClick, singleClickDisable;
54-
55-
// Event callbacks
56-
switchCallback_t _pushedCallback = nullptr;
57-
switchCallback_t _releasedCallback = nullptr;
58-
switchCallback_t _longPressCallback = nullptr;
59-
switchCallback_t _doubleClickCallback = nullptr;
60-
switchCallback_t _singleClickCallback = nullptr;
61-
static switchCallback_t _beepAllCallback; // static function pointer, can be used by all objects
62-
//static switchCallback_t _beepAllCallback = nullptr; // gives error with SAMD21
63-
//static void(*_beepAllCallback)(void*) = nullptr; // static function pointer without typedef
64-
65-
void* _pushedCallbackParam = nullptr;
66-
void* _releasedCallbackParam = nullptr;
67-
void* _longPressCallbackParam = nullptr;
68-
void* _doubleClickCallbackParam = nullptr;
69-
void* _singleClickCallbackParam = nullptr;
70-
static void* _beepAllCallbackParam; // can be used by all objects
71-
//static void* _beepAllCallbackParam = nullptr; // gives error with SAMD21
72-
};
73-
#endif
1+
/*
2+
Switch.cpp
3+
Copyright (C) 2012 Albert van Dalen http://www.avdweb.nl
4+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
5+
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
7+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.gnu.org/licenses .
8+
9+
AUTHOR: Albert van Dalen
10+
WEBSITE: http://www.avdweb.nl/arduino/hardware-interfacing/simple-switch-debouncer.html
11+
*/
12+
13+
#ifndef AVDWEB_SWITCH_H
14+
#define AVDWEB_SWITCH_H
15+
16+
typedef void (*switchCallback_t)(void*);
17+
18+
class Switch
19+
{
20+
public:
21+
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);
22+
bool poll(); // Returns 1 if switched
23+
bool switched(); // will be refreshed by poll()
24+
bool on();
25+
bool pushed(); // will be refreshed by poll()
26+
bool released(); // will be refreshed by poll()
27+
bool longPress(); // will be refreshed by poll()
28+
bool doubleClick(); // will be refreshed by poll()
29+
bool singleClick(); // will be refreshed by poll()
30+
31+
// Set methods for event callbacks
32+
void setPushedCallback(switchCallback_t cb, void* param = nullptr);
33+
void setReleasedCallback(switchCallback_t cb, void* param = nullptr);
34+
void setLongPressCallback(switchCallback_t cb, void* param = nullptr);
35+
void setDoubleClickCallback(switchCallback_t cb, void* param = nullptr);
36+
void setSingleClickCallback(switchCallback_t cb, void* param = nullptr);
37+
void setBeepAllCallback(switchCallback_t cb, void* param = nullptr);
38+
39+
unsigned long deglitchPeriod, debouncePeriod, longPressPeriod, doubleClickPeriod;
40+
41+
protected:
42+
bool process(); // not inline, used in child class
43+
void inline deglitch();
44+
void inline debounce();
45+
void inline calcLongPress();
46+
void inline calcDoubleClick();
47+
void inline calcSingleClick();
48+
void triggerCallbacks();
49+
50+
unsigned long deglitchTime, switchedTime, pushedTime, releasedTime, ms;
51+
const byte pin;
52+
const bool polarity;
53+
bool input, lastInput, equal, deglitched, debounced, _switched, _longPress, longPressDisable, _doubleClick, _singleClick, singleClickDisable;
54+
55+
// Event callbacks
56+
switchCallback_t _pushedCallback = nullptr;
57+
switchCallback_t _releasedCallback = nullptr;
58+
switchCallback_t _longPressCallback = nullptr;
59+
switchCallback_t _doubleClickCallback = nullptr;
60+
switchCallback_t _singleClickCallback = nullptr;
61+
static switchCallback_t _beepAllCallback; // static function pointer, can be used by all objects
62+
//static switchCallback_t _beepAllCallback = nullptr; // gives error with SAMD21
63+
//static void(*_beepAllCallback)(void*) = nullptr; // static function pointer without typedef
64+
65+
void* _pushedCallbackParam = nullptr;
66+
void* _releasedCallbackParam = nullptr;
67+
void* _longPressCallbackParam = nullptr;
68+
void* _doubleClickCallbackParam = nullptr;
69+
void* _singleClickCallbackParam = nullptr;
70+
static void* _beepAllCallbackParam; // can be used by all objects
71+
//static void* _beepAllCallbackParam = nullptr; // gives error with SAMD21
72+
};
73+
#endif

0 commit comments

Comments
 (0)