|
@@ -39,10 +39,9 @@ class Atm_blink : public Machine {
|
|
|
|
|
|
public:
|
|
|
Atm_blink( void ) : Machine() {};
|
|
|
-
|
|
|
short pin;
|
|
|
atm_timer_millis timer;
|
|
|
-
|
|
|
+ OSCMessage _msg ;
|
|
|
EthernetUDP* _udpRef ;
|
|
|
|
|
|
|
|
@@ -62,6 +61,7 @@ class Atm_blink : public Machine {
|
|
|
timer.set( blinkrate );
|
|
|
pinMode( pin, OUTPUT );
|
|
|
this->_udpRef = &udpRef;
|
|
|
+
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -69,9 +69,9 @@ class Atm_blink : public Machine {
|
|
|
switch ( id ) {
|
|
|
case EVT_TIMER :
|
|
|
return timer.expired( this );
|
|
|
- }
|
|
|
- return 0;
|
|
|
+
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
void action( int id ) {
|
|
|
|
|
@@ -79,119 +79,120 @@ class Atm_blink : public Machine {
|
|
|
case ENT_ON :
|
|
|
digitalWrite( pin, HIGH );
|
|
|
|
|
|
+
|
|
|
return;
|
|
|
|
|
|
case ENT_OFF :
|
|
|
digitalWrite( pin, LOW );
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Atm_blink& trigger( int event ) {
|
|
|
+ Machine::trigger( event );
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Control what the machine returns when another process requests its state
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Atm_blink& onOSC(OSCMessage& msg ){
|
|
|
- if(msg.fullMatch("/truc")){
|
|
|
- OSCMessage _msg("/blink");
|
|
|
- _msg.add("youpi");
|
|
|
- _udpRef->beginPacket(ipMulti, portMulti);
|
|
|
- _msg.send(*_udpRef);
|
|
|
- _udpRef->endPacket();
|
|
|
- _msg.empty();
|
|
|
+ Serial.println("OSC");
|
|
|
+ if(msg.fullMatch("/blink")){
|
|
|
+ Serial.println("ouais gros");
|
|
|
+
|
|
|
+
|
|
|
+ _msg = new OSCMessage("/on");
|
|
|
+ _msg.add("youpi");
|
|
|
+ _udpRef->beginPacket(ipMulti, portMulti);
|
|
|
+ _msg.send(*_udpRef);
|
|
|
+ _udpRef->endPacket();
|
|
|
+ _msg.empty();
|
|
|
+ return *this;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
};
|
|
|
|
|
|
Atm_blink led;
|
|
|
|
|
|
void test(OSCMessage &msg, int addrOffset){
|
|
|
+ Serial.println("test");
|
|
|
msg.getInt(0)?led.trigger( led.EVT_ON ):led.trigger( led.EVT_OFF );
|
|
|
}
|
|
|
|
|
|
-void routeTone(OSCMessage &msg, int addrOffset ){
|
|
|
-
|
|
|
-for(byte pin = 0; pin < NUM_DIGITAL_PINS; pin++){
|
|
|
-
|
|
|
- int pinMatched = msg.match("5", addrOffset);
|
|
|
- if(pinMatched){
|
|
|
- unsigned int frequency = 0;
|
|
|
-
|
|
|
- if (msg.isInt(0)){
|
|
|
- frequency = msg.getInt(0);
|
|
|
- }
|
|
|
- else if(msg.isFloat(0)){
|
|
|
- frequency = msg.getFloat(0);
|
|
|
- }
|
|
|
- else
|
|
|
- noTone(pin);
|
|
|
- if(frequency>0)
|
|
|
- {
|
|
|
- if(msg.isInt(1))
|
|
|
- tone(pin, frequency, msg.getInt(1));
|
|
|
- else
|
|
|
- tone(pin, frequency);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
void setup() {
|
|
|
- SPI.setSCK(27);
|
|
|
- Ethernet.init(10);
|
|
|
+
|
|
|
+ Ethernet.init(15);
|
|
|
teensyMAC(mac);
|
|
|
Ethernet.begin(mac, ip);
|
|
|
|
|
|
Udp.beginMulticast(ipMulti, portMulti);
|
|
|
Serial.begin(115200);
|
|
|
|
|
|
- led.begin( 14, 200, Udp);
|
|
|
- led.trigger( led.EVT_ON );
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- Serial.begin( 9600 );
|
|
|
- delay(1000);
|
|
|
- stepper.trace( Serial );
|
|
|
- Serial.println("Started");
|
|
|
- stepper.begin(A_stepper);
|
|
|
- stepper.cycle(1000);
|
|
|
- Serial.println("Started");
|
|
|
- stepper.gotoStep(1000);
|
|
|
- controller.moveAsync(*stepper.motor);
|
|
|
delay(1000);
|
|
|
- controller.moveAsync(*stepper.motor);
|
|
|
- delay(10000);
|
|
|
- stepper.motor->setMaxSpeed(30000);
|
|
|
- stepper.motor->setAcceleration(10000);
|
|
|
- stepper.gotoStep(-100000);
|
|
|
- controller.moveAsync(*stepper.motor);
|
|
|
- Serial.println("Started");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
- automaton.run();
|
|
|
- OSCMessage msgIn;
|
|
|
- int size;
|
|
|
-
|
|
|
- if( (size = Udp.parsePacket())>0)
|
|
|
- {
|
|
|
- while(size--)
|
|
|
- msgIn.fill(Udp.read());
|
|
|
-
|
|
|
- if(!msgIn.hasError())
|
|
|
- msgIn.route("/blink", test);
|
|
|
- led.onOSC(msgIn);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Serial.println("msgIn");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ OSCMessage msg("/analog/0");
|
|
|
+ msg.add((int32_t)analogRead(0));
|
|
|
+
|
|
|
+ Udp.beginPacket(ipMulti, portMulti);
|
|
|
+ msg.send(Udp);
|
|
|
+ Udp.endPacket();
|
|
|
+ msg.empty();
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+ delay(100);
|
|
|
|
|
|
|
|
|
|