void EFM32_CapSenseSlider::scanCallbackHandler(void) { /* Calculate slider position */ _position = CAPLESENSE_getSliderPosition(); /* Check for touch */ if(_position < 0) { /* Slider is no longer being touched */ if(_touched == true) { _touched = false; if(_untouchCb != NULL) _untouchCb(); } /* When no longer touched, go to sense mode */ CAPLESENSE_setupLESENSE(true); return; } /* Touched, check if this is the first touch */ if(_touched == false) { _touched = true; if(_touchCb != NULL) _touchCb(); } /* Check if we tripped the threshold */ if((_lastValue != _position) && (_slideCb != NULL)) { if((_trippingPoint == -1) || (_position >= _trippingPoint)) _slideCb(); } _lastValue = _position; }
void EFM32_CapSenseSlider::channelCallbackHandler(void) { /* When a touch is detected, go to responsive scan mode */ CAPLESENSE_setupLESENSE(false); }
/**************************************************************************//** * @brief Capsense demo loop *****************************************************************************/ void capSenseDemo(void) { int32_t slider; bool oldBoost = vboost; /* Setup RTC. */ RTCDRV_Setup(cmuSelect_LFRCO, cmuClkDiv_32); /* Setup capSense callbacks. */ CAPLESENSE_setupCallbacks(&capSenseScanComplete, &capSenseChTrigger); /* Main loop */ while (1) { switch(demoState) { case DEMO_SLEEP_PREPARE: { /* Setup LESENSE in sleep mode. */ CAPLESENSE_setupLESENSE(true); /* Disable LCD to avoid excessive current consumption */ SegmentLCD_Disable(); /* Disable Vdd check. */ VDDCHECK_Disable(); /* Go to sleep state. */ demoState = DEMO_SLEEP; } break; case DEMO_SLEEP: { /* Go to sleep and wait until the measurement completes. */ CAPLESENSE_Sleep(); } break; case DEMO_SENSE_PREPARE: { /* Setup LESENSE in high-accuracy sense mode. */ CAPLESENSE_setupLESENSE(false); /* Start timeout counter. */ RTCDRV_Trigger(1000U, &capSenseTimerFired); /* Enable vboost */ SegmentLCD_Init(vboost); /* Go to sense state. */ demoState = DEMO_SENSE; } break; case DEMO_SENSE: { /* Go to sleep and wait until the measurement completes. */ CAPLESENSE_Sleep(); /* Get slider position. */ slider = CAPLESENSE_getSliderPosition(); if (-1 != slider) { /* Reset RTC */ RTC_Enable(false); RTC_Enable(true); } capSenseAringUpdate(slider); /* Check for change in input voltage. Enable vboost if necessary */ /* Initialize voltage comparator */ VDDCHECK_Init(); /* Check if voltage is below 3V, if so use voltage boost */ if (VDDCHECK_LowVoltage(2.9)) { vboost = true; if (oldBoost != vboost) { /* Enable vboost */ SegmentLCD_Init(vboost); /* Use antenna symbol to signify enabling of vboost */ SegmentLCD_Symbol(LCD_SYMBOL_ANT, vboost); } oldBoost = vboost; } else { vboost = false; } switch (demoMode) { case (DEMOMODE_SCROLLTEXT): capSenseScrollText(); break; case (DEMOMODE_BARS): capSenseBars(); break; case (DEMOMODE_VALUES): capSenseValues(); break; default: break; } } break; default: { ; } break; } } }