servodisc goodness
Diff: cube.cpp
- Revision:
- 7:a278f58cdbd3
- Parent:
- 6:1143996ac690
--- a/cube.cpp Mon Jan 15 16:12:52 2018 +0000 +++ b/cube.cpp Mon Jan 22 05:33:06 2018 +0000 @@ -165,7 +165,7 @@ return 1; } - printf("move %d nturns: %d\r\n",i,n_turns); + //printf("move %d nturns: %d\r\n",i,n_turns); seq->moves[i].n_turns = n_turns; seq->moves[i].face = (face_t)face; } @@ -177,6 +177,7 @@ int states[6] = {0,0,0,0,0,0}; int move_counts[6] = {0,0,0,0,0,0}; int wait_counter[6] = {0,0,0,0,0,0}; +int current_move = 0; //states: // 0 - start command @@ -191,6 +192,7 @@ { states[i] = 0; move_counts[i] = 0; + current_move = 0; wait_counter[i] = 0; } } @@ -204,10 +206,13 @@ int n_turns = 0; if(states[cmd->face] == 0) { + printf("Hello. I am in state 0!\r\n"); + printf("the current move number is %d.\r\n",current_move); cmd->set_and(0,cmd->face); // and off // check if done - if(move_counts[cmd->face] > n_moves) + printf("about to check for end...\n"); + if(current_move > n_moves) { printf("SEQUENCE DONE!\r\n"); cmd->set_and(1,cmd->face); @@ -216,21 +221,31 @@ cmd->seq = NULL; return NULL; } + printf("nope! we aren't at the end!\r\n"); // check how many turns needed - if(cmd->face == cmd->seq->moves[move_counts[cmd->face]].face) + if(cmd->face == cmd->seq->moves[current_move].face) { - n_turns = cmd->seq->moves[move_counts[cmd->face]].n_turns; + n_turns = cmd->seq->moves[current_move].n_turns; } else n_turns = 0; // increment move counter - move_counts[cmd->face]++; - + current_move++; + printf("about to check n turns...\r\n"); // rotate if needed if(n_turns) + { + printf("i have a rotation to do!\r\n"); cmd->rotate(n_turns,cmd->face); + } + else + { + printf("i dont have a rotation to do.\r\n"); + } + printf("done checking nturns!\n"); + // wait... states[cmd->face] = 1; wait_counter[cmd->face] = 0; @@ -241,6 +256,7 @@ //printf("b%d 1\n",cmd->face); wait_counter[cmd->face]++; if(wait_counter[cmd->face] < 500) return NULL; + printf("i am done - waiting for everybody else...\r\n"); states[cmd->face] = 2; cmd->set_and(1,cmd->face); return NULL; @@ -251,15 +267,18 @@ //printf("b 1 %d\n",cmd->face); if(cmd->get_and()) { + printf("everybody is done!\r\n"); wait_counter[cmd->face] = 0; states[cmd->face] = 3; return NULL; } + } else if(states[cmd->face] == 3) { //printf("b%d 3\n",cmd->face); - if(wait_counter[cmd->face]++ < 100) return NULL; + if(wait_counter[cmd->face]++ < 500) return NULL; + printf("going to next thing...\r\n"); states[cmd->face] = 0; cmd->set_and(0,cmd->face); return NULL;