a

Fork of ESE519_Lab6_part1_skeleton by Carter Sharer

Revision:
1:98c414bbfe8a
Parent:
0:0ebe6f55caee
Child:
3:1d10014a4646
--- a/main.cpp	Thu Oct 20 22:16:49 2016 +0000
+++ b/main.cpp	Thu Oct 20 23:44:40 2016 +0000
@@ -11,7 +11,7 @@
 #include "Joystick.h"
 
 #define SEND        //Uncomment if you want to transmit data
-//#define RECEIVE     //Uncomment if you want to receive data
+#define RECEIVE     //Uncomment if you want to receive data
 
 #define NONE 250
 
@@ -138,21 +138,34 @@
 }
 //***************** You can start coding here *****************//
 
-//Returns true if c is a letter, false otherwise
+//Returns true if c is a letter (upper or lower case), false otherwise
 bool isLetter(char c) {
-    if(('a'<=c & c<='z') | ('A'<=c & c<='Z'))
-        return true;
+    
+    /*
+    * YOUR IMPLIMENTATION HERE
+    *
+    *
+    *
+    */
+    
     return false;
 }
 
-//Returns true if c is a number, false otherwise
+//Returns true if c is a number character (0-9), false otherwise
 bool isNumber(char c) {
-    if('0'<=c & c<='9')
-        return true;
+    
+    /*
+    * YOUR IMPLIMENTATION HERE
+    *
+    *
+    *
+    */
+    
     return false;
 }
 
 //Pulls data out of rxBuffer and updates global variables accordingly 
+//Len is the length of the rxBuffer we are going to scan 
 void communication_protocal(int len)
 {
     bool found_name = false;
@@ -167,7 +180,7 @@
         char c = rxBuffer[i];
         //pc.printf("Indexed char '%c'\r\n", c);
 
-        //Is is the start of a name? (Check if its a letter)
+        //Is it the start of a name? (Check if its a letter)
         if(isLetter(c) & name_start==NONE) { //if a num
             //If We havent found a name yet, this is start of a name
             if(found_name == false) {
@@ -223,21 +236,19 @@
             *num = &rxBuffer[num_start];
             rxBuffer[num_end] = '\0';
             
-            //Set variables
-            if(strcmp(*name, "Jstick_h\0")==0)
-                jstick_h = atof(*num);
-            else if(strcmp(*name, "Jstick_v\0")==0) 
-                jstick_v = atof(*num);
-            else if(strcmp(*name, "Knob1\0")==0) 
-                knob1 = atof(*num);
-            else if(strcmp(*name, "Knob2\0")==0) 
-                knob2 = atof(*num);
-            else if(strcmp(*name, "Knob3\0")==0)
-                knob3 = atof(*num);
-            else if(strcmp(*name, "Knob4\0")==0) 
-                knob4 = atof(*num);
-            else if(strcmp(*name, "Button\0")==0) 
-                button = atof(*num);
+            //Now that we have isolated a name and its number value
+            //we want to set the corresponding value to this number.
+            //Ex: if name is 'Knob4' and num is '0.34', we want to the the 
+            // variable name knob4 to the value 0.34.  
+            //Do this for all variable names in COMMUNICATION_FORMAT
+            //HINT: look up strcmp, and atof
+            /*
+            * YOUR IMPLIMENTATION HERE
+            *
+            *
+            *
+            */
+            
             
             //Reset flags
             name_start = NONE;
@@ -261,14 +272,14 @@
     //Start Timer
     timer.start();
 
-    //Scale Joystick Values
-    jstick.setScale(-50, 25);
+    //Scale Joystick Values, range[-100, 100]
+    jstick.setScale(-100, 100);
 
     while(1) {
         //(1) Read Joystick Values, round to int8_t presision
         jstick_h = (int8_t)jstick.horizontal();
         jstick_v = (int8_t)jstick.vertical();
-        //pc.printf("H: %d V:%d \r\n", jstick_h, jstick_v);
+        //pc.printf("H: %0.2f V:%0.2f \r\n", jstick.horizontal(), jstick.vertical());
 
         //(2) Read Pot Values, Scale, and round to precision
         knob1 = (uint8_t)(pot1.read() * 100); //rounded to uint8_t
@@ -290,6 +301,7 @@
             communication_protocal(rxLen);
             
             //Print values once we recieve and process data
+            pc.printf("Received| ");
             pc.printf(COMMUNICATION_FORMAT, jstick_h, jstick_v, knob1, knob2, knob3, knob4, button);
             pc.printf("\r\n");
         }//main if
@@ -308,7 +320,7 @@
     
             //(6) Send the buffer
             rf_send(txBuffer, strlen(txBuffer) + 1);
-            pc.printf("%s\r\n", txBuffer);
+            pc.printf("Sent| %s\r\n", txBuffer);
         }   
 #endif