summaryrefslogtreecommitdiff
path: root/test-tycbutton
diff options
context:
space:
mode:
Diffstat (limited to 'test-tycbutton')
-rw-r--r--test-tycbutton/Makefile13
-rw-r--r--test-tycbutton/addons.make1
-rw-r--r--test-tycbutton/config.make1
-rw-r--r--test-tycbutton/src/buttonChecker.cpp8
-rw-r--r--test-tycbutton/src/buttonChecker.h72
-rw-r--r--test-tycbutton/src/main.cpp16
-rw-r--r--test-tycbutton/src/testApp.cpp57
-rw-r--r--test-tycbutton/src/testApp.h26
8 files changed, 194 insertions, 0 deletions
diff --git a/test-tycbutton/Makefile b/test-tycbutton/Makefile
new file mode 100644
index 0000000..7a7fe8b
--- /dev/null
+++ b/test-tycbutton/Makefile
@@ -0,0 +1,13 @@
+# Attempt to load a config.make file.
+# If none is found, project defaults in config.project.make will be used.
+ifneq ($(wildcard config.make),)
+ include config.make
+endif
+
+# make sure the the OF_ROOT location is defined
+ifndef OF_ROOT
+ OF_ROOT=../../..
+endif
+
+# call the project makefile!
+include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
diff --git a/test-tycbutton/addons.make b/test-tycbutton/addons.make
new file mode 100644
index 0000000..c42773e
--- /dev/null
+++ b/test-tycbutton/addons.make
@@ -0,0 +1 @@
+ofxHttpUtils
diff --git a/test-tycbutton/config.make b/test-tycbutton/config.make
new file mode 100644
index 0000000..98bb09c
--- /dev/null
+++ b/test-tycbutton/config.make
@@ -0,0 +1 @@
+OF_ROOT=../../openFrameworks
diff --git a/test-tycbutton/src/buttonChecker.cpp b/test-tycbutton/src/buttonChecker.cpp
new file mode 100644
index 0000000..b8170e8
--- /dev/null
+++ b/test-tycbutton/src/buttonChecker.cpp
@@ -0,0 +1,8 @@
+#include "buttonChecker.h"
+
+long ofToLong(const string& intString) {
+ long x = 0;
+ istringstream cur(intString);
+ cur >> x;
+ return x;
+} \ No newline at end of file
diff --git a/test-tycbutton/src/buttonChecker.h b/test-tycbutton/src/buttonChecker.h
new file mode 100644
index 0000000..2de14cb
--- /dev/null
+++ b/test-tycbutton/src/buttonChecker.h
@@ -0,0 +1,72 @@
+#ifndef _BUTTON_CHECK
+#define _BUTTON_CHECK
+
+#include "ofMain.h"
+#include "ofURLFileLoader.h"
+
+long ofToLong(const string& intString);
+
+class buttonChecker : public ofThread{
+
+ public:
+
+ float interval; //time between refreshes in seconds
+ std::string url;
+ long last;
+ float triggerTime;
+ bool active;
+
+ buttonChecker(){
+ url = "http://tycleeson.com/trigger.php";
+ interval=0.05;
+ last=0;
+ triggerTime=0.0f;
+ active=false;
+ }
+
+ void set_interval(float _interval){
+ interval=_interval;
+ }
+
+ void start(){
+ startThread(true, false); // blocking, verbose
+ }
+
+ void stop(){
+ stopThread();
+ }
+
+ bool action(){
+ if(active){
+ active=false;
+ return true;
+ }
+ return false;
+ }
+
+
+ //--------------------------
+ void threadedFunction(){
+
+ cout << "Api: " << url<<endl;
+
+ while( isThreadRunning() != 0 ){
+
+ //cout<<"."<<std::flush;
+
+ long result = ofToLong(ofLoadURL(url).data.getText());
+ if (result>last){
+ last=result;
+ active=true;
+ triggerTime=ofGetElapsedTimef();
+ }
+
+
+ ofSleepMillis(interval * 1000);
+ }
+ }
+
+
+};
+
+#endif \ No newline at end of file
diff --git a/test-tycbutton/src/main.cpp b/test-tycbutton/src/main.cpp
new file mode 100644
index 0000000..6a32c6a
--- /dev/null
+++ b/test-tycbutton/src/main.cpp
@@ -0,0 +1,16 @@
+#include "ofMain.h"
+#include "testApp.h"
+#include "ofAppGlutWindow.h"
+
+//========================================================================
+int main( ){
+
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 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 testApp());
+
+}
diff --git a/test-tycbutton/src/testApp.cpp b/test-tycbutton/src/testApp.cpp
new file mode 100644
index 0000000..422b728
--- /dev/null
+++ b/test-tycbutton/src/testApp.cpp
@@ -0,0 +1,57 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup(){
+ ofSetVerticalSync(true);
+
+ ofBackground(0,0,0);
+ ofSetColor(255,255,255);
+
+ button.start();
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+ if (button.action()) cout<<"SNAP!"<<endl;
+}
+
+//--------------------------------------------------------------
+void testApp::draw(){
+ //ofDrawBitmapString(requestStr,20,20);
+ //ofDrawBitmapString(responseStr,20,60);
+ float ttime=ofGetElapsedTimef()-button.triggerTime;
+
+ int b=(1.0f-ttime)*255;
+
+ if (b>-1) ofBackground(b,b,b);
+}
+
+//--------------------------------------------------------------
+
+//--------------------------------------------------------------
+void testApp::keyPressed (int key){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
diff --git a/test-tycbutton/src/testApp.h b/test-tycbutton/src/testApp.h
new file mode 100644
index 0000000..de233d5
--- /dev/null
+++ b/test-tycbutton/src/testApp.h
@@ -0,0 +1,26 @@
+#ifndef _TEST_APP
+#define _TEST_APP
+
+#include "ofMain.h"
+#include "buttonChecker.h"
+
+class testApp : public ofBaseApp{
+
+ public:
+
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed (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 windowResized(int w, int h);
+
+ buttonChecker button;
+
+};
+
+#endif