From 79c3cd01ef47524e80bd2d242807ad60c5de1e0d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 21 Mar 2012 23:08:28 +0000 Subject: arduino added --- map4.cbp | 3 +++ map4.layout | 23 +++++++++++++---------- src/testApp.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- src/testApp.h | 17 ++++++++++++----- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/map4.cbp b/map4.cbp index 13593e5..c22aca4 100644 --- a/map4.cbp +++ b/map4.cbp @@ -111,6 +111,9 @@ + + diff --git a/map4.layout b/map4.layout index 11e325d..f85b1ee 100644 --- a/map4.layout +++ b/map4.layout @@ -4,22 +4,25 @@ - + + + + - - + + - + - + @@ -28,16 +31,16 @@ - - + + - + - + - + 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