summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-03-21 23:08:28 +0000
committerTim Redfern <tim@eclectronics.org>2012-03-21 23:08:28 +0000
commit79c3cd01ef47524e80bd2d242807ad60c5de1e0d (patch)
tree024bb9d79dba2892f7f2f57e83fa058cda6d7ca5
parent3d5588a7ead64f3b11ef132f21469b9471819850 (diff)
arduino added
-rw-r--r--map4.cbp3
-rw-r--r--map4.layout23
-rw-r--r--src/testApp.cpp43
-rw-r--r--src/testApp.h17
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 @@
<Unit filename="../../../addons/ofxXmlSettings/src/ofxXmlSettings.h">
<Option virtualFolder="addons/ofxXmlSettings/src" />
</Unit>
+ <Unit filename="addons.make">
+ <Option virtualFolder="build config/" />
+ </Unit>
<Unit filename="bin/data/defaults.xml">
<Option virtualFolder="build config/" />
</Unit>
diff --git a/map4.layout b/map4.layout
index 11e325d..f85b1ee 100644
--- a/map4.layout
+++ b/map4.layout
@@ -4,22 +4,25 @@
<File name="../../../addons/ofx3DModelLoader/src/3DS/model3DS.h" open="0" top="0" tabpos="0">
<Cursor position="136" topLine="0" />
</File>
- <File name="bin/data/defaults.xml" open="1" top="0" tabpos="3">
+ <File name="addons.make" open="1" top="0" tabpos="1">
+ <Cursor position="43" topLine="0" />
+ </File>
+ <File name="bin/data/defaults.xml" open="0" top="0" tabpos="3">
<Cursor position="1033" topLine="0" />
</File>
- <File name="bin/data/settings.xml" open="1" top="1" tabpos="11">
- <Cursor position="781" topLine="0" />
+ <File name="bin/data/settings.xml" open="0" top="0" tabpos="11">
+ <Cursor position="1063" topLine="0" />
</File>
<File name="config.make" open="0" top="0" tabpos="3">
<Cursor position="548" topLine="0" />
</File>
- <File name="src/keyVar.cpp" open="1" top="0" tabpos="7">
+ <File name="src/keyVar.cpp" open="0" top="0" tabpos="7">
<Cursor position="1236" topLine="16" />
</File>
<File name="src/keyVar.h" open="0" top="0" tabpos="8">
<Cursor position="0" topLine="0" />
</File>
- <File name="src/main.cpp" open="1" top="0" tabpos="5">
+ <File name="src/main.cpp" open="0" top="0" tabpos="5">
<Cursor position="275" topLine="0" />
</File>
<File name="src/mapUtils.cpp" open="0" top="0" tabpos="7">
@@ -28,16 +31,16 @@
<File name="src/mapUtils.h" open="0" top="0" tabpos="6">
<Cursor position="165" topLine="0" />
</File>
- <File name="src/testApp.cpp" open="1" top="0" tabpos="2">
- <Cursor position="6396" topLine="188" />
+ <File name="src/testApp.cpp" open="1" top="1" tabpos="2">
+ <Cursor position="3281" topLine="95" />
</File>
- <File name="src/testApp.h" open="1" top="0" tabpos="1">
+ <File name="src/testApp.h" open="0" top="0" tabpos="1">
<Cursor position="1267" topLine="33" />
</File>
- <File name="src/viewpoint.cpp" open="1" top="0" tabpos="4">
+ <File name="src/viewpoint.cpp" open="0" top="0" tabpos="4">
<Cursor position="566" topLine="0" />
</File>
- <File name="src/viewpoint.h" open="1" top="0" tabpos="6">
+ <File name="src/viewpoint.h" open="0" top="0" tabpos="6">
<Cursor position="808" topLine="13" />
</File>
</CodeBlocks_layout_file>
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;
};