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