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:
Wed Aug 01 03:52:55 2018 +0000
Revision:
40:6f8744c366c2
Parent:
39:df7c8bd2212e
Child:
41:1381a49e019e
Removed conflict that prevented ble.waitForEvent from being compiled due to a #define that was removed in cleaning up the main.cpp

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 40:6f8744c366c2 11
dev_alexander 40:6f8744c366c2 12 /***************************************************************************
dev_alexander 40:6f8744c366c2 13 * Misc Instantiation
dev_alexander 40:6f8744c366c2 14 **************************************************************************/\
dev_alexander 40:6f8744c366c2 15 #include "mbed.h"
dev_alexander 30:66f9750cc44c 16 #include "main.h"
dev_alexander 30:66f9750cc44c 17 #include "global_buffers.h"
dev_alexander 35:bae9b236070b 18 //#define DEBUG_GRID_EYE
dev_alexander 32:b108ed6096b0 19 #define RASPBERRY_PI
dev_alexander 40:6f8744c366c2 20 DigitalOut myled(LED);
dev_alexander 40:6f8744c366c2 21 Serial pc(USBTX, USBRX);
dev_alexander 23:f74a50977593 22
dev_alexander 40:6f8744c366c2 23 I2C i2cBus0(P1_6, P1_7);
dev_alexander 40:6f8744c366c2 24 I2C i2cBus1(P3_4, P3_5);
dev_alexander 40:6f8744c366c2 25 I2C i2cBus2(P5_7, P6_0);
dev_alexander 32:b108ed6096b0 26
dev_alexander 40:6f8744c366c2 27 /***************************************************************************
dev_alexander 40:6f8744c366c2 28 * MAX32630FTHR Instantiation
dev_alexander 40:6f8744c366c2 29 **************************************************************************/
dev_alexander 40:6f8744c366c2 30 #if defined(TARGET_MAX32630FTHR)
dev_alexander 40:6f8744c366c2 31 /* If the board that is compiled is the master device (BLE enabled MAX32630FTHR),
dev_alexander 40:6f8744c366c2 32 * then it needs this library and needs to be configed in order for the device to
dev_alexander 40:6f8744c366c2 33 * work with a 3.3volt output instead of a 1.8 volt output.
dev_alexander 40:6f8744c366c2 34 *
dev_alexander 40:6f8744c366c2 35 * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this
dev_alexander 40:6f8744c366c2 36 * additional setup in the main program.
dev_alexander 40:6f8744c366c2 37 */
dev_alexander 40:6f8744c366c2 38 #include "max32630fthr.h"
dev_alexander 40:6f8744c366c2 39 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
dev_alexander 32:b108ed6096b0 40 #endif
dev_alexander 32:b108ed6096b0 41
dev_alexander 40:6f8744c366c2 42 /***************************************************************************
dev_alexander 40:6f8744c366c2 43 * MAX32620FTHR Instantiation
dev_alexander 40:6f8744c366c2 44 **************************************************************************/
dev_alexander 32:b108ed6096b0 45 #if defined(TARGET_MAX32620FTHR)
dev_alexander 32:b108ed6096b0 46
dev_alexander 29:f7a0e49b826b 47 #endif
Helmut64 0:c43b6919ae15 48
dev_alexander 31:f15747cffb20 49
dev_alexander 40:6f8744c366c2 50 /***************************************************************************
dev_alexander 40:6f8744c366c2 51 * Grid Eye Sensor Instantiation
dev_alexander 40:6f8744c366c2 52 **************************************************************************/
dev_alexander 40:6f8744c366c2 53 #include "GridEye.h"
Helmut64 0:c43b6919ae15 54
dev_alexander 23:f74a50977593 55 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 23:f74a50977593 56 /* No grid eye object needed. The function the master uses to convert the raw
dev_alexander 23:f74a50977593 57 * data that is sent over from the slave deevice that contains the data from the
dev_alexander 23:f74a50977593 58 * actual grid eye sensor is actually a function that is not part of the grid eye
dev_alexander 23:f74a50977593 59 * class. this is due to the fact that the grid eye class requires n i2c bus to
dev_alexander 23:f74a50977593 60 * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye
dev_alexander 32:b108ed6096b0 61 * sensor has a support function that is used to convert data that is aquired from
dev_alexander 23:f74a50977593 62 * the grid eye sensor. So it is not supposed to be a class specific function.
dev_alexander 40:6f8744c366c2 63 */
dev_alexander 40:6f8744c366c2 64 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 65 GridEye gridEye(i2cBus0);
dev_alexander 40:6f8744c366c2 66 #endif
dev_alexander 40:6f8744c366c2 67
dev_alexander 40:6f8744c366c2 68 /***************************************************************************
dev_alexander 40:6f8744c366c2 69 * GPS Instantiation
dev_alexander 40:6f8744c366c2 70 **************************************************************************/
dev_alexander 40:6f8744c366c2 71 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 72 // No GPS module on the master device
dev_alexander 40:6f8744c366c2 73 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 74 #include "GPS.h"
dev_alexander 40:6f8744c366c2 75 GPS gps(P0_1, P0_0, 115200); // (Tx, Rx, Baud rate)
dev_alexander 40:6f8744c366c2 76 #endif
dev_alexander 40:6f8744c366c2 77
dev_alexander 40:6f8744c366c2 78 /***************************************************************************
dev_alexander 40:6f8744c366c2 79 * MAX77650 Instatiation
dev_alexander 40:6f8744c366c2 80 **************************************************************************/
dev_alexander 40:6f8744c366c2 81 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 82 // No MAX77650 PMIC on this board
dev_alexander 40:6f8744c366c2 83 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 84 #include "max77650.h"
dev_alexander 40:6f8744c366c2 85
dev_alexander 40:6f8744c366c2 86 // Definitions for running board off of battery
dev_alexander 40:6f8744c366c2 87 #define POWER_HOLD_ON 1
dev_alexander 40:6f8744c366c2 88 #define POWER_HOLD_OFF 0
dev_alexander 40:6f8744c366c2 89
dev_alexander 40:6f8744c366c2 90 /* This is the pin that the MAX77650's Power Hold pin is connected to on MAX32620FTHR
dev_alexander 40:6f8744c366c2 91 * Without programming it to POWER_HOLD_ON, the device cant be started off of battery
dev_alexander 40:6f8744c366c2 92 * power alone.
dev_alexander 40:6f8744c366c2 93 */
dev_alexander 40:6f8744c366c2 94 DigitalOut pw_Hold(P2_2, POWER_HOLD_ON);
dev_alexander 40:6f8744c366c2 95
dev_alexander 40:6f8744c366c2 96 // Instatiate instance of the Simo Pimic
dev_alexander 40:6f8744c366c2 97 MAX77650 simo_pmic(i2cBus2);
dev_alexander 40:6f8744c366c2 98
dev_alexander 40:6f8744c366c2 99 // Battery Charger Interrupt
dev_alexander 40:6f8744c366c2 100 InterruptIn simoIRQ(P2_3);
dev_alexander 40:6f8744c366c2 101
dev_alexander 40:6f8744c366c2 102 void charger_Detect();
dev_alexander 40:6f8744c366c2 103 bool chrg_State_fn();
dev_alexander 40:6f8744c366c2 104
dev_alexander 40:6f8744c366c2 105 void charger_Detect()
dev_alexander 40:6f8744c366c2 106 {
dev_alexander 40:6f8744c366c2 107
dev_alexander 40:6f8744c366c2 108 uint8_t int_chr_value,temp, int_chr_MASK = 0x04;
dev_alexander 40:6f8744c366c2 109 int status;
dev_alexander 40:6f8744c366c2 110 pc.printf("Charger Detected \n");
dev_alexander 40:6f8744c366c2 111 status = simo_pmic.readReg(MAX77650::INT_CHG, int_chr_value);
dev_alexander 40:6f8744c366c2 112 pc.printf("INT_CHR val= %X \n", int_chr_value);
dev_alexander 40:6f8744c366c2 113 if (status == 1){
dev_alexander 40:6f8744c366c2 114 temp = int_chr_value & int_chr_MASK;
dev_alexander 40:6f8744c366c2 115 pc.printf("INT_CHR anded= %X \n", temp);
dev_alexander 40:6f8744c366c2 116 if (temp == 4){
dev_alexander 40:6f8744c366c2 117 pc.printf("enable charger \n");
dev_alexander 40:6f8744c366c2 118 simo_pmic.enCharger();
dev_alexander 40:6f8744c366c2 119 }
dev_alexander 40:6f8744c366c2 120 }
dev_alexander 40:6f8744c366c2 121 }
dev_alexander 40:6f8744c366c2 122
dev_alexander 40:6f8744c366c2 123 bool chrg_State_fn()
dev_alexander 40:6f8744c366c2 124 {
dev_alexander 40:6f8744c366c2 125 uint8_t status_chr_value,temp, chr_status_MASK = 0x02;
dev_alexander 40:6f8744c366c2 126 int status;
dev_alexander 40:6f8744c366c2 127 pc.printf("Charger State \n");
dev_alexander 40:6f8744c366c2 128 status = simo_pmic.readReg(MAX77650::STAT_CHG_B, status_chr_value);
dev_alexander 40:6f8744c366c2 129 pc.printf("STAR_CHG_B val= %X \n", status_chr_value);
dev_alexander 40:6f8744c366c2 130 if (status == 1){
dev_alexander 40:6f8744c366c2 131 temp = status_chr_value & chr_status_MASK;
dev_alexander 40:6f8744c366c2 132 pc.printf("STAR_CHG_B val= %X \n", temp);
dev_alexander 40:6f8744c366c2 133 if (temp == 2){
dev_alexander 40:6f8744c366c2 134 return true;
dev_alexander 40:6f8744c366c2 135 }
dev_alexander 40:6f8744c366c2 136 return false;
dev_alexander 40:6f8744c366c2 137 }
dev_alexander 40:6f8744c366c2 138 return false;
dev_alexander 40:6f8744c366c2 139 }
dev_alexander 40:6f8744c366c2 140
dev_alexander 40:6f8744c366c2 141 #endif
dev_alexander 40:6f8744c366c2 142
dev_alexander 40:6f8744c366c2 143
dev_alexander 40:6f8744c366c2 144 /***************************************************************************
dev_alexander 40:6f8744c366c2 145 * MAX17055 Instatiation
dev_alexander 40:6f8744c366c2 146 **************************************************************************/
dev_alexander 40:6f8744c366c2 147 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 148 // No MAX77650 PMIC on this board
dev_alexander 40:6f8744c366c2 149 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 150 #include "max17055.h"
dev_alexander 40:6f8744c366c2 151
dev_alexander 40:6f8744c366c2 152 MAX17055 fuelGauge(i2cBus2);
dev_alexander 40:6f8744c366c2 153 MAX17055::platform_data design_param;
dev_alexander 40:6f8744c366c2 154
dev_alexander 40:6f8744c366c2 155 #endif
dev_alexander 40:6f8744c366c2 156
dev_alexander 40:6f8744c366c2 157
dev_alexander 40:6f8744c366c2 158 /***************************************************************************
dev_alexander 40:6f8744c366c2 159 * OLED Instatiation
dev_alexander 40:6f8744c366c2 160 **************************************************************************/
dev_alexander 40:6f8744c366c2 161 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 162 #include "Adafruit_SSD1306.h"
dev_alexander 40:6f8744c366c2 163 #include "maxim_bitmap.h"
dev_alexander 40:6f8744c366c2 164 Adafruit_SSD1306_I2c displayOled(i2cBus1);
dev_alexander 40:6f8744c366c2 165
dev_alexander 40:6f8744c366c2 166
dev_alexander 32:b108ed6096b0 167 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 168 /* Currently, there is no OLED display attached to the MAX32620,
dev_alexander 40:6f8744c366c2 169 * so we are not compiling for it at the moment
dev_alexander 40:6f8744c366c2 170 */
dev_alexander 40:6f8744c366c2 171 #endif
dev_alexander 40:6f8744c366c2 172
dev_alexander 40:6f8744c366c2 173
dev_alexander 40:6f8744c366c2 174 /***************************************************************************
dev_alexander 40:6f8744c366c2 175 * BLE Instatiation and Related Functions
dev_alexander 40:6f8744c366c2 176 **************************************************************************/
dev_alexander 40:6f8744c366c2 177 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 178 #include "ble/BLE.h"
dev_alexander 40:6f8744c366c2 179 //#include "ble/Gap.h"
dev_alexander 40:6f8744c366c2 180 #include "UARTService_custom.h"
dev_alexander 40:6f8744c366c2 181 #include <events/mbed_events.h>
dev_alexander 40:6f8744c366c2 182
dev_alexander 40:6f8744c366c2 183 DigitalOut led2(LED2);
dev_alexander 40:6f8744c366c2 184 UARTService *uart;
dev_alexander 40:6f8744c366c2 185
dev_alexander 40:6f8744c366c2 186 #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
dev_alexander 40:6f8744c366c2 187 * it will have an impact on code-size and power consumption. */
dev_alexander 40:6f8744c366c2 188
dev_alexander 40:6f8744c366c2 189 #if NEED_CONSOLE_OUTPUT
dev_alexander 40:6f8744c366c2 190 #define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); }
dev_alexander 40:6f8744c366c2 191 #define READ(STR) { if (uart) uart->read(STR, strlen(STR)); }
dev_alexander 40:6f8744c366c2 192
dev_alexander 40:6f8744c366c2 193 #else
dev_alexander 40:6f8744c366c2 194 #define DEBUG(...) /* nothing */
dev_alexander 40:6f8744c366c2 195 #endif /* #if NEED_CONSOLE_OUTPUT */
dev_alexander 40:6f8744c366c2 196
dev_alexander 40:6f8744c366c2 197 //Triggered when the robot is disconnected from the mobile app.
dev_alexander 40:6f8744c366c2 198 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
dev_alexander 40:6f8744c366c2 199 {
dev_alexander 40:6f8744c366c2 200 BLE &ble = BLE::Instance();
dev_alexander 40:6f8744c366c2 201 DEBUG("Disconnected!\n\r");
dev_alexander 40:6f8744c366c2 202 DEBUG("Restarting the advertising process\n\r");
dev_alexander 40:6f8744c366c2 203 ble.gap().startAdvertising();
dev_alexander 40:6f8744c366c2 204 }
dev_alexander 40:6f8744c366c2 205
dev_alexander 40:6f8744c366c2 206 /* This pointer is needed to reference data in the main program when filling
dev_alexander 40:6f8744c366c2 207 * with data from the BLE
dev_alexander 40:6f8744c366c2 208 */
dev_alexander 40:6f8744c366c2 209 uint8_t * onDataWritten_curr_ble_to_slave;
dev_alexander 40:6f8744c366c2 210
dev_alexander 40:6f8744c366c2 211 // Triggered when there is data written
dev_alexander 40:6f8744c366c2 212 void onDataWritten(const GattWriteCallbackParams *params)
dev_alexander 40:6f8744c366c2 213 {
dev_alexander 40:6f8744c366c2 214 //LED1 will be off when button is pressed, and on when button is released.
dev_alexander 40:6f8744c366c2 215 led2 = !led2;
dev_alexander 40:6f8744c366c2 216 uint8_t button_state;
dev_alexander 40:6f8744c366c2 217 uint8_t direction;
dev_alexander 40:6f8744c366c2 218
dev_alexander 40:6f8744c366c2 219 /* If there is a valid data sent by the mobile app */
dev_alexander 40:6f8744c366c2 220 if ((uart != NULL) && (params->handle == uart ->getTXCharacteristicHandle())) {
dev_alexander 40:6f8744c366c2 221 const uint8_t *packet = params->data;
dev_alexander 40:6f8744c366c2 222 button_state = packet[3];
dev_alexander 40:6f8744c366c2 223 direction = packet[2];
dev_alexander 40:6f8744c366c2 224
dev_alexander 40:6f8744c366c2 225 // make parameter to send over Lora
dev_alexander 40:6f8744c366c2 226 onDataWritten_curr_ble_to_slave[0] = direction;
dev_alexander 40:6f8744c366c2 227 onDataWritten_curr_ble_to_slave[1] = button_state;
dev_alexander 40:6f8744c366c2 228
dev_alexander 40:6f8744c366c2 229 //dprintf("direction: %d\n", direction);
dev_alexander 40:6f8744c366c2 230 //dprintf("button_state: %d\n", button_state);
dev_alexander 40:6f8744c366c2 231 }
dev_alexander 40:6f8744c366c2 232 }
dev_alexander 40:6f8744c366c2 233 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 234 // No BLE chip on the MAX32620FTHR so this is not needed
dev_alexander 23:f74a50977593 235 #endif
dev_alexander 40:6f8744c366c2 236
dev_alexander 40:6f8744c366c2 237 /***************************************************************************
dev_alexander 40:6f8744c366c2 238 * Motor Controller Instatiation and Related Functions
dev_alexander 40:6f8744c366c2 239 **************************************************************************/
dev_alexander 40:6f8744c366c2 240 #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 241 // There is no motor on this device.
dev_alexander 40:6f8744c366c2 242 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 243 /* This is a port of a library that was developed by Adafruit for the Arduino.
dev_alexander 40:6f8744c366c2 244 * This port was done by mbed user syundo0730. */
dev_alexander 40:6f8744c366c2 245 #include "Adafruit_MotorShield.h"
dev_alexander 40:6f8744c366c2 246 #include "Adafruit_PWMServoDriver.h"
dev_alexander 40:6f8744c366c2 247
dev_alexander 40:6f8744c366c2 248 // These are the defined speeds that are selected out of the number range (0, 255).
dev_alexander 40:6f8744c366c2 249 #define MOTOR_OFF 0
dev_alexander 40:6f8744c366c2 250 #define MOTOR_FORWARD 150
dev_alexander 40:6f8744c366c2 251 #define MOTOR_BACKWARD 150
dev_alexander 40:6f8744c366c2 252 #define MOTOR_TURN 100
dev_alexander 40:6f8744c366c2 253
dev_alexander 40:6f8744c366c2 254 // Create the motor shield object with the default I2C address
dev_alexander 40:6f8744c366c2 255 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 40:6f8744c366c2 256 // Or, create it with a different I2C address (say for stacking)
dev_alexander 40:6f8744c366c2 257 // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
dev_alexander 40:6f8744c366c2 258 // Select which 'port' M1, M2, M3 or M4. In this case, M1
dev_alexander 40:6f8744c366c2 259 Adafruit_DCMotor *rightMotor = AFMS.getMotor(1);
dev_alexander 40:6f8744c366c2 260 // You can also make another motor on port M4
dev_alexander 40:6f8744c366c2 261 Adafruit_DCMotor *leftMotor = AFMS.getMotor(4);
dev_alexander 40:6f8744c366c2 262
dev_alexander 40:6f8744c366c2 263
dev_alexander 40:6f8744c366c2 264 void MotorController(uint8_t (BLE_data_server)[2])
dev_alexander 40:6f8744c366c2 265 {
dev_alexander 40:6f8744c366c2 266 uint8_t button_state;
dev_alexander 40:6f8744c366c2 267 uint8_t direction;
dev_alexander 40:6f8744c366c2 268 /*Set up constants for direction of motion */
dev_alexander 40:6f8744c366c2 269 const char FRONT = '5';
dev_alexander 40:6f8744c366c2 270 const char BACK = '6';
dev_alexander 40:6f8744c366c2 271 const char LEFT = '7';
dev_alexander 40:6f8744c366c2 272 const char RIGHT = '8';
dev_alexander 40:6f8744c366c2 273
dev_alexander 40:6f8744c366c2 274 /*Set up constants for button state */
dev_alexander 40:6f8744c366c2 275 const char PRESSED = '1';
dev_alexander 40:6f8744c366c2 276 const char RELEASED = '0';
dev_alexander 40:6f8744c366c2 277
dev_alexander 40:6f8744c366c2 278
dev_alexander 40:6f8744c366c2 279 button_state = BLE_data_server[1];
dev_alexander 40:6f8744c366c2 280 direction = BLE_data_server[0];
dev_alexander 40:6f8744c366c2 281
dev_alexander 40:6f8744c366c2 282 switch (button_state)
dev_alexander 40:6f8744c366c2 283 {
dev_alexander 40:6f8744c366c2 284 case PRESSED:
dev_alexander 40:6f8744c366c2 285 switch (direction)
dev_alexander 40:6f8744c366c2 286 {
dev_alexander 40:6f8744c366c2 287 case FRONT:
dev_alexander 40:6f8744c366c2 288 rightMotor->run(FORWARD);
dev_alexander 40:6f8744c366c2 289 leftMotor->run(FORWARD);
dev_alexander 40:6f8744c366c2 290 rightMotor->setSpeed(MOTOR_FORWARD);
dev_alexander 40:6f8744c366c2 291 leftMotor->setSpeed(MOTOR_FORWARD);
dev_alexander 40:6f8744c366c2 292 break;
dev_alexander 40:6f8744c366c2 293 case BACK:
dev_alexander 40:6f8744c366c2 294 rightMotor->run(BACKWARD);
dev_alexander 40:6f8744c366c2 295 leftMotor->run(BACKWARD);
dev_alexander 40:6f8744c366c2 296 rightMotor->setSpeed(MOTOR_BACKWARD);
dev_alexander 40:6f8744c366c2 297 leftMotor->setSpeed(MOTOR_BACKWARD);
dev_alexander 40:6f8744c366c2 298 break;
dev_alexander 40:6f8744c366c2 299 case LEFT:
dev_alexander 40:6f8744c366c2 300 rightMotor->run(FORWARD);
dev_alexander 40:6f8744c366c2 301 leftMotor->run(BACKWARD);
dev_alexander 40:6f8744c366c2 302 rightMotor->setSpeed(MOTOR_TURN);
dev_alexander 40:6f8744c366c2 303 leftMotor->setSpeed(MOTOR_TURN);
dev_alexander 40:6f8744c366c2 304 break;
dev_alexander 40:6f8744c366c2 305 case RIGHT:
dev_alexander 40:6f8744c366c2 306 rightMotor->run(BACKWARD);
dev_alexander 40:6f8744c366c2 307 leftMotor->run(FORWARD);
dev_alexander 40:6f8744c366c2 308 rightMotor->setSpeed(MOTOR_TURN);
dev_alexander 40:6f8744c366c2 309 leftMotor->setSpeed(MOTOR_TURN);
dev_alexander 40:6f8744c366c2 310 break;
dev_alexander 40:6f8744c366c2 311 }
dev_alexander 40:6f8744c366c2 312 break;
dev_alexander 40:6f8744c366c2 313 case RELEASED:
dev_alexander 40:6f8744c366c2 314 rightMotor->setSpeed(MOTOR_OFF);
dev_alexander 40:6f8744c366c2 315 leftMotor->setSpeed(MOTOR_OFF);
dev_alexander 40:6f8744c366c2 316 break;
dev_alexander 40:6f8744c366c2 317 }
dev_alexander 40:6f8744c366c2 318 }
dev_alexander 40:6f8744c366c2 319 #endif
dev_alexander 40:6f8744c366c2 320
dev_alexander 40:6f8744c366c2 321
dev_alexander 40:6f8744c366c2 322
dev_alexander 40:6f8744c366c2 323
dev_alexander 40:6f8744c366c2 324
dev_alexander 19:9f035b9e65ec 325
dev_alexander 23:f74a50977593 326 int main()
dev_alexander 23:f74a50977593 327 {
dev_alexander 32:b108ed6096b0 328 /* Setup begins here: */
dev_alexander 32:b108ed6096b0 329 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 330 dprintf("MAX32630FTHR: Master");
dev_alexander 32:b108ed6096b0 331 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 332 dprintf("MAX32620FTHR: Slave");
dev_alexander 32:b108ed6096b0 333 #endif
dev_alexander 32:b108ed6096b0 334
dev_alexander 32:b108ed6096b0 335
dev_alexander 32:b108ed6096b0 336 #if defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 337 //Set Power Hold High for battery operation MAX77650 on MAX32620FTHR
dev_alexander 32:b108ed6096b0 338 pw_Hold = POWER_HOLD_ON;
dev_alexander 32:b108ed6096b0 339 #endif
dev_alexander 32:b108ed6096b0 340
Helmut64 17:98f2528e8399 341 /*
Helmut64 17:98f2528e8399 342 * inits the Serial or USBSerial when available (230400 baud).
Helmut64 17:98f2528e8399 343 * If the serial uart is not is not connected it swiches to USB Serial
Helmut64 17:98f2528e8399 344 * blinking LED means USBSerial detected, waiting for a connect.
Helmut64 17:98f2528e8399 345 * It waits up to 30 seconds for a USB terminal connections
Helmut64 17:98f2528e8399 346 */
Helmut64 17:98f2528e8399 347 InitSerial(30*1000, &myled);
Helmut64 17:98f2528e8399 348 dprintf("Welcome to the SX1276GenericLib");
Helmut64 18:d5527ce82e6b 349
Helmut64 17:98f2528e8399 350 dprintf("Starting a simple LoRa PingPong");
dev_alexander 23:f74a50977593 351
dev_alexander 32:b108ed6096b0 352
dev_alexander 26:69aba05f010f 353
dev_alexander 23:f74a50977593 354
dev_alexander 23:f74a50977593 355 /***************************************************************************
dev_alexander 23:f74a50977593 356 * Grid Eye Sensor: Non-Buffer Program Variables
dev_alexander 23:f74a50977593 357 **************************************************************************/
dev_alexander 23:f74a50977593 358 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 23:f74a50977593 359 int frame_idx = 0;
dev_alexander 24:e8d03912f303 360 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 361 #if defined(DEBUG_GRID_EYE_SLAVE)
dev_alexander 32:b108ed6096b0 362 int frame_idx = 0;
dev_alexander 32:b108ed6096b0 363 #endif
dev_alexander 23:f74a50977593 364 #endif
dev_alexander 23:f74a50977593 365
dev_alexander 23:f74a50977593 366
dev_alexander 28:0ed92c590607 367 /***************************************************************************
dev_alexander 28:0ed92c590607 368 * Combined Payload Buffers for LoRa Communications
dev_alexander 28:0ed92c590607 369 **************************************************************************/
dev_alexander 28:0ed92c590607 370 uint8_t BufferTx[BufferSizeTx];
dev_alexander 28:0ed92c590607 371 uint8_t BufferRx[BufferSizeRx];
dev_alexander 28:0ed92c590607 372
dev_alexander 28:0ed92c590607 373 /***************************************************************************
dev_alexander 32:b108ed6096b0 374 * Identification Buffers
dev_alexander 32:b108ed6096b0 375 **************************************************************************/
dev_alexander 32:b108ed6096b0 376 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 377 uint8_t ID_of_slave[size_signature];
dev_alexander 32:b108ed6096b0 378 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 379 uint8_t ID_of_master[size_signature];
dev_alexander 32:b108ed6096b0 380 #endif
dev_alexander 32:b108ed6096b0 381
dev_alexander 32:b108ed6096b0 382 /***************************************************************************
dev_alexander 28:0ed92c590607 383 * BLE Data Buffers
dev_alexander 28:0ed92c590607 384 **************************************************************************/
dev_alexander 28:0ed92c590607 385 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 31:f15747cffb20 386 uint8_t curr_ble_to_slave[size_of_ble];
dev_alexander 28:0ed92c590607 387 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 388 uint8_t curr_ble_from_master[size_of_ble];
dev_alexander 28:0ed92c590607 389 uint8_t prev_ble_from_master[size_of_ble];
dev_alexander 28:0ed92c590607 390 #endif
dev_alexander 28:0ed92c590607 391
dev_alexander 28:0ed92c590607 392 /***************************************************************************
dev_alexander 28:0ed92c590607 393 * Grid Eye Sensor Data Buffers
dev_alexander 28:0ed92c590607 394 **************************************************************************/
dev_alexander 28:0ed92c590607 395 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 396 char curr_raw_frame_from_slave[size_of_grid_eye];
dev_alexander 28:0ed92c590607 397 char prev_raw_frame_from_slave[size_of_grid_eye];
dev_alexander 28:0ed92c590607 398 int16_t conv_frame_from_slave[64];
dev_alexander 28:0ed92c590607 399 #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 400 char curr_raw_frame_to_master[size_of_grid_eye];
dev_alexander 28:0ed92c590607 401 char prev_raw_frame_to_master[size_of_grid_eye];
dev_alexander 28:0ed92c590607 402 int16_t conv_frame_to_master[64];
dev_alexander 28:0ed92c590607 403 #endif
dev_alexander 28:0ed92c590607 404
dev_alexander 28:0ed92c590607 405 /***************************************************************************
dev_alexander 28:0ed92c590607 406 * GPS Data Buffers
dev_alexander 28:0ed92c590607 407 **************************************************************************/
dev_alexander 28:0ed92c590607 408 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 409 uint8_t curr_gps_from_slave[size_of_gps];
dev_alexander 28:0ed92c590607 410 uint8_t prev_gps_from_slave[size_of_gps];
dev_alexander 28:0ed92c590607 411 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 412 uint8_t curr_gps_to_master[size_of_gps];
dev_alexander 28:0ed92c590607 413 #endif
dev_alexander 28:0ed92c590607 414
dev_alexander 28:0ed92c590607 415 /***************************************************************************
dev_alexander 28:0ed92c590607 416 * MAX17055 Data Buffers
dev_alexander 28:0ed92c590607 417 **************************************************************************/
dev_alexander 28:0ed92c590607 418 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 419 uint8_t curr_MAX17055_from_slave[size_of_MAX17055];
dev_alexander 28:0ed92c590607 420 uint8_t prev_MAX17055_from_slave[size_of_MAX17055];
dev_alexander 40:6f8744c366c2 421
dev_alexander 28:0ed92c590607 422 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 423 uint8_t curr_MAX17055_to_master[size_of_MAX17055];
dev_alexander 28:0ed92c590607 424 #endif
dev_alexander 28:0ed92c590607 425
dev_alexander 28:0ed92c590607 426 /***************************************************************************
dev_alexander 28:0ed92c590607 427 * MAX77650 Data Buffers
dev_alexander 28:0ed92c590607 428 **************************************************************************/
dev_alexander 28:0ed92c590607 429 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 430 uint8_t curr_MAX77650_from_slave[size_of_MAX77650];
dev_alexander 28:0ed92c590607 431 uint8_t prev_MAX77650_from_slave[size_of_MAX77650];
dev_alexander 28:0ed92c590607 432 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 433 uint8_t curr_MAX77650_to_master[size_of_MAX77650];
dev_alexander 28:0ed92c590607 434 #endif
dev_alexander 40:6f8744c366c2 435
dev_alexander 28:0ed92c590607 436
dev_alexander 28:0ed92c590607 437 /***************************************************************************
dev_alexander 28:0ed92c590607 438 * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send
dev_alexander 28:0ed92c590607 439 **************************************************************************/
dev_alexander 28:0ed92c590607 440 SX1276PingPongSetup(BufferTx, BufferRx);
dev_alexander 28:0ed92c590607 441
dev_alexander 32:b108ed6096b0 442 /***************************************************************************
dev_alexander 32:b108ed6096b0 443 * Finish Setting up BLE Radio on the MAX32630FTHR: Only on the Master Device
dev_alexander 32:b108ed6096b0 444 **************************************************************************/
dev_alexander 32:b108ed6096b0 445 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 446 BLE &ble = BLE::Instance();
dev_alexander 32:b108ed6096b0 447 /* Create alias for the BLE data to be saved in function above that
dev_alexander 32:b108ed6096b0 448 * writes data to this buffer when function onDataWritten is called
dev_alexander 32:b108ed6096b0 449 */
dev_alexander 32:b108ed6096b0 450 onDataWritten_curr_ble_to_slave = curr_ble_to_slave;
dev_alexander 32:b108ed6096b0 451
dev_alexander 32:b108ed6096b0 452 /* Initialize BLE */
dev_alexander 32:b108ed6096b0 453 ble.init();
dev_alexander 32:b108ed6096b0 454 ble.gap().onDisconnection(disconnectionCallback);
dev_alexander 32:b108ed6096b0 455 ble.gattServer().onDataWritten(onDataWritten);
dev_alexander 32:b108ed6096b0 456 uart = new UARTService(ble);
dev_alexander 32:b108ed6096b0 457 /* setup advertising */
dev_alexander 32:b108ed6096b0 458 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
dev_alexander 32:b108ed6096b0 459 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
dev_alexander 32:b108ed6096b0 460 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
dev_alexander 32:b108ed6096b0 461 (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
dev_alexander 32:b108ed6096b0 462 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
dev_alexander 32:b108ed6096b0 463 (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
dev_alexander 32:b108ed6096b0 464 ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
dev_alexander 32:b108ed6096b0 465 ble.gap().startAdvertising();
dev_alexander 32:b108ed6096b0 466 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 467 /* There is no BLE device that is integrated into the MAX32620FTHR. Also
dev_alexander 32:b108ed6096b0 468 * Also this program is meant to use the BLE gateway on the MAX32630FTHR
dev_alexander 32:b108ed6096b0 469 */
dev_alexander 32:b108ed6096b0 470 #endif
dev_alexander 32:b108ed6096b0 471
dev_alexander 32:b108ed6096b0 472 /***************************************************************************
dev_alexander 40:6f8744c366c2 473 * Finish Setting up the MAX77650 on the MAX32620FTHR: Only on the Slave Device
dev_alexander 40:6f8744c366c2 474 **************************************************************************/
dev_alexander 40:6f8744c366c2 475 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 476 // No MAX77650 on the MAX32630FTHR
dev_alexander 40:6f8744c366c2 477 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 478 //Set Power Hold High for battery operation MAX77650 on MAX32620FTHR
dev_alexander 40:6f8744c366c2 479 pw_Hold = POWER_HOLD_ON;
dev_alexander 40:6f8744c366c2 480 //Simo Pmic MAX77650 init
dev_alexander 40:6f8744c366c2 481 simo_pmic.initCharger();
dev_alexander 40:6f8744c366c2 482 simoIRQ.fall( &charger_Detect );
dev_alexander 40:6f8744c366c2 483 simo_pmic.enCharger();
dev_alexander 40:6f8744c366c2 484 bool chrg_status; //True = ON False = OFF
dev_alexander 40:6f8744c366c2 485 #endif
dev_alexander 40:6f8744c366c2 486 /***************************************************************************
dev_alexander 40:6f8744c366c2 487 * Finish Setting up the MAX17650 on the MAX32620FTHR: Only on the Slave Device
dev_alexander 40:6f8744c366c2 488 **************************************************************************/
dev_alexander 40:6f8744c366c2 489 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 490 // No MAX17055 on the MAX32630FTHR
dev_alexander 40:6f8744c366c2 491 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 492 //rsense 5mOhm for MAX32620FTHR
dev_alexander 40:6f8744c366c2 493 design_param.designcap = 0x0069; //Design Battery Capacity mAh
dev_alexander 40:6f8744c366c2 494 design_param.ichgterm = 0x0016; // Charge Termination Current for the Battery
dev_alexander 40:6f8744c366c2 495 design_param.vempty = 0x9B00; // Battery Empty Voltage
dev_alexander 40:6f8744c366c2 496 design_param.vcharge = 4200; // Battery Charge Voltage can be obtained from MAX77650 configuration
dev_alexander 40:6f8744c366c2 497 design_param.rsense = 5; //5mOhms
dev_alexander 40:6f8744c366c2 498
dev_alexander 40:6f8744c366c2 499 int soc_FG, tte_FG, ttf_FG, curr_FG,volt_FG, status, alsValue, proxValue;
dev_alexander 40:6f8744c366c2 500 int oper_f1, volt_mod_FG;
dev_alexander 40:6f8744c366c2 501 int alsCAL; //Variables
dev_alexander 40:6f8744c366c2 502 uint8_t prox_data;
dev_alexander 40:6f8744c366c2 503 uint8_t proxCAL; //Prox Sensor
dev_alexander 40:6f8744c366c2 504 int sensor_Case_value;
dev_alexander 40:6f8744c366c2 505 //serial.printf("Test Init and Temp Functions \r\n");
dev_alexander 40:6f8744c366c2 506 //status = fuelGauge.forcedExitHyberMode();
dev_alexander 40:6f8744c366c2 507 status = fuelGauge.init(design_param);
dev_alexander 40:6f8744c366c2 508 pc.printf("Init FuelGauge Function Status= %X \r\n",status);
dev_alexander 40:6f8744c366c2 509 #endif
dev_alexander 40:6f8744c366c2 510
dev_alexander 40:6f8744c366c2 511 /***************************************************************************
dev_alexander 40:6f8744c366c2 512 * Finish Setting up the SSD1306 OLED on the MAX32630FTHR: Only on the Master Device
dev_alexander 40:6f8744c366c2 513 **************************************************************************/
dev_alexander 40:6f8744c366c2 514 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 40:6f8744c366c2 515 displayOled.setTextColor(1);
dev_alexander 40:6f8744c366c2 516 displayOled.setTextSize(1);
dev_alexander 40:6f8744c366c2 517 displayOled.setTextWrap(false);
dev_alexander 40:6f8744c366c2 518
dev_alexander 40:6f8744c366c2 519 displayOled.clearDisplay();
dev_alexander 40:6f8744c366c2 520 displayOled.printf("%ux%u OLED Display\r\n", displayOled.width(), displayOled.height());
dev_alexander 40:6f8744c366c2 521 //displayOled.drawBitmap(0,0,maximLarge,128,32,1);
dev_alexander 40:6f8744c366c2 522 displayOled.display();
dev_alexander 40:6f8744c366c2 523 displayOled.display();
dev_alexander 40:6f8744c366c2 524 wait(1.0);
dev_alexander 40:6f8744c366c2 525
dev_alexander 40:6f8744c366c2 526 displayOled.startscrollright(0x00, 0x0F);
dev_alexander 40:6f8744c366c2 527 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 40:6f8744c366c2 528 // No oled on the MAX32620FTHR
dev_alexander 40:6f8744c366c2 529 #endif
dev_alexander 40:6f8744c366c2 530
dev_alexander 40:6f8744c366c2 531 /***************************************************************************
dev_alexander 32:b108ed6096b0 532 * Finish Setting up the motor controller on the MAX32620FTHR: Only on the Slave Device
dev_alexander 32:b108ed6096b0 533 **************************************************************************/
dev_alexander 32:b108ed6096b0 534 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 535 // No setup on the master device
dev_alexander 32:b108ed6096b0 536 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 537 AFMS.begin(); // create with the default frequency 1.6KHz
dev_alexander 32:b108ed6096b0 538 //AFMS.begin(1000); // OR with a different frequency, say 1KHz
dev_alexander 32:b108ed6096b0 539
dev_alexander 32:b108ed6096b0 540 // Set the speed to start, from 0 (off) to 255 (max speed)
dev_alexander 32:b108ed6096b0 541 rightMotor->setSpeed(150);
dev_alexander 32:b108ed6096b0 542 rightMotor->run(FORWARD);
dev_alexander 32:b108ed6096b0 543 // turn on motor
dev_alexander 32:b108ed6096b0 544 rightMotor->run(RELEASE);
dev_alexander 32:b108ed6096b0 545
dev_alexander 32:b108ed6096b0 546 leftMotor->setSpeed(150);
dev_alexander 32:b108ed6096b0 547 leftMotor->run(FORWARD);
dev_alexander 32:b108ed6096b0 548 // turn on motor
dev_alexander 32:b108ed6096b0 549 leftMotor->run(RELEASE);
dev_alexander 32:b108ed6096b0 550 #endif
dev_alexander 32:b108ed6096b0 551
dev_alexander 32:b108ed6096b0 552
dev_alexander 22:abca9d17d13d 553 while(1)
dev_alexander 40:6f8744c366c2 554 {
dev_alexander 23:f74a50977593 555 /***************************************************************************
dev_alexander 30:66f9750cc44c 556 * BLE Radio Data
dev_alexander 30:66f9750cc44c 557 **************************************************************************/
dev_alexander 30:66f9750cc44c 558 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 30:66f9750cc44c 559 ble.waitForEvent();
dev_alexander 30:66f9750cc44c 560 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 561 memcpy(curr_ble_from_master, prev_ble_from_master, sizeof(curr_ble_from_master));
dev_alexander 30:66f9750cc44c 562 #endif
dev_alexander 30:66f9750cc44c 563
dev_alexander 30:66f9750cc44c 564 /***************************************************************************
dev_alexander 23:f74a50977593 565 * Grid Eye Sensor
dev_alexander 23:f74a50977593 566 **************************************************************************/
dev_alexander 23:f74a50977593 567 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 568 // 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 569 #if defined(RASPBERRY_PI)
dev_alexander 32:b108ed6096b0 570 if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 )
dev_alexander 32:b108ed6096b0 571 {
dev_alexander 32:b108ed6096b0 572 char grid_eye_msg[130];
dev_alexander 32:b108ed6096b0 573 grid_eye_msg[0]=0x55;
dev_alexander 32:b108ed6096b0 574 grid_eye_msg[1]=0xaa;
dev_alexander 32:b108ed6096b0 575 for (int idx = 0; idx < 128; idx++)
dev_alexander 32:b108ed6096b0 576 grid_eye_msg[idx+2] = curr_raw_frame_from_slave[idx];
dev_alexander 32:b108ed6096b0 577 //pc.printf(grid_eye_msg);
dev_alexander 32:b108ed6096b0 578 for (int idx = 0; idx < 130; idx++)
dev_alexander 32:b108ed6096b0 579 pc.putc(grid_eye_msg[idx]);
dev_alexander 35:bae9b236070b 580 pc.printf("\r\n"); // seperate the lines
dev_alexander 32:b108ed6096b0 581 }
dev_alexander 35:bae9b236070b 582 #endif
dev_alexander 35:bae9b236070b 583 #if defined(DEBUG_GRID_EYE)
dev_alexander 32:b108ed6096b0 584 if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 )
dev_alexander 32:b108ed6096b0 585 {
dev_alexander 32:b108ed6096b0 586 // Convert raw data sent from slave to a 16 bit integer array by calling this
dev_alexander 32:b108ed6096b0 587 convRaw8x8Data2Point25degC(curr_raw_frame_from_slave, conv_frame_from_slave);
dev_alexander 32:b108ed6096b0 588
dev_alexander 32:b108ed6096b0 589 // Next Print off the Converted data
dev_alexander 32:b108ed6096b0 590 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
dev_alexander 32:b108ed6096b0 591 uint8_t idx;
dev_alexander 32:b108ed6096b0 592 float pixel_data;
dev_alexander 32:b108ed6096b0 593 for (int y = 0; y < 8; y++) {
dev_alexander 32:b108ed6096b0 594 for (int x = 0; x < 8; x++) {
dev_alexander 32:b108ed6096b0 595 idx = y*8 + x;
dev_alexander 32:b108ed6096b0 596 pixel_data = ((float)conv_frame_from_slave[idx])/4.0;
dev_alexander 32:b108ed6096b0 597 pc.printf("%.2f \t", pixel_data);
dev_alexander 32:b108ed6096b0 598 }
dev_alexander 32:b108ed6096b0 599 pc.printf("\r\n\r\n");
dev_alexander 23:f74a50977593 600 }
dev_alexander 32:b108ed6096b0 601 pc.printf("\r\n");
dev_alexander 32:b108ed6096b0 602
dev_alexander 32:b108ed6096b0 603 // Increment frame counter
dev_alexander 32:b108ed6096b0 604 frame_idx = frame_idx +1;
dev_alexander 23:f74a50977593 605 }
dev_alexander 32:b108ed6096b0 606 #endif
dev_alexander 32:b108ed6096b0 607 /* Next copy in data received from current data into buffer used for
dev_alexander 32:b108ed6096b0 608 * comparison next time the memcmp above is called. This prevents the
dev_alexander 32:b108ed6096b0 609 * program from converting the same raw data aquired by the grid eye
dev_alexander 32:b108ed6096b0 610 * sensor on the slave device to the floating point array with the
dev_alexander 32:b108ed6096b0 611 * 0.25 degrees celsius precision level when there is not new data.
dev_alexander 32:b108ed6096b0 612 */
dev_alexander 32:b108ed6096b0 613
dev_alexander 28:0ed92c590607 614 memcpy(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave));
dev_alexander 24:e8d03912f303 615 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 23:f74a50977593 616 // Aquire raw data about 8x8 frame from the grid eye sensor in this function call
dev_alexander 28:0ed92c590607 617 gridEye.getRaw8x8FrameData(curr_raw_frame_to_master);
dev_alexander 36:09e8b51fc91d 618 // wait_ms( 10 );
dev_alexander 35:bae9b236070b 619 #if defined(RASPBERRY_PI)
dev_alexander 35:bae9b236070b 620 if( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 )
dev_alexander 35:bae9b236070b 621 {
dev_alexander 35:bae9b236070b 622 char grid_eye_msg[130];
dev_alexander 35:bae9b236070b 623 grid_eye_msg[0]=0x55;
dev_alexander 35:bae9b236070b 624 grid_eye_msg[1]=0xaa;
dev_alexander 35:bae9b236070b 625 for (int idx = 0; idx < 128; idx++)
dev_alexander 35:bae9b236070b 626 grid_eye_msg[idx+2] = curr_raw_frame_to_master[idx];
dev_alexander 35:bae9b236070b 627 //pc.printf(grid_eye_msg);
dev_alexander 35:bae9b236070b 628 for (int idx = 0; idx < 130; idx++)
dev_alexander 35:bae9b236070b 629 pc.putc(grid_eye_msg[idx]);
dev_alexander 35:bae9b236070b 630 pc.printf("\r\n"); // seperate the lines
dev_alexander 35:bae9b236070b 631 }
dev_alexander 35:bae9b236070b 632 #endif
dev_alexander 35:bae9b236070b 633 #if defined(DEBUG_GRID_EYE)
dev_alexander 32:b108ed6096b0 634 if( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 )
dev_alexander 32:b108ed6096b0 635 {
dev_alexander 32:b108ed6096b0 636 // Convert raw data sent from slave to a 16 bit integer array by calling this
dev_alexander 32:b108ed6096b0 637 convRaw8x8Data2Point25degC(curr_raw_frame_to_master, conv_frame_to_master);
dev_alexander 32:b108ed6096b0 638
dev_alexander 32:b108ed6096b0 639
dev_alexander 32:b108ed6096b0 640 // Next Print off the Converted data
dev_alexander 32:b108ed6096b0 641 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
dev_alexander 32:b108ed6096b0 642 uint8_t idx;
dev_alexander 32:b108ed6096b0 643 float pixel_data;
dev_alexander 32:b108ed6096b0 644 for (int y = 0; y < 8; y++) {
dev_alexander 32:b108ed6096b0 645 for (int x = 0; x < 8; x++) {
dev_alexander 32:b108ed6096b0 646 idx = y*8 + x;
dev_alexander 32:b108ed6096b0 647 pixel_data = ((float)conv_frame_to_master[idx])/4.0;
dev_alexander 32:b108ed6096b0 648 pc.printf("%.2f \t", pixel_data);
dev_alexander 32:b108ed6096b0 649 }
dev_alexander 32:b108ed6096b0 650 pc.printf("\r\n\r\n");
dev_alexander 25:1a031add188a 651 }
dev_alexander 32:b108ed6096b0 652 pc.printf("\r\n");
dev_alexander 32:b108ed6096b0 653
dev_alexander 32:b108ed6096b0 654 // Increment frame counter
dev_alexander 32:b108ed6096b0 655 frame_idx = frame_idx +1;
dev_alexander 25:1a031add188a 656 }
dev_alexander 32:b108ed6096b0 657 #endif
dev_alexander 36:09e8b51fc91d 658 // wait_ms( 10 );
dev_alexander 33:52c898aca207 659 memcpy(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master));
dev_alexander 31:f15747cffb20 660 #endif
dev_alexander 31:f15747cffb20 661
dev_alexander 31:f15747cffb20 662 /***************************************************************************
dev_alexander 31:f15747cffb20 663 * GPS Sensor
dev_alexander 31:f15747cffb20 664 **************************************************************************/
dev_alexander 31:f15747cffb20 665 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 31:f15747cffb20 666 //None yet
dev_alexander 31:f15747cffb20 667 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 31:f15747cffb20 668 // The testing hasnt been done yet for the GPS Module. Will do this when more parts come in.
dev_alexander 31:f15747cffb20 669 /*
dev_alexander 31:f15747cffb20 670 if(gps.sample()){
dev_alexander 31:f15747cffb20 671 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 672 pc.printf("%d:%d:%d",gps.hour,gps.minute,gps.seconed);
dev_alexander 31:f15747cffb20 673 }
dev_alexander 31:f15747cffb20 674 */
dev_alexander 31:f15747cffb20 675 #endif
dev_alexander 28:0ed92c590607 676
dev_alexander 23:f74a50977593 677 /***************************************************************************
dev_alexander 28:0ed92c590607 678 * Fill Payload Buffer With Data From Sensors for LoRa Transmition
dev_alexander 28:0ed92c590607 679 **************************************************************************/
dev_alexander 28:0ed92c590607 680 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 28:0ed92c590607 681 memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature);
dev_alexander 28:0ed92c590607 682 memcpy(&BufferTx[tx_idx_ble], curr_ble_to_slave, size_of_ble);
dev_alexander 28:0ed92c590607 683 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 28:0ed92c590607 684 memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature);
dev_alexander 28:0ed92c590607 685 memcpy(&BufferTx[tx_idx_grid_eye], curr_raw_frame_to_master, size_of_grid_eye);
dev_alexander 28:0ed92c590607 686 memcpy(&BufferTx[tx_idx_gps], curr_gps_to_master, size_of_gps);
dev_alexander 28:0ed92c590607 687 memcpy(&BufferTx[tx_idx_MAX17055], curr_MAX17055_to_master, size_of_MAX17055);
dev_alexander 28:0ed92c590607 688 memcpy(&BufferTx[tx_idx_MAX77650], curr_MAX77650_to_master, size_of_MAX77650);
dev_alexander 28:0ed92c590607 689 #endif
dev_alexander 28:0ed92c590607 690
dev_alexander 28:0ed92c590607 691
dev_alexander 28:0ed92c590607 692
dev_alexander 32:b108ed6096b0 693
dev_alexander 28:0ed92c590607 694 /***************************************************************************
dev_alexander 28:0ed92c590607 695 * Lora Communications
dev_alexander 28:0ed92c590607 696 **************************************************************************/
dev_alexander 36:09e8b51fc91d 697 // wait_ms( 10 );
dev_alexander 22:abca9d17d13d 698 SX1276PingPong();
dev_alexander 28:0ed92c590607 699
dev_alexander 28:0ed92c590607 700 /***************************************************************************
dev_alexander 28:0ed92c590607 701 * Fill Global Buffers With Data From Received Payload Buffer
dev_alexander 28:0ed92c590607 702 **************************************************************************/
dev_alexander 28:0ed92c590607 703 /* The master and slave devices will have different requirements for offloading payload */
dev_alexander 28:0ed92c590607 704 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 705 memcpy(ID_of_slave, &BufferRx[rx_idx_signature], size_signature);
dev_alexander 32:b108ed6096b0 706 memcpy(curr_raw_frame_from_slave, &BufferRx[rx_idx_grid_eye], size_of_grid_eye);
dev_alexander 32:b108ed6096b0 707 memcpy(curr_gps_from_slave, &BufferRx[rx_idx_gps], size_of_gps);
dev_alexander 32:b108ed6096b0 708 memcpy(curr_MAX17055_from_slave, &BufferRx[rx_idx_MAX17055], size_of_MAX17055);
dev_alexander 32:b108ed6096b0 709 memcpy(curr_MAX77650_from_slave, &BufferRx[rx_idx_MAX77650], size_of_MAX77650);
dev_alexander 28:0ed92c590607 710 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 711 memcpy(ID_of_master, &BufferRx[rx_idx_signature], size_signature);
dev_alexander 32:b108ed6096b0 712 memcpy(curr_ble_from_master, &BufferRx[rx_idx_ble], size_of_ble);
dev_alexander 28:0ed92c590607 713 #endif
dev_alexander 23:f74a50977593 714
dev_alexander 32:b108ed6096b0 715 /***************************************************************************
dev_alexander 32:b108ed6096b0 716 * Motor Controller controlls go here
dev_alexander 32:b108ed6096b0 717 **************************************************************************/
dev_alexander 32:b108ed6096b0 718 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 32:b108ed6096b0 719 // No motor controller on master
dev_alexander 32:b108ed6096b0 720 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 32:b108ed6096b0 721 // 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 722 if( memcmp(prev_ble_from_master, curr_ble_from_master, sizeof(curr_ble_from_master)) != 0 )
dev_alexander 32:b108ed6096b0 723 {
dev_alexander 32:b108ed6096b0 724 MotorController(curr_ble_from_master);
dev_alexander 32:b108ed6096b0 725 }
dev_alexander 32:b108ed6096b0 726 #endif
dev_alexander 23:f74a50977593 727
dev_alexander 23:f74a50977593 728
dev_alexander 23:f74a50977593 729
dev_alexander 22:abca9d17d13d 730 }
dev_alexander 22:abca9d17d13d 731
Helmut64 0:c43b6919ae15 732 }