Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
SERIAL_COMMANDS.cpp@57:aba1296e51b1, 2018-08-15 (annotated)
- Committer:
- thomasmorris
- Date:
- Wed Aug 15 21:34:59 2018 +0000
- Revision:
- 57:aba1296e51b1
- Parent:
- 56:bc5345bc6650
Final Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 47:6d128e500875 | 1 | #include "SERIAL_COMMANDS.hpp" |
thomasmorris | 52:99915f5240b2 | 2 | int NetworkWaitTime; //Waiting time to update the network |
thomasmorris | 52:99915f5240b2 | 3 | char input[100] = {}; //Character array initialised to NULL |
thomasmorris | 53:71f59e195f06 | 4 | int steps = 0; |
thomasmorris | 53:71f59e195f06 | 5 | int direction = 1; |
thomasmorris | 53:71f59e195f06 | 6 | int Motor_To_Select = 1; |
thomasmorris | 53:71f59e195f06 | 7 | float angle = 0; |
thomasmorris | 57:aba1296e51b1 | 8 | bool move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 9 | bool List_move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 10 | |
thomasmorris | 57:aba1296e51b1 | 11 | |
thomasmorris | 52:99915f5240b2 | 12 | //Mutex Locks |
thomasmorris | 52:99915f5240b2 | 13 | |
thomasmorris | 52:99915f5240b2 | 14 | void Serial_Commands_Output() //Used for getting input from the user to determine the opperations to perform |
thomasmorris | 47:6d128e500875 | 15 | { |
thomasmorris | 52:99915f5240b2 | 16 | if(Log_Value == 4){pc.printf("In Serial_Commands\n");} //If logging is enabled, print debug statement |
thomasmorris | 47:6d128e500875 | 17 | |
thomasmorris | 52:99915f5240b2 | 18 | for (int x = 0; x < 100; x++){input[x] = ' ';}; //Fill input with spaces |
thomasmorris | 47:6d128e500875 | 19 | |
thomasmorris | 52:99915f5240b2 | 20 | pc.printf("Please type in a command\n"); //Request command in the terminal |
thomasmorris | 57:aba1296e51b1 | 21 | cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character |
thomasmorris | 57:aba1296e51b1 | 22 | |
thomasmorris | 55:e0e684531825 | 23 | |
thomasmorris | 52:99915f5240b2 | 24 | //LOGGING |
thomasmorris | 57:aba1296e51b1 | 25 | if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G' & input[7] == ' ') |
thomasmorris | 52:99915f5240b2 | 26 | { |
thomasmorris | 52:99915f5240b2 | 27 | int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 28 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
thomasmorris | 52:99915f5240b2 | 29 | for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} //Concatenate the characters between the space and the end |
thomasmorris | 52:99915f5240b2 | 30 | stringstream Number(LoggingNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 31 | Number >> NumberToLogging; //Convert stringstream to integer |
thomasmorris | 52:99915f5240b2 | 32 | if (NumberToLogging == 0){pc.printf("NOT LOGGING\n");} //Not Logging |
thomasmorris | 57:aba1296e51b1 | 33 | else if (NumberToLogging == 1){pc.printf("LOGGING SPI\n");} //Logging SPI |
thomasmorris | 52:99915f5240b2 | 34 | |
thomasmorris | 52:99915f5240b2 | 35 | if (NumberToLogging <= 5){Log_Value = NumberToLogging;} //If inputted value is within bounds equate it to the log state |
thomasmorris | 52:99915f5240b2 | 36 | } |
thomasmorris | 55:e0e684531825 | 37 | |
thomasmorris | 53:71f59e195f06 | 38 | //Motor Control |
thomasmorris | 53:71f59e195f06 | 39 | else if(input[0] == 'M' & input[1] == 'o' & input[2] == 't' & input[3] == 'o' & input[4] == 'r' & input[5] == ' ') |
thomasmorris | 53:71f59e195f06 | 40 | { |
thomasmorris | 53:71f59e195f06 | 41 | int NumberOfChars = 0; int ArrayAddress = 0; string MotorNumber; int Motor_Number; //Declare required variables |
thomasmorris | 53:71f59e195f06 | 42 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
thomasmorris | 53:71f59e195f06 | 43 | for(int x=6; x < NumberOfChars; x++){MotorNumber += input[x];} //Concatenate the characters between the space and the end |
thomasmorris | 53:71f59e195f06 | 44 | stringstream Number(MotorNumber); //Convert string to stringstream |
thomasmorris | 53:71f59e195f06 | 45 | Number >> Motor_Number; //Convert stringstream to integer |
thomasmorris | 53:71f59e195f06 | 46 | if(Motor_Number < 1 || Motor_Number > 6) |
thomasmorris | 53:71f59e195f06 | 47 | { |
thomasmorris | 53:71f59e195f06 | 48 | Motor_Number =0; |
thomasmorris | 53:71f59e195f06 | 49 | pc.printf("Please Select a motor from 1-6\n"); |
thomasmorris | 53:71f59e195f06 | 50 | } |
thomasmorris | 53:71f59e195f06 | 51 | Motor_To_Select = Motor_Number; |
thomasmorris | 53:71f59e195f06 | 52 | //Step Control |
thomasmorris | 53:71f59e195f06 | 53 | pc.printf("Enter the angle to rotate\n"); //Request command in the terminal |
thomasmorris | 53:71f59e195f06 | 54 | scanf("%f",&angle); |
thomasmorris | 53:71f59e195f06 | 55 | //cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character |
thomasmorris | 53:71f59e195f06 | 56 | //if(input[0] == 'S' & input[1] == 't' & input[2] == 'e' & input[3] == 'p' & input[4] == 's' & input[5] == ' ') |
thomasmorris | 53:71f59e195f06 | 57 | { |
thomasmorris | 53:71f59e195f06 | 58 | //angle = input; |
thomasmorris | 53:71f59e195f06 | 59 | if(angle < 0) |
thomasmorris | 53:71f59e195f06 | 60 | { |
thomasmorris | 55:e0e684531825 | 61 | direction = 0;//Anti Clockwise |
thomasmorris | 53:71f59e195f06 | 62 | } |
thomasmorris | 53:71f59e195f06 | 63 | else |
thomasmorris | 53:71f59e195f06 | 64 | { |
thomasmorris | 55:e0e684531825 | 65 | direction = 1;//Clockwise |
thomasmorris | 53:71f59e195f06 | 66 | } |
thomasmorris | 55:e0e684531825 | 67 | float new_angle = abs(angle/1.8);//Converts input to steps |
thomasmorris | 53:71f59e195f06 | 68 | steps = new_angle; |
thomasmorris | 53:71f59e195f06 | 69 | pc.printf("The Motor is: %d\n The Number to step is: %d\n", Motor_Number, steps); |
thomasmorris | 53:71f59e195f06 | 70 | } |
thomasmorris | 53:71f59e195f06 | 71 | |
thomasmorris | 53:71f59e195f06 | 72 | } |
thomasmorris | 56:bc5345bc6650 | 73 | //MOVE |
thomasmorris | 56:bc5345bc6650 | 74 | else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E') |
thomasmorris | 56:bc5345bc6650 | 75 | { |
thomasmorris | 57:aba1296e51b1 | 76 | move_loop = 1; |
thomasmorris | 57:aba1296e51b1 | 77 | pc.printf("Enter the Move\n"); //Request command in the terminal |
thomasmorris | 57:aba1296e51b1 | 78 | while(move_loop == 1) |
thomasmorris | 57:aba1296e51b1 | 79 | { |
thomasmorris | 57:aba1296e51b1 | 80 | cin.getline(input,sizeof(input),'\r'); |
thomasmorris | 57:aba1296e51b1 | 81 | |
thomasmorris | 57:aba1296e51b1 | 82 | if(input[0] == 'A' & input[1] == 'F'){STEPPER_MOTOR_1.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 83 | else if(input[0] == 'C' & input[1] == 'F'){STEPPER_MOTOR_1.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 84 | else if(input[0] == 'A' & input[1] == 'B'){STEPPER_MOTOR_2.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 85 | else if(input[0] == 'C' & input[1] == 'B'){STEPPER_MOTOR_2.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 86 | else if(input[0] == 'A' & input[1] == 'L'){STEPPER_MOTOR_3.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 87 | else if(input[0] == 'C' & input[1] == 'L'){STEPPER_MOTOR_3.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 88 | else if(input[0] == 'A' & input[1] == 'R'){STEPPER_MOTOR_4.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 89 | else if(input[0] == 'C' & input[1] == 'R'){STEPPER_MOTOR_4.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 90 | else if(input[0] == 'A' & input[1] == 'U'){STEPPER_MOTOR_5.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 91 | else if(input[0] == 'C' & input[1] == 'U'){STEPPER_MOTOR_5.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 92 | else if(input[0] == 'A' & input[1] == 'D'){STEPPER_MOTOR_6.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 93 | else if(input[0] == 'C' & input[1] == 'D'){STEPPER_MOTOR_6.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 94 | else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E') |
thomasmorris | 57:aba1296e51b1 | 95 | { |
thomasmorris | 57:aba1296e51b1 | 96 | move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 97 | pc.printf("Exiting Move loop\n"); |
thomasmorris | 57:aba1296e51b1 | 98 | //Exit moves function |
thomasmorris | 57:aba1296e51b1 | 99 | } |
thomasmorris | 57:aba1296e51b1 | 100 | else |
thomasmorris | 57:aba1296e51b1 | 101 | { |
thomasmorris | 57:aba1296e51b1 | 102 | pc.printf("Error please enter a allowed move\n"); |
thomasmorris | 57:aba1296e51b1 | 103 | //Error case |
thomasmorris | 57:aba1296e51b1 | 104 | } |
thomasmorris | 57:aba1296e51b1 | 105 | |
thomasmorris | 57:aba1296e51b1 | 106 | } |
thomasmorris | 57:aba1296e51b1 | 107 | } |
thomasmorris | 57:aba1296e51b1 | 108 | //LIST |
thomasmorris | 57:aba1296e51b1 | 109 | else if(input[0] == 'L' & input[1] == 'I' & input[2] == 'S' & input[3] == 'T')//This is where the move list shall be added to |
thomasmorris | 57:aba1296e51b1 | 110 | { |
thomasmorris | 57:aba1296e51b1 | 111 | List_move_loop = 1; |
thomasmorris | 57:aba1296e51b1 | 112 | pc.printf("Entered the Move_List Section\n"); //Request command in the terminal |
thomasmorris | 57:aba1296e51b1 | 113 | while(List_move_loop == 1) |
thomasmorris | 57:aba1296e51b1 | 114 | { |
thomasmorris | 57:aba1296e51b1 | 115 | cin.getline(input,sizeof(input),'\r'); |
thomasmorris | 57:aba1296e51b1 | 116 | |
thomasmorris | 57:aba1296e51b1 | 117 | if(input[0] == 'A' & input[1] == 'F'){Move_list[Move_list_pointer] = 1; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 118 | else if(input[0] == 'C' & input[1] == 'F'){Move_list[Move_list_pointer] = 2; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 119 | else if(input[0] == 'A' & input[1] == 'B'){Move_list[Move_list_pointer] = 3; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 120 | else if(input[0] == 'C' & input[1] == 'B'){Move_list[Move_list_pointer] = 4; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 121 | else if(input[0] == 'A' & input[1] == 'L'){Move_list[Move_list_pointer] = 5; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 122 | else if(input[0] == 'C' & input[1] == 'L'){Move_list[Move_list_pointer] = 6; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 123 | else if(input[0] == 'A' & input[1] == 'R'){Move_list[Move_list_pointer] = 7; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 124 | else if(input[0] == 'C' & input[1] == 'R'){Move_list[Move_list_pointer] = 8; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 125 | else if(input[0] == 'A' & input[1] == 'U'){Move_list[Move_list_pointer] = 9; Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 126 | else if(input[0] == 'C' & input[1] == 'U'){Move_list[Move_list_pointer] = 10;Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 127 | else if(input[0] == 'A' & input[1] == 'D'){Move_list[Move_list_pointer] = 11;Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 128 | else if(input[0] == 'C' & input[1] == 'D'){Move_list[Move_list_pointer] = 12;Move_list_pointer = Move_list_pointer + 1;} |
thomasmorris | 57:aba1296e51b1 | 129 | |
thomasmorris | 57:aba1296e51b1 | 130 | |
thomasmorris | 57:aba1296e51b1 | 131 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] =='T' & input[5] == 'E') |
thomasmorris | 57:aba1296e51b1 | 132 | { |
thomasmorris | 57:aba1296e51b1 | 133 | pc.printf("Delete Clear Test\n"); |
thomasmorris | 57:aba1296e51b1 | 134 | memset(Move_list, 0, sizeof(Move_list)); |
thomasmorris | 57:aba1296e51b1 | 135 | Move_list_pointer = 0; |
thomasmorris | 57:aba1296e51b1 | 136 | pc.printf("Move List array and pointer reset\n"); |
thomasmorris | 57:aba1296e51b1 | 137 | List_move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 138 | pc.printf("Exiting Move List loop\n"); |
thomasmorris | 57:aba1296e51b1 | 139 | } |
thomasmorris | 57:aba1296e51b1 | 140 | else if(input[0] == 'L' & input[1] == 'I' & input[2] == 'S' & input[3] == 'T') |
thomasmorris | 57:aba1296e51b1 | 141 | { |
thomasmorris | 57:aba1296e51b1 | 142 | List_move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 143 | pc.printf("Exiting Move List loop\n"); |
thomasmorris | 57:aba1296e51b1 | 144 | //Exit moves function |
thomasmorris | 57:aba1296e51b1 | 145 | } |
thomasmorris | 57:aba1296e51b1 | 146 | else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D') |
thomasmorris | 57:aba1296e51b1 | 147 | { |
thomasmorris | 57:aba1296e51b1 | 148 | pc.printf("Printing out the move list\n"); |
thomasmorris | 57:aba1296e51b1 | 149 | for(int i=0;i <= Move_list_pointer; i+=1) |
thomasmorris | 57:aba1296e51b1 | 150 | { |
thomasmorris | 57:aba1296e51b1 | 151 | pc.printf("Value %d is %d\n",i,Move_list[i]); |
thomasmorris | 57:aba1296e51b1 | 152 | } |
thomasmorris | 57:aba1296e51b1 | 153 | pc.printf("Move List test passed\n"); |
thomasmorris | 57:aba1296e51b1 | 154 | List_move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 155 | pc.printf("Exiting Move List loop\n"); |
thomasmorris | 57:aba1296e51b1 | 156 | //Exit moves function |
thomasmorris | 57:aba1296e51b1 | 157 | } |
thomasmorris | 57:aba1296e51b1 | 158 | else if(input[0] == 'R' & input[1] == 'U' & input[2] == 'N') |
thomasmorris | 57:aba1296e51b1 | 159 | { |
thomasmorris | 57:aba1296e51b1 | 160 | List_move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 161 | { |
thomasmorris | 57:aba1296e51b1 | 162 | pc.printf("Move point value is : %d\n",Move_list_pointer); |
thomasmorris | 57:aba1296e51b1 | 163 | for(int i = 0; i<= Move_list_pointer; i += 1) |
thomasmorris | 57:aba1296e51b1 | 164 | { |
thomasmorris | 57:aba1296e51b1 | 165 | if(Move_list[i] == 0){pc.printf("Move List Finished\n");} |
thomasmorris | 57:aba1296e51b1 | 166 | else if (Move_list[i] == 1){STEPPER_MOTOR_1.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 167 | else if (Move_list[i] == 2){STEPPER_MOTOR_1.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 168 | else if (Move_list[i] == 3){STEPPER_MOTOR_2.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 169 | else if (Move_list[i] == 4){STEPPER_MOTOR_2.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 170 | else if (Move_list[i] == 5){STEPPER_MOTOR_3.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 171 | else if (Move_list[i] == 6){STEPPER_MOTOR_3.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 172 | else if (Move_list[i] == 7){STEPPER_MOTOR_4.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 173 | else if (Move_list[i] == 8){STEPPER_MOTOR_4.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 174 | else if (Move_list[i] == 9){STEPPER_MOTOR_5.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 175 | else if (Move_list[i] == 10){STEPPER_MOTOR_5.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 176 | else if (Move_list[i] == 11){STEPPER_MOTOR_6.Rotate_Steps(50 ,1);} |
thomasmorris | 57:aba1296e51b1 | 177 | else if (Move_list[i] == 12){STEPPER_MOTOR_6.Rotate_Steps(50 ,0);} |
thomasmorris | 57:aba1296e51b1 | 178 | else pc.printf("Finished\n"); |
thomasmorris | 57:aba1296e51b1 | 179 | } |
thomasmorris | 57:aba1296e51b1 | 180 | pc.printf("List Run sucessful\n"); |
thomasmorris | 57:aba1296e51b1 | 181 | } |
thomasmorris | 57:aba1296e51b1 | 182 | pc.printf("List execution finished\n"); |
thomasmorris | 57:aba1296e51b1 | 183 | } |
thomasmorris | 57:aba1296e51b1 | 184 | //TEST RUN |
thomasmorris | 57:aba1296e51b1 | 185 | else if(input[0] == 'T' & input[1] == 'E' & input[2] == 'S' & input[3] == 'T' & input[4] == '_' & input[5] == 'R' & input[6] == 'U' & input[7] == 'N')//This is the test run code |
thomasmorris | 57:aba1296e51b1 | 186 | { |
thomasmorris | 57:aba1296e51b1 | 187 | memset(Move_list, 0, sizeof(Move_list)); |
thomasmorris | 57:aba1296e51b1 | 188 | Move_list_pointer = 0; |
thomasmorris | 57:aba1296e51b1 | 189 | Move_list[Move_list_pointer] = 1 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 190 | Move_list[Move_list_pointer] = 2 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 191 | Move_list[Move_list_pointer] = 3 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 192 | Move_list[Move_list_pointer] = 4 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 193 | Move_list[Move_list_pointer] = 5 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 194 | Move_list[Move_list_pointer] = 6 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 195 | Move_list[Move_list_pointer] = 7 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 196 | Move_list[Move_list_pointer] = 8 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 197 | Move_list[Move_list_pointer] = 9 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 198 | Move_list[Move_list_pointer] = 10 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 199 | Move_list[Move_list_pointer] = 11 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 200 | Move_list[Move_list_pointer] = 12 ;Move_list_pointer = Move_list_pointer + 1; |
thomasmorris | 57:aba1296e51b1 | 201 | |
thomasmorris | 57:aba1296e51b1 | 202 | pc.printf("Array filled for test\n"); |
thomasmorris | 57:aba1296e51b1 | 203 | List_move_loop = 0; |
thomasmorris | 57:aba1296e51b1 | 204 | pc.printf("Exiting Move List loop\n"); |
thomasmorris | 57:aba1296e51b1 | 205 | } |
thomasmorris | 57:aba1296e51b1 | 206 | else |
thomasmorris | 57:aba1296e51b1 | 207 | { |
thomasmorris | 57:aba1296e51b1 | 208 | pc.printf("Error please enter a allowed move\n"); |
thomasmorris | 57:aba1296e51b1 | 209 | //Error case |
thomasmorris | 57:aba1296e51b1 | 210 | } |
thomasmorris | 57:aba1296e51b1 | 211 | |
thomasmorris | 57:aba1296e51b1 | 212 | } |
thomasmorris | 57:aba1296e51b1 | 213 | } |
thomasmorris | 57:aba1296e51b1 | 214 | //Colours |
thomasmorris | 57:aba1296e51b1 | 215 | if(input[0] == 'C' & input[1] == 'O' & input[2] == 'L' & input[3] == 'O' & input[4] == 'U' & input[5] == 'R' & input[6] == 'S' & input[7] == ' ') |
thomasmorris | 56:bc5345bc6650 | 216 | { |
thomasmorris | 57:aba1296e51b1 | 217 | int NumberOfChars = 0; int ArrayAddress = 0; string COLOURSNUBMER; int NUMBERTOCOLOUR; //Declare required variables |
thomasmorris | 57:aba1296e51b1 | 218 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
thomasmorris | 57:aba1296e51b1 | 219 | for(int x=8; x < NumberOfChars; x++){COLOURSNUBMER += input[x];} //Concatenate the characters between the space and the end |
thomasmorris | 57:aba1296e51b1 | 220 | stringstream Number(COLOURSNUBMER); //Convert string to stringstream |
thomasmorris | 57:aba1296e51b1 | 221 | Number >> NUMBERTOCOLOUR; |
thomasmorris | 57:aba1296e51b1 | 222 | int n = NUMBERTOCOLOUR -1 ; //Convert stringstream to integer |
thomasmorris | 57:aba1296e51b1 | 223 | pc.printf("Showing side %D\n",NUMBERTOCOLOUR); |
thomasmorris | 57:aba1296e51b1 | 224 | |
thomasmorris | 57:aba1296e51b1 | 225 | |
thomasmorris | 57:aba1296e51b1 | 226 | pc.printf("%c,%c,%c\n%c,%c,%c\n%c,%c,%c\n", |
thomasmorris | 57:aba1296e51b1 | 227 | Value_convert(CubeMap[n][0][0]),Value_convert(CubeMap[n][0][1]),Value_convert(CubeMap[n][0][2]) |
thomasmorris | 57:aba1296e51b1 | 228 | ,Value_convert(CubeMap[n][1][0]),Value_convert(CubeMap[n][1][1]),Value_convert(CubeMap[n][1][2]) |
thomasmorris | 57:aba1296e51b1 | 229 | ,Value_convert(CubeMap[n][2][0]),Value_convert(CubeMap[n][2][1]),Value_convert(CubeMap[n][2][2]));;//Side n |
thomasmorris | 57:aba1296e51b1 | 230 | |
thomasmorris | 57:aba1296e51b1 | 231 | |
thomasmorris | 57:aba1296e51b1 | 232 | } |
thomasmorris | 57:aba1296e51b1 | 233 | //SIDE_ADD |
thomasmorris | 57:aba1296e51b1 | 234 | if(input[0] == 'S' & input[1] == 'I' & input[2] == 'D' & input[3] == 'E' & input[4] == '_' & input[5] == 'A' & input[6] == 'D' & input[7] == 'D' & input[8] == ' ') |
thomasmorris | 57:aba1296e51b1 | 235 | { |
thomasmorris | 57:aba1296e51b1 | 236 | int NumberOfChars = 0; int ArrayAddress = 0; string SIDENUMBER; int NUMBERTOSIDE; //Declare required variables |
thomasmorris | 57:aba1296e51b1 | 237 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
thomasmorris | 57:aba1296e51b1 | 238 | for(int x=9; x < NumberOfChars; x++){SIDENUMBER += input[x];} //Concatenate the characters between the space and the end |
thomasmorris | 57:aba1296e51b1 | 239 | stringstream Number(SIDENUMBER); //Convert string to stringstream |
thomasmorris | 57:aba1296e51b1 | 240 | Number >> NUMBERTOSIDE; |
thomasmorris | 57:aba1296e51b1 | 241 | pc.printf("Please enter in the colour of segment 1:\n"); |
thomasmorris | 57:aba1296e51b1 | 242 | int Colour_value; |
thomasmorris | 57:aba1296e51b1 | 243 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 244 | NUMBERTOSIDE = NUMBERTOSIDE - 1; |
thomasmorris | 57:aba1296e51b1 | 245 | |
thomasmorris | 57:aba1296e51b1 | 246 | CubeMap[NUMBERTOSIDE][0][0] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 247 | pc.printf("Please enter in the colour of segment 2:\n"); |
thomasmorris | 57:aba1296e51b1 | 248 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 249 | CubeMap[NUMBERTOSIDE][0][1] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 250 | pc.printf("Please enter in the colour of segment 3:\n"); |
thomasmorris | 57:aba1296e51b1 | 251 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 252 | CubeMap[NUMBERTOSIDE][0][2] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 253 | pc.printf("Please enter in the colour of segment 4:\n"); |
thomasmorris | 57:aba1296e51b1 | 254 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 255 | CubeMap[NUMBERTOSIDE][1][0] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 256 | pc.printf("Please enter in the colour of segment 5:\n"); |
thomasmorris | 57:aba1296e51b1 | 257 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 258 | CubeMap[NUMBERTOSIDE][1][1] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 259 | pc.printf("Please enter in the colour of segment 6:\n"); |
thomasmorris | 57:aba1296e51b1 | 260 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 261 | CubeMap[NUMBERTOSIDE][1][2] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 262 | pc.printf("Please enter in the colour of segment 7:\n"); |
thomasmorris | 57:aba1296e51b1 | 263 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 264 | CubeMap[NUMBERTOSIDE][2][0] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 265 | pc.printf("Please enter in the colour of segment 8:\n"); |
thomasmorris | 57:aba1296e51b1 | 266 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 267 | CubeMap[NUMBERTOSIDE][2][1] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 268 | pc.printf("Please enter in the colour of segment 9:\n"); |
thomasmorris | 57:aba1296e51b1 | 269 | cin >>Colour_value; |
thomasmorris | 57:aba1296e51b1 | 270 | CubeMap[NUMBERTOSIDE][2][2] = convert(Colour_value); |
thomasmorris | 57:aba1296e51b1 | 271 | pc.printf("Side filled\n"); |
thomasmorris | 57:aba1296e51b1 | 272 | cin.getline(input,sizeof(input),'\r'); |
thomasmorris | 57:aba1296e51b1 | 273 | } |
thomasmorris | 57:aba1296e51b1 | 274 | //SIDE_CLEAR |
thomasmorris | 57:aba1296e51b1 | 275 | if(input[0] == 'S' & input[1] == 'I' & input[2] == 'D' & input[3] == 'E' & input[4] == '_' & input[5] == 'C' & input[6] == 'L' & input[7] == 'E' & input[8] == 'A' & input[9] == 'R') |
thomasmorris | 57:aba1296e51b1 | 276 | { |
thomasmorris | 57:aba1296e51b1 | 277 | |
thomasmorris | 57:aba1296e51b1 | 278 | for(int i =0; i<=6;i++) |
thomasmorris | 57:aba1296e51b1 | 279 | { |
thomasmorris | 57:aba1296e51b1 | 280 | CubeMap[i][0][0] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 281 | CubeMap[i][0][1] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 282 | CubeMap[i][0][2] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 283 | CubeMap[i][1][0] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 284 | CubeMap[i][1][1] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 285 | CubeMap[i][1][2] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 286 | CubeMap[i][2][0] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 287 | CubeMap[i][2][1] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 288 | CubeMap[i][2][2] = convert(0); |
thomasmorris | 57:aba1296e51b1 | 289 | } |
thomasmorris | 57:aba1296e51b1 | 290 | pc.printf("All sides cleared of data\n"); |
thomasmorris | 56:bc5345bc6650 | 291 | } |
thomasmorris | 52:99915f5240b2 | 292 | //HELP |
thomasmorris | 52:99915f5240b2 | 293 | else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P') |
thomasmorris | 52:99915f5240b2 | 294 | { |
thomasmorris | 57:aba1296e51b1 | 295 | pc.printf("Please specify the function you would like help in\nMOTOR , LOGGING , MOVE \n"); //Print introduction line |
thomasmorris | 57:aba1296e51b1 | 296 | cin.getline(input,sizeof(input),'\r'); |
thomasmorris | 57:aba1296e51b1 | 297 | if(input[0] == 'M' & input[1] == 'O' & input[2] == 'T' & input[3] == 'O' & input[4] == 'R'){pc.printf("Motor x selects a motor in the range of 1-6\nThen you issue the angle which is a number either positive or negative\n");} |
thomasmorris | 57:aba1296e51b1 | 298 | else if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G'){pc.printf("Logging enables to user to get more information from the specific area which is logged\n");} |
thomasmorris | 57:aba1296e51b1 | 299 | else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E'){pc.printf("Allows the user to enter in a movement\n");} |
thomasmorris | 57:aba1296e51b1 | 300 | else if(input[0] == 'L' & input[1] == 'I' & input[2] == 'S' & input[3] == 'T'){pc.printf("Allows the user to to view / set a list of movements that can be performed\n");} |
thomasmorris | 57:aba1296e51b1 | 301 | else if(input[0] == 'C' & input[1] == 'O' & input[2] == 'L' & input[3] == 'O' & input[4] == 'U' & input[5] == 'R' & input[6] == 'S'){pc.printf("Allows the user to view and set the information upon the cubemap\n");} |
thomasmorris | 57:aba1296e51b1 | 302 | else{pc.printf("Enter the specific help area for more information\n");} |
thomasmorris | 52:99915f5240b2 | 303 | } |
thomasmorris | 52:99915f5240b2 | 304 | else |
thomasmorris | 52:99915f5240b2 | 305 | { |
thomasmorris | 52:99915f5240b2 | 306 | pc.printf("Please enter an acceptable command\n"); |
thomasmorris | 52:99915f5240b2 | 307 | } |
thomasmorris | 53:71f59e195f06 | 308 | } |