|
@@ -14,6 +14,8 @@ SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
|
|
|
#endif
|
|
|
|
|
|
bool update_stepper_status[NUM_OF_STEPPERS];
|
|
|
+long int last_updated_status ;
|
|
|
+int update_ms = 1000 ;
|
|
|
|
|
|
//// UTILITIES /////////
|
|
|
|
|
@@ -72,6 +74,12 @@ void move_Stepper_OSC (OSCMessage &msg){
|
|
|
sendOSC("/stepper/distanceToGo", index, distance );
|
|
|
}
|
|
|
|
|
|
+void setSpeed_Stepper (OSCMessage &msg){
|
|
|
+ int index = msg.getInt(0);
|
|
|
+ steppers[index].setSpeed(msg.getInt(1));
|
|
|
+ sendOSC("/stepper/speed", index, steppers[index].speed() );
|
|
|
+}
|
|
|
+
|
|
|
void maxSpeed_Stepper (OSCMessage &msg){
|
|
|
int index = msg.getInt(0);
|
|
|
long int max_speed = maxSpeed_Stepper(index, msg.getInt(1));
|
|
@@ -125,13 +133,37 @@ void setup_OSC(){
|
|
|
void handleOSCIn() {
|
|
|
|
|
|
//send stepper status while it is running
|
|
|
- for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
|
|
|
- if (update_stepper_status[i]) {
|
|
|
- status_Stepper_OSC(i) ;
|
|
|
+ if (millis() - last_updated_status > update_ms ) {
|
|
|
+ for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
|
|
|
+ if (update_stepper_status[i]) {
|
|
|
+ status_Stepper_OSC(i) ;
|
|
|
+ }
|
|
|
+ if (!steppers[i].isRunning()) { update_stepper_status[i] = 0 ;}
|
|
|
+ else update_stepper_status[i] = 1 ;
|
|
|
}
|
|
|
- if (!steppers[i].isRunning()) { update_stepper_status[i] = 0 ;}
|
|
|
- else update_stepper_status[i] = 1 ;
|
|
|
+ last_updated_status = millis() ;
|
|
|
+ }
|
|
|
+
|
|
|
+ //send stepper status while it is running
|
|
|
+ if ((millis() - last_updated_status > update_ms) && update_stepper_status[0] ) {
|
|
|
+
|
|
|
+ status_Stepper_OSC(0) ;
|
|
|
+
|
|
|
+ if (!steppers[0].isRunning()) { update_stepper_status[0] = 0 ;}
|
|
|
+ else update_stepper_status[0] = 1 ;
|
|
|
+
|
|
|
+ last_updated_status = millis() ;
|
|
|
+ }
|
|
|
+ if ((millis() - last_updated_status > update_ms*1.5) && update_stepper_status[1] ) {
|
|
|
+
|
|
|
+ status_Stepper_OSC(1) ;
|
|
|
+
|
|
|
+ if (!steppers[1].isRunning()) { update_stepper_status[1] = 0 ;}
|
|
|
+ else update_stepper_status[1] = 1 ;
|
|
|
+
|
|
|
+ last_updated_status = millis() ;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -163,6 +195,7 @@ void handleOSCIn() {
|
|
|
OSCin.dispatch("/stepper/move", move_Stepper_OSC);
|
|
|
// OSCin.dispatch("/stepper/moveTo/cm", moveToCm_Stepper_OSC);
|
|
|
// OSCin.dispatch("/stepper/move/cm", moveCm_Stepper_OSC);
|
|
|
+ OSCin.dispatch("/stepper/setSpeed", setSpeed_Stepper);
|
|
|
OSCin.dispatch("/stepper/maxSpeed", maxSpeed_Stepper);
|
|
|
OSCin.dispatch("/stepper/acceleration", acceleration_Stepper);
|
|
|
// OSCin.dispatch("/stepper/randomMove", randomMove_Stepper_OSC);
|