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; }
/**************************************************************************//** * @brief Cap sense values demo *****************************************************************************/ void capSenseBars(void) { int barNum; int sliderPos; const char bars[3] = {'{', '!', '1' }; char msg[8]; sliderPos = CAPLESENSE_getSliderPosition(); SegmentLCD_Number(sliderPos); if (sliderPos == -1) { SegmentLCD_Write("SLIDER"); } else { /* Clear the msg string */ snprintf(msg, 7, " "); /* There are 21 possible "bars" on the display, while there are 48 slider * positions. This maps these 48 into 21 slider positions. */ barNum = (sliderPos * 21) / 48; msg[barNum / 3] = bars[barNum %3]; SegmentLCD_Write(msg); } }
/**************************************************************************//** * @brief ScrollText demo *****************************************************************************/ void capSenseScrollText(void) { char msg[10]; int sliderPos; static int oldSliderPos = -2; int offset; sliderPos = CAPLESENSE_getSliderPosition(); if (oldSliderPos != sliderPos) { oldSliderPos = sliderPos; SegmentLCD_Number(sliderPos); if (sliderPos == -1) sliderPos = 0; offset = ((strlen(message) - 7) * sliderPos) / 48; snprintf(msg, 8, "%s", message + offset); SegmentLCD_Write(msg); } }
/**************************************************************************//** * @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; } } }
void menuLCD(menu_t menu1, menu_t menu2, menu_t menu3, menu_t menu4, menu_t menu5){ old_a=a; a= CAPLESENSE_getSliderPosition(); if (current == 1){ lcd_str("Main Menu ",0,1); lcd_str("Start ",1,4); lcd_str("Tasks ",2,4); lcd_str("ok ",3,0); lcd_str("move",3,11); //lcd_str(s2,3,3); lcd_str(">",choice,3); lcd_str(" ",oc,3); if( Button0pressed ) { if(choice==1){ current=2; } else if (choice == 2){ current=6; } lcd_str(" ",0,1); lcd_str(" ",1,4); lcd_str(" ",2,4); lcd_str(" ",3,0); lcd_str(" ",3,11); }op0= GPIO_PinInGet(BTN_PORT, PB0); } else if (current == 2) { // start menu if(a>-1 && old_a>-1) if(abs(a-old_a)>2) power+=10*(a-old_a); if(power<0) power=0; if(power>2000) power=2000; sprintf(s2,"%0004d Watts",power); sprintf(s,"Time: %02d:%02d",curr_time.h,curr_time.m); lcd_str(s,0,1); lcd_str("Power: ",1,4); lcd_str(s2,2,4); lcd_str("ok ",3,0); lcd_str("back",3,11); //lcd_str(">",choice,3); //lcd_str(" ",oc,3); if( Button0pressed ) { tasks[nextid].pow=power; current=3; lcd_str(" ",0,1); lcd_str(" ",1,0); lcd_str(" ",2,4); lcd_str(" ",3,0); lcd_str(" ",3,11); }op0= GPIO_PinInGet(BTN_PORT, PB0); } else if (current == 3) { if(a>-1 && old_a>-1) power+=(a-old_a); if(power<0) power=0; if(power>24) power=24; sprintf(s2,"%02d hours",power); sprintf(s,"Time: %02d:%02d ",curr_time.h,curr_time.m); lcd_str(s,0,1); lcd_str("Duration: ",1,4); lcd_str(s2,2,4); lcd_str("ok ",3,0); lcd_str("back ",3,11); if( Button0pressed ) { tasks[nextid].duration=power; current=4; select=1; lcd_str(s,0,1); lcd_str(" ",1,0); lcd_str(" ",2,4); lcd_str(" ",3,0); lcd_str(" ",3,11); }op0= GPIO_PinInGet(BTN_PORT, PB0); } else if (current == 4){ if(a>-1 && old_a>-1) power+=(a-old_a); if(power<0) power=0; if(power>24) power=24; if(select==1){ sprintf(s2,"%02d:00 ",power); sprintf(s,"Time: %02d:%02d ",curr_time.h,curr_time.m); lcd_str(s,0,1); lcd_str("Deadline: ",1,4); lcd_str(s2,2,4); lcd_str("ok ",3,0); lcd_str("back ",3,11); }else{ sprintf(s2,"%02d:%02d ",tasks[nextid].deadline.h,power); sprintf(s,"Time: %02d:%02d ",curr_time.h,curr_time.m); lcd_str(s,0,1); lcd_str("Deadline: ",1,4); lcd_str(s2,2,4); lcd_str("ok ",3,0); lcd_str("back ",3,11); } if( Button0pressed ) { if(select==1){ select=2; tasks[nextid].deadline.h=power; } else{ //tasks[nextid].duration=power; //tasks[nextid].id=nextid+1; tasks[nextid].deadline.m=power; tasks[nextid].id=nextid+1; sprintf(s,"new_task %d %d %d %d\n",tasks[nextid].id,tasks[nextid].pow,tasks[nextid].duration * 60,tasks[nextid].deadline.h); sendserial(s); delay(100); sendserial(s); while(completed==0); completed=0; sscanf(Buffer,"status %d %d:%d %s",&tasks[nextid].id,&tasks[nextid].deadline.h,&tasks[nextid].deadline.m,tasks[nextid].status); sscanf(Buffer,"status %d %d:%d",&tasks[nextid].id,&tasks[nextid].deadline.h,&tasks[nextid].deadline.m); sscanf(Buffer,"status %d %d",&tasks[nextid].id,&tasks[nextid].deadline.h); sscanf(Buffer,"status %d",&tasks[nextid].id); sprintf(s,"get_cost %d\n",tasks[nextid].id); sendserial(s); delay(100); sendserial(s); while(completed==0); completed=0; //sscanf(Buffer,"cost %d %d",&tasks[nextid].id,&tasks[nextid].cost); //(Buffer,"cost %d",&tasks[nextid].id); nextid++; current=5; lcd_str(" ",0,1); lcd_str(" ",1,0); lcd_str(" ",2,4); lcd_str(" " ,3,0); lcd_str(" ",3,11); } }op0= GPIO_PinInGet(BTN_PORT, PB0); } else if (current == 5){ sprintf(s,"cost: %d cents",tasks[nextid-1].cost); Buffer[5]=' '; Buffer[4]=':'; lcd_str(Buffer,0,1); //lcd_str("accept ",1,4); lcd_str("Run it now?",2,4); lcd_str("yes",3,0); lcd_str("later",3,11); //lcd_str(">",choice,3); //lcd_str(" ",oc,3); if( op0=1 & GPIO_PinInGet(BTN_PORT, PB0)==0 ) { strcpy(tasks[nextid-1].status,"running"); sprintf(s,"set_status %d %s\n",tasks[nextid-1].id,tasks[nextid-1].status); sendserial(s); delay(100); sendserial(s); while(completed==0); completed=0; current=1; lcd_str(" ",0,1); //lcd_str("accept ",1,4); lcd_str(" ",2,4); lcd_str(" ",3,0); lcd_str(" ",3,11); }op0= GPIO_PinInGet(BTN_PORT, PB0); } else if (current == 6){ //sprintf(s,"%s",tasks[nextid-1].status); lcd_str("Tasks:",0,1); //lcd_str("accept ",1,4); lcd_str(tasks[nextid-1].status,2,4); lcd_str("back",3,0); lcd_str("home",3,11); //lcd_str(">",choice,3); //lcd_str(" ",oc,3); if( op0=1 & GPIO_PinInGet(BTN_PORT, PB0)==0 ) { current=1; }op0= GPIO_PinInGet(BTN_PORT, PB0); } }