Commit e7ebdd58ef24d71bfbf51b5f19af9f2a2abd4808
1 parent
75bd8616
Exists in
master
and in
1 other branch
User Interface
Showing
11 changed files
with
87 additions
and
24 deletions
Show diff stats
app/res/settings/_dev_tty.usbmodem411.xml
app/res/settings/_dev_tty.usbmodem641.xml
app/src/inoChannel.h
app/src/inoControl.cpp
1 | 1 | #include "inoControl.h" |
2 | 2 | #include "ofMain.h" |
3 | 3 | |
4 | +string inoControl::defaultSettings = "settings-dev.xml"; | |
5 | + | |
4 | 6 | inoControl::inoControl(string device) { |
5 | 7 | connect.addListener(this, &inoControl::toggleConnection); |
8 | + reset.addListener(this, &inoControl::resetSettings); | |
6 | 9 | gui.setup(device); |
7 | 10 | gui.add(status.setup("Status", "Setup...")); |
8 | 11 | gui.add(connect.setup("Connect", false)); |
12 | + gui.add(hide.setup("Hide", false)); | |
9 | 13 | gui.add(settings.setup("Settings")); |
14 | + settings.add(reset.setup("Reset")); | |
10 | 15 | settings.add(color.setup("Color", |
11 | 16 | ofColor(100, 100, 140), |
12 | 17 | ofColor(0, 0), ofColor(255, 255))); |
18 | + settings.add(offset.setup("Offset", ofVec2f(0,0) | |
19 | + , ofVec2f(-0.5,-0.5), ofVec2f(0.5,0.5))); | |
13 | 20 | |
14 | 21 | filePath = device; |
15 | 22 | ofStringReplace(filePath, "/", "_"); |
16 | - filePath = "settings/" + filePath + ".xml"; | |
23 | + filePath = "devices/" + filePath + ".xml"; | |
17 | 24 | |
18 | - if(ofFile::doesFileExist(filePath)) { | |
19 | - settings.loadFromFile(filePath); | |
20 | - } else { | |
21 | - ofFile newFile(ofToDataPath(filePath), ofFile::WriteOnly); | |
22 | - newFile.create(); | |
23 | - newFile.close(); | |
25 | + if(!ofFile::doesFileExist(filePath)) { | |
26 | + ofFile::copyFromTo(inoControl::defaultSettings, filePath); | |
24 | 27 | } |
28 | + settings.loadFromFile(filePath); | |
25 | 29 | status = "Idle"; |
26 | 30 | |
31 | + buffer = new unsigned char[BUFFER_SIZE]; | |
32 | + | |
27 | 33 | channel.setup(device); |
28 | 34 | ofAddListener( |
29 | 35 | channel.statusChange, |
... | ... | @@ -35,6 +41,7 @@ inoControl::~inoControl() { |
35 | 41 | channel.exit(); |
36 | 42 | channel.waitForThread(); |
37 | 43 | settings.saveToFile(filePath); |
44 | + delete[] buffer; | |
38 | 45 | } |
39 | 46 | |
40 | 47 | ofxGuiGroup * inoControl::getGui() { |
... | ... | @@ -52,3 +59,34 @@ void inoControl::toggleConnection(bool & status) { |
52 | 59 | void inoControl::onStatusChanged(string & str) { |
53 | 60 | status = str; |
54 | 61 | } |
62 | + | |
63 | +void inoControl::drawWave(float zoom) { | |
64 | + if(hide) return; | |
65 | + | |
66 | + int width = ofGetViewportWidth(); | |
67 | + int height = ofGetViewportHeight(); | |
68 | + | |
69 | + ofPushMatrix(); | |
70 | + | |
71 | + ofTranslate(offset->x * (float)width, | |
72 | + offset->y * (float)width); | |
73 | + ofScale(zoom, 1); | |
74 | + | |
75 | + ofSetColor(color); | |
76 | + ofSetPolyMode(OF_POLY_WINDING_ODD); | |
77 | + ofNoFill(); | |
78 | + ofSetLineWidth(1.5); | |
79 | + ofBeginShape(); | |
80 | + for(int i = 0; i <= BUFFER_SIZE; i++) { | |
81 | + ofVertex((float)i/BUFFER_SIZE * (float)width, | |
82 | + 300 + sin(8* M_PI* (double)i/BUFFER_SIZE) * 100); | |
83 | + } | |
84 | + ofEndShape(false); | |
85 | + | |
86 | + ofPopMatrix(); | |
87 | +} | |
88 | + | |
89 | +void inoControl::resetSettings() { | |
90 | + settings.loadFromFile(inoControl::defaultSettings); | |
91 | +} | |
92 | + | ... | ... |
app/src/inoControl.h
1 | 1 | #pragma once |
2 | 2 | |
3 | +#define BUFFER_SIZE 1024 | |
4 | + | |
3 | 5 | #include "ofMain.h" |
4 | 6 | #include "ofxGui.h" |
5 | 7 | |
... | ... | @@ -12,13 +14,22 @@ public: |
12 | 14 | ofxGuiGroup * getGui(); |
13 | 15 | void toggleConnection(bool & status); |
14 | 16 | void onStatusChanged(string & status); |
17 | + void resetSettings(); | |
18 | + | |
19 | + void drawWave(float zoom); | |
20 | + | |
15 | 21 | private: |
22 | + static string defaultSettings; | |
16 | 23 | string filePath; |
17 | 24 | string device; |
18 | 25 | ofxGuiGroup gui; |
19 | 26 | ofxToggle connect; |
27 | + ofxToggle hide; | |
20 | 28 | ofxLabel status; |
21 | 29 | ofxGuiGroup settings; |
30 | + ofxButton reset; | |
22 | 31 | ofxColorSlider color; |
32 | + ofxVec2Slider offset; | |
23 | 33 | inoChannel channel; |
34 | + unsigned char *buffer; | |
24 | 35 | }; | ... | ... |
app/src/ofApp.cpp
... | ... | @@ -11,6 +11,7 @@ void ofApp::setup(){ |
11 | 11 | discoverBtn.addListener(this, &ofApp::discoverArduinos); |
12 | 12 | gui.setup(); |
13 | 13 | discoverBtn.setup("Discover"); |
14 | + zoom.setup("Zoom", 1.0f, 0.25f, 4.0f); | |
14 | 15 | discoverArduinos(); |
15 | 16 | } |
16 | 17 | |
... | ... | @@ -24,16 +25,11 @@ void ofApp::update() { |
24 | 25 | } |
25 | 26 | |
26 | 27 | void ofApp::draw() { |
27 | - /* | |
28 | - ofSetPolyMode(OF_POLY_WINDING_ODD); | |
29 | - ofNoFill(); | |
30 | - ofSetLineWidth(1.5); | |
31 | - ofBeginShape(); | |
32 | - for(int i = 0; i <= 100; i++) { | |
33 | - ofVertex((float)i/100 * 800, (float)i/100 * 600); | |
34 | - } | |
35 | - ofEndShape(false); | |
36 | - */ | |
28 | + ofPushMatrix(); | |
29 | + for(auto p : controls) { | |
30 | + p.second->drawWave(zoom); | |
31 | + } | |
32 | + ofPopMatrix(); | |
37 | 33 | if(showGui) { |
38 | 34 | gui.draw(); |
39 | 35 | } |
... | ... | @@ -71,6 +67,7 @@ void ofApp::discoverArduinos() { |
71 | 67 | void ofApp::rebuildGui() { |
72 | 68 | gui.clear(); |
73 | 69 | gui.add(&discoverBtn); |
70 | + gui.add(&zoom); | |
74 | 71 | for(auto ctrl : controls) { |
75 | 72 | gui.add(ctrl.second->getGui()); |
76 | 73 | } | ... | ... |
app/src/ofApp.h
ino/src/sketch.ino
... | ... | @@ -86,10 +86,11 @@ void print_time_lcd() { |
86 | 86 | } |
87 | 87 | |
88 | 88 | void hardware_setup() { |
89 | + // Max Prescaler | |
89 | 90 | ADCSRA |= (0<<ADPS2) | (0<<ADPS1) | (1<<ADPS0) | (1<<ADATE) | (1<<ADEN) | (1<<ADIE); |
90 | 91 | ADMUX |= (1<<REFS0) | (1<<ADLAR); |
91 | 92 | ADMUX &= ~(1<<REFS1); |
92 | - ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0)); // wut? OCR0A | |
93 | + ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0)); | |
93 | 94 | ADCSRA |= (1<<ADSC); |
94 | 95 | } |
95 | 96 | ... | ... |