diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/testApp.cpp | 43 | ||||
| -rw-r--r-- | src/testApp.h | 17 |
2 files changed, 53 insertions, 7 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index 81b77e2..081c3e6 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -41,7 +41,7 @@ void testApp::setup(){ light=true; - camWidth = 320; // try to grab at this size. + camWidth = 320; // try to grab at this size. camHeight = 240; vidGrabber.setVerbose(true); @@ -49,12 +49,17 @@ void testApp::setup(){ vidGrabber.setDeviceID(0); - vidGrabber.initGrabber(camWidth,camHeight); + grabberAvailable=vidGrabber.initGrabber(camWidth,camHeight); //printf("asked for 320 by 240 - actual size is %i by %i\n", vidGrabber.width, vidGrabber.height); videoInverted = new unsigned char[camWidth*camHeight*3]; videoTexture.allocate(camWidth,camHeight, GL_RGB); + ard.connect("/dev/ttyUSB0", 57600); + ofAddListener(ard.EInitialized, this, &testApp::setupArduino); + bSetupArduino = false; + bSwitchArduino = false; + } //-------------------------------------------------------------- @@ -76,10 +81,44 @@ void testApp::update(){ videoTexture.loadData(videoInverted, camWidth,camHeight, GL_RGB); } } + + updateArduino(); +} + +//-------------------------------------------------------------- +void testApp::setupArduino(const int & version) { + + // remove listener because we don't need it anymore + ofRemoveListener(ard.EInitialized, this, &testApp::setupArduino); + + // this is where you setup all the pins and pin modes, etc + for (int i = 0; i < 13; i++){ + ard.sendDigitalPinMode(i, ARD_OUTPUT); + } + ard.sendDigitalPinMode(7, ARD_INPUT); + + bSetupArduino = true; + printf("arduino ready\n"); +} + +//-------------------------------------------------------------- +void testApp::updateArduino(){ + + // update the arduino, get any data or messages. + ard.update(); + + // do not send anything until the arduino has been set up + if (bSetupArduino) { + if (bSwitchArduino!=ard.getDigital(7)) { + bSwitchArduino=ard.getDigital(7); + printf("pin 7 %i\n",bSwitchArduino); + } + } } //-------------------------------------------------------------- void testApp::draw(){ + if (mode!=CALIBRATE&&bSetupArduino&!bSwitchArduino) return; for (int i=0;i<numViews;i++) { views[i].setLight(); } diff --git a/src/testApp.h b/src/testApp.h index 32dae89..17ba87d 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -27,6 +27,7 @@ have to track how many frames each key has been pressed for #include "ofMain.h" +#include "ofEvents.h" #include "ofxXmlSettings.h" #include "ofx3DModelLoader.h" @@ -76,10 +77,16 @@ class testApp : public ofBaseApp{ bool light; ofVideoGrabber vidGrabber; - - unsigned char * videoInverted; - ofTexture videoTexture; - int camWidth; - int camHeight; + unsigned char * videoInverted; + ofTexture videoTexture; + int camWidth; + int camHeight; + bool grabberAvailable; + + void setupArduino(const int & version); + void updateArduino(); + ofArduino ard; + bool bSetupArduino; // flag variable for setting up arduino once + int bSwitchArduino; }; |
