a

Fork of ESE519_Lab6_part1_skeleton by Carter Sharer

Committer:
hydroguy45
Date:
Fri Nov 01 18:48:35 2019 +0000
Revision:
11:46c532b752d5
Parent:
10:dafae6093487
Child:
12:ea030e3181d3
Removed parsing commands only used when the remote needed to receive data

Who changed what in which revision?

UserRevisionLine numberNew contents of line
csharer 3:1d10014a4646 1 //ESE519 Lab6 Controller Part 1 (INCOMPLETE IMPLIMENTATION)
csharer 0:0ebe6f55caee 2 //Author: Carter Sharer
csharer 0:0ebe6f55caee 3 //Date: 10/18/2016
csharer 0:0ebe6f55caee 4 //Sources: ESE350 Whack-A-Mole: https://developer.mbed.org/users/mlab4/code/ESE350-Whack-a-Mole/
csharer 0:0ebe6f55caee 5 //This is a simple working templete for sending and receving between two MRF24J40 Modules
csharer 0:0ebe6f55caee 6 //Contains a communication protocol for sending a receiving
csharer 0:0ebe6f55caee 7
csharer 0:0ebe6f55caee 8 #include "mbed.h"
csharer 0:0ebe6f55caee 9 #include <string>
csharer 0:0ebe6f55caee 10 #include "Joystick.h"
hydroguy45 7:ca226305d28b 11 #include "wifiGETWrapper.h"
hydroguy45 9:b8801ba7d7c2 12 #define SEND //Uncomment if you want to transmit data
csharer 0:0ebe6f55caee 13 #define NONE 250
csharer 0:0ebe6f55caee 14
csharer 0:0ebe6f55caee 15 //============================
csharer 0:0ebe6f55caee 16 //== Pin Assignments ==
csharer 0:0ebe6f55caee 17 //============================
csharer 0:0ebe6f55caee 18 //Knobs
csharer 0:0ebe6f55caee 19 #define POT1 p17 //Knob1
csharer 0:0ebe6f55caee 20 #define POT2 p18 //Knob2
csharer 0:0ebe6f55caee 21 #define POT3 p16 //Knob3
csharer 0:0ebe6f55caee 22 #define POT4 p15 //Knob4
csharer 0:0ebe6f55caee 23 //JoyStick
csharer 0:0ebe6f55caee 24 #define POTV p19 //Vertial
csharer 0:0ebe6f55caee 25 #define POTH p20 //Horizontal
csharer 0:0ebe6f55caee 26 //Button
csharer 0:0ebe6f55caee 27 #define BUTTON1 p21
hydroguy45 10:dafae6093487 28 #define COMMUNICATION_FORMAT "Jstickh:|%0.0f|Jstickv:|%0.0f|Knob1|%0.2f|Knob2|%0.2f|Knob3|%0.2f|Knob4|%0.2f|Button:|%d"
csharer 0:0ebe6f55caee 29
csharer 0:0ebe6f55caee 30 //============================
csharer 0:0ebe6f55caee 31 //== Objects ==
csharer 0:0ebe6f55caee 32 //============================
csharer 0:0ebe6f55caee 33 //Knobs
csharer 0:0ebe6f55caee 34 AnalogIn pot1(POT1);
csharer 0:0ebe6f55caee 35 AnalogIn pot2(POT2);
csharer 0:0ebe6f55caee 36 AnalogIn pot3(POT3);
csharer 0:0ebe6f55caee 37 AnalogIn pot4(POT4);
csharer 0:0ebe6f55caee 38 float knob1, knob2, knob3, knob4;
csharer 0:0ebe6f55caee 39
csharer 0:0ebe6f55caee 40 //Joystick
csharer 0:0ebe6f55caee 41 Joystick jstick(POTV, POTH);
csharer 0:0ebe6f55caee 42 float jstick_h, jstick_v;
csharer 0:0ebe6f55caee 43
csharer 0:0ebe6f55caee 44 //Button
csharer 0:0ebe6f55caee 45 DigitalIn Button(BUTTON1);
csharer 0:0ebe6f55caee 46 bool button;
csharer 0:0ebe6f55caee 47
csharer 0:0ebe6f55caee 48 // LEDs
csharer 0:0ebe6f55caee 49 DigitalOut led1(LED1);
csharer 0:0ebe6f55caee 50 DigitalOut led2(LED2);
csharer 0:0ebe6f55caee 51 DigitalOut led3(LED3);
csharer 0:0ebe6f55caee 52 DigitalOut led4(LED4);
csharer 0:0ebe6f55caee 53
csharer 0:0ebe6f55caee 54 // Timer
csharer 0:0ebe6f55caee 55 Timer timer;
csharer 0:0ebe6f55caee 56
csharer 0:0ebe6f55caee 57 // Serial port for showing RX data.
csharer 0:0ebe6f55caee 58 Serial pc(USBTX, USBRX);
csharer 0:0ebe6f55caee 59
csharer 0:0ebe6f55caee 60 char txBuffer[128];
csharer 0:0ebe6f55caee 61 char rxBuffer[128];
csharer 0:0ebe6f55caee 62 int rxLen;
csharer 0:0ebe6f55caee 63
csharer 0:0ebe6f55caee 64 int main (void)
csharer 0:0ebe6f55caee 65 {
hydroguy45 7:ca226305d28b 66
csharer 0:0ebe6f55caee 67 //Set Baud rate (9600-115200 is ideal)
csharer 0:0ebe6f55caee 68 pc.baud(115200);
csharer 0:0ebe6f55caee 69 pc.printf("\r\n Start! \r\n");
hydroguy45 11:46c532b752d5 70
hydroguy45 9:b8801ba7d7c2 71 //This is an example wifi connection! Please fill this in with the SSID of your BBBL and the password too.
hydroguy45 11:46c532b752d5 72 const char * SSID = "BeagleBone-365E";//TODO: CHANGE THIS LINE
hydroguy45 11:46c532b752d5 73 const char * password = "BeagleBone";//TODO: CHANGE THIS LINE
hydroguy45 11:46c532b752d5 74
hydroguy45 9:b8801ba7d7c2 75 initConnection(SSID,password);
hydroguy45 11:46c532b752d5 76
csharer 0:0ebe6f55caee 77 //Start Timer
csharer 0:0ebe6f55caee 78 timer.start();
csharer 0:0ebe6f55caee 79
csharer 1:98c414bbfe8a 80 //Scale Joystick Values, range[-100, 100]
csharer 1:98c414bbfe8a 81 jstick.setScale(-100, 100);
hydroguy45 6:e0c358a351aa 82 int counter = 0;
csharer 0:0ebe6f55caee 83 while(1) {
csharer 0:0ebe6f55caee 84 //(1) Read Joystick Values, round to int8_t presision
csharer 0:0ebe6f55caee 85 jstick_h = (int8_t)jstick.horizontal();
csharer 0:0ebe6f55caee 86 jstick_v = (int8_t)jstick.vertical();
hydroguy45 9:b8801ba7d7c2 87 pc.printf("H: %0.2f V:%0.2f \r\n", jstick_h, jstick_v);
csharer 0:0ebe6f55caee 88
csharer 0:0ebe6f55caee 89 //(2) Read Pot Values, Scale, and round to precision
csharer 0:0ebe6f55caee 90 knob1 = (uint8_t)(pot1.read() * 100); //rounded to uint8_t
csharer 0:0ebe6f55caee 91 knob2 = (pot2.read() * 100);
csharer 0:0ebe6f55caee 92 knob3 = (pot3.read());
csharer 0:0ebe6f55caee 93 knob4 = (int)(pot4.read() * 100); //rounded to float
csharer 0:0ebe6f55caee 94
csharer 0:0ebe6f55caee 95 //(3)Read Button Val, Add to buffer
csharer 0:0ebe6f55caee 96 button = !Button.read(); //button is active low
csharer 0:0ebe6f55caee 97
csharer 0:0ebe6f55caee 98 #ifdef SEND
csharer 0:0ebe6f55caee 99 //SEND DATA: Send some data every 1/2 second
csharer 0:0ebe6f55caee 100 if(timer.read_ms() >= 500) {
csharer 0:0ebe6f55caee 101 //Reset the timer to 0
csharer 0:0ebe6f55caee 102 timer.reset();
csharer 0:0ebe6f55caee 103 // Toggle LED 2.
csharer 0:0ebe6f55caee 104 led2 = led2^1;
csharer 0:0ebe6f55caee 105
csharer 0:0ebe6f55caee 106 //(5) Add all values to buffer to be sent
csharer 0:0ebe6f55caee 107 sprintf(txBuffer, COMMUNICATION_FORMAT, jstick_h, jstick_v, knob1, knob2, knob3, knob4, button);
csharer 0:0ebe6f55caee 108
csharer 0:0ebe6f55caee 109 //(6) Send the buffer
hydroguy45 7:ca226305d28b 110 sendGET(txBuffer);
csharer 1:98c414bbfe8a 111 pc.printf("Sent| %s\r\n", txBuffer);
csharer 0:0ebe6f55caee 112 }
csharer 0:0ebe6f55caee 113 #endif
csharer 0:0ebe6f55caee 114
csharer 0:0ebe6f55caee 115 } //end loop
csharer 0:0ebe6f55caee 116 }//end main