![](/media/cache/profiles/profile_pic_for_github_less_than_1MB.jpg.50x50_q85.jpg)
This is example code that can get you started with building your own IR vision robot that communicates over LoRa
Dependencies: Adafruit-MotorShield Adafruit-PWM-Servo-Driver Adafruit_GFX BufferedSerial MAX17055_EZconfig NEO-6m-GPS SX1276GenericLib USBDeviceHT max32630fthr max77650_charger_sample
Fork of MAX326xxFTHR_LoRa_Example_test by
GridEye/GridEye.h@28:0ed92c590607, 2018-07-23 (annotated)
- Committer:
- dev_alexander
- Date:
- Mon Jul 23 23:39:35 2018 +0000
- Revision:
- 28:0ed92c590607
- Parent:
- 23:f74a50977593
- Child:
- 38:c10d2a04a0c2
Reworked how the buffers are loaded and unloaded. Now prints off data received from the Slave on the Master. This is a stable release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dev_alexander | 23:f74a50977593 | 1 | /********************************************************************** |
dev_alexander | 23:f74a50977593 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
dev_alexander | 23:f74a50977593 | 3 | * |
dev_alexander | 23:f74a50977593 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
dev_alexander | 23:f74a50977593 | 5 | * copy of this software and associated documentation files (the "Software"), |
dev_alexander | 23:f74a50977593 | 6 | * to deal in the Software without restriction, including without limitation |
dev_alexander | 23:f74a50977593 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
dev_alexander | 23:f74a50977593 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
dev_alexander | 23:f74a50977593 | 9 | * Software is furnished to do so, subject to the following conditions: |
dev_alexander | 23:f74a50977593 | 10 | * |
dev_alexander | 23:f74a50977593 | 11 | * The above copyright notice and this permission notice shall be included |
dev_alexander | 23:f74a50977593 | 12 | * in all copies or substantial portions of the Software. |
dev_alexander | 23:f74a50977593 | 13 | * |
dev_alexander | 23:f74a50977593 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
dev_alexander | 23:f74a50977593 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
dev_alexander | 23:f74a50977593 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
dev_alexander | 23:f74a50977593 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
dev_alexander | 23:f74a50977593 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
dev_alexander | 23:f74a50977593 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
dev_alexander | 23:f74a50977593 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
dev_alexander | 23:f74a50977593 | 21 | * |
dev_alexander | 23:f74a50977593 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
dev_alexander | 23:f74a50977593 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
dev_alexander | 23:f74a50977593 | 24 | * Products, Inc. Branding Policy. |
dev_alexander | 23:f74a50977593 | 25 | * |
dev_alexander | 23:f74a50977593 | 26 | * The mere transfer of this software does not imply any licenses |
dev_alexander | 23:f74a50977593 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
dev_alexander | 23:f74a50977593 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
dev_alexander | 23:f74a50977593 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
dev_alexander | 23:f74a50977593 | 30 | * ownership rights. |
dev_alexander | 23:f74a50977593 | 31 | **********************************************************************/ |
dev_alexander | 23:f74a50977593 | 32 | |
dev_alexander | 23:f74a50977593 | 33 | |
dev_alexander | 23:f74a50977593 | 34 | #ifndef GRIDEYE_H |
dev_alexander | 23:f74a50977593 | 35 | #define GRIDEYE_H |
dev_alexander | 23:f74a50977593 | 36 | |
dev_alexander | 23:f74a50977593 | 37 | |
dev_alexander | 23:f74a50977593 | 38 | #include "mbed.h" |
dev_alexander | 23:f74a50977593 | 39 | |
dev_alexander | 23:f74a50977593 | 40 | #define I2C_WR_SUCCESS 0 |
dev_alexander | 23:f74a50977593 | 41 | #define I2C_WR_ERROR -1 |
dev_alexander | 23:f74a50977593 | 42 | |
dev_alexander | 23:f74a50977593 | 43 | /** |
dev_alexander | 23:f74a50977593 | 44 | * @brief Object for interfacing to MAXREFDES131# |
dev_alexander | 23:f74a50977593 | 45 | * |
dev_alexander | 23:f74a50977593 | 46 | * @details MAXREFDES131# combines the DS28E17 1-wire to I2C bridge |
dev_alexander | 23:f74a50977593 | 47 | * with the Panasonic AMG8833 GridEye sensor. The reference design also |
dev_alexander | 23:f74a50977593 | 48 | * includes a DS2413 2ch open drain switch for controlling the MAX4717 |
dev_alexander | 23:f74a50977593 | 49 | * dual SPDT analog switch. The DS28E17 and AMG8833 are connected to |
dev_alexander | 23:f74a50977593 | 50 | * the 1-wire bus via COM2 of the MAX4717 and COM1 is used for |
dev_alexander | 23:f74a50977593 | 51 | * daisy-chaining additional modules. Disconnecting the DS28E17/AMG8833 |
dev_alexander | 23:f74a50977593 | 52 | * from the main 1-wire branch puts both devices to sleep and reduces current |
dev_alexander | 23:f74a50977593 | 53 | * consumption from 10mA to a couple hundred uA. |
dev_alexander | 23:f74a50977593 | 54 | */ |
dev_alexander | 23:f74a50977593 | 55 | class GridEye |
dev_alexander | 23:f74a50977593 | 56 | { |
dev_alexander | 23:f74a50977593 | 57 | private: |
dev_alexander | 23:f74a50977593 | 58 | I2C &m_i2cBus; |
dev_alexander | 23:f74a50977593 | 59 | |
dev_alexander | 23:f74a50977593 | 60 | static const uint8_t I2C_ADRS = 0x68; |
dev_alexander | 23:f74a50977593 | 61 | static const uint8_t I2C_W_ADRS = (uint8_t)((0x68)<<1); |
dev_alexander | 23:f74a50977593 | 62 | static const uint8_t I2C_R_ADRS = (uint8_t)((0x68)<<1)+1; |
dev_alexander | 23:f74a50977593 | 63 | |
dev_alexander | 23:f74a50977593 | 64 | |
dev_alexander | 23:f74a50977593 | 65 | public: |
dev_alexander | 23:f74a50977593 | 66 | |
dev_alexander | 23:f74a50977593 | 67 | /** |
dev_alexander | 23:f74a50977593 | 68 | * @brief GridEye operating modes |
dev_alexander | 23:f74a50977593 | 69 | */ |
dev_alexander | 23:f74a50977593 | 70 | enum OperatingMode |
dev_alexander | 23:f74a50977593 | 71 | { |
dev_alexander | 23:f74a50977593 | 72 | NormalMode = 0x00, |
dev_alexander | 23:f74a50977593 | 73 | SleepMode = 0x10, |
dev_alexander | 23:f74a50977593 | 74 | StandBy60sec = 0x20, |
dev_alexander | 23:f74a50977593 | 75 | StandBy10sec = 0x21 |
dev_alexander | 23:f74a50977593 | 76 | }; |
dev_alexander | 23:f74a50977593 | 77 | |
dev_alexander | 23:f74a50977593 | 78 | /** |
dev_alexander | 23:f74a50977593 | 79 | * @brief GridEye operating modes |
dev_alexander | 23:f74a50977593 | 80 | */ |
dev_alexander | 23:f74a50977593 | 81 | enum FrameRate |
dev_alexander | 23:f74a50977593 | 82 | { |
dev_alexander | 23:f74a50977593 | 83 | TenFPS = 0x00, |
dev_alexander | 23:f74a50977593 | 84 | OneFPS = 0x01 |
dev_alexander | 23:f74a50977593 | 85 | }; |
dev_alexander | 23:f74a50977593 | 86 | |
dev_alexander | 23:f74a50977593 | 87 | /** |
dev_alexander | 23:f74a50977593 | 88 | * @brief AMG8833 register map |
dev_alexander | 23:f74a50977593 | 89 | */ |
dev_alexander | 23:f74a50977593 | 90 | enum GridEyeRegister |
dev_alexander | 23:f74a50977593 | 91 | { |
dev_alexander | 23:f74a50977593 | 92 | OPERATING_MODE, |
dev_alexander | 23:f74a50977593 | 93 | RESET, |
dev_alexander | 23:f74a50977593 | 94 | FRAME_RATE, |
dev_alexander | 23:f74a50977593 | 95 | INT_CONTROL, |
dev_alexander | 23:f74a50977593 | 96 | STATUS, |
dev_alexander | 23:f74a50977593 | 97 | STATUS_CLEAR, |
dev_alexander | 23:f74a50977593 | 98 | AVERAGE = 7, |
dev_alexander | 23:f74a50977593 | 99 | INT_LEVEL_1, |
dev_alexander | 23:f74a50977593 | 100 | INT_LEVEL_2, |
dev_alexander | 23:f74a50977593 | 101 | INT_LEVEL_3, |
dev_alexander | 23:f74a50977593 | 102 | INT_LEVEL_4, |
dev_alexander | 23:f74a50977593 | 103 | INT_LEVEL_5, |
dev_alexander | 23:f74a50977593 | 104 | INT_LEVEL_6, |
dev_alexander | 23:f74a50977593 | 105 | THERMISTOR_LOW, |
dev_alexander | 23:f74a50977593 | 106 | THERMISTOR_HI, |
dev_alexander | 23:f74a50977593 | 107 | INT_1, |
dev_alexander | 23:f74a50977593 | 108 | INT_2, |
dev_alexander | 23:f74a50977593 | 109 | INT_3, |
dev_alexander | 23:f74a50977593 | 110 | INT_4, |
dev_alexander | 23:f74a50977593 | 111 | INT_5, |
dev_alexander | 23:f74a50977593 | 112 | INT_6, |
dev_alexander | 23:f74a50977593 | 113 | INT_7, |
dev_alexander | 23:f74a50977593 | 114 | INT_8, |
dev_alexander | 23:f74a50977593 | 115 | PIXEL_BASE_ADRS = 0x80 |
dev_alexander | 23:f74a50977593 | 116 | }; |
dev_alexander | 23:f74a50977593 | 117 | |
dev_alexander | 23:f74a50977593 | 118 | /* static const uint8_t DS2413_FAMILY_CODE = 0x3A; |
dev_alexander | 23:f74a50977593 | 119 | |
dev_alexander | 23:f74a50977593 | 120 | static const uint8_t DS28E17_FAMILY_CODE = 0x19; |
dev_alexander | 23:f74a50977593 | 121 | */ |
dev_alexander | 23:f74a50977593 | 122 | /** |
dev_alexander | 23:f74a50977593 | 123 | * @brief GridEye Constructor |
dev_alexander | 23:f74a50977593 | 124 | * |
dev_alexander | 23:f74a50977593 | 125 | * @details setI2CBridge() by passing in I2C parameter |
dev_alexander | 23:f74a50977593 | 126 | * |
dev_alexander | 23:f74a50977593 | 127 | * @param[in] selector - MultidropRomIterator object that |
dev_alexander | 23:f74a50977593 | 128 | * encapsulates ROM fxs of 1-wire protocol |
dev_alexander | 23:f74a50977593 | 129 | */ |
dev_alexander | 23:f74a50977593 | 130 | GridEye(I2C &i2c); |
dev_alexander | 23:f74a50977593 | 131 | |
dev_alexander | 23:f74a50977593 | 132 | |
dev_alexander | 23:f74a50977593 | 133 | |
dev_alexander | 23:f74a50977593 | 134 | |
dev_alexander | 23:f74a50977593 | 135 | /** |
dev_alexander | 23:f74a50977593 | 136 | * @brief gridEyeWriteReg |
dev_alexander | 23:f74a50977593 | 137 | * |
dev_alexander | 23:f74a50977593 | 138 | * @details Provides read/write access to the AMG8833 |
dev_alexander | 23:f74a50977593 | 139 | * |
dev_alexander | 23:f74a50977593 | 140 | * On Entry: |
dev_alexander | 23:f74a50977593 | 141 | * @param[in] regAdrs - AMG8833 register to start reading/writting |
dev_alexander | 23:f74a50977593 | 142 | * from/to |
dev_alexander | 23:f74a50977593 | 143 | * @param[in] numBytes - Number of bytes of data to write |
dev_alexander | 23:f74a50977593 | 144 | * @param[in] dataBuf - Pointer to data buffer for storing data in |
dev_alexander | 23:f74a50977593 | 145 | * on read, or data to be written on write |
dev_alexander | 23:f74a50977593 | 146 | * |
dev_alexander | 23:f74a50977593 | 147 | * On Exit: |
dev_alexander | 23:f74a50977593 | 148 | * |
dev_alexander | 23:f74a50977593 | 149 | * @return CmdResult - return 0 if the operation was sucessful, return -1 if unsucessful |
dev_alexander | 23:f74a50977593 | 150 | */ |
dev_alexander | 23:f74a50977593 | 151 | int8_t gridEyeWriteReg(GridEyeRegister reg_addr, int num_bytes, char * data_buf); |
dev_alexander | 23:f74a50977593 | 152 | |
dev_alexander | 23:f74a50977593 | 153 | /** |
dev_alexander | 23:f74a50977593 | 154 | * @brief gridEyeReadReg |
dev_alexander | 23:f74a50977593 | 155 | * |
dev_alexander | 23:f74a50977593 | 156 | * @details Provides read/write access to the AMG8833 |
dev_alexander | 23:f74a50977593 | 157 | * |
dev_alexander | 23:f74a50977593 | 158 | * On Entry: |
dev_alexander | 23:f74a50977593 | 159 | * @param[in] regAdrs - AMG8833 register to start reading/writting |
dev_alexander | 23:f74a50977593 | 160 | * from/to |
dev_alexander | 23:f74a50977593 | 161 | * @param[in] numBytes - Number of bytes to read |
dev_alexander | 23:f74a50977593 | 162 | * @param[in] dataBuf - Pointer to data buffer for storing data in |
dev_alexander | 23:f74a50977593 | 163 | * on read, or data to be written on write |
dev_alexander | 23:f74a50977593 | 164 | * |
dev_alexander | 23:f74a50977593 | 165 | * On Exit: |
dev_alexander | 23:f74a50977593 | 166 | * @param[out] dataBuf - Read data on read operation |
dev_alexander | 23:f74a50977593 | 167 | * |
dev_alexander | 23:f74a50977593 | 168 | * @return CmdResult - return 0 if the operation was sucessful, return -1 if unsucessful |
dev_alexander | 23:f74a50977593 | 169 | */ |
dev_alexander | 23:f74a50977593 | 170 | int8_t gridEyeReadReg(GridEyeRegister reg_addr, int num_bytes, char * data_buf); |
dev_alexander | 23:f74a50977593 | 171 | |
dev_alexander | 23:f74a50977593 | 172 | |
dev_alexander | 23:f74a50977593 | 173 | /** |
dev_alexander | 23:f74a50977593 | 174 | * @brief getThermistorTemperature |
dev_alexander | 23:f74a50977593 | 175 | * |
dev_alexander | 23:f74a50977593 | 176 | * @details Gets internal thermistor temperature |
dev_alexander | 23:f74a50977593 | 177 | * |
dev_alexander | 23:f74a50977593 | 178 | * On Entry: |
dev_alexander | 23:f74a50977593 | 179 | * @param[in] thermTemp - reference to int16_t var that will be overwritten |
dev_alexander | 23:f74a50977593 | 180 | * with thermistor data |
dev_alexander | 23:f74a50977593 | 181 | * |
dev_alexander | 23:f74a50977593 | 182 | * On Exit: |
dev_alexander | 23:f74a50977593 | 183 | * @param[out] thermTemp - thermistor data |
dev_alexander | 23:f74a50977593 | 184 | * |
dev_alexander | 23:f74a50977593 | 185 | * @return CmdResult - result of operation |
dev_alexander | 23:f74a50977593 | 186 | */ |
dev_alexander | 23:f74a50977593 | 187 | int8_t getThermistorTemperature(int16_t & therm_temp); |
dev_alexander | 23:f74a50977593 | 188 | |
dev_alexander | 23:f74a50977593 | 189 | |
dev_alexander | 23:f74a50977593 | 190 | /** |
dev_alexander | 23:f74a50977593 | 191 | * @brief getPixelTemperature |
dev_alexander | 23:f74a50977593 | 192 | * |
dev_alexander | 23:f74a50977593 | 193 | * @details Gets individual pixel temperature |
dev_alexander | 23:f74a50977593 | 194 | * |
dev_alexander | 23:f74a50977593 | 195 | * On Entry: |
dev_alexander | 23:f74a50977593 | 196 | * @param[in] pixelAdrs - address of pixel to read |
dev_alexander | 23:f74a50977593 | 197 | * @param[in] pixelTemp - reference to int16_t var that will be overwritten |
dev_alexander | 23:f74a50977593 | 198 | * with thermistor data |
dev_alexander | 23:f74a50977593 | 199 | * |
dev_alexander | 23:f74a50977593 | 200 | * On Exit: |
dev_alexander | 23:f74a50977593 | 201 | * @param[out] pixelTemp - pixel data |
dev_alexander | 23:f74a50977593 | 202 | * |
dev_alexander | 23:f74a50977593 | 203 | * @return CmdResult - result of operation |
dev_alexander | 23:f74a50977593 | 204 | */ |
dev_alexander | 23:f74a50977593 | 205 | int8_t getPixelTemperature(uint8_t pixel_addr, int16_t & pixel_temp); |
dev_alexander | 23:f74a50977593 | 206 | |
dev_alexander | 23:f74a50977593 | 207 | /** |
dev_alexander | 23:f74a50977593 | 208 | * @brief getRaw8x8FrameData |
dev_alexander | 23:f74a50977593 | 209 | * |
dev_alexander | 23:f74a50977593 | 210 | * @details Gets pixel frame(64 pixels in 128 bytes) temperature |
dev_alexander | 23:f74a50977593 | 211 | * |
dev_alexander | 23:f74a50977593 | 212 | * On Entry: |
dev_alexander | 23:f74a50977593 | 213 | * @param[in] raw_frame_data - buffer to hold 2 bytes data per pixel |
dev_alexander | 23:f74a50977593 | 214 | * |
dev_alexander | 23:f74a50977593 | 215 | * On Exit: |
dev_alexander | 23:f74a50977593 | 216 | * @param[out] raw_frame_data - pixel data not yet formatted |
dev_alexander | 23:f74a50977593 | 217 | * |
dev_alexander | 23:f74a50977593 | 218 | * @return int8_t - result of operation, 0 on success, -1 on failure |
dev_alexander | 23:f74a50977593 | 219 | */ |
dev_alexander | 23:f74a50977593 | 220 | int8_t getRaw8x8FrameData(char * raw_frame_data); |
dev_alexander | 23:f74a50977593 | 221 | |
dev_alexander | 23:f74a50977593 | 222 | |
dev_alexander | 28:0ed92c590607 | 223 | /** |
dev_alexander | 28:0ed92c590607 | 224 | * @brief softwareReset |
dev_alexander | 28:0ed92c590607 | 225 | * |
dev_alexander | 28:0ed92c590607 | 226 | * @details Makes the Grid Eye device perform a software restart with Initial conditions |
dev_alexander | 28:0ed92c590607 | 227 | * |
dev_alexander | 28:0ed92c590607 | 228 | * @return int8_t - result of operation, 0 on success, -1 on failure |
dev_alexander | 28:0ed92c590607 | 229 | */ |
dev_alexander | 28:0ed92c590607 | 230 | int8_t softwareReset(); |
dev_alexander | 28:0ed92c590607 | 231 | |
dev_alexander | 28:0ed92c590607 | 232 | |
dev_alexander | 28:0ed92c590607 | 233 | /** |
dev_alexander | 28:0ed92c590607 | 234 | * @brief setOperatingMode |
dev_alexander | 28:0ed92c590607 | 235 | * |
dev_alexander | 28:0ed92c590607 | 236 | * @details Sets the mode of operation for the Grid Eye device |
dev_alexander | 28:0ed92c590607 | 237 | * |
dev_alexander | 28:0ed92c590607 | 238 | * On Entry: |
dev_alexander | 28:0ed92c590607 | 239 | * @param[in] mode - Choose power operating mode from struct |
dev_alexander | 28:0ed92c590607 | 240 | * |
dev_alexander | 28:0ed92c590607 | 241 | * @return int8_t - result of operation, 0 on success, -1 on failure |
dev_alexander | 28:0ed92c590607 | 242 | */ |
dev_alexander | 23:f74a50977593 | 243 | int8_t setOperatingMode(GridEye::OperatingMode mode); |
dev_alexander | 23:f74a50977593 | 244 | |
dev_alexander | 28:0ed92c590607 | 245 | |
dev_alexander | 28:0ed92c590607 | 246 | /** |
dev_alexander | 28:0ed92c590607 | 247 | * @brief setFrameRate |
dev_alexander | 28:0ed92c590607 | 248 | * |
dev_alexander | 28:0ed92c590607 | 249 | * @details Sets the frames per second that the grid eye device resolves |
dev_alexander | 28:0ed92c590607 | 250 | * |
dev_alexander | 28:0ed92c590607 | 251 | * On Entry: |
dev_alexander | 28:0ed92c590607 | 252 | * @param[in] mode - Choose option from either 10 fps or 1 fps |
dev_alexander | 28:0ed92c590607 | 253 | * |
dev_alexander | 28:0ed92c590607 | 254 | * @return int8_t - result of operation, 0 on success, -1 on failure |
dev_alexander | 28:0ed92c590607 | 255 | */ |
dev_alexander | 23:f74a50977593 | 256 | int8_t setFrameRate(GridEye::FrameRate rate); |
dev_alexander | 23:f74a50977593 | 257 | |
dev_alexander | 23:f74a50977593 | 258 | }; |
dev_alexander | 23:f74a50977593 | 259 | |
dev_alexander | 23:f74a50977593 | 260 | |
dev_alexander | 23:f74a50977593 | 261 | void convRaw8x8Data2Int(char * data, int16_t * frame_temp); |
dev_alexander | 23:f74a50977593 | 262 | |
dev_alexander | 23:f74a50977593 | 263 | void convRaw8x8Data2Point25degC(char * data, int16_t * frame_temp); |
dev_alexander | 23:f74a50977593 | 264 | |
dev_alexander | 23:f74a50977593 | 265 | void convSingleRawTempData2Int(char * data, int16_t & pixel_temp); |
dev_alexander | 23:f74a50977593 | 266 | |
dev_alexander | 23:f74a50977593 | 267 | #endif /*GridEye_H*/ |