void Light::toggle() { if (m_isLedOn) { setLedOff(); } else { setLedOn(); } }
//------------------------------------------------------------------------------ int __attribute__((OS_main)) main(void) { dnaUsbInit(); enableLed(); usbCommand = ceCommandIdle; usbRNAPacketExpected = 1; TCCR0B = 1<<CS01 | 1<<CS00; // set 8-bit timer prescaler to div/64 TIMSK0 = 1<<TOIE0; // enable the interrupt rnaInit(); sei(); setLedOff(); for(;;) { rnaPoll(); if ( rnaPacketAvail ) { setLedOn(); rnaPacketAvail = 0; _delay_ms( 50 ); while ( !rnaSend(usbRNATo, usbRNAPacket, usbRNAPacketExpected) ) { _delay_ms(1); } setLedOff(); } /* if ( usbRNAPacketPos == usbRNAPacketExpected ) { usbRNAPacketPos = 0; if ( *usbRNAPacket == RNATypeDebugString ) { usbRNAPacket[usbRNAPacketExpected] = 0; usbprint( (char *)usbRNAPacket + 1, usbRNAPacketExpected ); } } */ } }
//------------------------------------------------------------------------------ // entered 1994.7 times per second ISR( TIM0_COMPA_vect, ISR_NOBLOCK ) { if ( scheduleShotBox ) { if ( !--scheduleShotBox && (currentFireMode == ceRamp) && enhancedTriggerTimeout ) { startFireCycle = true; scheduleShotBox = scheduleShotRate; } } if ( !isAnnunciatorOn() ) { if ( debounceBox ) // programmable debounce, sample every X milliseconds { debounceBox--; } else if ( (triggerState && !readTrigger()) || (!triggerState && readTrigger()) ) { // rebounce check part 2, make sure the state change lasts long enough if ( !triggerStateChangeValid && consts.rebounce ) { debounceBox = consts.rebounce; triggerStateChangeValid = true; // next time around it counts } else { debounceBox = consts.debounce; triggerState = readTrigger() ? true : false; if ( !triggerState ) // been pressed { triggerWavelength = triggerWavelengthBox; triggerWavelengthBox = 0; if ( inProgramMode ) { millisecondCountBoxLong = MS_UNTIL_ENTRY_VALID; currentEntry++; } else { // ramping and in a qualified-long-enough string? if ( (currentFireMode == ceRamp) && (shotsInString >= consts.rampEnableCount) ) { // RAMPING // get the current rate and schedule a shot for // 50% faster in the future base, increasing // per ramp climb scheduleShotRate = triggerWavelength - (triggerWavelength / rampLevel); rampLevel += consts.rampClimb; if ( !scheduleShotBox || (scheduleShotBox > scheduleShotRate) ) { scheduleShotBox = scheduleShotRate; } } startFireCycle = true; // trigger has been depressed, reset the "do what you're doing" timeout rampTimeoutBox = consts.rampTimeout; // after this many milliseconds Enhanced will not fire enhancedTriggerTimeout = consts.enhancedTriggerTimeout; if ( currentFireMode == ceBurst ) { burstCount = consts.burstCount; } } } else if ( !inProgramMode ) // been released { if ( (currentFireMode == ceAutoresponse) && enhancedTriggerTimeout ) { startFireCycle = true; } else { startFireCycle = false; } } } } else { triggerStateChangeValid = false; } } // duty cycle for LED, effecting a dimmer if ( isLedOn ) { if ( dimmerBox++ > 8 ) { dimmerBox = 0; } if ( consts.dimmer > dimmerBox ) { setLedOn(); } else { setLedOff(); } } else { setLedOff(); } //-------------------------------------------------------------------------------- // everything below here has a ~1ms resulotion static uint8 s_ms; if ( ++s_ms & 0x01 ) { return; } annunciatorToggle(); if ( triggerWavelengthBox < 1000 ) { triggerWavelengthBox++; } if ( enhancedTriggerTimeout ) { enhancedTriggerTimeout--; } if ( millisecondCountBox ) { millisecondCountBox--; } if ( millisecondCountBox2 ) { millisecondCountBox2--; } if ( millisecondCountBox3 ) { millisecondCountBox3--; } if ( antiBoltstickTimeout ) { antiBoltstickTimeout--; } if ( rampTimeoutBox ) { if ( !--rampTimeoutBox ) { shotsInString = 0; rampLevel = 2; currentFireMode = consts.fireMode; scheduleShotBox = 0; scheduleShotRate = 0; } } // fet2 being used to run a hopper? turn it off now if ( accessoryRunTime && !--accessoryRunTime ) { fet2Off(); } // handle program mode activity if ( millisecondCountBoxLong ) // waiting for idle trigger? (signifying an entry has been made) { if ( !--millisecondCountBoxLong && triggerState && inProgramMode ) // this the one? { if ( programSelectState == ceStateSelectingRegister ) { if ( currentEntry >= ceRegisterLast ) { timesToBlinkLight = 4; } else { programSelectState++; selectedRegister = currentEntry; if ( selectedRegister == ceRegisterFireMode ) { programSelectState++; // for fire mode, jump right to set } else if ( selectedRegister == ceRegisterEyeToggle ) { consts.eyeEnabled = consts.eyeEnabled ? false : true; eepromConstantsDirty = true; programSelectState--; } timesToBlinkLight = 1; } } else if ( programSelectState == ceStateSelectingDeltaMethod ) { if ( currentEntry >= 4 ) { timesToBlinkLight = 4; programSelectState = ceStateSelectingRegister; } else { programSelectState++; plusMinusDelta = currentEntry; timesToBlinkLight = 1; } } else { programSelectState = ceStateSelectingRegister; if ( selectedRegister == ceRegisterFireMode ) { consts.fireMode = currentEntry; timesToBlinkLight = consts.fireMode; inProgramMode = false; } else if ( selectedRegister == ceRegisterFireRate ) { if ( plusMinusDelta == 1 ) { consts.ballsPerSecondX10 += currentEntry; } else if ( plusMinusDelta == 2 ) { consts.ballsPerSecondX10 -= currentEntry; } else { consts.ballsPerSecondX10 = currentEntry; } timesToBlinkLight = consts.ballsPerSecondX10 / 10; } else if ( selectedRegister == ceRegisterDwell1 ) { if ( plusMinusDelta == 1 ) { consts.dwell1 += currentEntry; } else if ( plusMinusDelta == 2 ) { consts.dwell1 -= currentEntry; } else { consts.dwell1 = currentEntry; } timesToBlinkLight = consts.dwell1; } else // dwell2 { if ( plusMinusDelta == 1 ) { consts.dwell2 += currentEntry; } else if ( plusMinusDelta == 2 ) { consts.dwell2 -= currentEntry; } else { consts.dwell2 = currentEntry; } timesToBlinkLight = consts.dwell2; } eepromConstantsDirty = true; } currentEntry = 0; } } // if the LED is being told to blink, handle that here if ( timesToBlinkLight ) { if ( !blinkBox ) { if ( blinkOn ) { blinkOn = false; isLedOn = true; blinkBox = LIGHT_ON_FOR; } else { blinkOn = true; isLedOn = false; blinkBox = LIGHT_OFF_FOR; if ( !--timesToBlinkLight ) { isLedOn = inProgramMode; } } } else { blinkBox--; } } usbPoll(); // check for USB activity // only check the eye when we need to, as the emitter consumes non-trivial power if ( consts.eyeEnabled && sampleEye ) { digitizeEye(); } }
THREAD(SoundRecord, arg) { printf("SoundAnalyzer started\n"); fflush(stdout); VsTest(); NutSleep(200); SoundStruct* ss = arg; int i; int recording = -1; ResetDevice(); unsigned int samplecount = 0; short sample; short * recordBuffer = malloc( RECORD_BUFFER_SIZE * sizeof(short) ); for(i = 0; i < RECORD_BUFFER_SIZE; i++) recordBuffer[i] = 0; i = 0; int absolute = 0; //sum of the absolute values of samples short absoluteCount = 0; //number of recorded samples up to ABSOLUTE_COUNT bool readyToBegin = false; bool lastWindow = false; RecordDeviceInit(8000, 1, 0, 20); for(;;) { NutSleep(3); samplecount = VsRegRead(VS_HDAT1_REG); // spec page 54: if sci_hdat1 >= 896 may be better not // to read and wait for overflow while ( (samplecount > 0 && samplecount < 896 )) { samplecount--; sample = VsRegRead(VS_HDAT0_REG); recordBuffer[i] = sample; absolute += abs(sample); if( absoluteCount < ABSOLUTE_COUNT) absoluteCount++; else //the oldest sample must be deducted from the sum variable (absolute) { if ( i - ABSOLUTE_COUNT < 0) absolute -= abs(recordBuffer[RECORD_BUFFER_SIZE+i-ABSOLUTE_COUNT]); else absolute -= abs(recordBuffer[i-ABSOLUTE_COUNT]); } i++; if ( i == RECORD_BUFFER_SIZE ) { i=0; readyToBegin = true; //printf("%d, ", absolute/ABSOLUTE_COUNT); //DEBUG } if( absoluteCount < ABSOLUTE_COUNT) continue; //recording does not begin until the averaging window has been fully covered //start recording, if the treshold is exceeded //if (readyToBegin && (absolute/ABSOLUTE_COUNT > RECORD_START) && recording == -1) if(readyToBegin && sample > RECORD_START && recording == -1) { setLedOn(_BV(_LED_1)); recording = 0; /* if ( i < BACKTRACE ) { memcpy(ss->buffer, recordBuffer+i-BACKTRACE, BACKTRACE-i); memcpy(ss->buffer+(BACKTRACE-i), recordBuffer, i); } else memcpy(ss->buffer, recordBuffer+i, BACKTRACE); */ } //if we are recording, save sample if ( recording != -1) { ss->buffer[BACKTRACE+recording] = sample; recording++; } if (recording >= 0 && ( (BACKTRACE+recording == WIN_SIZE* CEPS_COUNT) || (absolute/ABSOLUTE_COUNT < RECORD_STOP) ) ) lastWindow = true; //-2 means that recording should be stopped whenever the last window is filled if( lastWindow && ((BACKTRACE + recording) % WIN_SIZE == 0) ) //dynamic length { //if ( ABSOLUTE_COUNT+recording == WIN_SIZE* CEPS_COUNT && recording != -1) { //fixed length ss->ceps_count = (BACKTRACE + recording) / WIN_SIZE; lastWindow = false; if(ss->ceps_count < 5) continue; setLedOff(_BV(_LED_1)); recording = -1; if(ss->ceps_count < MIN_CEPS_COUNT) continue; if(ss->ceps_count != CEPS_COUNT && ss->ceps_count > 3) ss->ceps_count -= 3; //WAWISETTI // printf("\n\n"); // int j; // for(j = 0; j < 44; j++) // printf("%02x ", wavheader[j]); // // printf("\n\n\n"); // for(j = 0; j < ss->ceps_count*WIN_SIZE; j++) // printf("%02x ", recordBuffer[j]); // // printf("\n\n\n"); // for(;;) // NutThreadYield(); NutEventPost( &recordBufferReadyRead ); //for(;;) // NutThreadYield(); //break; //mihi tätä breakkii tarvitaan?? } } } }
MainWindow::MainWindow( QWidget *_parent ): QMainWindow(_parent) { this->resize(QSize(1024,800)); m_kinect=QKinect::instance(); QToolBar *toolbar = new QToolBar(this); toolbar->setObjectName("KinectToolbar"); QLabel *label= new QLabel(toolbar); label->setText("angle"); toolbar->addWidget(label); QDoubleSpinBox *angle = new QDoubleSpinBox(this); angle->setMaximum(30.0); angle->setMinimum(-30.0); angle->setSingleStep(1.0); QObject::connect(angle,SIGNAL(valueChanged(double)),m_kinect,SLOT(setAngle(double))); toolbar->addWidget(angle); QPushButton *reset = new QPushButton("reset"); QObject::connect(reset,SIGNAL(clicked()),m_kinect,SLOT(resetAngle())); toolbar->addWidget(reset); QLabel *label2= new QLabel(toolbar); label2->setText("Camera Mode"); toolbar->addWidget(label2); QComboBox *videoMode= new QComboBox(toolbar); videoMode->addItem("RGB"); videoMode->addItem("Bayer"); videoMode->addItem("IR 8"); videoMode->addItem("IR 10"); videoMode->addItem("IR 10 P"); videoMode->addItem("YUV_RGB"); videoMode->addItem("YUV_RAW"); QObject::connect(videoMode,SIGNAL(currentIndexChanged(int)),m_kinect,SLOT(setVideoMode(int))); toolbar->addWidget(videoMode); QRadioButton *off = new QRadioButton("LED off",toolbar); off->setDown(true); QObject::connect(off,SIGNAL(clicked()),m_kinect,SLOT(setLedOff())); toolbar->addWidget(off); QRadioButton *red = new QRadioButton("LED red",toolbar); QObject::connect(red,SIGNAL(clicked()),m_kinect,SLOT(setRedLed())); toolbar->addWidget(red); QRadioButton *green = new QRadioButton("LED green",toolbar); QObject::connect(green,SIGNAL(clicked()),m_kinect,SLOT(setGreenLed())); toolbar->addWidget(green); QRadioButton *yellow = new QRadioButton("LED yellow",toolbar); QObject::connect(yellow,SIGNAL(clicked()),m_kinect,SLOT(setYellowLed())); toolbar->addWidget(yellow); QRadioButton *redF = new QRadioButton("flash red ",toolbar); QObject::connect(redF,SIGNAL(clicked()),m_kinect,SLOT(setRedLedFlash())); toolbar->addWidget(redF); QRadioButton *greenF = new QRadioButton("flash green",toolbar); QObject::connect(greenF,SIGNAL(clicked()),m_kinect,SLOT(setGreenLedFlash())); toolbar->addWidget(greenF); QRadioButton *yellowF = new QRadioButton("flash yellow",toolbar); QObject::connect(yellowF,SIGNAL(clicked()),m_kinect,SLOT(setYellowLedFlash())); toolbar->addWidget(yellowF); this->addToolBar(toolbar); m_mdiArea = new QMdiArea; m_mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); m_mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setCentralWidget(m_mdiArea); this->setWindowTitle(QString("Kinect Demo")); QGLFormat format; format.setVersion(4,1); format.setProfile( QGLFormat::CoreProfile); format.setSwapInterval(1); QMdiSubWindow *subWindow1 = new QMdiSubWindow; VideoWindow *rgb = new VideoWindow(VideoWindow::RGB); QWidget *container = QWidget::createWindowContainer(rgb); subWindow1->setWidget(container); subWindow1->setAttribute(Qt::WA_DeleteOnClose); subWindow1->setWindowTitle("RGB Output"); subWindow1->resize(500,350); m_mdiArea->addSubWindow(subWindow1); VideoWindow *depth = new VideoWindow(VideoWindow::DEPTH); container = QWidget::createWindowContainer(depth); QMdiSubWindow *subWindow2 = new QMdiSubWindow; subWindow2->setWidget(container); subWindow2->setAttribute(Qt::WA_DeleteOnClose); subWindow2->setWindowTitle("Depth Output"); subWindow2->resize(500,350); m_mdiArea->addSubWindow(subWindow2); PointCloud *cloud = new PointCloud(); container = QWidget::createWindowContainer(cloud); QMdiSubWindow *subWindow3 = new QMdiSubWindow; subWindow3->setWidget(container); subWindow3->setAttribute(Qt::WA_DeleteOnClose); subWindow3->setWindowTitle("PointCloud"); subWindow3->resize(500,350); m_mdiArea->addSubWindow(subWindow3); this->setWindowTitle(QString("kinect demo")); }
void Light::off() { m_pulseScheduler.stop(); setLedOff(); }