Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Thu May 24 13:31:20 2018 +0000
Revision:
55:e0e684531825
Parent:
53:71f59e195f06
Child:
56:bc5345bc6650
edge and corner colour list filling;

Who changed what in which revision?

UserRevisionLine numberNew 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 52:99915f5240b2 8 //Mutex Locks
thomasmorris 52:99915f5240b2 9
thomasmorris 52:99915f5240b2 10 void Serial_Commands_Output() //Used for getting input from the user to determine the opperations to perform
thomasmorris 47:6d128e500875 11 {
thomasmorris 52:99915f5240b2 12 if(Log_Value == 4){pc.printf("In Serial_Commands\n");} //If logging is enabled, print debug statement
thomasmorris 47:6d128e500875 13
thomasmorris 52:99915f5240b2 14 for (int x = 0; x < 100; x++){input[x] = ' ';}; //Fill input with spaces
thomasmorris 47:6d128e500875 15
thomasmorris 52:99915f5240b2 16 pc.printf("Please type in a command\n"); //Request command in the terminal
thomasmorris 52:99915f5240b2 17 cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character
thomasmorris 53:71f59e195f06 18 //cout << "Input is : " << input << endl;
thomasmorris 47:6d128e500875 19
thomasmorris 52:99915f5240b2 20 //READ ALL
thomasmorris 52:99915f5240b2 21 if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L')
thomasmorris 52:99915f5240b2 22 {
thomasmorris 52:99915f5240b2 23 if(Log_Value == 4){pc.printf("READ ALL Confirmed\n");} //If logging is enabled, print debug statement
thomasmorris 53:71f59e195f06 24
thomasmorris 52:99915f5240b2 25 }
thomasmorris 55:e0e684531825 26
thomasmorris 52:99915f5240b2 27 //LOGGING
thomasmorris 52:99915f5240b2 28 else 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 29 {
thomasmorris 52:99915f5240b2 30 int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; //Declare required variables
thomasmorris 52:99915f5240b2 31 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console
thomasmorris 52:99915f5240b2 32 for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} //Concatenate the characters between the space and the end
thomasmorris 52:99915f5240b2 33 stringstream Number(LoggingNumber); //Convert string to stringstream
thomasmorris 52:99915f5240b2 34 Number >> NumberToLogging; //Convert stringstream to integer
thomasmorris 52:99915f5240b2 35 if (NumberToLogging == 0){pc.printf("NOT LOGGING\n");} //Not Logging
thomasmorris 52:99915f5240b2 36 else if (NumberToLogging == 1){pc.printf("LOGGING LCD\n");} //Logging LCD
thomasmorris 52:99915f5240b2 37 else if (NumberToLogging == 2){pc.printf("LOGGING NETWORKING\n");} //Logging Networking
thomasmorris 52:99915f5240b2 38 else if (NumberToLogging == 3){pc.printf("LOGGING SAMPLING\n");} //Logging Sampling
thomasmorris 52:99915f5240b2 39 else if (NumberToLogging == 4){pc.printf("LOGGING SERIAL COMMANDS\n");} //Logging serial commands
thomasmorris 52:99915f5240b2 40 else if (NumberToLogging == 5){pc.printf("LOGGING SD CARD\n");} //Logging SD card
thomasmorris 52:99915f5240b2 41 else if (NumberToLogging >= 6){pc.printf("INVALID LOGGING COMMAND\n");} //Invalud Logging Command
thomasmorris 52:99915f5240b2 42
thomasmorris 52:99915f5240b2 43 if (NumberToLogging <= 5){Log_Value = NumberToLogging;} //If inputted value is within bounds equate it to the log state
thomasmorris 52:99915f5240b2 44 }
thomasmorris 55:e0e684531825 45
thomasmorris 53:71f59e195f06 46 //Motor Control
thomasmorris 53:71f59e195f06 47 else if(input[0] == 'M' & input[1] == 'o' & input[2] == 't' & input[3] == 'o' & input[4] == 'r' & input[5] == ' ')
thomasmorris 53:71f59e195f06 48 {
thomasmorris 53:71f59e195f06 49 int NumberOfChars = 0; int ArrayAddress = 0; string MotorNumber; int Motor_Number; //Declare required variables
thomasmorris 53:71f59e195f06 50 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console
thomasmorris 53:71f59e195f06 51 for(int x=6; x < NumberOfChars; x++){MotorNumber += input[x];} //Concatenate the characters between the space and the end
thomasmorris 53:71f59e195f06 52 stringstream Number(MotorNumber); //Convert string to stringstream
thomasmorris 53:71f59e195f06 53 Number >> Motor_Number; //Convert stringstream to integer
thomasmorris 53:71f59e195f06 54 if(Motor_Number < 1 || Motor_Number > 6)
thomasmorris 53:71f59e195f06 55 {
thomasmorris 53:71f59e195f06 56 Motor_Number =0;
thomasmorris 53:71f59e195f06 57 pc.printf("Please Select a motor from 1-6\n");
thomasmorris 53:71f59e195f06 58 }
thomasmorris 53:71f59e195f06 59 Motor_To_Select = Motor_Number;
thomasmorris 53:71f59e195f06 60 //Step Control
thomasmorris 53:71f59e195f06 61 pc.printf("Enter the angle to rotate\n"); //Request command in the terminal
thomasmorris 53:71f59e195f06 62 scanf("%f",&angle);
thomasmorris 53:71f59e195f06 63 //cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character
thomasmorris 53:71f59e195f06 64 //if(input[0] == 'S' & input[1] == 't' & input[2] == 'e' & input[3] == 'p' & input[4] == 's' & input[5] == ' ')
thomasmorris 53:71f59e195f06 65 {
thomasmorris 53:71f59e195f06 66 //angle = input;
thomasmorris 53:71f59e195f06 67 if(angle < 0)
thomasmorris 53:71f59e195f06 68 {
thomasmorris 55:e0e684531825 69 direction = 0;//Anti Clockwise
thomasmorris 53:71f59e195f06 70 }
thomasmorris 53:71f59e195f06 71 else
thomasmorris 53:71f59e195f06 72 {
thomasmorris 55:e0e684531825 73 direction = 1;//Clockwise
thomasmorris 53:71f59e195f06 74 }
thomasmorris 55:e0e684531825 75 float new_angle = abs(angle/1.8);//Converts input to steps
thomasmorris 53:71f59e195f06 76 steps = new_angle;
thomasmorris 53:71f59e195f06 77 pc.printf("The Motor is: %d\n The Number to step is: %d\n", Motor_Number, steps);
thomasmorris 53:71f59e195f06 78 }
thomasmorris 53:71f59e195f06 79
thomasmorris 53:71f59e195f06 80 }
thomasmorris 52:99915f5240b2 81 //HELP
thomasmorris 52:99915f5240b2 82 else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P')
thomasmorris 52:99915f5240b2 83 {
thomasmorris 52:99915f5240b2 84 pc.printf("Avalible Commands are: \n"); //Print introduction line
thomasmorris 55:e0e684531825 85 pc.printf("Motor x selects a motor in the range of 1-6\n"); //Print list of commands
thomasmorris 52:99915f5240b2 86 }
thomasmorris 52:99915f5240b2 87 else
thomasmorris 52:99915f5240b2 88 {
thomasmorris 52:99915f5240b2 89 pc.printf("Please enter an acceptable command\n");
thomasmorris 52:99915f5240b2 90 }
thomasmorris 53:71f59e195f06 91 }