MCPcopy Create free account
hub / github.com/Michael-Manning/E-Paper-Climate-Logger / updateButtonState

Function updateButtonState

firmware/src/buttons.cpp:86–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85
86void updateButtonState(bool btn1State, bool btn2State, uint32_t timestampMS){
87 prevBtn1State = currentBtn1State;
88 prevBtn2State = currentBtn2State;
89 currentBtn1State = btn1State;
90 currentBtn2State = btn2State;
91 currentTimestampMS = timestampMS;
92
93 btn1MultipressCountConfirmed = -1;
94 btn2MultipressCountConfirmed = -1;
95
96 // I don't know how to comment this function. It's just raw state logic
97
98 if(getBtn1Down())
99 {
100 if(currentTimestampMS - btn1LastDownMS < multipressMaxPeriodMS)
101 {
102 if(btn1MultipressCount < maxMultipress && btn1MultipressCount != 0)
103 btn1MultipressCount++;
104 }
105 else if (btn1MultipressCount == 0)
106 {
107 btn1MultipressCount++;
108 }
109
110 btn1LastDownMS = timestampMS;
111 }
112 else{
113 if(btn1MultipressCount == maxMultipress)
114 btn1MultipressCount = 0;
115
116
117 if(currentTimestampMS - btn1LastDownMS >= multipressMaxPeriodMS && btn1MultipressCount > 0)
118 {
119 btn1MultipressCountConfirmed = btn1MultipressCount;
120 btn1MultipressCount = 0;
121 }
122 }
123 if(!getBtn1())
124 btn1HoldStartMS = timestampMS;
125
126
127 if(getBtn2Down())
128 {
129 if(currentTimestampMS - btn2LastDownMS < multipressMaxPeriodMS)
130 {
131 if(btn2MultipressCount < maxMultipress && btn2MultipressCount != 0)
132 btn2MultipressCount++;
133 }
134 else if (btn2MultipressCount == 0)
135 {
136 btn2MultipressCount++;
137 }
138
139 btn2LastDownMS = timestampMS;
140 }
141 else{
142 if(btn2MultipressCount == maxMultipress)
143 btn2MultipressCount = 0;

Callers 2

doLightSleepFunction · 0.85
loopFunction · 0.85

Calls 4

getBtn1DownFunction · 0.85
getBtn1Function · 0.85
getBtn2DownFunction · 0.85
getBtn2Function · 0.85

Tested by

no test coverage detected