Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed ADS1115 StepperMotor SRF05 TPA81new
AMG8833.h
00001 #ifndef LIB_ADAFRUIT_AMG88XX_H 00002 #define LIB_ADAFRUIT_AMG88XX_H 00003 00004 #include "mbed.h" 00005 00006 /*========================================================================= 00007 I2C ADDRESS/BITS 00008 -----------------------------------------------------------------------*/ 00009 #define AMG88xx_ADDRESS (0x69 << 1) 00010 /*=========================================================================*/ 00011 00012 /*========================================================================= 00013 REGISTERS 00014 -----------------------------------------------------------------------*/ 00015 enum 00016 { 00017 AMG88xx_PCTL = 0x00, 00018 AMG88xx_RST = 0x01, 00019 AMG88xx_FPSC = 0x02, 00020 AMG88xx_INTC = 0x03, 00021 AMG88xx_STAT = 0x04, 00022 AMG88xx_SCLR = 0x05, 00023 //0x06 reserved 00024 AMG88xx_AVE = 0x07, 00025 AMG88xx_INTHL = 0x08, 00026 AMG88xx_INTHH = 0x09, 00027 AMG88xx_INTLL = 0x0A, 00028 AMG88xx_INTLH = 0x0B, 00029 AMG88xx_IHYSL = 0x0C, 00030 AMG88xx_IHYSH = 0x0D, 00031 AMG88xx_TTHL = 0x0E, 00032 AMG88xx_TTHH = 0x0F, 00033 AMG88xx_INT_OFFSET = 0x010, 00034 AMG88xx_PIXEL_OFFSET = 0x80 00035 }; 00036 00037 enum power_modes{ 00038 AMG88xx_NORMAL_MODE = 0x00, 00039 AMG88xx_SLEEP_MODE = 0x01, 00040 AMG88xx_STAND_BY_60 = 0x20, 00041 AMG88xx_STAND_BY_10 = 0x21 00042 }; 00043 00044 enum sw_resets { 00045 AMG88xx_FLAG_RESET = 0x30, 00046 AMG88xx_INITIAL_RESET = 0x3F 00047 }; 00048 00049 enum frame_rates { 00050 AMG88xx_FPS_10 = 0x00, 00051 AMG88xx_FPS_1 = 0x01 00052 }; 00053 00054 enum int_enables{ 00055 AMG88xx_INT_DISABLED = 0x00, 00056 AMG88xx_INT_ENABLED = 0x01 00057 }; 00058 00059 enum int_modes { 00060 AMG88xx_DIFFERENCE = 0x00, 00061 AMG88xx_ABSOLUTE_VALUE = 0x01 00062 }; 00063 00064 /*=========================================================================*/ 00065 00066 #define AMG88xx_PIXEL_ARRAY_SIZE 64 00067 #define AMG88xx_PIXEL_TEMP_CONVERSION .25 00068 #define AMG88xx_THERMISTOR_CONVERSION .0625 00069 00070 /**************************************************************************/ 00071 /*! 00072 @brief Class that stores state and functions for interacting with AMG88xx IR sensor chips 00073 */ 00074 /**************************************************************************/ 00075 class Adafruit_AMG88xx { 00076 public: 00077 //constructors 00078 Adafruit_AMG88xx(PinName sda, PinName scl); 00079 00080 int begin(char addr = AMG88xx_ADDRESS); 00081 00082 void readPixels(float *buf, uint8_t size = AMG88xx_PIXEL_ARRAY_SIZE); 00083 float readThermistor(); 00084 00085 void setMovingAverageMode(int mode); 00086 00087 void enableInterrupt(); 00088 void disableInterrupt(); 00089 void setInterruptMode(uint8_t mode); 00090 void getInterrupt(uint8_t *buf, uint8_t size = 8); 00091 void clearInterrupt(); 00092 00093 //this will automatically set hysteresis to 95% of the high value 00094 void setInterruptLevels(float high, float low); 00095 00096 //this will manually set hysteresis 00097 void setInterruptLevels(float high, float low, float hysteresis); 00098 00099 private: 00100 char _i2caddr; 00101 00102 I2C _i2c; 00103 00104 void write8(uint8_t reg, uint8_t value); 00105 void write16(uint8_t reg, uint16_t value); 00106 uint8_t read8(uint8_t reg); 00107 00108 int read(uint8_t reg, uint8_t *buf, uint8_t num); 00109 int write(uint8_t reg, uint8_t *buf, uint8_t num); 00110 void _i2c_init(); 00111 00112 float signedMag12ToFloat(uint16_t val); 00113 float int12ToFloat(uint16_t val); 00114 00115 int constrain(int value, int min, int max); 00116 int min(int val1, int val2); 00117 int max(int val1, int val2); 00118 00119 uint8_t min(uint8_t val1, uint8_t val2); 00120 uint8_t max(uint8_t val1, uint8_t val2); 00121 00122 // The power control register 00123 struct pctl { 00124 // 0x00 = Normal Mode 00125 // 0x01 = Sleep Mode 00126 // 0x20 = Stand-by mode (60 sec intermittence) 00127 // 0x21 = Stand-by mode (10 sec intermittence) 00128 00129 uint8_t PCTL : 8; 00130 00131 uint8_t get() { 00132 return PCTL; 00133 } 00134 }; 00135 pctl _pctl; 00136 00137 //reset register 00138 struct rst { 00139 //0x30 = flag reset (all clear status reg 0x04, interrupt flag and interrupt table) 00140 //0x3F = initial reset (brings flag reset and returns to initial setting) 00141 00142 uint8_t RST : 8; 00143 00144 uint8_t get() { 00145 return RST; 00146 } 00147 }; 00148 rst _rst; 00149 00150 //frame rate register 00151 struct fpsc { 00152 00153 //0 = 10FPS 00154 //1 = 1FPS 00155 uint8_t FPS : 1; 00156 00157 uint8_t get() { 00158 return FPS & 0x01; 00159 } 00160 }; 00161 fpsc _fpsc; 00162 00163 //interrupt control register 00164 struct intc { 00165 00166 // 0 = INT output reactive (Hi-Z) 00167 // 1 = INT output active 00168 uint8_t INTEN : 1; 00169 00170 // 0 = Difference interrupt mode 00171 // 1 = absolute value interrupt mode 00172 uint8_t INTMOD : 1; 00173 00174 uint8_t get(){ 00175 return (INTMOD << 1 | INTEN) & 0x03; 00176 } 00177 }; 00178 intc _intc; 00179 00180 //status register 00181 struct stat { 00182 uint8_t unused : 1; 00183 //interrupt outbreak (val of interrupt table reg) 00184 uint8_t INTF : 1; 00185 00186 //temperature output overflow (val of temperature reg) 00187 uint8_t OVF_IRS : 1; 00188 00189 //thermistor temperature output overflow (value of thermistor) 00190 uint8_t OVF_THS : 1; 00191 00192 uint8_t get(){ 00193 return ( (OVF_THS << 3) | (OVF_IRS << 2) | (INTF << 1) ) & 0x0E; 00194 } 00195 }; 00196 stat _stat; 00197 00198 //status clear register 00199 //write to clear overflow flag and interrupt flag 00200 //after writing automatically turns to 0x00 00201 struct sclr { 00202 uint8_t unused : 1; 00203 //interrupt flag clear 00204 uint8_t INTCLR : 1; 00205 //temp output overflow flag clear 00206 uint8_t OVS_CLR : 1; 00207 //thermistor temp output overflow flag clear 00208 uint8_t OVT_CLR : 1; 00209 00210 uint8_t get(){ 00211 return ((OVT_CLR << 3) | (OVS_CLR << 2) | (INTCLR << 1)) & 0x0E; 00212 } 00213 }; 00214 sclr _sclr; 00215 00216 //average register 00217 //for setting moving average output mode 00218 struct ave { 00219 uint8_t unused : 5; 00220 //1 = twice moving average mode 00221 uint8_t MAMOD : 1; 00222 00223 uint8_t get(){ 00224 return (MAMOD << 5); 00225 } 00226 }; 00227 struct ave _ave; 00228 00229 //interrupt level registers 00230 //for setting upper / lower limit hysteresis on interrupt level 00231 00232 //interrupt level upper limit setting. Interrupt output 00233 // and interrupt pixel table are set when value exceeds set value 00234 struct inthl { 00235 uint8_t INT_LVL_H : 8; 00236 00237 uint8_t get(){ 00238 return INT_LVL_H; 00239 } 00240 }; 00241 struct inthl _inthl; 00242 00243 struct inthh { 00244 uint8_t INT_LVL_H : 4; 00245 00246 uint8_t get(){ 00247 return INT_LVL_H; 00248 } 00249 }; 00250 struct inthh _inthh; 00251 00252 //interrupt level lower limit. Interrupt output 00253 //and interrupt pixel table are set when value is lower than set value 00254 struct intll { 00255 uint8_t INT_LVL_L : 8; 00256 00257 uint8_t get(){ 00258 return INT_LVL_L; 00259 } 00260 }; 00261 struct intll _intll; 00262 00263 struct intlh { 00264 uint8_t INT_LVL_L : 4; 00265 00266 uint8_t get(){ 00267 return (INT_LVL_L & 0xF); 00268 } 00269 }; 00270 struct intlh _intlh; 00271 00272 //setting of interrupt hysteresis level when interrupt is generated. 00273 //should not be higher than interrupt level 00274 struct ihysl { 00275 uint8_t INT_HYS : 8; 00276 00277 uint8_t get(){ 00278 return INT_HYS; 00279 } 00280 }; 00281 struct ihysl _ihysl; 00282 00283 struct ihysh { 00284 uint8_t INT_HYS : 4; 00285 00286 uint8_t get(){ 00287 return (INT_HYS & 0xF); 00288 } 00289 }; 00290 struct ihysh _ihysh; 00291 00292 //thermistor register 00293 //SIGNED MAGNITUDE FORMAT 00294 struct tthl { 00295 uint8_t TEMP : 8; 00296 00297 uint8_t get(){ 00298 return TEMP; 00299 } 00300 }; 00301 struct tthl _tthl; 00302 00303 struct tthh { 00304 uint8_t TEMP : 3; 00305 uint8_t SIGN : 1; 00306 00307 uint8_t get(){ 00308 return ( (SIGN << 3) | TEMP) & 0xF; 00309 } 00310 }; 00311 struct tthh _tthh; 00312 00313 //temperature registers 0x80 - 0xFF 00314 /* 00315 //read to indicate temperature data per 1 pixel 00316 //SIGNED MAGNITUDE FORMAT 00317 struct t01l { 00318 char TEMP : 8; 00319 00320 char get(){ 00321 return TEMP; 00322 } 00323 }; 00324 struct t01l _t01l; 00325 00326 struct t01h { 00327 char TEMP : 3; 00328 char SIGN : 1; 00329 00330 char get(){ 00331 return ( (SIGN << 3) | TEMP) & 0xF; 00332 } 00333 }; 00334 struct t01h _t01h; 00335 */ 00336 00337 00338 }; 00339 00340 #endif
Generated on Wed Jul 13 2022 00:38:51 by
1.7.2