LP Long Distance IR Vision Robot

Dependencies:   max77650_charger_sample BufferedSerial SX1276GenericLib Adafruit-MotorShield NEO-6m-GPS MAX17055_EZconfig Adafruit_GFX USBDeviceHT Adafruit-PWM-Servo-Driver

Committer:
dev_alexander
Date:
Tue Jul 31 23:21:01 2018 +0000
Revision:
37:f0fcc0341654
Parent:
36:09e8b51fc91d
Child:
38:c10d2a04a0c2
Really cleaned up the main.cpp. This revision demonstrates more clearly what is going on at compile time and how the program is compiled differently for the master and slave(robot) device

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:c43b6919ae15 1 /*
Helmut64 17:98f2528e8399 2 * Copyright (c) 2018 HELIOS Software GmbH
Helmut64 0:c43b6919ae15 3 * 30826 Garbsen (Hannover) Germany
Helmut64 0:c43b6919ae15 4 * Licensed under the Apache License, Version 2.0);
Helmut64 0:c43b6919ae15 5 */
dev_alexander 21:1b92cabe8a3b 6
dev_alexander 21:1b92cabe8a3b 7 /*
dev_alexander 21:1b92cabe8a3b 8 * For Wiring Instructions, please visit the link below:
dev_alexander 21:1b92cabe8a3b 9 * https://www.hackster.io/DevinAlex64/getting-started-with-the-max32620fthr-and-lora-f9d8dd\
dev_alexander 21:1b92cabe8a3b 10 */
dev_alexander 37:f0fcc0341654 11
dev_alexander 37:f0fcc0341654 12 /***************************************************************************
dev_alexander 37:f0fcc0341654 13 * Misc Instantiation
dev_alexander 37:f0fcc0341654 14 **************************************************************************/
dev_alexander 30:66f9750cc44c 15 #include "main.h"
dev_alexander 30:66f9750cc44c 16 #include "global_buffers.h"
dev_alexander 35:bae9b236070b 17 //#define DEBUG_GRID_EYE
dev_alexander 32:b108ed6096b0 18 #define RASPBERRY_PI
dev_alexander 37:f0fcc0341654 19 DigitalOut myled(LED);
dev_alexander 37:f0fcc0341654 20 Serial pc(USBTX, USBRX);
dev_alexander 32:b108ed6096b0 21
dev_alexander 23:f74a50977593 22
dev_alexander 37:f0fcc0341654 23 /***************************************************************************
dev_alexander 37:f0fcc0341654 24 * MAX32630FTHR Instantiation
dev_alexander 37:f0fcc0341654 25 **************************************************************************/
dev_alexander 37:f0fcc0341654 26 #if defined(TARGET_MAX32630FTHR)
dev_alexander 37:f0fcc0341654 27 /* If the board that is compiled is the master device (BLE enabled MAX32630FTHR),
dev_alexander 37:f0fcc0341654 28 * then it needs this library and needs to be configed in order for the device to
dev_alexander 37:f0fcc0341654 29 * work with a 3.3volt output instead of a 1.8 volt output.
dev_alexander 37:f0fcc0341654 30 *
dev_alexander 37:f0fcc0341654 31 * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this
dev_alexander 37:f0fcc0341654 32 * additional setup in the main program.
dev_alexander 37:f0fcc0341654 33 */
dev_alexander 37:f0fcc0341654 34 #include "max32630fthr.h"
dev_alexander 37:f0fcc0341654 35 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
dev_alexander 37:f0fcc0341654 36 #endif
dev_alexander 37:f0fcc0341654 37
dev_alexander 37:f0fcc0341654 38 /***************************************************************************
dev_alexander 37:f0fcc0341654 39 * MAX32620FTHR Instantiation
dev_alexander 37:f0fcc0341654 40 **************************************************************************/
dev_alexander 31:f15747cffb20 41 #if defined(TARGET_MAX32620FTHR)
dev_alexander 32:b108ed6096b0 42 // Definitions for running board off of battery
dev_alexander 32:b108ed6096b0 43 #define POWER_HOLD_ON 1
dev_alexander 32:b108ed6096b0 44 #define POWER_HOLD_OFF 0
dev_alexander 32:b108ed6096b0 45
dev_alexander 37:f0fcc0341654 46 // MAX77650
dev_alexander 32:b108ed6096b0 47 DigitalOut pw_Hold(P2_2, POWER_HOLD_ON);
dev_alexander 32:b108ed6096b0 48 #endif
dev_alexander 32:b108ed6096b0 49
dev_alexander 32:b108ed6096b0 50
dev_alexander 37:f0fcc0341654 51 /***************************************************************************
dev_alexander 37:f0fcc0341654 52 * Grid Eye Sensor Instantiation
dev_alexander 37:f0fcc0341654 53 **************************************************************************/
dev_alexander 37:f0fcc0341654 54 #include "GridEye.h"
Helmut64 0:c43b6919ae15 55
dev_alexander 23:f74a50977593 56 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 23:f74a50977593 57 /* No grid eye object needed. The function the master uses to convert the raw
dev_alexander 23:f74a50977593 58 * data that is sent over from the slave deevice that contains the data from the
dev_alexander 23:f74a50977593 59 * actual grid eye sensor is actually a function that is not part of the grid eye
dev_alexander 23:f74a50977593 60 * class. this is due to the fact that the grid eye class requires n i2c bus to
dev_alexander 23:f74a50977593 61 * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye
dev_alexander 32:b108ed6096b0 62 * sensor has a support function that is used to convert data that is aquired from
dev_alexander 23:f74a50977593 63 * the grid eye sensor. So it is not supposed to be a class specific function.
dev_alexander 37:f0fcc0341654 64 */
dev_alexander 32:b108ed6096b0 65 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 66 // I2C i2cGridEye(SDA,SCL);
dev_alexander 32:b108ed6096b0 67 //I2C i2cGridEye(P3_4,P3_5);
dev_alexander 32:b108ed6096b0 68 I2C i2cGridEye(P1_6,P1_7);
dev_alexander 23:f74a50977593 69 GridEye gridEye(i2cGridEye);
dev_alexander 23:f74a50977593 70 #endif
dev_alexander 19:9f035b9e65ec 71
dev_alexander 37:f0fcc0341654 72 /***************************************************************************
dev_alexander 37:f0fcc0341654 73 * GPS Instantiation
dev_alexander 37:f0fcc0341654 74 **************************************************************************/
dev_alexander 37:f0fcc0341654 75 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 37:f0fcc0341654 76 // No GPS module on the master device
dev_alexander 37:f0fcc0341654 77 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 37:f0fcc0341654 78 #include "GPS.h"
dev_alexander 37:f0fcc0341654 79 GPS gps(P0_1, P0_0, 115200); // (Tx, Rx, Baud rate)
dev_alexander 37:f0fcc0341654 80 #endif
dev_alexander 37:f0fcc0341654 81
dev_alexander 37:f0fcc0341654 82 /***************************************************************************
dev_alexander 37:f0fcc0341654 83 * MAX77650 Instatiation
dev_alexander 37:f0fcc0341654 84 **************************************************************************/
dev_alexander 37:f0fcc0341654 85
dev_alexander 37:f0fcc0341654 86 /***************************************************************************
dev_alexander 37:f0fcc0341654 87 * MAX17055 Instatiation
dev_alexander 37:f0fcc0341654 88 **************************************************************************/
dev_alexander 37:f0fcc0341654 89
dev_alexander 37:f0fcc0341654 90 /***************************************************************************
dev_alexander 37:f0fcc0341654 91 * OLED Instatiation
dev_alexander 37:f0fcc0341654 92 **************************************************************************/
dev_alexander 37:f0fcc0341654 93
dev_alexander 37:f0fcc0341654 94 /***************************************************************************
dev_alexander 37:f0fcc0341654 95 * BLE Instatiation and Related Functions
dev_alexander 37:f0fcc0341654 96 **************************************************************************/
dev_alexander 37:f0fcc0341654 97 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 37:f0fcc0341654 98 #include "ble/BLE.h"
dev_alexander 37:f0fcc0341654 99 //#include "ble/Gap.h"
dev_alexander 37:f0fcc0341654 100 #include "UARTService_custom.h"
dev_alexander 37:f0fcc0341654 101 #include <events/mbed_events.h>
dev_alexander 37:f0fcc0341654 102
dev_alexander 37:f0fcc0341654 103 DigitalOut led2(LED2);
dev_alexander 37:f0fcc0341654 104 UARTService *uart;
dev_alexander 37:f0fcc0341654 105
dev_alexander 37:f0fcc0341654 106 #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
dev_alexander 37:f0fcc0341654 107 * it will have an impact on code-size and power consumption. */
dev_alexander 37:f0fcc0341654 108
dev_alexander 37:f0fcc0341654 109 #if NEED_CONSOLE_OUTPUT
dev_alexander 37:f0fcc0341654 110 #define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); }
dev_alexander 37:f0fcc0341654 111 #define READ(STR) { if (uart) uart->read(STR, strlen(STR)); }
dev_alexander 37:f0fcc0341654 112
dev_alexander 37:f0fcc0341654 113 #else
dev_alexander 37:f0fcc0341654 114 #define DEBUG(...) /* nothing */
dev_alexander 37:f0fcc0341654 115 #endif /* #if NEED_CONSOLE_OUTPUT */
dev_alexander 37:f0fcc0341654 116
dev_alexander 37:f0fcc0341654 117 //Triggered when the robot is disconnected from the mobile app.
dev_alexander 37:f0fcc0341654 118 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
dev_alexander 37:f0fcc0341654 119 {
dev_alexander 37:f0fcc0341654 120 BLE &ble = BLE::Instance();
dev_alexander 37:f0fcc0341654 121 DEBUG("Disconnected!\n\r");
dev_alexander 37:f0fcc0341654 122 DEBUG("Restarting the advertising process\n\r");
dev_alexander 37:f0fcc0341654 123 ble.gap().startAdvertising();
dev_alexander 37:f0fcc0341654 124 }
dev_alexander 37:f0fcc0341654 125
dev_alexander 37:f0fcc0341654 126 /* This pointer is needed to reference data in the main program when filling
dev_alexander 37:f0fcc0341654 127 * with data from the BLE
dev_alexander 37:f0fcc0341654 128 */
dev_alexander 37:f0fcc0341654 129 uint8_t * onDataWritten_curr_ble_to_slave;
dev_alexander 37:f0fcc0341654 130
dev_alexander 37:f0fcc0341654 131 // Triggered when there is data written
dev_alexander 37:f0fcc0341654 132 void onDataWritten(const GattWriteCallbackParams *params)
dev_alexander 37:f0fcc0341654 133 {
dev_alexander 37:f0fcc0341654 134 //LED1 will be off when button is pressed, and on when button is released.
dev_alexander 37:f0fcc0341654 135 led2 = !led2;
dev_alexander 37:f0fcc0341654 136 uint8_t button_state;
dev_alexander 37:f0fcc0341654 137 uint8_t direction;
dev_alexander 37:f0fcc0341654 138
dev_alexander 37:f0fcc0341654 139 /* If there is a valid data sent by the mobile app */
dev_alexander 37:f0fcc0341654 140 if ((uart != NULL) && (params->handle == uart ->getTXCharacteristicHandle())) {
dev_alexander 37:f0fcc0341654 141 const uint8_t *packet = params->data;
dev_alexander 37:f0fcc0341654 142 button_state = packet[3];
dev_alexander 37:f0fcc0341654 143 direction = packet[2];
dev_alexander 37:f0fcc0341654 144
dev_alexander 37:f0fcc0341654 145 // make parameter to send over Lora
dev_alexander 37:f0fcc0341654 146 onDataWritten_curr_ble_to_slave[0] = direction;
dev_alexander 37:f0fcc0341654 147 onDataWritten_curr_ble_to_slave[1] = button_state;
dev_alexander 37:f0fcc0341654 148
dev_alexander 37:f0fcc0341654 149 //dprintf("direction: %d\n", direction);
dev_alexander 37:f0fcc0341654 150 //dprintf("button_state: %d\n", button_state);
dev_alexander 37:f0fcc0341654 151 }
dev_alexander 37:f0fcc0341654 152 }
dev_alexander 37:f0fcc0341654 153 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 37:f0fcc0341654 154 // No BLE chip on the MAX32620FTHR so this is not needed
dev_alexander 37:f0fcc0341654 155 #endif
dev_alexander 37:f0fcc0341654 156
dev_alexander 37:f0fcc0341654 157 /***************************************************************************
dev_alexander 37:f0fcc0341654 158 * Motor Controller Instatiation and Related Functions
dev_alexander 37:f0fcc0341654 159 **************************************************************************/
dev_alexander 37:f0fcc0341654 160 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 37:f0fcc0341654 161 // There is no motor on this device.
dev_alexander 37:f0fcc0341654 162 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 37:f0fcc0341654 163 /* This is a port of a library that was developed by Adafruit for the Arduino.
dev_alexander 37:f0fcc0341654 164 * This port was done by mbed user syundo0730. */
dev_alexander 37:f0fcc0341654 165 #include "Adafruit_MotorShield.h"
dev_alexander 37:f0fcc0341654 166 #include "Adafruit_PWMServoDriver.h"
dev_alexander 37:f0fcc0341654 167
dev_alexander 37:f0fcc0341654 168 // These are the defined speeds that are selected out of the number range (0, 255).
dev_alexander 37:f0fcc0341654 169 #define MOTOR_OFF 0
dev_alexander 37:f0fcc0341654 170 #define MOTOR_FORWARD 150
dev_alexander 37:f0fcc0341654 171 #define MOTOR_BACKWARD 150
dev_alexander 37:f0fcc0341654 172 #define MOTOR_TURN 100
dev_alexander 37:f0fcc0341654 173
dev_alexander 37:f0fcc0341654 174 // Create the motor shield object with the default I2C address
dev_alexander 37:f0fcc0341654 175 Adafruit_MotorShield AFMS = Adafruit_MotorShield(P3_4, P3_5, 0x60 << 1); // You have to shift it over by one due to how mbed does its I2C Addressing.
dev_alexander 37:f0fcc0341654 176 // Or, create it with a different I2C address (say for stacking)
dev_alexander 37:f0fcc0341654 177 // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
dev_alexander 37:f0fcc0341654 178 // Select which 'port' M1, M2, M3 or M4. In this case, M1
dev_alexander 37:f0fcc0341654 179 Adafruit_DCMotor *rightMotor = AFMS.getMotor(1);
dev_alexander 37:f0fcc0341654 180 // You can also make another motor on port M4
dev_alexander 37:f0fcc0341654 181 Adafruit_DCMotor *leftMotor = AFMS.getMotor(4);
dev_alexander 37:f0fcc0341654 182
dev_alexander 37:f0fcc0341654 183
dev_alexander 37:f0fcc0341654 184 void MotorController(uint8_t (BLE_data_server)[2])
dev_alexander 37:f0fcc0341654 185 {
dev_alexander 37:f0fcc0341654 186 uint8_t button_state;
dev_alexander 37:f0fcc0341654 187 uint8_t direction;
dev_alexander 37:f0fcc0341654 188 /*Set up constants for direction of motion */
dev_alexander 37:f0fcc0341654 189 const char FRONT = '5';
dev_alexander 37:f0fcc0341654 190 const char BACK = '6';
dev_alexander 37:f0fcc0341654 191 const char LEFT = '7';
dev_alexander 37:f0fcc0341654 192 const char RIGHT = '8';
dev_alexander 37:f0fcc0341654 193
dev_alexander 37:f0fcc0341654 194 /*Set up constants for button state */
dev_alexander 37:f0fcc0341654 195 const char PRESSED = '1';
dev_alexander 37:f0fcc0341654 196 const char RELEASED = '0';
dev_alexander 37:f0fcc0341654 197
dev_alexander 37:f0fcc0341654 198
dev_alexander 37:f0fcc0341654 199 button_state = BLE_data_server[1];
dev_alexander 37:f0fcc0341654 200 direction = BLE_data_server[0];
dev_alexander 37:f0fcc0341654 201
dev_alexander 37:f0fcc0341654 202 switch (button_state)
dev_alexander 37:f0fcc0341654 203 {
dev_alexander 37:f0fcc0341654 204 case PRESSED:
dev_alexander 37:f0fcc0341654 205 switch (direction)
dev_alexander 37:f0fcc0341654 206 {
dev_alexander 37:f0fcc0341654 207 case FRONT:
dev_alexander 37:f0fcc0341654 208 rightMotor->run(FORWARD);
dev_alexander 37:f0fcc0341654 209 leftMotor->run(FORWARD);
dev_alexander 37:f0fcc0341654 210 rightMotor->setSpeed(MOTOR_FORWARD);
dev_alexander 37:f0fcc0341654 211 leftMotor->setSpeed(MOTOR_FORWARD);
dev_alexander 37:f0fcc0341654 212 break;
dev_alexander 37:f0fcc0341654 213 case BACK:
dev_alexander 37:f0fcc0341654 214 rightMotor->run(BACKWARD);
dev_alexander 37:f0fcc0341654 215 leftMotor->run(BACKWARD);
dev_alexander 37:f0fcc0341654 216 rightMotor->setSpeed(MOTOR_BACKWARD);
dev_alexander 37:f0fcc0341654 217 leftMotor->setSpeed(MOTOR_BACKWARD);
dev_alexander 37:f0fcc0341654 218 break;
dev_alexander 37:f0fcc0341654 219 case LEFT:
dev_alexander 37:f0fcc0341654 220 rightMotor->run(FORWARD);
dev_alexander 37:f0fcc0341654 221 leftMotor->run(BACKWARD);
dev_alexander 37:f0fcc0341654 222 rightMotor->setSpeed(MOTOR_TURN);
dev_alexander 37:f0fcc0341654 223 leftMotor->setSpeed(MOTOR_TURN);
dev_alexander 37:f0fcc0341654 224 break;
dev_alexander 37:f0fcc0341654 225 case RIGHT:
dev_alexander 37:f0fcc0341654 226 rightMotor->run(BACKWARD);
dev_alexander 37:f0fcc0341654 227 leftMotor->run(FORWARD);
dev_alexander 37:f0fcc0341654 228 rightMotor->setSpeed(MOTOR_TURN);
dev_alexander 37:f0fcc0341654 229 leftMotor->setSpeed(MOTOR_TURN);
dev_alexander 37:f0fcc0341654 230 break;
dev_alexander 37:f0fcc0341654 231 }
dev_alexander 37:f0fcc0341654 232 break;
dev_alexander 37:f0fcc0341654 233 case RELEASED:
dev_alexander 37:f0fcc0341654 234 rightMotor->setSpeed(MOTOR_OFF);
dev_alexander 37:f0fcc0341654 235 leftMotor->setSpeed(MOTOR_OFF);
dev_alexander 37:f0fcc0341654 236 break;
dev_alexander 37:f0fcc0341654 237 }
dev_alexander 37:f0fcc0341654 238 }
dev_alexander 37:f0fcc0341654 239 #endif
dev_alexander 37:f0fcc0341654 240
dev_alexander 37:f0fcc0341654 241
dev_alexander 37:f0fcc0341654 242
dev_alexander 37:f0fcc0341654 243
dev_alexander 37:f0fcc0341654 244
dev_alexander 37:f0fcc0341654 245
dev_alexander 23:f74a50977593 246 int main()
dev_alexander 23:f74a50977593 247 {
dev_alexander 32:b108ed6096b0 248 /* Setup begins here: */
dev_alexander 32:b108ed6096b0 249 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 250 dprintf("MAX32630FTHR: Master");
dev_alexander 32:b108ed6096b0 251 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 252 dprintf("MAX32620FTHR: Slave");
dev_alexander 32:b108ed6096b0 253 #endif
dev_alexander 32:b108ed6096b0 254
dev_alexander 32:b108ed6096b0 255
dev_alexander 32:b108ed6096b0 256 #if defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 257 //Set Power Hold High for battery operation MAX77650 on MAX32620FTHR
dev_alexander 32:b108ed6096b0 258 pw_Hold = POWER_HOLD_ON;
dev_alexander 32:b108ed6096b0 259 #endif
dev_alexander 32:b108ed6096b0 260
Helmut64 17:98f2528e8399 261 /*
Helmut64 17:98f2528e8399 262 * inits the Serial or USBSerial when available (230400 baud).
Helmut64 17:98f2528e8399 263 * If the serial uart is not is not connected it swiches to USB Serial
Helmut64 17:98f2528e8399 264 * blinking LED means USBSerial detected, waiting for a connect.
Helmut64 17:98f2528e8399 265 * It waits up to 30 seconds for a USB terminal connections
Helmut64 17:98f2528e8399 266 */
Helmut64 17:98f2528e8399 267 InitSerial(30*1000, &myled);
Helmut64 17:98f2528e8399 268 dprintf("Welcome to the SX1276GenericLib");
Helmut64 18:d5527ce82e6b 269
Helmut64 17:98f2528e8399 270 dprintf("Starting a simple LoRa PingPong");
dev_alexander 23:f74a50977593 271
dev_alexander 32:b108ed6096b0 272
dev_alexander 26:69aba05f010f 273
dev_alexander 23:f74a50977593 274
dev_alexander 23:f74a50977593 275 /***************************************************************************
dev_alexander 23:f74a50977593 276 * Grid Eye Sensor: Non-Buffer Program Variables
dev_alexander 23:f74a50977593 277 **************************************************************************/
dev_alexander 23:f74a50977593 278 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 23:f74a50977593 279 int frame_idx = 0;
dev_alexander 24:e8d03912f303 280 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 281 #if defined(DEBUG_GRID_EYE_SLAVE)
dev_alexander 32:b108ed6096b0 282 int frame_idx = 0;
dev_alexander 32:b108ed6096b0 283 #endif
dev_alexander 23:f74a50977593 284 #endif
dev_alexander 23:f74a50977593 285
dev_alexander 23:f74a50977593 286
dev_alexander 28:0ed92c590607 287 /***************************************************************************
dev_alexander 28:0ed92c590607 288 * Combined Payload Buffers for LoRa Communications
dev_alexander 28:0ed92c590607 289 **************************************************************************/
dev_alexander 28:0ed92c590607 290 uint8_t BufferTx[BufferSizeTx];
dev_alexander 28:0ed92c590607 291 uint8_t BufferRx[BufferSizeRx];
dev_alexander 28:0ed92c590607 292
dev_alexander 28:0ed92c590607 293 /***************************************************************************
dev_alexander 32:b108ed6096b0 294 * Identification Buffers
dev_alexander 32:b108ed6096b0 295 **************************************************************************/
dev_alexander 32:b108ed6096b0 296 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 297 uint8_t ID_of_slave[size_signature];
dev_alexander 32:b108ed6096b0 298 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 299 uint8_t ID_of_master[size_signature];
dev_alexander 32:b108ed6096b0 300 #endif
dev_alexander 32:b108ed6096b0 301
dev_alexander 32:b108ed6096b0 302 /***************************************************************************
dev_alexander 28:0ed92c590607 303 * BLE Data Buffers
dev_alexander 28:0ed92c590607 304 **************************************************************************/
dev_alexander 28:0ed92c590607 305 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 31:f15747cffb20 306 uint8_t curr_ble_to_slave[size_of_ble];
dev_alexander 28:0ed92c590607 307 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 308 uint8_t curr_ble_from_master[size_of_ble];
dev_alexander 28:0ed92c590607 309 uint8_t prev_ble_from_master[size_of_ble];
dev_alexander 28:0ed92c590607 310 #endif
dev_alexander 28:0ed92c590607 311
dev_alexander 28:0ed92c590607 312 /***************************************************************************
dev_alexander 28:0ed92c590607 313 * Grid Eye Sensor Data Buffers
dev_alexander 28:0ed92c590607 314 **************************************************************************/
dev_alexander 28:0ed92c590607 315 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 316 char curr_raw_frame_from_slave[size_of_grid_eye];
dev_alexander 28:0ed92c590607 317 char prev_raw_frame_from_slave[size_of_grid_eye];
dev_alexander 28:0ed92c590607 318 int16_t conv_frame_from_slave[64];
dev_alexander 28:0ed92c590607 319 #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 320 char curr_raw_frame_to_master[size_of_grid_eye];
dev_alexander 28:0ed92c590607 321 char prev_raw_frame_to_master[size_of_grid_eye];
dev_alexander 28:0ed92c590607 322 int16_t conv_frame_to_master[64];
dev_alexander 28:0ed92c590607 323 #endif
dev_alexander 28:0ed92c590607 324
dev_alexander 28:0ed92c590607 325 /***************************************************************************
dev_alexander 28:0ed92c590607 326 * GPS Data Buffers
dev_alexander 28:0ed92c590607 327 **************************************************************************/
dev_alexander 28:0ed92c590607 328 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 329 uint8_t curr_gps_from_slave[size_of_gps];
dev_alexander 28:0ed92c590607 330 uint8_t prev_gps_from_slave[size_of_gps];
dev_alexander 28:0ed92c590607 331 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 332 uint8_t curr_gps_to_master[size_of_gps];
dev_alexander 28:0ed92c590607 333 #endif
dev_alexander 28:0ed92c590607 334
dev_alexander 28:0ed92c590607 335 /***************************************************************************
dev_alexander 28:0ed92c590607 336 * MAX17055 Data Buffers
dev_alexander 28:0ed92c590607 337 **************************************************************************/
dev_alexander 28:0ed92c590607 338 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 339 uint8_t curr_MAX17055_from_slave[size_of_MAX17055];
dev_alexander 28:0ed92c590607 340 uint8_t prev_MAX17055_from_slave[size_of_MAX17055];
dev_alexander 28:0ed92c590607 341 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 342 uint8_t curr_MAX17055_to_master[size_of_MAX17055];
dev_alexander 28:0ed92c590607 343 #endif
dev_alexander 28:0ed92c590607 344
dev_alexander 28:0ed92c590607 345 /***************************************************************************
dev_alexander 28:0ed92c590607 346 * MAX77650 Data Buffers
dev_alexander 28:0ed92c590607 347 **************************************************************************/
dev_alexander 28:0ed92c590607 348 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 349 uint8_t curr_MAX77650_from_slave[size_of_MAX77650];
dev_alexander 28:0ed92c590607 350 uint8_t prev_MAX77650_from_slave[size_of_MAX77650];
dev_alexander 28:0ed92c590607 351 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 352 uint8_t curr_MAX77650_to_master[size_of_MAX77650];
dev_alexander 28:0ed92c590607 353 #endif
dev_alexander 28:0ed92c590607 354
dev_alexander 28:0ed92c590607 355 /***************************************************************************
dev_alexander 28:0ed92c590607 356 * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send
dev_alexander 28:0ed92c590607 357 **************************************************************************/
dev_alexander 28:0ed92c590607 358 SX1276PingPongSetup(BufferTx, BufferRx);
dev_alexander 28:0ed92c590607 359
dev_alexander 32:b108ed6096b0 360 /***************************************************************************
dev_alexander 32:b108ed6096b0 361 * Finish Setting up BLE Radio on the MAX32630FTHR: Only on the Master Device
dev_alexander 32:b108ed6096b0 362 **************************************************************************/
dev_alexander 32:b108ed6096b0 363 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 364 BLE &ble = BLE::Instance();
dev_alexander 32:b108ed6096b0 365 /* Create alias for the BLE data to be saved in function above that
dev_alexander 32:b108ed6096b0 366 * writes data to this buffer when function onDataWritten is called
dev_alexander 32:b108ed6096b0 367 */
dev_alexander 32:b108ed6096b0 368 onDataWritten_curr_ble_to_slave = curr_ble_to_slave;
dev_alexander 32:b108ed6096b0 369
dev_alexander 32:b108ed6096b0 370 /* Initialize BLE */
dev_alexander 32:b108ed6096b0 371 ble.init();
dev_alexander 32:b108ed6096b0 372 ble.gap().onDisconnection(disconnectionCallback);
dev_alexander 32:b108ed6096b0 373 ble.gattServer().onDataWritten(onDataWritten);
dev_alexander 32:b108ed6096b0 374 uart = new UARTService(ble);
dev_alexander 32:b108ed6096b0 375 /* setup advertising */
dev_alexander 32:b108ed6096b0 376 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
dev_alexander 32:b108ed6096b0 377 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
dev_alexander 32:b108ed6096b0 378 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
dev_alexander 32:b108ed6096b0 379 (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
dev_alexander 32:b108ed6096b0 380 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
dev_alexander 32:b108ed6096b0 381 (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
dev_alexander 32:b108ed6096b0 382 ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
dev_alexander 32:b108ed6096b0 383 ble.gap().startAdvertising();
dev_alexander 32:b108ed6096b0 384 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 385 /* There is no BLE device that is integrated into the MAX32620FTHR. Also
dev_alexander 32:b108ed6096b0 386 * Also this program is meant to use the BLE gateway on the MAX32630FTHR
dev_alexander 32:b108ed6096b0 387 */
dev_alexander 32:b108ed6096b0 388 #endif
dev_alexander 32:b108ed6096b0 389
dev_alexander 32:b108ed6096b0 390 /***************************************************************************
dev_alexander 32:b108ed6096b0 391 * Finish Setting up the motor controller on the MAX32620FTHR: Only on the Slave Device
dev_alexander 32:b108ed6096b0 392 **************************************************************************/
dev_alexander 32:b108ed6096b0 393 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 394 // No setup on the master device
dev_alexander 32:b108ed6096b0 395 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 396 AFMS.begin(); // create with the default frequency 1.6KHz
dev_alexander 32:b108ed6096b0 397 //AFMS.begin(1000); // OR with a different frequency, say 1KHz
dev_alexander 32:b108ed6096b0 398
dev_alexander 32:b108ed6096b0 399 // Set the speed to start, from 0 (off) to 255 (max speed)
dev_alexander 32:b108ed6096b0 400 rightMotor->setSpeed(150);
dev_alexander 32:b108ed6096b0 401 rightMotor->run(FORWARD);
dev_alexander 32:b108ed6096b0 402 // turn on motor
dev_alexander 32:b108ed6096b0 403 rightMotor->run(RELEASE);
dev_alexander 32:b108ed6096b0 404
dev_alexander 32:b108ed6096b0 405 leftMotor->setSpeed(150);
dev_alexander 32:b108ed6096b0 406 leftMotor->run(FORWARD);
dev_alexander 32:b108ed6096b0 407 // turn on motor
dev_alexander 32:b108ed6096b0 408 leftMotor->run(RELEASE);
dev_alexander 32:b108ed6096b0 409 #endif
dev_alexander 32:b108ed6096b0 410
dev_alexander 32:b108ed6096b0 411
dev_alexander 22:abca9d17d13d 412 while(1)
dev_alexander 28:0ed92c590607 413 {
dev_alexander 23:f74a50977593 414 /***************************************************************************
dev_alexander 30:66f9750cc44c 415 * BLE Radio Data
dev_alexander 30:66f9750cc44c 416 **************************************************************************/
dev_alexander 30:66f9750cc44c 417 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 30:66f9750cc44c 418 #if defined(COMPILE_BLE)
dev_alexander 30:66f9750cc44c 419 ble.waitForEvent();
dev_alexander 30:66f9750cc44c 420 #endif
dev_alexander 30:66f9750cc44c 421 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 422 memcpy(curr_ble_from_master, prev_ble_from_master, sizeof(curr_ble_from_master));
dev_alexander 30:66f9750cc44c 423 #endif
dev_alexander 30:66f9750cc44c 424
dev_alexander 30:66f9750cc44c 425 /***************************************************************************
dev_alexander 23:f74a50977593 426 * Grid Eye Sensor
dev_alexander 23:f74a50977593 427 **************************************************************************/
dev_alexander 23:f74a50977593 428 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 429 // Check to see if the contents of the previous scan are the same. If they are different then continue with converting
dev_alexander 32:b108ed6096b0 430 #if defined(RASPBERRY_PI)
dev_alexander 32:b108ed6096b0 431 if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 )
dev_alexander 32:b108ed6096b0 432 {
dev_alexander 32:b108ed6096b0 433 char grid_eye_msg[130];
dev_alexander 32:b108ed6096b0 434 grid_eye_msg[0]=0x55;
dev_alexander 32:b108ed6096b0 435 grid_eye_msg[1]=0xaa;
dev_alexander 32:b108ed6096b0 436 for (int idx = 0; idx < 128; idx++)
dev_alexander 32:b108ed6096b0 437 grid_eye_msg[idx+2] = curr_raw_frame_from_slave[idx];
dev_alexander 32:b108ed6096b0 438 //pc.printf(grid_eye_msg);
dev_alexander 32:b108ed6096b0 439 for (int idx = 0; idx < 130; idx++)
dev_alexander 32:b108ed6096b0 440 pc.putc(grid_eye_msg[idx]);
dev_alexander 35:bae9b236070b 441 pc.printf("\r\n"); // seperate the lines
dev_alexander 32:b108ed6096b0 442 }
dev_alexander 35:bae9b236070b 443 #endif
dev_alexander 35:bae9b236070b 444 #if defined(DEBUG_GRID_EYE)
dev_alexander 32:b108ed6096b0 445 if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 )
dev_alexander 32:b108ed6096b0 446 {
dev_alexander 32:b108ed6096b0 447 // Convert raw data sent from slave to a 16 bit integer array by calling this
dev_alexander 32:b108ed6096b0 448 convRaw8x8Data2Point25degC(curr_raw_frame_from_slave, conv_frame_from_slave);
dev_alexander 32:b108ed6096b0 449
dev_alexander 32:b108ed6096b0 450 // Next Print off the Converted data
dev_alexander 32:b108ed6096b0 451 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
dev_alexander 32:b108ed6096b0 452 uint8_t idx;
dev_alexander 32:b108ed6096b0 453 float pixel_data;
dev_alexander 32:b108ed6096b0 454 for (int y = 0; y < 8; y++) {
dev_alexander 32:b108ed6096b0 455 for (int x = 0; x < 8; x++) {
dev_alexander 32:b108ed6096b0 456 idx = y*8 + x;
dev_alexander 32:b108ed6096b0 457 pixel_data = ((float)conv_frame_from_slave[idx])/4.0;
dev_alexander 32:b108ed6096b0 458 pc.printf("%.2f \t", pixel_data);
dev_alexander 32:b108ed6096b0 459 }
dev_alexander 32:b108ed6096b0 460 pc.printf("\r\n\r\n");
dev_alexander 23:f74a50977593 461 }
dev_alexander 32:b108ed6096b0 462 pc.printf("\r\n");
dev_alexander 32:b108ed6096b0 463
dev_alexander 32:b108ed6096b0 464 // Increment frame counter
dev_alexander 32:b108ed6096b0 465 frame_idx = frame_idx +1;
dev_alexander 23:f74a50977593 466 }
dev_alexander 32:b108ed6096b0 467 #endif
dev_alexander 32:b108ed6096b0 468 /* Next copy in data received from current data into buffer used for
dev_alexander 32:b108ed6096b0 469 * comparison next time the memcmp above is called. This prevents the
dev_alexander 32:b108ed6096b0 470 * program from converting the same raw data aquired by the grid eye
dev_alexander 32:b108ed6096b0 471 * sensor on the slave device to the floating point array with the
dev_alexander 32:b108ed6096b0 472 * 0.25 degrees celsius precision level when there is not new data.
dev_alexander 32:b108ed6096b0 473 */
dev_alexander 32:b108ed6096b0 474
dev_alexander 28:0ed92c590607 475 memcpy(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave));
dev_alexander 24:e8d03912f303 476 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 23:f74a50977593 477 // Aquire raw data about 8x8 frame from the grid eye sensor in this function call
dev_alexander 28:0ed92c590607 478 gridEye.getRaw8x8FrameData(curr_raw_frame_to_master);
dev_alexander 36:09e8b51fc91d 479 // wait_ms( 10 );
dev_alexander 35:bae9b236070b 480 #if defined(RASPBERRY_PI)
dev_alexander 35:bae9b236070b 481 if( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 )
dev_alexander 35:bae9b236070b 482 {
dev_alexander 35:bae9b236070b 483 char grid_eye_msg[130];
dev_alexander 35:bae9b236070b 484 grid_eye_msg[0]=0x55;
dev_alexander 35:bae9b236070b 485 grid_eye_msg[1]=0xaa;
dev_alexander 35:bae9b236070b 486 for (int idx = 0; idx < 128; idx++)
dev_alexander 35:bae9b236070b 487 grid_eye_msg[idx+2] = curr_raw_frame_to_master[idx];
dev_alexander 35:bae9b236070b 488 //pc.printf(grid_eye_msg);
dev_alexander 35:bae9b236070b 489 for (int idx = 0; idx < 130; idx++)
dev_alexander 35:bae9b236070b 490 pc.putc(grid_eye_msg[idx]);
dev_alexander 35:bae9b236070b 491 pc.printf("\r\n"); // seperate the lines
dev_alexander 35:bae9b236070b 492 }
dev_alexander 35:bae9b236070b 493 #endif
dev_alexander 35:bae9b236070b 494 #if defined(DEBUG_GRID_EYE)
dev_alexander 32:b108ed6096b0 495 if( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 )
dev_alexander 32:b108ed6096b0 496 {
dev_alexander 32:b108ed6096b0 497 // Convert raw data sent from slave to a 16 bit integer array by calling this
dev_alexander 32:b108ed6096b0 498 convRaw8x8Data2Point25degC(curr_raw_frame_to_master, conv_frame_to_master);
dev_alexander 32:b108ed6096b0 499
dev_alexander 32:b108ed6096b0 500
dev_alexander 32:b108ed6096b0 501 // Next Print off the Converted data
dev_alexander 32:b108ed6096b0 502 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
dev_alexander 32:b108ed6096b0 503 uint8_t idx;
dev_alexander 32:b108ed6096b0 504 float pixel_data;
dev_alexander 32:b108ed6096b0 505 for (int y = 0; y < 8; y++) {
dev_alexander 32:b108ed6096b0 506 for (int x = 0; x < 8; x++) {
dev_alexander 32:b108ed6096b0 507 idx = y*8 + x;
dev_alexander 32:b108ed6096b0 508 pixel_data = ((float)conv_frame_to_master[idx])/4.0;
dev_alexander 32:b108ed6096b0 509 pc.printf("%.2f \t", pixel_data);
dev_alexander 32:b108ed6096b0 510 }
dev_alexander 32:b108ed6096b0 511 pc.printf("\r\n\r\n");
dev_alexander 25:1a031add188a 512 }
dev_alexander 32:b108ed6096b0 513 pc.printf("\r\n");
dev_alexander 32:b108ed6096b0 514
dev_alexander 32:b108ed6096b0 515 // Increment frame counter
dev_alexander 32:b108ed6096b0 516 frame_idx = frame_idx +1;
dev_alexander 25:1a031add188a 517 }
dev_alexander 32:b108ed6096b0 518 #endif
dev_alexander 36:09e8b51fc91d 519 // wait_ms( 10 );
dev_alexander 33:52c898aca207 520 memcpy(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master));
dev_alexander 31:f15747cffb20 521 #endif
dev_alexander 31:f15747cffb20 522
dev_alexander 31:f15747cffb20 523 /***************************************************************************
dev_alexander 31:f15747cffb20 524 * GPS Sensor
dev_alexander 31:f15747cffb20 525 **************************************************************************/
dev_alexander 31:f15747cffb20 526 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 31:f15747cffb20 527 //None yet
dev_alexander 31:f15747cffb20 528 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 31:f15747cffb20 529 // The testing hasnt been done yet for the GPS Module. Will do this when more parts come in.
dev_alexander 31:f15747cffb20 530 /*
dev_alexander 31:f15747cffb20 531 if(gps.sample()){
dev_alexander 31:f15747cffb20 532 pc.printf("%f\t%c\t%f\t%c\t%f\t%f\t%f\n\r",gps.longitude, gps.ns,gps.latitude,gps.ew, gps.alt, gps.geoid, gps.time);
dev_alexander 31:f15747cffb20 533 pc.printf("%d:%d:%d",gps.hour,gps.minute,gps.seconed);
dev_alexander 31:f15747cffb20 534 }
dev_alexander 31:f15747cffb20 535 */
dev_alexander 31:f15747cffb20 536 #endif
dev_alexander 28:0ed92c590607 537
dev_alexander 23:f74a50977593 538 /***************************************************************************
dev_alexander 28:0ed92c590607 539 * Fill Payload Buffer With Data From Sensors for LoRa Transmition
dev_alexander 28:0ed92c590607 540 **************************************************************************/
dev_alexander 28:0ed92c590607 541 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 542 memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature);
dev_alexander 28:0ed92c590607 543 memcpy(&BufferTx[tx_idx_ble], curr_ble_to_slave, size_of_ble);
dev_alexander 28:0ed92c590607 544 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 545 memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature);
dev_alexander 28:0ed92c590607 546 memcpy(&BufferTx[tx_idx_grid_eye], curr_raw_frame_to_master, size_of_grid_eye);
dev_alexander 28:0ed92c590607 547 memcpy(&BufferTx[tx_idx_gps], curr_gps_to_master, size_of_gps);
dev_alexander 28:0ed92c590607 548 memcpy(&BufferTx[tx_idx_MAX17055], curr_MAX17055_to_master, size_of_MAX17055);
dev_alexander 28:0ed92c590607 549 memcpy(&BufferTx[tx_idx_MAX77650], curr_MAX77650_to_master, size_of_MAX77650);
dev_alexander 28:0ed92c590607 550 #endif
dev_alexander 28:0ed92c590607 551
dev_alexander 28:0ed92c590607 552
dev_alexander 28:0ed92c590607 553
dev_alexander 32:b108ed6096b0 554
dev_alexander 28:0ed92c590607 555 /***************************************************************************
dev_alexander 28:0ed92c590607 556 * Lora Communications
dev_alexander 28:0ed92c590607 557 **************************************************************************/
dev_alexander 36:09e8b51fc91d 558 // wait_ms( 10 );
dev_alexander 22:abca9d17d13d 559 SX1276PingPong();
dev_alexander 28:0ed92c590607 560
dev_alexander 28:0ed92c590607 561 /***************************************************************************
dev_alexander 28:0ed92c590607 562 * Fill Global Buffers With Data From Received Payload Buffer
dev_alexander 28:0ed92c590607 563 **************************************************************************/
dev_alexander 28:0ed92c590607 564 /* The master and slave devices will have different requirements for offloading payload */
dev_alexander 28:0ed92c590607 565 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 566 memcpy(ID_of_slave, &BufferRx[rx_idx_signature], size_signature);
dev_alexander 32:b108ed6096b0 567 memcpy(curr_raw_frame_from_slave, &BufferRx[rx_idx_grid_eye], size_of_grid_eye);
dev_alexander 32:b108ed6096b0 568 memcpy(curr_gps_from_slave, &BufferRx[rx_idx_gps], size_of_gps);
dev_alexander 32:b108ed6096b0 569 memcpy(curr_MAX17055_from_slave, &BufferRx[rx_idx_MAX17055], size_of_MAX17055);
dev_alexander 32:b108ed6096b0 570 memcpy(curr_MAX77650_from_slave, &BufferRx[rx_idx_MAX77650], size_of_MAX77650);
dev_alexander 28:0ed92c590607 571 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 572 memcpy(ID_of_master, &BufferRx[rx_idx_signature], size_signature);
dev_alexander 32:b108ed6096b0 573 memcpy(curr_ble_from_master, &BufferRx[rx_idx_ble], size_of_ble);
dev_alexander 28:0ed92c590607 574 #endif
dev_alexander 23:f74a50977593 575
dev_alexander 32:b108ed6096b0 576 /***************************************************************************
dev_alexander 32:b108ed6096b0 577 * Motor Controller controlls go here
dev_alexander 32:b108ed6096b0 578 **************************************************************************/
dev_alexander 32:b108ed6096b0 579 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 580 // No motor controller on master
dev_alexander 32:b108ed6096b0 581 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 582 // Check to see if the contents of the previous ble sdata received are the same. If they are different then change motor controllers registers
dev_alexander 32:b108ed6096b0 583 if( memcmp(prev_ble_from_master, curr_ble_from_master, sizeof(curr_ble_from_master)) != 0 )
dev_alexander 32:b108ed6096b0 584 {
dev_alexander 32:b108ed6096b0 585 MotorController(curr_ble_from_master);
dev_alexander 32:b108ed6096b0 586 }
dev_alexander 32:b108ed6096b0 587 #endif
dev_alexander 23:f74a50977593 588
dev_alexander 23:f74a50977593 589
dev_alexander 23:f74a50977593 590
dev_alexander 22:abca9d17d13d 591 }
dev_alexander 22:abca9d17d13d 592
Helmut64 0:c43b6919ae15 593 }