diff --git a/Box.cpp b/Box.cpp new file mode 100644 index 0000000..6adcc43 --- /dev/null +++ b/Box.cpp @@ -0,0 +1,34 @@ +#include "Box.h" + +Box::Box() +{ + isOpen = false; +} + +void Box::setName(string _name) +{ + name = _name; +} + +void Box::setOpen(bool _val) +{ + isOpen = _val; +} + +void Box::loadFont(const string &filename, int fontsize) +{ + int offset = fontsize / 2; + label.loadFont(filename, fontsize); +} + + +void Box::drawBox() +{ + ofSetColor(color); + ofDrawRectangle(shape); + ofSetColor(ofColor(255, 255, 0)); + /*Set Label*/ + float xCenter = (shape.width - label.stringWidth(name)) / 2; //offset by leftover spaces + float yOffset = (shape.height / 5) + 3; + label.drawString(name, shape.x + xCenter, shape.y + yOffset); +} \ No newline at end of file diff --git a/Box.h b/Box.h new file mode 100644 index 0000000..33bcf66 --- /dev/null +++ b/Box.h @@ -0,0 +1,21 @@ +#pragma once +#include "ofMain.h" +#include + +class Box +{ +public: + Box(); + void drawBox(); + void setName(string _name); + void setOpen(bool _val); + void loadFont(const string &filename, int fontsize); + +protected: + ofRectangle shape; + ofColor color; + string name; + bool isOpen; + ofTrueTypeFont label; +}; + diff --git a/ButtonBox.cpp b/ButtonBox.cpp new file mode 100644 index 0000000..fb412fd --- /dev/null +++ b/ButtonBox.cpp @@ -0,0 +1,17 @@ +#include "ButtonBox.h" + + + +ButtonBox::ButtonBox() +{ +} + + +ButtonBox::~ButtonBox() +{ +} + +void ButtonBox::clicked(int x, int y) +{ + +} \ No newline at end of file diff --git a/ButtonBox.h b/ButtonBox.h new file mode 100644 index 0000000..677d7ea --- /dev/null +++ b/ButtonBox.h @@ -0,0 +1,16 @@ +#pragma once +#include "Box.h" + +class ButtonBox +{ +public: + ButtonBox(); + ~ButtonBox(); + + void clicked(int x, int y); + +protected: + + +}; + diff --git a/DataBox.cpp b/DataBox.cpp new file mode 100644 index 0000000..d931c38 --- /dev/null +++ b/DataBox.cpp @@ -0,0 +1,54 @@ +#include "DataBox.h" + +const float DNULL = 0.01021; //custom null +DataBox::DataBox() +{ + isOpen = false; +} + +DataBox::~DataBox() +{ +} + +void DataBox::set(float _x, float _y, float _px, float _py, double data) +{ + shape.set(_px, _py, _x, _y); + this->data = data; + color = ofColor(150, 150, 150); +} + +double DataBox::getData() { + return data; + } + +void DataBox::loadFont(const string &filename, int fontsize) +{ + int offset = fontsize / 2; + label.loadFont(filename, fontsize); + dataLabel.loadFont(filename, offset); + +} + +void DataBox::setData(double data) +{ + this->data = data; +} + + +void DataBox::draw() +{ + drawBox(); + float xCenter = (shape.width - label.stringWidth(name)) / 2; //offset by leftover spaces + float yOffset = (shape.height / 5) + 3; + /*Set Data Label + Positions are partially hardcoded + FIX!!! */ + float newHeight = yOffset; + if (data != DNULL) + { + xCenter = (shape.width - dataLabel.stringWidth(to_string(data))) / 2; //offset by leftover spaces + yOffset = newHeight*2 + (newHeight - label.stringHeight(to_string(data))) / 4; + dataLabel.drawString(to_string(data), shape.x + xCenter, shape.y + yOffset); + } + +} \ No newline at end of file diff --git a/DataBox.h b/DataBox.h new file mode 100644 index 0000000..0c3d040 --- /dev/null +++ b/DataBox.h @@ -0,0 +1,22 @@ +#pragma once +#include "Box.h" + + +class DataBox: public Box +{ +public: + DataBox(); + virtual ~DataBox(); + + void draw(); + void set(float _x, float _y, float _px, float _py, double data); + void setData(double data); + double getData(); + void loadFont(const string &filename, int fontsize); + + +private: + double data; + ofTrueTypeFont dataLabel; +}; + diff --git a/Exo-Light.otf b/Exo-Light.otf new file mode 100644 index 0000000..0a6faa7 Binary files /dev/null and b/Exo-Light.otf differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..65f6689 --- /dev/null +++ b/main.cpp @@ -0,0 +1,14 @@ +#include "ofMain.h" +#include "ofApp.h" + + +//======================================================================== +int main( ){ + ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp(new ofApp()); + +} diff --git a/ofApp.cpp b/ofApp.cpp new file mode 100644 index 0000000..62b3f7f --- /dev/null +++ b/ofApp.cpp @@ -0,0 +1,213 @@ +#include "ofApp.h" + +int const dataCount = 5; +int const dataLength = 37; // length of string in serial +ofstream myFile; + +//-------------------------------------------------------------- +void ofApp::setup(){ + + myFile.open("Data.csv"); + myFile.clear(); + myFile << "Accelaration,Altitude,Temprature,Pressure,Events\n"; + + ofBackground(0, 0, 0); + + data = new DataBox[dataCount]; + + /*initialize all data boxes*/ + string dataNames[dataCount] = { "Accelaration", "Altitude", "Temprature", "Pressure", "Event"}; + for (int i = 0; i < dataCount; i++) + { + data[i].set(200, 100, ofGetWidth()/2, 105*(i+1), 30); //load to the left side + data[i].setOpen(true); + data[i].setName(dataNames[i]); + data[i].loadFont("Exo-Light.otf", 20); + } + serial.setup("COM12", 9600); +} + +//-------------------------------------------------------------- +/*void parsData(DataBox data[], double val, int counter) { + if (counter % 3 == 0) { + data[static_cast(counter / 3)].setX(val); + } + else if (counter % 3 == 1) { + data[static_cast(counter / 3)].setY(val); + } + else if (counter % 3 == 2) { + data[static_cast(counter / 3)].setZ(val); + } + +}*/ + +void ofApp::update() { + //bool filter = true; // to see the data is correct (will create filter function to check the datas tring) + unsigned char test; + test = serial.readByte(); + if (test == '#') { + int bytesRequired = dataLength; + unsigned char sbyte[dataLength]; + int bytesRemaining = bytesRequired; + while (bytesRemaining > 0) { + // check for data + if (serial.available() > 0) { + + // try to read - note offset into the bytes[] array, this is so + // that we don't overwrite the bytes we already have + int bytesArrayOffset = bytesRequired - bytesRemaining; + int result = serial.readBytes(&sbyte[bytesArrayOffset], + bytesRemaining); + + // check for error code + if (result == OF_SERIAL_ERROR) { + // something bad happened + ofLog(OF_LOG_ERROR, "unrecoverable error reading from serial"); + // bail out + break; + } + else if (result == OF_SERIAL_NO_DATA) { + // nothing was read, try again + } + else { + // we read some data! + bytesRemaining -= result; + } + } + } + if (sbyte[0] == '!') { + string temp = ""; + string sData(reinterpret_cast(sbyte)); + int j = 0; + for (int i = 1; i < dataLength && j qData; + string temp = ""; + + + serial.readBytes(sbyte, dataLength); + string sData(reinterpret_cast(sbyte)); + for (int i = 0; i < dataLength; i++) { + if (sData[i] == ',' || sData[i] == '!') { + while (!qData.empty()) { + temp += qData.front(); + qData.pop(); + } + parsData(data, atof(temp.c_str()), counter); + counter++; + temp = ""; + } + else + qData.push(sData[i]); + } + } + for (int i = 0; i < 5; i++) { + myFile << data[i].getX() << "," << data[i].getY() << "," << data[i].getZ() << ","; + if (i == 4) + myFile << endl; + } + + + + + /*for (int i = 0; sbyte[i] != '!'; i++) { + if (sbyte[i] == ',') { + temp = sbyte[i - 1] + sbyte[i - 2] - '0' - '0'; + } + if (sbyte[i] == ',' || sbyte[i] == '!') { + j++; + if (j % 3 == 0) { + _zByte = temp; + data[(j / 3)].setData(_xByte, _yByte, _zByte); + } + else if (j % 3 == 2) + _yByte = temp; + else + _xByte = temp; + } + } + //int ibyte = sbyte - '0'; + //data[0].setData(ibyte, ibyte, ibyte);*/ + + } +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + for (int i = 0; i < dataCount; i++) + { + data[i].draw(); + } +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y ){ + mouseX = x; + mouseY = y; +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseEntered(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseExited(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/ofApp.h b/ofApp.h new file mode 100644 index 0000000..fd3e921 --- /dev/null +++ b/ofApp.h @@ -0,0 +1,34 @@ +#pragma once + +#include "ofMain.h" +#include +#include +#include +#include +#include "DataBox.h" + +class ofApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + int mouseX, mouseY; + + DataBox *data; + DataBox testBox; + ofSerial serial; +}; diff --git a/testingGui.ino b/testingGui.ino new file mode 100644 index 0000000..0b7646a --- /dev/null +++ b/testingGui.ino @@ -0,0 +1,13 @@ +int i=10000; +void setup() { +Serial.begin(9600); + +} + +void loop() { + Serial.print("#"); + String a=String("!"+String(i)+","+String(i)+","+String(i)+","+String(i)+","+String(i)+","); + Serial.println(a); + i++; + delay(50); +}