diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-03-28 00:43:07 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-03-28 00:43:07 +0100 |
| commit | 11850d1ded455e135cfa42aa1598b89be9544807 (patch) | |
| tree | 7ee41d76618c4843c659c42ca2620d6ae1974689 /src/testApp.cpp | |
| parent | ec078a99e2924c1709242f981651409f7ae9e940 (diff) | |
for strongbow demo
Diffstat (limited to 'src/testApp.cpp')
| -rw-r--r-- | src/testApp.cpp | 102 |
1 files changed, 95 insertions, 7 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index dff1f18..a7b90d1 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -66,6 +66,10 @@ void testApp::setup(){ ofAddListener(ard.EInitialized, this, &testApp::setupArduino); bSetupArduino = false; bSwitchArduino = false; + + //----------------avahi stuff + avahiService.start("ofMrmr","_mrmrsrvr._udp",1337); + oscReceiver.setup(1337); //default mrmr port } @@ -93,6 +97,9 @@ void testApp::update(){ } } updateArduino(); + + //----------------avahi stuff + ProcessMessages(); } //-------------------------------------------------------------- @@ -139,6 +146,81 @@ void testApp::updateArduino(){ } } +bool startswith(const char* _str1, const char* _start){ + for(int i=0;_start[i]>0;i++){ + if(_str1[i]!=_start[i]) + return false; + } + return true; +} + +void testApp::SendInterface(std::string targetIP, std::string interfaceString){ + + /* Example: + "/mrmrIB mrmr_clear_all\n"\ + "/mrmrIB tactilezone nil .1 1 10 1 2 1 9 _ 2\n"\ + "/mrmrIB textinputview nil .1 1 10 1 1 1 1 placeholder_text_for_textinput_field\n"*/ + + tcpClient.close(); //just open a fresh socket to do this one-time setup/send to the new client + tcpClient.setup(targetIP,31337); + + printf("Sending interface...\n"); + + int count = interfaceString.length(); + tcpClient.sendRawBytes(interfaceString.c_str(),count); //don't use send() as it appends [/TCP] tag, which screws up mrmr client +} + +void testApp::ProcessMessages(){ + + while( oscReceiver.hasWaitingMessages() ) + + + { + + // get the next message + ofxOscMessage m; + oscReceiver.getNextMessage( &m ); + std::string messageAddress = m.getAddress(); + + printf("Message: %s\n",messageAddress.c_str()); + + std::string rip = m.getRemoteIp(); + int rp = m.getRemotePort(); + std::string arg1; + + if(messageAddress.compare("/mrmr connect")==0){ + SendInterface(rip, + "/mrmrIB mrmr_clear_all\n"\ + "/mrmrIB titleview nil .1 1 10 1 1 1 1 StrongbowDemo 3"\ + "/mrmrIB pushbutton nil .1 2 10 1 6 1 1 < 11\n"\ + "/mrmrIB pushbutton nil .1 2 10 1 6 1 1 < 11\n"\ + "/mrmrIB pushbutton nil .1 2 10 2 6 1 1 > 11\n" + ); + } + else + { + int ls = messageAddress.find_last_of("/"); + int msg=-1; + + if(m.getNumArgs()) msg=m.getArgAsInt32( 0 ); + + if(startswith(messageAddress.c_str(),"/mrmr/pushbutton/1")) + { + printf("previous movie %i\n",msg); + if (msg) prevMovie(); + } + if(startswith(messageAddress.c_str(),"/mrmr/pushbutton/2")) + { + printf("next movie %i\n",msg); + if (msg) nextMovie(); + } + + } + } +} + + + //-------------------------------------------------------------- void testApp::draw(){ for (int i=0;i<numViews;i++) { @@ -237,16 +319,11 @@ void testApp::keyPressed(int key){ break; case ',': case '<': - whichClip--; - if (whichClip<1) whichClip=numClips-1; - transTime=ofGetElapsedTimef()+1.0; - transition=true; + prevMovie(); break; case '.': case '>': - whichClip=max(1,(whichClip+1)%numClips); - transTime=ofGetElapsedTimef()+1.0; - transition=true; + nextMovie(); break; case '/': light=!light; @@ -258,6 +335,17 @@ void testApp::keyPressed(int key){ break; } } +void testApp::prevMovie(){ + whichClip--; + if (whichClip<1) whichClip=numClips-1; + transTime=ofGetElapsedTimef()+1.0; + transition=true; +} +void testApp::nextMovie(){ + whichClip=max(1,(whichClip+1)%numClips); + transTime=ofGetElapsedTimef()+1.0; + transition=true; +} void testApp::doTransition(){ if (transition) { if (ofGetElapsedTimef()>transTime) { |
