|
|
@@ -0,0 +1,68 @@
|
|
|
+
|
|
|
+
|
|
|
+void step_ctrl_send(step_seq_T* step_seqX_A, step_seq_T* step_seqY_A, step_curr_T &step_currX_A, step_curr_T &step_currY_A, int stepsX, int stepsY ) {
|
|
|
+
|
|
|
+ if(stepsX > 0) {
|
|
|
+ step_currX_A ++;
|
|
|
+ } else if(stepsX < 0) {
|
|
|
+ step_currX_A --;
|
|
|
+ } else {
|
|
|
+ // step_currX_A --;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(stepsY > 0) {
|
|
|
+ step_currY_A ++;
|
|
|
+ } else if(stepsY < 0) {
|
|
|
+ step_currY_A --;
|
|
|
+ } else {
|
|
|
+ // step_currY_A --;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(step_currX_A >= 9) step_currX_A = 1;
|
|
|
+ if(step_currX_A <= 0) step_currX_A = 8;
|
|
|
+
|
|
|
+ if(step_currY_A >= 9) step_currY_A = 1;
|
|
|
+ if(step_currY_A <= 0) step_currY_A = 8;
|
|
|
+
|
|
|
+
|
|
|
+ Serial.println( );
|
|
|
+ Serial.print(" SEQ "); Serial.print(stepsX); Serial.print("]["); Serial.println(step_currX_A);
|
|
|
+ //Serial.print(String(step_seq_A[step_curr_A].step_byte_A , BIN));
|
|
|
+ delay(10);
|
|
|
+ Wire.beginTransmission(PCF_ADDR);
|
|
|
+ Wire.write(step_seqX_A[step_currX_A].step_byte_A | step_seqY_A[step_currY_A].step_byte_A );
|
|
|
+ Wire.endTransmission();
|
|
|
+ // return step_seq_A[step_curr_A].step_byte_A ;
|
|
|
+}
|
|
|
+
|
|
|
+void step_ctrl(step_seq_T* step_seqX_A, step_seq_T* step_seqY_A, step_curr_T &step_currX_A, step_curr_T &step_currY_A, int stepsX, int stepsY) {
|
|
|
+ int ratio ;
|
|
|
+ int mod_ratio ;
|
|
|
+ for(int i = 1 ; i<=abs(stepsX) or i<= abs(stepsY); i++) {
|
|
|
+
|
|
|
+ if(abs(stepsX) == abs(stepsY) or stepsX == 0 or stepsY == 0) {
|
|
|
+ step_ctrl_send(step_seqX_A, step_seqY_A, step_currX_A, step_currY_A,stepsX, stepsY );
|
|
|
+ } else if(abs(stepsX) > abs(stepsY)) {
|
|
|
+ ratio = abs(stepsX) / abs(stepsY) ;
|
|
|
+ mod_ratio = i % ratio ;
|
|
|
+ if(mod_ratio < 1) {
|
|
|
+ step_ctrl_send(step_seqX_A, step_seqY_A, step_currX_A, step_currY_A,stepsX, stepsY );
|
|
|
+ Serial.print(" [Y+] ");
|
|
|
+ } else {
|
|
|
+ step_ctrl_send(step_seqX_A, step_seqY_A, step_currX_A, step_currY_A,stepsX, 0 );
|
|
|
+ Serial.print(" [Y-] ");
|
|
|
+ }
|
|
|
+ } else if(abs(stepsX) < abs(stepsY)) {
|
|
|
+ ratio = abs(stepsY) / abs(stepsX) ;
|
|
|
+ mod_ratio = i % ratio ;
|
|
|
+ if(mod_ratio < 1) {
|
|
|
+ step_ctrl_send(step_seqX_A, step_seqY_A, step_currX_A, step_currY_A,stepsX, stepsY );
|
|
|
+ Serial.print(" [X+] ");
|
|
|
+ } else {
|
|
|
+ step_ctrl_send(step_seqX_A, step_seqY_A, step_currX_A, step_currY_A,0, stepsY );
|
|
|
+ Serial.print(" [X-] %["); Serial.print(mod_ratio); Serial.print("] r["); Serial.print(ratio);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|