Example #1
0
/**
 * the interrupt to fire when the input pin is pulled up to 3v
 */
void signalIsr(void)
{
    unsigned long long interruptTimeMs = getCurrentMilliseconds();

    // determine whether this is rising edge or falling edge
    if(digitalRead(PIN_INPUT) == 1) {
        // rising edge
        interruptTimeMsRising = interruptTimeMs;
        return;
    }

    // Was there a preceding rising edge detected?
    if(interruptTimeMsRising == 0) {
        // No rising value, ignore
        return;
    }

    // else, falling edge
    unsigned long long intervalTimeMs = interruptTimeMs - interruptTimeMsRising;

    // reset, ready for next event
    interruptTimeMsRising = 0;

    printf("\n\nnew signal - interval was %llu\n", intervalTimeMs);

    if(intervalTimeMs < triggerInterval) {
        printf("ignoring, signal time was not long enough\n");
        return;
    }

    // record the signal count to file
    fileRecordSignalCount(interruptTimeMs);

    // blink the LED to show we recorded the signal
    //piThreadCreate(ledSignalCounted);
    ledBlink(50);

    // attempt to submit the count file
    // disable - threads become unresponsive after a while. Rely on main loop call to processCountFile();
    //processCountFile();
}
Example #2
0
 unsigned long Timer::getMilliseconds()
 {
     return getCurrentMilliseconds() - mTimeStart;
 }
Example #3
0
 void Timer::reset()
 {
     mTimeStart = getCurrentMilliseconds();
 }
Example #4
0
/**
 * init and run the application
 */
int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        printf("signalCount: usage: signalCounter [endpoint] (trigger_interval_ms)\n");
        return 1;
    }

    // store endpoint
    strcpy(endPointUrl, argv[1]);
    printf("Using [%s] as endpoint URL\n", endPointUrl);

    // store trigger interval, if we have one
    if(argc == 3)
    {
        char* p; // will be set to the "first invalid character" set by strtol
        errno = 0;
        triggerInterval = strtol(argv[2], &p, 10);
        if (*p != '\0' || errno != 0)
        {
            fprintf(stderr, "invalid trigger interval [%s]\n", argv[2]);
            return 1;
        }
    }

    printf("Using [%d] for trigger interval\n", triggerInterval);

    // init the wiringPi library
    if (wiringPiSetup () < 0)
    {
        fprintf(stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
        return 1 ;
    }

    // set up an interrupt on our input pin
    if (wiringPiISR(PIN_INPUT, INT_EDGE_BOTH, &signalIsr) < 0)
    {
        fprintf(stderr, "Unable to setup ISR: %s\n", strerror (errno));
        return 1 ;
    }

    // configure the output pin for output. Output output output
    pinMode(PIN_OUTPUT, OUTPUT);

    pinMode(PIN_INPUT, INPUT);

    // pull the internal logic gate down to 0v - we don't want it floating around
    pullUpDnControl(PIN_INPUT, PUD_DOWN);

    // blink 3 times - we're ready to go
    ledBlink(300);
    delay(300);
    ledBlink(300);
    delay(300);
    ledBlink(300);

    // send a test signal count with the current timestamp
    fileRecordSignalCount(getCurrentMilliseconds());

    printf("signalCount started\n");

    for(;;) {
        delay(1000);

        // this thread will submit any count files that have not been sent
        printf("about to run cleanup thread\n");
        processCountFile();
    }

    return 0;
}
float ofxDepthImageSequence::getCurrentSeconds(){
	return getCurrentMilliseconds()/1000.0;
}