Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prepared for interfacing with arduino. Started work on gui.

  • Loading branch information...
commit ec5604a66e8ffd011b51877e4260e59a5dc4f113 1 parent daf8e4b
@mrbichel mrbichel authored
View
4 README.md
@@ -21,6 +21,4 @@ Run the server:
$ python server/chaosflow.py
-Then you can run the openframeworks app.
-
-
+Then you can run the openframeworks app.
View
2  chaosFlow.xcodeproj/project.pbxproj
@@ -75,6 +75,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 04163F8D16105D7900382C5C /* installationControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = installationControl.h; sourceTree = "<group>"; };
042338EF15F691BC00E5AE1A /* changelog.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = changelog.txt; sourceTree = "<group>"; };
042338F215F691BC00E5AE1A /* install.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = install.xml; sourceTree = "<group>"; };
042338F315F691BC00E5AE1A /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE.txt; sourceTree = "<group>"; };
@@ -884,6 +885,7 @@
04CAE0A215F5052C0073E46D /* gui.cpp */,
04CAE0A515F520590073E46D /* visualizer.cpp */,
04CAE0A715F520660073E46D /* visualizer.h */,
+ 04163F8D16105D7900382C5C /* installationControl.h */,
);
path = src;
sourceTree = SOURCE_ROOT;
View
58 src/data.cpp
@@ -1,27 +1,24 @@
#include "data.h"
void Data::setup(){
- DATA_HOST = "http://127.0.0.1:5000";
-
maxStatEntry = 0;
maxCombinedStatEntry = 0;
+ endpoint = "http://" + ofToString(DATA_HOST) + ":" + ofToString(DATA_PORT) + "/";
}
void Data::update(){
-
}
void Data::debugDraw(){
-
}
// import all data
void Data::getData(){
- // don't do this if we already have the datan
+ // todo: don't do this if we already have the data
- cout<<"Importing data ... "<<endl;
+ ofLogNotice()<<"Importing data from endpoint at "<<endpoint<<" ..."<<endl;
getLocations();
for (int i=0; i<locations.size(); i++) {
@@ -34,9 +31,9 @@ void Data::getData(){
void Data::getLocations(){
- string url = DATA_HOST + "/locations";
+ ofLogNotice()<<"Importing all locations ..."<<endl;
- ofHttpResponse response = ofLoadURL(url);
+ ofHttpResponse response = ofLoadURL(endpoint + "/locations");
string responseStr = response.data;
// todo: add error handling here and tell me to turn on the db and start flask
@@ -80,9 +77,10 @@ void Data::getLocations(){
void Data::getStatEntries(Location* location){
- //cout<<"Getting entries for "<<location->road<<endl;
+ ofLogNotice()<<"Importing stat entries for "<<location->road<<" ..."<<endl;
+
+ ofHttpResponse response = ofLoadURL(endpoint + "locations/" + location->oid + "/entries" );
- ofHttpResponse response = ofLoadURL(DATA_HOST + "/locations/" + location->oid + "/entries" );
string responseStr = response.data;
json_t* root;
@@ -113,3 +111,43 @@ void Data::getStatEntries(Location* location){
json_decref(root);
}
+
+void Path::addLocation(Location * loc) {
+ locations.push_back(loc);
+ update();
+}
+
+void Path::removeLocation(int index) {
+ locations.erase(locations.begin()+index);
+ update();
+}
+
+
+void Path::update() {
+ dir_one.clear();
+ dir_two.clear();
+
+ for(int h=0; h<DATA_HOURS; h++) {
+ int dir_one_a = 0;
+ int dir_two_a = 0;
+
+ for(int i=0; i<locations.size(); i++) {
+ Location * loc = locations[i];
+
+ //cout<<ofToString(loc->dir_one.size())<<" long"<<endl;
+
+ if(loc->dir_one.size()>0) {
+ //cout<<"dir_one +"<<endl;
+ dir_one_a += loc->dir_one.at(h);
+ }
+ if(loc->dir_two.size()>0) {
+ //cout<<"dir_two +"<<endl;
+ dir_two_a += loc->dir_two.at(h);
+ }
+ }
+
+ dir_one.push_back(dir_one_a);
+ dir_two.push_back(dir_two_a);
+ }
+
+}
View
21 src/data.h
@@ -6,6 +6,8 @@
#include "ofxJansson.h"
#include "MSAInterpolator.h"
+#include "defines.h"
+
struct Location {
@@ -27,7 +29,20 @@ struct Location {
MSA::Interpolator1D dir_one;
MSA::Interpolator1D dir_two;
-
+
+};
+
+struct Path {
+ vector<Location*> locations;
+ MSA::Interpolator1D dir_one;
+ MSA::Interpolator1D dir_two;
+
+ void addLocation(Location * loc);
+ void removeLocation(int index);
+
+ void update();
+
+ int size() { return locations.size(); };
};
class Data {
@@ -40,6 +55,7 @@ class Data {
void getData();
vector<Location> locations;
+ vector<Path> paths;
//double maxLat;
//double minLat;
@@ -55,6 +71,7 @@ class Data {
void getStatEntries(Location* location);
ofxJansson ofxjan;
- string DATA_HOST;
+
+ string endpoint;
};
View
7 src/defines.h
@@ -1,2 +1,9 @@
#pragma once
+#define DATA_HOST "127.0.0.1"
+#define DATA_PORT 5000
+
+#define DATA_HOURS 10
+
+#define NUM_CHANNELS 8
+
View
26 src/flowControl.cpp
@@ -10,4 +10,30 @@ void flowControl::update(){
void flowControl::debugDraw(){
+ for(int i = 0; i < NUM_CHANNELS; i++) {
+ //channels[i].
+ }
+
+}
+
+void flowControl::injectAir(Channel * c, float duration) {
+ openWaterValve(c);
+ c->lock = true;
+ // trigger close watervalve after duration time and set lock false;
+}
+
+void flowControl::openWaterValve(Channel * c) {
+ c->waterOpen = true;
+}
+
+void flowControl::closeWaterValve(Channel * c) {
+ c->waterOpen = false;
+}
+
+void flowControl::openAirValve(Channel * c) {
+ c->airOpen = true;
+}
+
+void flowControl::closeAirValve(Channel * c) {
+ c->airOpen = false;
}
View
29 src/flowControl.h
@@ -3,9 +3,38 @@
#include "ofMain.h"
#include "defines.h"
+struct Channel {
+public:
+ int address; // serial address
+
+ float airPressure;
+ float waterPressure;
+
+ bool airOpen;
+ bool waterOpen;
+
+ bool lock; // when lock true the channel does not accept new valve commands
+ // maybe do a vector of waiting commands
+};
+
class flowControl {
public:
void setup();
void update();
void debugDraw();
+
+ Channel channels [NUM_CHANNELS];
+
+ void injectAir(Channel * c, float duration);
+ //void injectAir(Channel * c, float duration, float pressure);
+
+ void openAirValve(Channel * c);
+ void closeAirValve(Channel * c);
+ void setAirPressure(Channel * c, float pressure);
+
+ void openWaterValve(Channel * c);
+ void closeWaterValve(Channel * c);
+ void setWaterPressure(Channel * c, float pressure);
+
+
};
View
24 src/gui.cpp
@@ -2,14 +2,21 @@
void Gui::setup(){
- ui = new ofxUICanvas(0,0,320,320);
+ ui = new ofxUICanvas(0,0,320,620);
+
+ 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 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);
@@ -29,7 +36,9 @@ void Gui::update(){
}
void Gui::draw(){
-
+ ui->draw();
+ ui->drawBack();
+ ui->ofxUIWidget::update();
}
void Gui::exit()
@@ -44,15 +53,6 @@ void Gui::guiEvent(ofxUIEventArgs &e)
{
ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
ofSetFullscreen(toggle->getValue());
- } else if (e.widget->getName() == "PLAY/PAUSE") {
- ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
-
- if(toggle->getValue()) {
- playToggle = true;
- } else {
- playToggle = false;
- }
-
}
}
View
19 src/installationControl.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "ofMain.h"
+#include "data.h"
+#include "gui.h"
+#include "defines.h"
+
+class installationControl {
+public:
+
+ void setup(Data * dataRef, Gui * guiRef);
+ void update();
+ void debugDraw();
+
+ // data
+ Data * data;
+ Gui * gui;
+
+};
View
2  src/main.cpp
@@ -5,6 +5,6 @@
int main(){
ofAppGlutWindow window; // create a window
// set width, height, mode (OF_WINDOW or OF_FULLSCREEN)
- ofSetupOpenGL(&window, 1280, 800, OF_WINDOW);
+ ofSetupOpenGL(&window, 1074, 764, OF_WINDOW);
ofRunApp(new testApp()); // start the app
}
View
28 src/simulator.cpp
@@ -2,19 +2,18 @@
#include "simulator.h"
void Simulator::setup(Data * dataRef, Gui * guiRef){
-
+
data = dataRef;
gui = guiRef;
- simDuration = 10 * 3600000;
+ simDuration = DATA_HOURS * 3600000;
simElapsedTime = 0;
lastUpdateTime = 0;
speed = 1200.;
- playing = false;
-
+ gui->playToggle = false;
}
void Simulator::update(){
@@ -27,31 +26,36 @@ void Simulator::update(){
pause();
}
- //speed = gui->simSpeed;
+ speed = gui->simSpeed;
if (playing) {
int updateTime = ofGetElapsedTimeMillis();
-
- simElapsedTime += (updateTime - lastUpdateTime) * speed;
-
+ simElapsedTime = abs(simElapsedTime + (updateTime - lastUpdateTime) * speed);
+
lastUpdateTime = updateTime;
- if (simElapsedTime > simDuration) {
+ if (simElapsedTime >= simDuration) {
simElapsedTime = simDuration;
stop();
}
}
+
+ realDuration = abs(simDuration/speed);
+ realElapsedTime = abs(simElapsedTime/speed);
+
}
void Simulator::pause(){
if (playing) {
playing = false;
+ gui->playToggle = false;
}
}
void Simulator::stop(){
playing = false;
+ gui->playToggle = false;
simElapsedTime = 0;
}
@@ -59,6 +63,7 @@ void Simulator::play(){
if (!playing) {
lastUpdateTime = ofGetElapsedTimeMillis();
playing = true;
+ gui->playToggle = true;
}
}
@@ -74,11 +79,6 @@ void Simulator::debugDraw(){
ofDrawBitmapString("Speed: " + ofToString(speed), 10, 80);
-
- int realDuration = simDuration/speed;
- int realElapsedTime = simElapsedTime/speed;
-
-
ofDrawBitmapString("Real time: " + formatTime(realElapsedTime) + " / " + formatTime(realDuration), 10, 60);
View
2  src/simulator.h
@@ -34,6 +34,8 @@ class Simulator {
int simDuration;
int lastUpdateTime;
int simStartOffset;
+ int realDuration;
+ int realElapsedTime;
bool playing;
View
4 src/testApp.cpp
@@ -19,7 +19,8 @@ void testApp::setup(){
ofSetVerticalSync(true);
ofSetSphereResolution(128);
- ofBackground(0,0,0);
+ ofBackground(50,50,50);
+ ofEnableSmoothing();
ofSetColor(255,255,255);
ofEnableAlphaBlending();
@@ -57,6 +58,7 @@ void testApp::exit() {
void testApp::keyPressed(int key){
gui->keyPressed(key);
+ visualizer->keyPressed(key);
}
void testApp::keyReleased(int key){
View
2  src/testApp.h
@@ -7,7 +7,6 @@
#include "flowControl.h"
#include "visualizer.h"
-
class testApp : public ofBaseApp {
public:
@@ -26,7 +25,6 @@ class testApp : public ofBaseApp {
void gotMessage(ofMessage msg);
void exit();
-
Data * data;
Gui * gui;
View
76 src/visualizer.cpp
@@ -35,6 +35,23 @@ void Visualizer::mousePressed(int x, int y, int button){
}
+void Visualizer::keyPressed(int key){
+ if(key == 'P') {
+ Path p;
+ data->paths.push_back(p);
+ }
+
+ if(selectedLoc) {
+ if(key == '1') {
+ data->paths[0].addLocation(selectedLoc);
+ }
+ }
+}
+
+void Visualizer::drawMapPoint() {
+
+}
+
void Visualizer::drawLocation(Location * loc) {
if(loc->lat != 0 && loc->lng != 0) {
@@ -42,18 +59,22 @@ void Visualizer::drawLocation(Location * loc) {
float aOne = loc->dir_one.sampleAt(sim->elapsedFloat);
float aTwo = loc->dir_two.sampleAt(sim->elapsedFloat);
- loc->marker = ofPoint(ofMap(loc->lat, minLat, maxLat, 20, 680), ofMap(loc->lng, minLng, maxLng, 20, 680));
+ loc->marker = ofPoint(ofMap(loc->lng, minLng, maxLng, 200, 680), ofMap(loc->lat, minLat, maxLat, 680, 200));
+
+
loc->markerRadius = ofMap(aOne+aTwo, 0, data->maxCombinedStatEntry, 2, 36);
ofSetColor(ofMap(aOne, 0, data->maxStatEntry, 80, 255), 100, ofMap(aTwo, 0, data->maxStatEntry, 0, 255));
ofCircle(loc->marker, loc->markerRadius);
}
-
-
}
+void Visualizer::drawTimeline() {
+
+}
+
void Visualizer::draw() {
ofNoFill();
@@ -62,12 +83,49 @@ void Visualizer::draw() {
drawLocation(&data->locations[i]);
}
+ for (int i=0; i<data->paths.size(); i++) {
+ drawPath(&data->paths[i]);
+ }
+
if (selectedLoc) {
drawInterpolation(selectedLoc);
}
}
+void Visualizer::drawPath(Path * path) {
+
+ string s;
+
+ for(int i=0; i<path->locations.size(); i++) {
+ s += path->locations[i]->road + " < -- > ";
+ }
+
+ ofDrawBitmapString(s, ofGetWidth()-800, 200);
+
+ if(path->dir_one.size() > 0) {
+
+ for(int i=0; i < path->dir_one.size(); i++) {
+ ofDrawBitmapString(ofToString(path->dir_one.at(i)), (ofGetWidth()-300)+(i*(300/10)), ofGetHeight()-20);
+ }
+
+ for(int p=0; p < 300; p++) {
+
+ float finto = p / float(300);
+
+ //cout<<ofToString(finto)<<endl;
+ float val = path->dir_one.sampleAt(finto);
+
+ ofCircle(ofGetWidth()-300+p, ofMap(val, 0, data->maxStatEntry, ofGetHeight()-20, 20), 1);
+ }
+ }
+}
+
+
+void Visualizer::drawInterpolation(MSA::Interpolator1D * ipo, float width, float height, float max) {
+
+}
+
void Visualizer::drawInterpolation(Location * loc) {
int width = 700;
@@ -82,19 +140,17 @@ void Visualizer::drawInterpolation(Location * loc) {
ofSetColor(255, 255, 255, 255);
for(i=0; i < loc->dir_one.size(); i++) {
- ofDrawBitmapString(ofToString(loc->dir_one.at(i)), 10+(i*(width/10)), ofGetWindowHeight()-20);
+ ofDrawBitmapString(ofToString(loc->dir_one.at(i)), 10+(i*(width/10)), ofGetHeight()-20);
}
for(i=0; i < loc->dir_two.size(); i++) {
- ofDrawBitmapString(ofToString(loc->dir_two.at(i)), 10+(i*(width/10)), ofGetWindowHeight()-50);
+ ofDrawBitmapString(ofToString(loc->dir_two.at(i)), 10+(i*(width/10)), ofGetHeight()-50);
}
- ofDrawBitmapString(loc->road, 20, ofGetWindowHeight()-200);
-
- //ofPath()
-
+ ofDrawBitmapString(loc->road, 20, ofGetHeight()-200);
+
ofSetColor(100, 250, 60, 200);
for(i=0; i < width; i++) {
@@ -104,7 +160,7 @@ void Visualizer::drawInterpolation(Location * loc) {
//cout<<ofToString(finto)<<endl;
float val = loc->dir_one.sampleAt(finto);
- ofCircle(10+i, ofMap(val, 0, data->maxStatEntry, ofGetWindowHeight()-20, 20), 1);
+ ofCircle(10+i, ofMap(val, 0, data->maxStatEntry, ofGetHeight()-20, 20), 1);
}
ofSetColor(250, 100, 60, 200);
View
31 src/visualizer.h
@@ -1,5 +1,7 @@
#pragma once
+// This module has functions for visualizing the data. Does it also handle interface events like making paths or should I add this to data? Maybe add it all to gui class?
+
#include "ofMain.h"
#include "gui.h"
#include "data.h"
@@ -12,12 +14,7 @@ class Visualizer {
void update();
void mousePressed(int x, int y, int button);
-
- void debugDraw();
-
- void draw();
- void drawLocation(Location * loc);
- void drawInterpolation(Location * loc);
+ void keyPressed(int key);
Data * data;
Gui * gui;
@@ -29,6 +26,28 @@ class Visualizer {
double maxLat;
double maxLng;
+ void debugDraw();
+
+ void draw();
+
+ void drawLocation(Location * loc);
+ void drawPath(Path * path);
+
+ void drawMap();
+
+ void drawMapPoint();
+
+ void drawMapPath();
+
+ void drawInterpolation(MSA::Interpolator1D * ipo, float width, float height, float max);
+
+ void drawInterpolation(Location * loc);
+
+ void drawTimeline();
+
+
+ Path * selectedPath;
Location * selectedLoc;
+
};
Please sign in to comment.
Something went wrong with that request. Please try again.