unsigned char MPR121_t::getNumTouches(){ if(!isInited()) return(0xFF); unsigned char scratch = 0; for(unsigned char i=0; i<13; i++){ if(getTouchData(i)) scratch++; } return(scratch); }
static void eventThread(void *) { const int timeout=30000/pollPeriod; //30s int timeoutCounter=0; bool aPrev=false; bool tPrev=false; Point pOld; for(;;) { Thread::sleep(pollPeriod); //Check buttons if(POWER_BTN_PRESS_Pin::value()) { timeoutCounter=0; if(aPrev==false) callback(Event(EventType::ButtonA,EventDirection::DOWN)); aPrev=true; } else { if(aPrev==true) callback(Event(EventType::ButtonA,EventDirection::UP)); aPrev=false; } //Check touchscreen Point p=getTouchData(); if(p.x()>=0) //Is someone touching the screen? { timeoutCounter=0; //Ok, someone is touching the screen //did the touch point differ that much from the previous? if(abs(pOld.x()-p.x())>3 || abs(pOld.y()-p.y())>3 || !tPrev) { pOld=p; if(tPrev==false) callback(Event(EventType::TouchDown,pOld,EventDirection::DOWN)); else callback(Event(EventType::TouchMove,pOld,EventDirection::DOWN)); } tPrev=true; } else { //No, no one is touching the screen if(tPrev==true) callback(Event(EventType::TouchUp,pOld,EventDirection::UP)); tPrev=false; } if(++timeoutCounter==timeout) callback(Event(EventType::Timeout)); } }
bool MPR121_t::isNewRelease(unsigned char electrode){ if(electrode>12 || !isInited()) return(false); // avoid out of bounds behaviour return((getLastTouchData(electrode) == true) && (getTouchData(electrode) == false)); }