Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
recotana committed Oct 17, 2011
0 parents commit b5db4d3
Show file tree
Hide file tree
Showing 32 changed files with 2,221 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
60 changes: 60 additions & 0 deletions ArdOSC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
ArdOSC - OSC Library for Arduino.
This library works with arduino firmware0018.
2010/02/01 version 2.0 changed Project OSCClass -> ArdOSC
2009/03/22 version 1.0.1 add errror process。change Doc.
2009/03/21 version 1.0.0
-------- Lisence -----------------------------------------------------------
ArdOSC
The MIT License
Copyright (c) 2009 - 2010 recotana( http://recotana.com ) All right reserved
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Thanks "Open Sound Control org" http://opensoundcontrol.org/
*/

#ifndef ArdOSC_h
#define ArdOSC_h





#include "OSCCommon/OSCcommon.h"
#include "OSCCommon/OSCMessage.h"


#include "OSCCommon/OSCClient.h"
#include "OSCCommon/OSCServer.h"



#endif
94 changes: 94 additions & 0 deletions Example/OSCArguments/OSCArguments.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <SPI.h>
#include <Ethernet.h>

#include <ArdOSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[] = { 192, 168, 0, 177 };
int serverPort = 10000;

int destPort=12000;

char oscadr[]="/ard/aaa";

OSCServer server;
OSCClient client;


void setup(){

// Serial.begin(19200);

Ethernet.begin(myMac ,myIp);
server.begin(serverPort);

//set callback function
server.addCallback(oscadr,&func1);

}

void loop(){
if(server.aviableCheck()>0){
// Serial.println("alive! ");
}
}


void func1(OSCMessage *_mes){

logIp(_mes);
logOscAddress(_mes);

//get source ip address
byte *sourceIp = _mes->getIpAddress();

//get 1st argument(int32)
int tmpI=_mes->getArgInt32(0);

//get 2nd argument(float)
float tmpF=_mes->getArgFloat(1);

//get 3rd argument(string)
int strSize=_mes->getArgStringSize(2);
char tmpStr[strSize]; //string memory allocation
_mes->getArgString(2,tmpStr);



//create new osc message
OSCMessage newMes;

//set destination ip address & port no
newMes.setAddress(sourceIp,destPort);

//set argument
newMes.beginMessage(oscadr);
newMes.addArgInt32(tmpI+1);
newMes.addArgFloat(tmpF+0.1);
newMes.addArgString(tmpStr);

//send osc message
client.send(&newMes);

}




void logIp(OSCMessage *_mes){
byte *ip = _mes->getIpAddress();
Serial.print("IP:");
Serial.print(ip[0],DEC);
Serial.print(".");
Serial.print(ip[1],DEC);
Serial.print(".");
Serial.print(ip[2],DEC);
Serial.print(".");
Serial.print(ip[3],DEC);
Serial.print(" ");
}

void logOscAddress(OSCMessage *_mes){
Serial.println(_mes->getOSCAddress());
}

60 changes: 60 additions & 0 deletions Example/OSCArguments/OSCArguments_p5/OSCArguments_p5.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* oscP5oscArgument by andreas schlegel
* example shows how to parse incoming osc messages "by hand".
* it is recommended to take a look at oscP5plug for an alternative way to parse messages.
* oscP5 website at http://www.sojamo.de/oscP5
*/

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

int a;
float b;

void setup() {
background(0);

oscP5 = new OscP5(this,12000);


// myRemoteLocation = new NetAddress("192.168.0.177",10000);
myRemoteLocation = new NetAddress("224.0.0.0",10000); //multicast address


a=0;
b=0.0;

}

void draw() {

sender();

delay(1000);

}

void sender(){
a+=1;
b+=0.1;
if(a>999) a=0;
if(b>999.0) b=0.0;

OscMessage myMessage = new OscMessage("/ard/aaa");

myMessage.add(a);
myMessage.add(b);
myMessage.add("some text");
oscP5.send(myMessage, myRemoteLocation);
}



void oscEvent(OscMessage theOscMessage) {
print("### received an osc message.");

theOscMessage.print();
}
51 changes: 51 additions & 0 deletions Example/SImpleRecieve/SImpleRecieve.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <SPI.h>
#include <Ethernet.h>

#include <ArdOSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[] = { 192, 168, 0, 177 };
int serverPort = 10000;

int ledPin = 9;

int t=100;

OSCServer server;

void setup(){

Serial.begin(19200);

Ethernet.begin(myMac ,myIp);
server.begin(serverPort);

//set callback function
server.addCallback("/ard/aaa",&func1);

pinMode(ledPin, OUTPUT);

}

void loop(){
if(server.aviableCheck()>0){
// Serial.println("alive! ");
}

digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(t);
}


void func1(OSCMessage *_mes){

//get 1st argument(int32)
t = _mes->getArgInt32(0);



}


91 changes: 91 additions & 0 deletions Example/SImpleRecieve/SimpleRecieve_p5/SimpleRecieve_p5.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Mouse Functions.
*
* Click on the box and drag it across the screen.
*/

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

int bx;
int by;
int bs = 20;
boolean bover = false;
boolean locked = false;
int bdifx = 0;
int bdify = 0;
int oldv;

void setup()
{
size(200, 400);
bx = width/2;
by = height/2;
rectMode(RADIUS);

oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("224.0.0.0",10000);

}

void draw()
{
background(0);

// Test if the cursor is over the box
if (mouseX > bx-bs && mouseX < bx+bs &&
mouseY > by-bs && mouseY < by+bs) {
bover = true;
if(!locked) {
stroke(255);
fill(153);
}
} else {
stroke(153);
fill(153);
bover = false;
}

// Draw the box
rect(bx, by, bs, bs);
}

void mousePressed() {
if(bover) {
locked = true;
fill(255, 255, 255);
} else {
locked = false;
}
// bdifx = mouseX-bx;
bdify = mouseY-by;

}

void mouseDragged() {
if(locked) {
if(mouseY>360) by = 360;
else if(mouseY<30) by = 60;
else by = mouseY-bdify;
print(by+"\n");

int value=by;
value = int(value/100)*100;
if(oldv==value) return;
OscMessage myMessage = new OscMessage("/ard/aaa");

myMessage.add(value);
oscP5.send(myMessage, myRemoteLocation);

oldv=value;
}

}

void mouseReleased() {
locked = false;
}

Loading

0 comments on commit b5db4d3

Please sign in to comment.