Part 1 + 3
Dependencies: Joystick_skeleton_Pengineers mbed
Fork of ESE519_Lab6_part1_skeleton by
Diff: main.cpp
- Revision:
- 6:4a70f13c0bca
- Parent:
- 4:3044edf0cc5d
--- a/main.cpp Tue Oct 25 15:11:18 2016 +0000 +++ b/main.cpp Sun Nov 13 20:40:15 2016 +0000 @@ -10,7 +10,7 @@ #include <string> #include "Joystick.h" -#define SEND //Uncomment if you want to transmit data +//#define SEND //Uncomment if you want to transmit data #define RECEIVE //Uncomment if you want to receive data #define NONE 250 @@ -84,6 +84,10 @@ char rxBuffer[128]; int rxLen; + +// Lab 6 +int txCounter = 0; +int rxCounter = 0; //***************** Do not change these methods (please) *****************// /** * Receive data from the MRF24J40. @@ -146,7 +150,7 @@ * */ - return false; + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); } //Returns true if c is a number character (0-9), false otherwise @@ -159,7 +163,7 @@ * */ - return false; + return (c >= '0' && c <= '9'); } //Pulls data out of rxBuffer and updates global variables accordingly @@ -247,7 +251,28 @@ * */ + //pc.printf("Name: %s, num: %s\n", *name, *num); + if (strcmp("Knob1", *name) == 0) { + knob1 = atof(*num); + } else if (strcmp("Knob2", *name) == 0) { + knob2 = atof(*num); + } else if(strcmp("Knob3", *name) == 0) { + knob3 = atof(*num); + } else if (strcmp("Knob4", *name) == 0) { + knob4 = atof(*num); + } else if (strcmp("Jstick_h", *name) == 0) { + jstick_h = atof(*num); + } else if (strcmp("Jstick_v", *name) == 0) { + jstick_v = atof(*num); + } else if (strcmp("Button", *name) == 0) { + int decoded = atoi(*num); + if(decoded > 0) { + button = true; + } else { + button = false; + } + } //Reset flags name_start = NONE; name_end = NONE; @@ -260,7 +285,7 @@ int main (void) { //Set the Channel. 0 is default, 15 is max - uint8_t channel = 2; //channel = (Group# - 1) + uint8_t channel = 15; //channel = (Group# - 1) mrf.SetChannel(channel); //Set Baud rate (9600-115200 is ideal) @@ -287,7 +312,9 @@ //(3)Read Button Val, Add to buffer button = !Button.read(); //button is active low - + + //printf("jstick_h: %d, jstick_v: %d, knob1: %f, knob2: %f, knob3: %f, knob4: %f\n", (int)jstick_h, (int)jstick_v, knob1, knob2, knob3, knob4); + #ifdef RECEIVE //RECEIVE DATA: Try to receive some data rxLen = rf_receive(rxBuffer, 128); @@ -299,6 +326,8 @@ communication_protocal(rxLen); //Print values once we recieve and process data + rxCounter++; + printf("Receive: %d\n", rxCounter); pc.printf("Received| "); pc.printf(COMMUNICATION_FORMAT, jstick_h, jstick_v, knob1, knob2, knob3, knob4, button); pc.printf("\r\n"); @@ -307,7 +336,7 @@ #ifdef SEND //SEND DATA: Send some data every 1/2 second - if(timer.read_ms() >= 500) { + if(timer.read_ms() >= 50) { //Reset the timer to 0 timer.reset(); // Toggle LED 2. @@ -319,6 +348,8 @@ //(6) Send the buffer rf_send(txBuffer, strlen(txBuffer) + 1); pc.printf("Sent| %s\r\n", txBuffer); + txCounter++; + printf("Sent: %d\n", txCounter); } #endif