MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / buttonTaskMainLoop

Method buttonTaskMainLoop

src/Hal/ButtonDrv.cpp:307–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307void ButtonDrv::buttonTaskMainLoop()
308{
309 ButtonId buttonId = BUTTON_ID_CNT;
310 uint8_t buttonIdx = 0U;
311
312 /* The main loop scans several times during one debounce period
313 * for any pin change. If there is no change, the state is
314 * considered as stable.
315 */
316
317 /* Wait 25% of debouncing time whether any button level changed. */
318 if (pdTRUE == xQueueReceive(gxQueue, &buttonId, (DEBOUNCING_TIME / 4U) * portTICK_PERIOD_MS))
319 {
320 if (BUTTON_ID_CNT > buttonId)
321 {
322 m_timer[buttonId].start(DEBOUNCING_TIME);
323 }
324 }
325
326 /* Debounce buttons */
327 while (BUTTON_ID_CNT > buttonIdx)
328 {
329 if ((true == m_timer[buttonIdx].isTimerRunning()) &&
330 (true == m_timer[buttonIdx].isTimeout()))
331 {
332 ButtonState buttonState = BUTTON_STATE_UNKNOWN;
333 uint8_t buttonValue = HIGH;
334
335 switch (buttonIdx)
336 {
337 case BUTTON_ID_OK:
338 buttonValue = Board::buttonOkIn.read();
339 break;
340
341 case BUTTON_ID_LEFT:
342 buttonValue = Board::buttonLeftIn.read();
343 break;
344
345 case BUTTON_ID_RIGHT:
346 buttonValue = Board::buttonRightIn.read();
347 break;
348
349 default:
350 break;
351 }
352
353 if (LOW == buttonValue)
354 {
355 buttonState = BUTTON_STATE_PRESSED;
356 }
357 else
358 {
359 buttonState = BUTTON_STATE_RELEASED;
360 }
361
362 if (BUTTON_STATE_NC != m_state[buttonIdx])
363 {
364 if (m_state[buttonIdx] != buttonState)

Callers 1

buttonTaskMethod · 0.95

Calls 6

isTimerRunningMethod · 0.80
isTimeoutMethod · 0.80
startMethod · 0.45
readMethod · 0.45
notifyMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected