Skip to content

Commit dc4dac2

Browse files
authored
Merge pull request #104 from mkinney/add_cppcheck
* Add cppcheck as a github action, * Some CPP syntax improvements.
2 parents f5448ef + f516983 commit dc4dac2

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

.github/workflows/cppcheck.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: cppcheck-action-test
2+
on: [push]
3+
4+
jobs:
5+
build:
6+
name: cppcheck-test
7+
runs-on: ubuntu-latest
8+
steps:
9+
10+
- uses: actions/checkout@v2
11+
12+
- name: Install cppcheck
13+
run: |
14+
sudo apt-get install cppcheck
15+
16+
- name: Run cppcheck
17+
run: |
18+
./run_cppcheck.sh

run_cppcheck.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cppcheck --enable=all --suppressions-list=suppressions.txt --language=c++ -I./src --error-exitcode=2 ./src/*

src/OneButton.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class OneButton
4646
* @param activeLow Set to true when the input level is LOW when the button is pressed, Default is true.
4747
* @param pullupActive Activate the internal pullup when available. Default is true.
4848
*/
49-
OneButton(const int pin, const boolean activeLow = true, const bool pullupActive = true);
49+
explicit OneButton(const int pin, const boolean activeLow = true, const bool pullupActive = true);
5050

5151
// ----- Set runtime parameters -----
5252

@@ -149,12 +149,12 @@ class OneButton
149149

150150

151151
private:
152-
int _pin; // hardware pin number.
152+
int _pin = 0; // hardware pin number.
153153
unsigned int _debounceTicks = 50; // number of ticks for debounce times.
154154
unsigned int _clickTicks = 400; // number of msecs before a click is detected.
155155
unsigned int _pressTicks = 800; // number of msecs before a long button press is detected
156156

157-
int _buttonPressed;
157+
int _buttonPressed = 0;
158158

159159
// These variables will hold functions acting as event source.
160160
callbackFunction _clickFunc = NULL;
@@ -175,7 +175,7 @@ class OneButton
175175

176176
callbackFunction _longPressStopFunc = NULL;
177177
parameterizedCallbackFunction _paramLongPressStopFunc = NULL;
178-
void *_longPressStopFuncParam;
178+
void *_longPressStopFuncParam = NULL;
179179

180180
callbackFunction _duringLongPressFunc = NULL;
181181
parameterizedCallbackFunction _paramDuringLongPressFunc = NULL;
@@ -204,9 +204,9 @@ class OneButton
204204
stateMachine_t _state = OCS_INIT;
205205
stateMachine_t _lastState = OCS_INIT; // used for debouncing
206206

207-
unsigned long _startTime; // start of current input change to checking debouncing
208-
int _nClicks; // count the number of clicks with this variable
209-
int _maxClicks = 1; // max number (1, 2, multi=3) of clicks of interest by registration of event functions.
207+
unsigned long _startTime = 0; // start of current input change to checking debouncing
208+
int _nClicks = 0; // count the number of clicks with this variable
209+
int _maxClicks = 1; // max number (1, 2, multi=3) of clicks of interest by registration of event functions.
210210
};
211211

212212
#endif

suppressions.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// cppcheck suppressions
2+
unusedFunction
3+
missingInclude
4+
5+
// this one might be something to look into
6+
knownConditionTrueFalse

0 commit comments

Comments
 (0)