Skip to content

Commit

Permalink
Merge pull request #27 from betarho/read-pixels-raw
Browse files Browse the repository at this point in the history
Add method to read the pixels' raw registers
  • Loading branch information
ladyada authored Jan 10, 2022
2 parents df09300 + 6471176 commit 52a6327
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
28 changes: 22 additions & 6 deletions Adafruit_AMG88xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,40 @@ float Adafruit_AMG88xx::readThermistor() {
return signedMag12ToFloat(recast) * AMG88xx_THERMISTOR_CONVERSION;
}

/**************************************************************************/
/*!
@brief Read Infrared sensor raw values
@param buf the array to place the pixels in
@param pixels Optional number of pixels to read (up to 64). Default is
64 pixels. Each pixel value is 12 bits, so it is stored in 2 bytes of
the buf array,
@return up to 128 bytes of pixel data in buf
*/
/**************************************************************************/
void Adafruit_AMG88xx::readPixelsRaw(uint8_t *buf, uint8_t pixels) {
uint8_t bytesToRead =
min((uint8_t)(pixels << 1), (uint8_t)(AMG88xx_PIXEL_ARRAY_SIZE << 1));
this->read(AMG88xx_PIXEL_OFFSET, buf, bytesToRead);
}

/**************************************************************************/
/*!
@brief Read Infrared sensor values
@param buf the array to place the pixels in
@param size Optionsl number of bytes to read (up to 64). Default is 64
bytes.
@return up to 64 bytes of pixel data in buf
@param pixels Optional number of pixels to read (up to 64). Default is
64 pixels.
@return up to 64 float values of pixel data in buf
*/
/**************************************************************************/
void Adafruit_AMG88xx::readPixels(float *buf, uint8_t size) {
void Adafruit_AMG88xx::readPixels(float *buf, uint8_t pixels) {
uint16_t recast;
float converted;
uint8_t bytesToRead =
min((uint8_t)(size << 1), (uint8_t)(AMG88xx_PIXEL_ARRAY_SIZE << 1));
min((uint8_t)(pixels << 1), (uint8_t)(AMG88xx_PIXEL_ARRAY_SIZE << 1));
uint8_t rawArray[bytesToRead];
this->read(AMG88xx_PIXEL_OFFSET, rawArray, bytesToRead);

for (int i = 0; i < size; i++) {
for (int i = 0; i < pixels; i++) {
uint8_t pos = i << 1;
recast = ((uint16_t)rawArray[pos + 1] << 8) | ((uint16_t)rawArray[pos]);

Expand Down
3 changes: 2 additions & 1 deletion Adafruit_AMG88xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class Adafruit_AMG88xx {

bool begin(uint8_t addr = AMG88xx_ADDRESS, TwoWire *theWire = &Wire);

void readPixels(float *buf, uint8_t size = AMG88xx_PIXEL_ARRAY_SIZE);
void readPixelsRaw(uint8_t *buf, uint8_t pixels = AMG88xx_PIXEL_ARRAY_SIZE);
void readPixels(float *buf, uint8_t pixels = AMG88xx_PIXEL_ARRAY_SIZE);
float readThermistor();

void setMovingAverageMode(bool mode);
Expand Down

0 comments on commit 52a6327

Please sign in to comment.