int main() { //init the wiringPi wiringPiSetup(); piHiPri(99); //set up pin directions pinMode(US_TRIGGER_PIN, OUTPUT); pinMode(US_ECHO_PIN, INPUT); digitalWrite(US_TRIGGER_PIN, 0); //set up pin pullups pullUpDnControl(US_TRIGGER_PIN, PUD_OFF); pullUpDnControl(US_ECHO_PIN, PUD_OFF); printf("\nGPIO config done.\r\n\r\n"); printf("\nULTRASONIC MEASURE.\r\n\r\n"); wiringPiISR (US_ECHO_PIN,INT_EDGE_RISING , echoArrived); doTrigger(); gettimeofday(&t1, NULL); waitEcho(); gettimeofday(&t2, NULL); elapsedTime = (double)(t2.tv_usec - t1.tv_usec); printf("\nULTRASONIC MEASURE DONE.\r\n\r\n"); printf("\nTIME %f us\r\n", elapsedTime); return 0; }
BOOL LLViewerGesture::trigger(KEY key, MASK mask) { if (mKey == key && mMask == mask) { doTrigger( TRUE ); return TRUE; } else { return FALSE; } }
BOOL LLViewerGesture::trigger(const std::string &trigger_string) { // Assumes trigger_string is lowercase if (mTriggerLower == trigger_string) { doTrigger( FALSE ); return TRUE; } else { return FALSE; } }
mt_throws Result PollPollGroup::trigger () { if (poll_tlocal && poll_tlocal == libMary_getThreadLocal()) { mutex.lock (); triggered = true; mutex.unlock (); return Result::Success; } mutex.lock (); return mt_unlocks (mutex) doTrigger (); }
mt_throws Result PollPollGroup::activatePollable (PollableKey const mt_nonnull key) { PollableEntry * const pollable_entry = static_cast <PollableEntry*> ((void*) key); mutex.lock (); assert (!pollable_entry->activated); pollable_entry->activated = true; inactive_pollable_list.remove (pollable_entry); pollable_list.append (pollable_entry); if (!(poll_tlocal && poll_tlocal == libMary_getThreadLocal())) return mt_unlocks (mutex) doTrigger (); mutex.unlock (); return Result::Success; }
// The pollable should be available for unsafe callbacks while this method is called. mt_throws PollGroup::PollableKey PollPollGroup::addPollable (CbDesc<Pollable> const &pollable, bool activate) { PollableEntry * const pollable_entry = new PollableEntry; pollable_entry->poll_poll_group = this; pollable_entry->valid = true; pollable_entry->activated = activate; pollable_entry->pollable = pollable; // We're making an unsafe call, assuming that the pollable is available. pollable_entry->fd = pollable->getFd (pollable.cb_data); pollable_entry->need_input = true; pollable_entry->need_output = true; // We're making an unsafe call, assuming that the pollable is available. // // We're counting on the fact that the poll group will always be available // when pollable_feedback callbacks are called - that's why we use NULL // for coderef_container. pollable->setFeedback ( Cb<Feedback> (&pollable_feedback, pollable_entry, NULL /* coderef_container */), pollable.cb_data); mutex.lock (); if (activate) pollable_list.append (pollable_entry); else inactive_pollable_list.append (pollable_entry); ++num_pollables; if (activate && !(poll_tlocal && poll_tlocal == libMary_getThreadLocal())) { if (!mt_unlocks (mutex) doTrigger ()) logF_ (_func, "doTrigger() failed: ", exc->toString()); } else { mutex.unlock (); } return static_cast <void*> (pollable_entry); }
bool Trigger::update(float deltaTime, ofRectangle& triggerArea) { this->deltaTime = deltaTime; elapsedTime+=deltaTime; if((moving) || ( (elapsedTime-lastTriggerTime > 4) && (rechargeSettings->restoreSpeed>0) && !disabled && (unitPower>=rechargeSettings->triggerPower) )) { sampleBrightness += deltaTime; } else { sampleBrightness-=deltaTime*2; } sampleBrightness = ofClamp(sampleBrightness, 0, 1); moving = false; if(lastSettings!=NULL) { lastScale-=deltaTime*5; if(lastScale<=0.0) { lastScale = 0; lastSettings = NULL; } } // scale up / down on start stop if(stopping) { scale-=deltaTime*5; if(scale<=0.0) { scale = 0; active = false; return false; } return active; } else if(scale<1){ scale+= deltaTime*5; // (1-scale)*0.2; if(scale>1) scale = 1; } if((settings!=NULL) &&(!settings->rotateOnFire)) { angle = 0; if(settings->rotationSpeed>0) { float sinoffset = settings->rotateOscillationOffset * ofMap(pos.x, triggerArea.getLeft(), triggerArea.getRight(), -1, 1); angle = (sin((elapsedTime + sinoffset)*settings->rotationSpeed )*settings->rotationExtent); } if(settings->rotateMirrorOffset!=0) { angle+= ofMap(pos.x, triggerArea.getLeft(), triggerArea.getRight(), 1, -1) * settings->rotateMirrorOffset; } } if(showDebugData) { if((elapsedTime-lastUpdate>0.032)||(motionValues.size()==0)) { motionValues.push_back(motionLevel); lastUpdate = elapsedTime; } else { float lastlevel = 0; lastlevel = motionValues[motionValues.size()-1]; motionValues[motionValues.size()-1] = (motionLevel>lastlevel) ? motionLevel : lastlevel; } if(motionValues.size()>motionValueCount) { motionValues.pop_front(); } } unitPower+=rechargeSettings->restoreSpeed * deltaTime; if(unitPower>1) unitPower = 1; if((rechargeSettings->restoreSpeed==0) && (unitPower<=0)) { stopping = true; } // we need to have sensed motion, // AND we need to have enough unitPower to trigger if( (!disabled) && (!stopping) && (scale>0.95) && (motionLevel >= rechargeSettings->motionTriggerLevel) && (unitPower>=rechargeSettings->triggerPower) && (elapsedTime - lastTriggerTime > rechargeSettings->minTriggerInterval) ) { if(doTrigger()) { motionLevel = 0; unitPower-=rechargeSettings->triggerPower; lastTriggerTime = elapsedTime; } } motionLevel -= rechargeSettings->motionDecay*deltaTime; if(motionLevel<0) motionLevel = 0; return active; }