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@31:f15747cffb20, 2018-07-24 (annotated)
- Committer:
- dev_alexander
- Date:
- Tue Jul 24 18:30:26 2018 +0000
- Revision:
- 31:f15747cffb20
- Parent:
- 30:66f9750cc44c
- Child:
- 32:b108ed6096b0
Added library that adds support for a GPS module to the Sketch. However, hasn't been tested though, so this needs to be reexamined in the future.
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 | 31:f15747cffb20 | 15 | #include "GPS.h" |
dev_alexander | 23:f74a50977593 | 16 | |
dev_alexander | 23:f74a50977593 | 17 | /* If the board that is compiled is the master device (BLE enabled MAX32630FTHR), |
dev_alexander | 23:f74a50977593 | 18 | * then it needs this library and needs to be configed in order for the device to |
dev_alexander | 23:f74a50977593 | 19 | * work with a 3.3volt output instead of a 1.8 volt output. |
dev_alexander | 23:f74a50977593 | 20 | * |
dev_alexander | 23:f74a50977593 | 21 | * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this |
dev_alexander | 23:f74a50977593 | 22 | * additional setup in the main program. |
dev_alexander | 23:f74a50977593 | 23 | */ |
dev_alexander | 31:f15747cffb20 | 24 | |
dev_alexander | 31:f15747cffb20 | 25 | #if defined(TARGET_MAX32620FTHR) |
dev_alexander | 31:f15747cffb20 | 26 | GPS gps(P0_1, P0_0, 115200); |
dev_alexander | 29:f7a0e49b826b | 27 | #endif |
Helmut64 | 0:c43b6919ae15 | 28 | |
dev_alexander | 31:f15747cffb20 | 29 | #if defined(TARGET_MAX32630FTHR) |
dev_alexander | 31:f15747cffb20 | 30 | #include "max32630fthr.h" |
dev_alexander | 31:f15747cffb20 | 31 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
dev_alexander | 31:f15747cffb20 | 32 | |
dev_alexander | 31:f15747cffb20 | 33 | #define COMPILE_BLE |
dev_alexander | 31:f15747cffb20 | 34 | |
dev_alexander | 31:f15747cffb20 | 35 | #if defined(COMPILE_BLE) |
dev_alexander | 31:f15747cffb20 | 36 | /* BLE Related MAX32630FTHR Specific stuff */ |
dev_alexander | 31:f15747cffb20 | 37 | #include "ble/BLE.h" |
dev_alexander | 31:f15747cffb20 | 38 | //#include "ble/Gap.h" |
dev_alexander | 31:f15747cffb20 | 39 | #include "UARTService_custom.h" |
dev_alexander | 31:f15747cffb20 | 40 | #include <events/mbed_events.h> |
dev_alexander | 31:f15747cffb20 | 41 | |
dev_alexander | 31:f15747cffb20 | 42 | DigitalOut led2(LED2); |
dev_alexander | 31:f15747cffb20 | 43 | UARTService *uart; |
dev_alexander | 30:66f9750cc44c | 44 | |
dev_alexander | 31:f15747cffb20 | 45 | #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console; |
dev_alexander | 31:f15747cffb20 | 46 | * it will have an impact on code-size and power consumption. */ |
dev_alexander | 31:f15747cffb20 | 47 | |
dev_alexander | 31:f15747cffb20 | 48 | #if NEED_CONSOLE_OUTPUT |
dev_alexander | 31:f15747cffb20 | 49 | #define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); } |
dev_alexander | 31:f15747cffb20 | 50 | #define READ(STR) { if (uart) uart->read(STR, strlen(STR)); } |
dev_alexander | 31:f15747cffb20 | 51 | |
dev_alexander | 31:f15747cffb20 | 52 | #else |
dev_alexander | 31:f15747cffb20 | 53 | #define DEBUG(...) /* nothing */ |
dev_alexander | 31:f15747cffb20 | 54 | #endif /* #if NEED_CONSOLE_OUTPUT */ |
dev_alexander | 31:f15747cffb20 | 55 | |
dev_alexander | 31:f15747cffb20 | 56 | //Triggered when the robot is disconnected from the mobile app. |
dev_alexander | 31:f15747cffb20 | 57 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
dev_alexander | 31:f15747cffb20 | 58 | { |
dev_alexander | 31:f15747cffb20 | 59 | BLE &ble = BLE::Instance(); |
dev_alexander | 31:f15747cffb20 | 60 | DEBUG("Disconnected!\n\r"); |
dev_alexander | 31:f15747cffb20 | 61 | DEBUG("Restarting the advertising process\n\r"); |
dev_alexander | 31:f15747cffb20 | 62 | ble.gap().startAdvertising(); |
dev_alexander | 31:f15747cffb20 | 63 | } |
dev_alexander | 31:f15747cffb20 | 64 | |
dev_alexander | 31:f15747cffb20 | 65 | /* This pointer is needed to reference data in the main program when filling |
dev_alexander | 31:f15747cffb20 | 66 | * with data from the BLE |
dev_alexander | 31:f15747cffb20 | 67 | */ |
dev_alexander | 31:f15747cffb20 | 68 | uint8_t * onDataWritten_curr_ble_to_slave; |
dev_alexander | 30:66f9750cc44c | 69 | |
dev_alexander | 31:f15747cffb20 | 70 | // Triggered when there is data written |
dev_alexander | 31:f15747cffb20 | 71 | void onDataWritten(const GattWriteCallbackParams *params) |
dev_alexander | 31:f15747cffb20 | 72 | { |
dev_alexander | 31:f15747cffb20 | 73 | //LED1 will be off when button is pressed, and on when button is released. |
dev_alexander | 31:f15747cffb20 | 74 | led2 = !led2; |
dev_alexander | 31:f15747cffb20 | 75 | uint8_t button_state; |
dev_alexander | 31:f15747cffb20 | 76 | uint8_t direction; |
dev_alexander | 31:f15747cffb20 | 77 | /*Set up constants for direction of motion */ |
dev_alexander | 31:f15747cffb20 | 78 | // const char FRONT = '5'; |
dev_alexander | 31:f15747cffb20 | 79 | // const char BACK = '6'; |
dev_alexander | 31:f15747cffb20 | 80 | // const char LEFT = '7'; |
dev_alexander | 31:f15747cffb20 | 81 | // const char RIGHT = '8'; |
dev_alexander | 31:f15747cffb20 | 82 | |
dev_alexander | 31:f15747cffb20 | 83 | /*Set up constants for button state */ |
dev_alexander | 31:f15747cffb20 | 84 | // const char PRESSED = '1'; |
dev_alexander | 31:f15747cffb20 | 85 | // const char RELEASED = '0'; |
dev_alexander | 30:66f9750cc44c | 86 | |
dev_alexander | 31:f15747cffb20 | 87 | /* If there is a valid data sent by the mobile app */ |
dev_alexander | 31:f15747cffb20 | 88 | if ((uart != NULL) && (params->handle == uart ->getTXCharacteristicHandle())) { |
dev_alexander | 31:f15747cffb20 | 89 | const uint8_t *packet = params->data; |
dev_alexander | 31:f15747cffb20 | 90 | button_state = packet[3]; |
dev_alexander | 31:f15747cffb20 | 91 | direction = packet[2]; |
dev_alexander | 31:f15747cffb20 | 92 | |
dev_alexander | 31:f15747cffb20 | 93 | // make parameter to send over Lora |
dev_alexander | 31:f15747cffb20 | 94 | onDataWritten_curr_ble_to_slave[0] = direction; |
dev_alexander | 31:f15747cffb20 | 95 | onDataWritten_curr_ble_to_slave[1] = button_state; |
dev_alexander | 31:f15747cffb20 | 96 | |
dev_alexander | 31:f15747cffb20 | 97 | dprintf("direction: %d\n", direction); |
dev_alexander | 31:f15747cffb20 | 98 | dprintf("button_state: %d\n", button_state); |
dev_alexander | 31:f15747cffb20 | 99 | |
dev_alexander | 31:f15747cffb20 | 100 | /* |
dev_alexander | 31:f15747cffb20 | 101 | switch (button_state) |
dev_alexander | 31:f15747cffb20 | 102 | { |
dev_alexander | 31:f15747cffb20 | 103 | case PRESSED: |
dev_alexander | 31:f15747cffb20 | 104 | md_left_pwm = static_cast<float>(20/100.0F); |
dev_alexander | 31:f15747cffb20 | 105 | md_right_pwm = static_cast<float>(20/100.0F); |
dev_alexander | 31:f15747cffb20 | 106 | |
dev_alexander | 31:f15747cffb20 | 107 | switch (direction) |
dev_alexander | 31:f15747cffb20 | 108 | { |
dev_alexander | 31:f15747cffb20 | 109 | case FRONT: |
dev_alexander | 31:f15747cffb20 | 110 | md_left_dir = 1; |
dev_alexander | 31:f15747cffb20 | 111 | md_left_pwm = 0.7; |
dev_alexander | 31:f15747cffb20 | 112 | md_right_dir = 1; |
dev_alexander | 31:f15747cffb20 | 113 | md_right_pwm = 0.7; |
dev_alexander | 31:f15747cffb20 | 114 | break; |
dev_alexander | 31:f15747cffb20 | 115 | case BACK: |
dev_alexander | 31:f15747cffb20 | 116 | md_left_dir = 0; |
dev_alexander | 31:f15747cffb20 | 117 | md_left_pwm = 0.7; |
dev_alexander | 31:f15747cffb20 | 118 | md_right_dir = 0; |
dev_alexander | 31:f15747cffb20 | 119 | md_right_pwm = 0.7; |
dev_alexander | 31:f15747cffb20 | 120 | break; |
dev_alexander | 31:f15747cffb20 | 121 | case LEFT: |
dev_alexander | 31:f15747cffb20 | 122 | md_left_dir = 0; |
dev_alexander | 31:f15747cffb20 | 123 | md_left_pwm = 0.5; |
dev_alexander | 31:f15747cffb20 | 124 | md_right_dir = 1; |
dev_alexander | 31:f15747cffb20 | 125 | md_right_pwm = 0.5; |
dev_alexander | 31:f15747cffb20 | 126 | break; |
dev_alexander | 31:f15747cffb20 | 127 | case RIGHT: |
dev_alexander | 31:f15747cffb20 | 128 | md_left_dir = 1; |
dev_alexander | 31:f15747cffb20 | 129 | md_left_pwm = 0.5; |
dev_alexander | 31:f15747cffb20 | 130 | md_right_dir = 0; |
dev_alexander | 31:f15747cffb20 | 131 | md_right_pwm = 0.5; |
dev_alexander | 31:f15747cffb20 | 132 | break; |
dev_alexander | 31:f15747cffb20 | 133 | } |
dev_alexander | 31:f15747cffb20 | 134 | break; |
dev_alexander | 31:f15747cffb20 | 135 | case RELEASED: |
dev_alexander | 31:f15747cffb20 | 136 | md_left_pwm = 0; |
dev_alexander | 31:f15747cffb20 | 137 | md_right_pwm = 0; |
dev_alexander | 31:f15747cffb20 | 138 | break; |
dev_alexander | 31:f15747cffb20 | 139 | } |
dev_alexander | 31:f15747cffb20 | 140 | */ |
dev_alexander | 31:f15747cffb20 | 141 | |
dev_alexander | 30:66f9750cc44c | 142 | } |
dev_alexander | 30:66f9750cc44c | 143 | } |
dev_alexander | 31:f15747cffb20 | 144 | #endif |
dev_alexander | 30:66f9750cc44c | 145 | #endif |
dev_alexander | 30:66f9750cc44c | 146 | |
Helmut64 | 17:98f2528e8399 | 147 | DigitalOut myled(LED); |
Helmut64 | 0:c43b6919ae15 | 148 | |
dev_alexander | 28:0ed92c590607 | 149 | Serial pc(USBTX, USBRX); |
dev_alexander | 25:1a031add188a | 150 | |
Helmut64 | 0:c43b6919ae15 | 151 | |
dev_alexander | 23:f74a50977593 | 152 | #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 153 | /* No grid eye object needed. The function the master uses to convert the raw |
dev_alexander | 23:f74a50977593 | 154 | * data that is sent over from the slave deevice that contains the data from the |
dev_alexander | 23:f74a50977593 | 155 | * actual grid eye sensor is actually a function that is not part of the grid eye |
dev_alexander | 23:f74a50977593 | 156 | * class. this is due to the fact that the grid eye class requires n i2c bus to |
dev_alexander | 23:f74a50977593 | 157 | * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye |
dev_alexander | 23:f74a50977593 | 158 | * sensor has a support functin that is used to convert data that is aquired from |
dev_alexander | 23:f74a50977593 | 159 | * the grid eye sensor. So it is not supposed to be a class specific function. |
dev_alexander | 23:f74a50977593 | 160 | */ |
dev_alexander | 23:f74a50977593 | 161 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot |
dev_alexander | 23:f74a50977593 | 162 | //Init I2C communications in default I2C bus I2C #1 |
dev_alexander | 23:f74a50977593 | 163 | I2C i2cGridEye(P3_4,P3_5); |
dev_alexander | 23:f74a50977593 | 164 | GridEye gridEye(i2cGridEye); |
dev_alexander | 23:f74a50977593 | 165 | #endif |
dev_alexander | 19:9f035b9e65ec | 166 | |
dev_alexander | 23:f74a50977593 | 167 | int main() |
dev_alexander | 23:f74a50977593 | 168 | { |
Helmut64 | 17:98f2528e8399 | 169 | /* |
Helmut64 | 17:98f2528e8399 | 170 | * inits the Serial or USBSerial when available (230400 baud). |
Helmut64 | 17:98f2528e8399 | 171 | * If the serial uart is not is not connected it swiches to USB Serial |
Helmut64 | 17:98f2528e8399 | 172 | * blinking LED means USBSerial detected, waiting for a connect. |
Helmut64 | 17:98f2528e8399 | 173 | * It waits up to 30 seconds for a USB terminal connections |
Helmut64 | 17:98f2528e8399 | 174 | */ |
Helmut64 | 17:98f2528e8399 | 175 | InitSerial(30*1000, &myled); |
Helmut64 | 17:98f2528e8399 | 176 | dprintf("Welcome to the SX1276GenericLib"); |
Helmut64 | 18:d5527ce82e6b | 177 | |
Helmut64 | 17:98f2528e8399 | 178 | dprintf("Starting a simple LoRa PingPong"); |
dev_alexander | 23:f74a50977593 | 179 | |
dev_alexander | 23:f74a50977593 | 180 | /* Setup begins here: */ |
dev_alexander | 25:1a031add188a | 181 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 25:1a031add188a | 182 | dprintf("MAX32630FTHR: Master"); |
dev_alexander | 25:1a031add188a | 183 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 25:1a031add188a | 184 | dprintf("MAX32620FTHR: Slave"); |
dev_alexander | 25:1a031add188a | 185 | #endif |
dev_alexander | 26:69aba05f010f | 186 | |
dev_alexander | 23:f74a50977593 | 187 | |
dev_alexander | 23:f74a50977593 | 188 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 189 | * Grid Eye Sensor: Non-Buffer Program Variables |
dev_alexander | 23:f74a50977593 | 190 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 191 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 192 | int frame_idx = 0; |
dev_alexander | 24:e8d03912f303 | 193 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 194 | // none yet |
dev_alexander | 25:1a031add188a | 195 | int frame_idx = 0; |
dev_alexander | 23:f74a50977593 | 196 | #endif |
dev_alexander | 23:f74a50977593 | 197 | |
dev_alexander | 23:f74a50977593 | 198 | |
dev_alexander | 28:0ed92c590607 | 199 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 200 | * Combined Payload Buffers for LoRa Communications |
dev_alexander | 28:0ed92c590607 | 201 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 202 | uint8_t BufferTx[BufferSizeTx]; |
dev_alexander | 28:0ed92c590607 | 203 | uint8_t BufferRx[BufferSizeRx]; |
dev_alexander | 28:0ed92c590607 | 204 | |
dev_alexander | 28:0ed92c590607 | 205 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 206 | * BLE Data Buffers |
dev_alexander | 28:0ed92c590607 | 207 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 208 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 31:f15747cffb20 | 209 | uint8_t curr_ble_to_slave[size_of_ble]; |
dev_alexander | 31:f15747cffb20 | 210 | #if defined(COMPILE_BLE) |
dev_alexander | 31:f15747cffb20 | 211 | BLE &ble = BLE::Instance(); |
dev_alexander | 31:f15747cffb20 | 212 | /* Create alias for the BLE data to be saved in function above that |
dev_alexander | 31:f15747cffb20 | 213 | * writes data to this buffer when function onDataWritten is called |
dev_alexander | 31:f15747cffb20 | 214 | */ |
dev_alexander | 31:f15747cffb20 | 215 | onDataWritten_curr_ble_to_slave = curr_ble_to_slave; |
dev_alexander | 31:f15747cffb20 | 216 | |
dev_alexander | 31:f15747cffb20 | 217 | /* Initialize BLE */ |
dev_alexander | 31:f15747cffb20 | 218 | ble.init(); |
dev_alexander | 31:f15747cffb20 | 219 | ble.gap().onDisconnection(disconnectionCallback); |
dev_alexander | 31:f15747cffb20 | 220 | ble.gattServer().onDataWritten(onDataWritten); |
dev_alexander | 31:f15747cffb20 | 221 | uart = new UARTService(ble); |
dev_alexander | 31:f15747cffb20 | 222 | /* setup advertising */ |
dev_alexander | 31:f15747cffb20 | 223 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
dev_alexander | 31:f15747cffb20 | 224 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
dev_alexander | 31:f15747cffb20 | 225 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
dev_alexander | 31:f15747cffb20 | 226 | (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1); |
dev_alexander | 31:f15747cffb20 | 227 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
dev_alexander | 31:f15747cffb20 | 228 | (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); |
dev_alexander | 31:f15747cffb20 | 229 | ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ |
dev_alexander | 31:f15747cffb20 | 230 | ble.gap().startAdvertising(); |
dev_alexander | 31:f15747cffb20 | 231 | #endif |
dev_alexander | 28:0ed92c590607 | 232 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 233 | uint8_t curr_ble_from_master[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 234 | uint8_t prev_ble_from_master[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 235 | #endif |
dev_alexander | 28:0ed92c590607 | 236 | |
dev_alexander | 28:0ed92c590607 | 237 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 238 | * Grid Eye Sensor Data Buffers |
dev_alexander | 28:0ed92c590607 | 239 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 240 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 241 | char curr_raw_frame_from_slave[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 242 | char prev_raw_frame_from_slave[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 243 | int16_t conv_frame_from_slave[64]; |
dev_alexander | 28:0ed92c590607 | 244 | #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 245 | char curr_raw_frame_to_master[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 246 | char prev_raw_frame_to_master[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 247 | int16_t conv_frame_to_master[64]; |
dev_alexander | 28:0ed92c590607 | 248 | #endif |
dev_alexander | 28:0ed92c590607 | 249 | |
dev_alexander | 28:0ed92c590607 | 250 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 251 | * GPS Data Buffers |
dev_alexander | 28:0ed92c590607 | 252 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 253 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 254 | uint8_t curr_gps_from_slave[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 255 | uint8_t prev_gps_from_slave[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 256 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 257 | uint8_t curr_gps_to_master[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 258 | #endif |
dev_alexander | 28:0ed92c590607 | 259 | |
dev_alexander | 28:0ed92c590607 | 260 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 261 | * MAX17055 Data Buffers |
dev_alexander | 28:0ed92c590607 | 262 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 263 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 264 | uint8_t curr_MAX17055_from_slave[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 265 | uint8_t prev_MAX17055_from_slave[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 266 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 267 | uint8_t curr_MAX17055_to_master[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 268 | #endif |
dev_alexander | 28:0ed92c590607 | 269 | |
dev_alexander | 28:0ed92c590607 | 270 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 271 | * MAX77650 Data Buffers |
dev_alexander | 28:0ed92c590607 | 272 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 273 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 274 | uint8_t curr_MAX77650_from_slave[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 275 | uint8_t prev_MAX77650_from_slave[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 276 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 277 | uint8_t curr_MAX77650_to_master[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 278 | #endif |
dev_alexander | 28:0ed92c590607 | 279 | |
dev_alexander | 28:0ed92c590607 | 280 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 281 | * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send |
dev_alexander | 28:0ed92c590607 | 282 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 283 | SX1276PingPongSetup(BufferTx, BufferRx); |
dev_alexander | 28:0ed92c590607 | 284 | |
dev_alexander | 22:abca9d17d13d | 285 | while(1) |
dev_alexander | 28:0ed92c590607 | 286 | { |
dev_alexander | 23:f74a50977593 | 287 | /*************************************************************************** |
dev_alexander | 30:66f9750cc44c | 288 | * BLE Radio Data |
dev_alexander | 30:66f9750cc44c | 289 | **************************************************************************/ |
dev_alexander | 30:66f9750cc44c | 290 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 30:66f9750cc44c | 291 | #if defined(COMPILE_BLE) |
dev_alexander | 30:66f9750cc44c | 292 | ble.waitForEvent(); |
dev_alexander | 30:66f9750cc44c | 293 | #endif |
dev_alexander | 30:66f9750cc44c | 294 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 30:66f9750cc44c | 295 | // NOTHING YET |
dev_alexander | 30:66f9750cc44c | 296 | #endif |
dev_alexander | 30:66f9750cc44c | 297 | |
dev_alexander | 30:66f9750cc44c | 298 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 299 | * Grid Eye Sensor |
dev_alexander | 23:f74a50977593 | 300 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 301 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 302 | // Check to see if the contents of the previous scan are the same. If they are different then continue with converting |
dev_alexander | 28:0ed92c590607 | 303 | if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 ) |
dev_alexander | 27:6b549f838f0a | 304 | { |
dev_alexander | 23:f74a50977593 | 305 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 28:0ed92c590607 | 306 | convRaw8x8Data2Point25degC(curr_raw_frame_from_slave, conv_frame_from_slave); |
dev_alexander | 26:69aba05f010f | 307 | |
dev_alexander | 23:f74a50977593 | 308 | // Next Print off the Converted data |
dev_alexander | 26:69aba05f010f | 309 | pc.printf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 23:f74a50977593 | 310 | uint8_t idx; |
dev_alexander | 23:f74a50977593 | 311 | float pixel_data; |
dev_alexander | 23:f74a50977593 | 312 | for (int y = 0; y < 8; y++) { |
dev_alexander | 23:f74a50977593 | 313 | for (int x = 0; x < 8; x++) { |
dev_alexander | 23:f74a50977593 | 314 | idx = y*8 + x; |
dev_alexander | 28:0ed92c590607 | 315 | pixel_data = ((float)conv_frame_from_slave[idx])/4.0; |
dev_alexander | 26:69aba05f010f | 316 | pc.printf("%.2f \t", pixel_data); |
dev_alexander | 23:f74a50977593 | 317 | } |
dev_alexander | 26:69aba05f010f | 318 | pc.printf("\r\n\r\n"); |
dev_alexander | 23:f74a50977593 | 319 | } |
dev_alexander | 26:69aba05f010f | 320 | pc.printf("\r\n"); |
dev_alexander | 23:f74a50977593 | 321 | |
dev_alexander | 23:f74a50977593 | 322 | // Increment frame counter |
dev_alexander | 23:f74a50977593 | 323 | frame_idx = frame_idx +1; |
dev_alexander | 27:6b549f838f0a | 324 | } |
dev_alexander | 28:0ed92c590607 | 325 | |
dev_alexander | 25:1a031add188a | 326 | /* Next copy in data received from current data into buffer used for |
dev_alexander | 25:1a031add188a | 327 | * comparison next time the memcmp above is called. This prevents the |
dev_alexander | 25:1a031add188a | 328 | * program from converting the same raw data aquired by the grid eye |
dev_alexander | 25:1a031add188a | 329 | * sensor on the slave device to the floating point array with the |
dev_alexander | 25:1a031add188a | 330 | * 0.25 degrees celsius precision level when there is not new data. |
dev_alexander | 25:1a031add188a | 331 | */ |
dev_alexander | 28:0ed92c590607 | 332 | memcpy(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)); |
dev_alexander | 25:1a031add188a | 333 | |
dev_alexander | 24:e8d03912f303 | 334 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 335 | // Aquire raw data about 8x8 frame from the grid eye sensor in this function call |
dev_alexander | 28:0ed92c590607 | 336 | gridEye.getRaw8x8FrameData(curr_raw_frame_to_master); |
dev_alexander | 28:0ed92c590607 | 337 | wait_ms( 10 ); |
dev_alexander | 28:0ed92c590607 | 338 | /* |
dev_alexander | 28:0ed92c590607 | 339 | //if ( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 ) |
dev_alexander | 28:0ed92c590607 | 340 | //{ |
dev_alexander | 25:1a031add188a | 341 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 28:0ed92c590607 | 342 | convRaw8x8Data2Point25degC(curr_raw_frame_to_master, conv_frame_to_master); |
dev_alexander | 25:1a031add188a | 343 | |
dev_alexander | 25:1a031add188a | 344 | // Next Print off the Converted data |
dev_alexander | 25:1a031add188a | 345 | pc.printf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 25:1a031add188a | 346 | uint8_t idx; |
dev_alexander | 25:1a031add188a | 347 | float pixel_data; |
dev_alexander | 25:1a031add188a | 348 | for (int y = 0; y < 8; y++) { |
dev_alexander | 25:1a031add188a | 349 | for (int x = 0; x < 8; x++) { |
dev_alexander | 25:1a031add188a | 350 | idx = y*8 + x; |
dev_alexander | 28:0ed92c590607 | 351 | pixel_data = conv_frame_to_master[idx]/4.0; |
dev_alexander | 25:1a031add188a | 352 | pc.printf("%.2f \t", pixel_data); |
dev_alexander | 25:1a031add188a | 353 | } |
dev_alexander | 25:1a031add188a | 354 | pc.printf("\r\n\r\n"); |
dev_alexander | 25:1a031add188a | 355 | } |
dev_alexander | 25:1a031add188a | 356 | pc.printf("\r\n"); |
dev_alexander | 25:1a031add188a | 357 | |
dev_alexander | 25:1a031add188a | 358 | // Increment frame counter |
dev_alexander | 25:1a031add188a | 359 | frame_idx = frame_idx +1; |
dev_alexander | 28:0ed92c590607 | 360 | //} |
dev_alexander | 28:0ed92c590607 | 361 | */ |
dev_alexander | 28:0ed92c590607 | 362 | memcpy(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)); |
dev_alexander | 31:f15747cffb20 | 363 | #endif |
dev_alexander | 31:f15747cffb20 | 364 | |
dev_alexander | 31:f15747cffb20 | 365 | /*************************************************************************** |
dev_alexander | 31:f15747cffb20 | 366 | * GPS Sensor |
dev_alexander | 31:f15747cffb20 | 367 | **************************************************************************/ |
dev_alexander | 31:f15747cffb20 | 368 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 31:f15747cffb20 | 369 | //None yet |
dev_alexander | 31:f15747cffb20 | 370 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 31:f15747cffb20 | 371 | // The testing hasnt been done yet for the GPS Module. Will do this when more parts come in. |
dev_alexander | 31:f15747cffb20 | 372 | /* |
dev_alexander | 31:f15747cffb20 | 373 | if(gps.sample()){ |
dev_alexander | 31:f15747cffb20 | 374 | 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 | 375 | pc.printf("%d:%d:%d",gps.hour,gps.minute,gps.seconed); |
dev_alexander | 31:f15747cffb20 | 376 | } |
dev_alexander | 31:f15747cffb20 | 377 | */ |
dev_alexander | 31:f15747cffb20 | 378 | #endif |
dev_alexander | 28:0ed92c590607 | 379 | |
dev_alexander | 23:f74a50977593 | 380 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 381 | * Fill Payload Buffer With Data From Sensors for LoRa Transmition |
dev_alexander | 28:0ed92c590607 | 382 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 383 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 384 | memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature); |
dev_alexander | 28:0ed92c590607 | 385 | memcpy(&BufferTx[tx_idx_ble], curr_ble_to_slave, size_of_ble); |
dev_alexander | 28:0ed92c590607 | 386 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 387 | memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature); |
dev_alexander | 28:0ed92c590607 | 388 | memcpy(&BufferTx[tx_idx_grid_eye], curr_raw_frame_to_master, size_of_grid_eye); |
dev_alexander | 28:0ed92c590607 | 389 | memcpy(&BufferTx[tx_idx_gps], curr_gps_to_master, size_of_gps); |
dev_alexander | 28:0ed92c590607 | 390 | memcpy(&BufferTx[tx_idx_MAX17055], curr_MAX17055_to_master, size_of_MAX17055); |
dev_alexander | 28:0ed92c590607 | 391 | memcpy(&BufferTx[tx_idx_MAX77650], curr_MAX77650_to_master, size_of_MAX77650); |
dev_alexander | 28:0ed92c590607 | 392 | #endif |
dev_alexander | 28:0ed92c590607 | 393 | |
dev_alexander | 28:0ed92c590607 | 394 | |
dev_alexander | 28:0ed92c590607 | 395 | |
dev_alexander | 28:0ed92c590607 | 396 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 397 | * Lora Communications |
dev_alexander | 28:0ed92c590607 | 398 | **************************************************************************/ |
dev_alexander | 25:1a031add188a | 399 | wait_ms( 10 ); |
dev_alexander | 22:abca9d17d13d | 400 | SX1276PingPong(); |
dev_alexander | 28:0ed92c590607 | 401 | |
dev_alexander | 28:0ed92c590607 | 402 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 403 | * Fill Global Buffers With Data From Received Payload Buffer |
dev_alexander | 28:0ed92c590607 | 404 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 405 | /* The master and slave devices will have different requirements for offloading payload */ |
dev_alexander | 28:0ed92c590607 | 406 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 407 | memcpy(curr_raw_frame_from_slave, &BufferRx[rx_idx_grid_eye], size_of_grid_eye); |
dev_alexander | 28:0ed92c590607 | 408 | memcpy(curr_gps_from_slave, &BufferRx[rx_idx_gps], size_of_gps); |
dev_alexander | 28:0ed92c590607 | 409 | memcpy(curr_MAX17055_from_slave, &BufferRx[rx_idx_MAX17055], size_of_MAX17055); |
dev_alexander | 28:0ed92c590607 | 410 | memcpy(curr_MAX77650_from_slave, &BufferRx[rx_idx_MAX77650], size_of_MAX77650); |
dev_alexander | 28:0ed92c590607 | 411 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 412 | memcpy(curr_ble_from_master, &BufferRx[rx_idx_ble], size_of_ble); |
dev_alexander | 28:0ed92c590607 | 413 | #endif |
dev_alexander | 23:f74a50977593 | 414 | |
dev_alexander | 23:f74a50977593 | 415 | |
dev_alexander | 23:f74a50977593 | 416 | |
dev_alexander | 23:f74a50977593 | 417 | |
dev_alexander | 23:f74a50977593 | 418 | |
dev_alexander | 22:abca9d17d13d | 419 | } |
dev_alexander | 22:abca9d17d13d | 420 | |
Helmut64 | 0:c43b6919ae15 | 421 | } |