Permalink
Browse files

Finished interface and started simulator code.

  • Loading branch information...
1 parent 4090191 commit 8fdcf23642dc5512c81f7262e786a6886802d590 @mrbichel mrbichel committed Oct 16, 2012
Showing with 252 additions and 219 deletions.
  1. +0 −22 chaosFlow.xcodeproj/project.pbxproj
  2. +23 −2 src/data.cpp
  3. +5 −1 src/data.h
  4. +45 −1 src/flowControl.cpp
  5. +10 −1 src/flowControl.h
  6. +0 −73 src/gui.cpp
  7. +0 −25 src/gui.h
  8. +107 −52 src/interface.cpp
  9. +13 −9 src/interface.h
  10. +34 −15 src/simulator.cpp
  11. +6 −3 src/simulator.h
  12. +9 −13 src/testApp.cpp
  13. +0 −2 src/testApp.h
@@ -23,7 +23,6 @@
04CAE09915F4E6690073E46D /* data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE09815F4E6690073E46D /* data.cpp */; };
04CAE09D15F5003F0073E46D /* simulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE09C15F5003F0073E46D /* simulator.cpp */; };
04CAE09F15F504FB0073E46D /* flowControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE09E15F504FB0073E46D /* flowControl.cpp */; };
- 04CAE0A315F5052C0073E46D /* gui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE0A215F5052C0073E46D /* gui.cpp */; };
04CAE0A615F520590073E46D /* interface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE0A515F520590073E46D /* interface.cpp */; };
BBAB23CB13894F3D00AA2426 /* GLUT.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = BBAB23BE13894E4700AA2426 /* GLUT.framework */; };
E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
@@ -221,8 +220,6 @@
04CAE09C15F5003F0073E46D /* simulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = simulator.cpp; sourceTree = "<group>"; };
04CAE09E15F504FB0073E46D /* flowControl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = flowControl.cpp; sourceTree = "<group>"; };
04CAE0A015F5050A0073E46D /* flowControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = flowControl.h; sourceTree = "<group>"; };
- 04CAE0A115F505210073E46D /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = "<group>"; };
- 04CAE0A215F5052C0073E46D /* gui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gui.cpp; sourceTree = "<group>"; };
04CAE0A415F50CB80073E46D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
04CAE0A515F520590073E46D /* interface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = interface.cpp; sourceTree = "<group>"; };
04CAE0A715F520660073E46D /* interface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = interface.h; sourceTree = "<group>"; };
@@ -278,7 +275,6 @@
isa = PBXGroup;
children = (
042338EF15F691BC00E5AE1A /* changelog.txt */,
- 042338F015F691BC00E5AE1A /* examples */,
042338F215F691BC00E5AE1A /* install.xml */,
042338F315F691BC00E5AE1A /* LICENSE.txt */,
042338F415F691BC00E5AE1A /* src */,
@@ -287,21 +283,6 @@
path = ../../../addons/MSAInterpolator;
sourceTree = "<group>";
};
- 042338F015F691BC00E5AE1A /* examples */ = {
- isa = PBXGroup;
- children = (
- 042338F115F691BC00E5AE1A /* openFrameworks */,
- );
- path = examples;
- sourceTree = "<group>";
- };
- 042338F115F691BC00E5AE1A /* openFrameworks */ = {
- isa = PBXGroup;
- children = (
- );
- path = openFrameworks;
- sourceTree = "<group>";
- };
042338F415F691BC00E5AE1A /* src */ = {
isa = PBXGroup;
children = (
@@ -880,8 +861,6 @@
04CAE09C15F5003F0073E46D /* simulator.cpp */,
04CAE09E15F504FB0073E46D /* flowControl.cpp */,
04CAE0A015F5050A0073E46D /* flowControl.h */,
- 04CAE0A115F505210073E46D /* gui.h */,
- 04CAE0A215F5052C0073E46D /* gui.cpp */,
04CAE0A515F520590073E46D /* interface.cpp */,
04CAE0A715F520660073E46D /* interface.h */,
);
@@ -997,7 +976,6 @@
04CAE09915F4E6690073E46D /* data.cpp in Sources */,
04CAE09D15F5003F0073E46D /* simulator.cpp in Sources */,
04CAE09F15F504FB0073E46D /* flowControl.cpp in Sources */,
- 04CAE0A315F5052C0073E46D /* gui.cpp in Sources */,
04CAE0A615F520590073E46D /* interface.cpp in Sources */,
0423390B15F69DFC00E5AE1A /* Color.cpp in Sources */,
0423390C15F69DFC00E5AE1A /* MSACoreGL.cpp in Sources */,
View
@@ -9,7 +9,8 @@ void Data::setup(){
NSString *path = @"/Users/johan/dev/openframeworks/apps/myApps/chaosFlow/data-utils";
NSArray *args = [NSArray arrayWithObjects:..., nil];
[[NSTask launchedTaskWithLaunchPath:path arguments:args] waitUntilExit];
- */
+ */
+
}
@@ -152,6 +153,21 @@ DataPoint* Data::getPreviousPoint(DataPoint * point) {
}
}
+Path* Data::getNextPath(Path * path) {
+ if(path->i >= paths.size()-1) {
+ return &paths[0];
+ } else {
+ return &paths[path->i+1];
+ }
+}
+Path* Data::getPreviousPath(Path * path) {
+ if(path->i <= 0) {
+ return &paths[paths.size()-1];
+ } else {
+ return &paths[path->i-1];
+ }
+}
+
void Path::addPoint(DataPoint * point) {
points.push_back(point);
update();
@@ -165,7 +181,8 @@ void Path::removeLocation(int index) {
void Path::update() {
sum.clear();
-
+ sum_max = 0;
+
for(int h=0; h<DATA_HOURS; h++) {
int s = 0;
@@ -179,6 +196,10 @@ void Path::update() {
}
}
+ if (s > sum_max) {
+ sum_max = s;
+ }
+
sum.push_back(s);
}
View
@@ -43,7 +43,7 @@ struct DataPoint {
};
struct Path {
- int index;
+ int i; //index
vector<DataPoint*> points;
@@ -55,6 +55,7 @@ struct Path {
void update();
int size() { return points.size(); };
+
};
class Data {
@@ -73,6 +74,9 @@ class Data {
DataPoint* getNextPoint(DataPoint * point);
DataPoint* getPreviousPoint(DataPoint * point);
+ Path* getNextPath(Path * path);
+ Path* getPreviousPath(Path * path);
+
vector<Path> paths;
double maxLat;
View
@@ -2,10 +2,44 @@
void flowControl::setup(){
// establish connection to arduino
+
+ // for 1 in 3 arduinos
+ // set up serial connection
+
+ arduino[0].enumerateDevices();
+ arduino[0].setup("/dev/cu.usbserial-A9007KHo", 9600);
+ arduino[0].setVerbose(true);
+
+ for (int i = 0; i < NUM_CHANNELS; i++) {
+ channels[i].i = i;
+ }
}
+Channel* flowControl::getNextChannel(Channel * c) {
+ if(c->i >= NUM_CHANNELS-1) {
+ return &channels[0];
+ } else {
+ return &channels[c->i+1];
+ }
+}
+Channel* flowControl::getPreviousChannel(Channel * c) {
+ if(c->i <= 0) {
+ return &channels[NUM_CHANNELS-1];
+ } else {
+ return &channels[c->i-1];
+ }
+}
+
+
void flowControl::update(){
+ // period that increases probability of bikes
+
+ if(ofGetFrameNum() % 4 == 0) {
+ for (int i = 0; i < NUM_CHANNELS; i++) {
+ updateChannel(&channels[i]);
+ }
+ }
}
void flowControl::debugDraw(){
@@ -32,4 +66,14 @@ void flowControl::openAirValve(Channel * c) {
void flowControl::closeAirValve(Channel * c) {
c->airOpen = false;
-}
+}
+
+
+void flowControl::updateChannel(Channel * c) {
+ // data format is channel number int; air pressure float 0-1, water pressure float 0-1, air open bool, water open bool,
+
+ //const char
+ unsigned char buf[10] = {c->i, ';', c->airPressure, ';', c->waterPressure, ';', c->airOpen, ';', c->waterOpen, '\n'};
+ arduino[c->arduinoNum].writeBytes(&buf[0], 10);
+
+}
View
@@ -6,7 +6,10 @@
struct Channel {
public:
- int address; // serial address
+ int i;
+
+ int arduinoNum;
+ // consider having pins losted here if arduinos are not wired similarily
float airPressure;
float waterPressure;
@@ -28,6 +31,9 @@ class flowControl {
Channel channels [NUM_CHANNELS];
+ Channel * getNextChannel(Channel * c);
+ Channel * getPreviousChannel(Channel * c);
+
void injectAir(Channel * c, float duration);
//void injectAir(Channel * c, float duration, float pressure);
@@ -39,4 +45,7 @@ class flowControl {
void closeWaterValve(Channel * c);
void setWaterPressure(Channel * c, float pressure);
+ void updateChannel(Channel * c);
+
+ ofSerial arduino [3];
};
View
@@ -1,73 +0,0 @@
-#include "gui.h"
-
-void Gui::setup(){
-
- ui = new ofxUICanvas(0,0,0,0);
-
- ui->setDrawBack(true);
-
- ui->addWidgetDown(new ofxUILabel("Chaotic flow", OFX_UI_FONT_MEDIUM));
-
- ui->addWidgetDown(new ofxUIToggle(32, 32, false, "FULLSCREEN"));
-
- //ui->addWidgetDown(new ofxUIToggle(32, 32, false, "PLAY/PAUSE"));
-
- //ui->addWidgetDown(new ofxUILabelToggle(&playToggle, "Play / Pause"));
- ui->addToggle("Play Pause", &playToggle, 32, 32);
-
- ui->addWidgetDown(new ofxUIRotarySlider(32, 32, 100, -1200, 1200, &simSpeed, "Speed"));
-
- //ui->addWidgetDown(new ofxUISlider(32, 32, false, "PLAY/PAUSE"));
-
- //ui->addToggle("Play / Pause",playToggle,304,16);
-
-
- ofAddListener(ui->newGUIEvent, this, &Gui::guiEvent);
-
-
-
-}
-
-void Gui::loadSettings(){
- ui->loadSettings("GUI/guiSettings.xml");
-}
-
-void Gui::update(){
-}
-
-void Gui::draw(){
- ui->draw();
- ui->drawBack();
- ui->ofxUIWidget::update();
-}
-
-void Gui::exit()
-{
- ui->saveSettings("GUI/guiSettings.xml");
- delete ui;
-}
-
-void Gui::guiEvent(ofxUIEventArgs &e)
-{
- if(e.widget->getName() == "FULLSCREEN")
- {
- ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
- ofSetFullscreen(toggle->getValue());
- }
-}
-
-void Gui::keyPressed(int key)
-{
- switch (key) {
- case 'p':
- ui->setDrawWidgetPadding(true);
- break;
- case 'P':
- ui->setDrawWidgetPadding(false);
- break;
-
-
- default:
- break;
- }
-}
View
@@ -1,25 +0,0 @@
-#pragma once
-
-#include "ofMain.h"
-#include "ofxUI.h"
-#include "defines.h"
-
-class Gui {
-public:
- void setup();
- void update();
- void draw();
- void keyPressed(int key);
-
- ofxUICanvas * ui;
- void exit();
- void guiEvent(ofxUIEventArgs &e);
-
- void loadSettings();
-
-
- bool playToggle;
- float simSpeed;
-
-
-};
Oops, something went wrong.

0 comments on commit 8fdcf23

Please sign in to comment.