avdwebLibraries / avdweb_Switch

Switch library with longPress and doubleClick
http://www.avdweb.nl/arduino/hardware-interfacing/simple-switch-debouncer.html
GNU General Public License v3.0
45 stars 16 forks source link

Lots of warning when compiling the library. #17

Closed j9brown closed 2 months ago

j9brown commented 3 years ago

These all look quite straightforward to fix. Without having read the code too closely, I'm a little concerned about the comparison between signed and unsigned types as that's often a source of bugs.

In file included from /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:111:0: /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.h: In constructor 'Switch::Switch(byte, byte, bool, int, int, int, int)': /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.h:50:14: warning: 'Switch::polarity' will be initialized after [-Wreorder] const bool polarity; ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.h:49:13: warning: 'const int Switch::deglitchPeriod' [-Wreorder] const int deglitchPeriod, debouncePeriod, longPressPeriod, doubleClickPeriod; ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:113:1: warning: when initialized here [-Wreorder] Switch::Switch(byte _pin, byte PinMode, bool polarity, int debouncePeriod, int longPressPeriod, int doubleClickPeriod, int deglitchPeriod): ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp: In member function 'void Switch::deglitch()': /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:152:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if(equal && ((ms - deglitchTime) > deglitchPeriod)) // max 50ms, disable deglitch: 0ms ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp: In member function 'void Switch::debounce()': /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:162:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if((deglitched != debounced) && ((ms - switchedTime) > debouncePeriod)) ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp: In member function 'void Switch::calcSingleClick()': /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:171:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] { if((ms - pushedTime) >= doubleClickPeriod) ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:177:73: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] { _singleClick = !switched() && !on() && ((releasedTime - pushedTime) <= longPressPeriod) && ((ms - pushedTime) >= doubleClickPeriod); // true just one time between polls ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:177:115: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] { _singleClick = !switched() && !on() && ((releasedTime - pushedTime) <= longPressPeriod) && ((ms - pushedTime) >= doubleClickPeriod); // true just one time between polls ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp: In member function 'void Switch::calcDoubleClick()': /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:183:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] { _doubleClick = pushed() && ((ms - pushedTime) < doubleClickPeriod); ^ /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp: In member function 'void Switch::calcLongPress()': /Users/jeff/Documents/Arduino/libraries/Switch/avdweb_Switch.cpp:190:60: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] { _longPress = !switched() && on() && ((ms - pushedTime) > longPressPeriod); // true just one time between polls ^

gpambrozio commented 2 years ago

@avandalen I'm hitting problems that this latest merge seems to fix. Could you create a new release of the library so that I can use the arduino library manager to install? Thanks.

avandalen commented 2 years ago

Hi, can't you do that yourselve?

gpambrozio commented 2 years ago

@avandalen no, I'm not a contributor to the project, github won't let me do that...

nomakewan commented 3 months ago

Since the library was successfully updated and resolved all these compilation errors, this issue should be closed. :)

boseji commented 2 months ago

Fixed all the warnings in latest release.