Skip to content

Commit

Permalink
Merge pull request #86 from MK16kawai/dev
Browse files Browse the repository at this point in the history
[thermal32] fixed compile error
  • Loading branch information
Neutree authored Jan 13, 2025
2 parents 637d7b4 + b50c73b commit bd99d58
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include <cstdint>

#include "maix_image.hpp"
#include "MLX90640_API.h"

#include "maix_cmap.hpp"

struct paramsMLX90640;

namespace maix::ext_dev::mlx90640 {

/**
Expand Down Expand Up @@ -102,6 +103,8 @@ class MLX90640Celsius final {
::maix::ext_dev::cmap::Cmap cmap=::maix::ext_dev::cmap::Cmap::WHITE_HOT,
float temp_min=-1, float temp_max=-1, float emissivity=0.95);

~MLX90640Celsius();

/**
* @brief Retrieves sensor data and returns a temperature matrix of size MLX_H * MLX_W
*
Expand Down Expand Up @@ -245,7 +248,8 @@ class MLX90640Celsius final {
uint16_t _eeMLX90640[832];
uint16_t _frame[834];
float _mlx90640To[768];
paramsMLX90640 _mlx90640;
// paramsMLX90640 _mlx90640;
std::unique_ptr<paramsMLX90640> _mlx90640;
Point _temp_min;
Point _temp_max;
Point _center;
Expand Down
42 changes: 9 additions & 33 deletions components/ext_devs/ext_dev_mlx90640/src/maix_mlx90640.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "maix_mlx90640.hpp"
#include "MLX90640_I2C_Driver.h"
#include "MLX90640_API.h"
#include "maix_basic.hpp"

namespace maix::ext_dev::mlx90640 {
Expand Down Expand Up @@ -58,21 +59,6 @@ KMatrix to_kmatrix(const CMatrix& matrix)
});

return kmatrix;

// size_t rows = matrix.size();
// size_t cols = rows > 0 ? matrix[0].size() : 0;

// KMatrix kmatrix(rows, std::vector<uint16_t>(cols));

// for (size_t i = 0; i < rows; ++i) {
// for (size_t j = 0; j < cols; ++j) {
// float celsius = matrix[i][j];
// float kelvin = (celsius+KC);
// kmatrix[i][j] = static_cast<uint16_t>(kelvin*100);
// }
// }

// return kmatrix;
}

CMatrix to_cmatrix(const KMatrix& matrix)
Expand All @@ -91,21 +77,6 @@ CMatrix to_cmatrix(const KMatrix& matrix)
});

return cmatrix;

// size_t rows = matrix.size();
// size_t cols = rows > 0 ? matrix[0].size() : 0;

// CMatrix cmatrix(rows, std::vector<float>(cols));

// for (size_t i = 0; i < rows; ++i) {
// for (size_t j = 0; j < cols; ++j) {
// float kelvin = static_cast<float>(matrix[i][j])/100;
// float celsius = kelvin-KC;
// cmatrix[i][j] = celsius;
// }
// }

// return cmatrix;
}

void make_maix_image_pixel(float min, float max, float value, uint8_t* buffer, const cmap::CmapArray* array)
Expand Down Expand Up @@ -147,6 +118,8 @@ MLX90640Kelvin::MLX90640Kelvin(int i2c_bus_num, FPS fps, Cmap cmap, float temp_m
this->_mlx = std::make_unique<MLX90640Celsius>(i2c_bus_num, fps, cmap, ctemp_min, ctemp_max, emissivity);
}



KMatrix MLX90640Kelvin::matrix()
{
return to_kmatrix(this->_mlx->matrix());
Expand Down Expand Up @@ -198,6 +171,7 @@ MLX90640Celsius::MLX90640Celsius(int i2c_bus_num, FPS fps, Cmap cmap, float temp
this->_max = temp_max;
this->_min = temp_min;
this->_emissivity = emissivity;
this->_mlx90640 = std::make_unique<paramsMLX90640>();

::memset(this->_eeMLX90640, 0x00, std::size(this->_eeMLX90640)*sizeof(uint16_t));
::memset(this->_frame, 0x00, std::size(this->_frame)*sizeof(uint16_t));
Expand All @@ -209,19 +183,21 @@ MLX90640Celsius::MLX90640Celsius(int i2c_bus_num, FPS fps, Cmap cmap, float temp

MLX90640_SetChessMode(MLX_ADDR);
MLX90640_DumpEE(MLX_ADDR, this->_eeMLX90640);
MLX90640_ExtractParameters(this->_eeMLX90640, &this->_mlx90640);
MLX90640_ExtractParameters(this->_eeMLX90640, this->_mlx90640.get());

}

MLX90640Celsius::~MLX90640Celsius() {}

CMatrix MLX90640Celsius::matrix()
{

MLX90640_GetFrameData(MLX_ADDR, this->_frame);

auto eTa = MLX90640_GetTa(this->_frame, &this->_mlx90640);
auto eTa = MLX90640_GetTa(this->_frame, this->_mlx90640.get());
auto eTr = eTa-8.0;

MLX90640_CalculateTo(this->_frame, &this->_mlx90640, this->_emissivity, eTr, this->_mlx90640To);
MLX90640_CalculateTo(this->_frame, this->_mlx90640.get(), this->_emissivity, eTr, this->_mlx90640To);

CMatrix m(MLX_H, std::vector<float>(MLX_W));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern "C" {

#define SCALEALPHA 0.000001

typedef struct
struct paramsMLX90640
{
int16_t kVdd;
int16_t vdd25;
Expand Down Expand Up @@ -110,7 +110,7 @@ typedef struct
float ilChessC[3];
uint16_t brokenPixels[5];
uint16_t outlierPixels[5];
} paramsMLX90640;
};

int MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData);
int MLX90640_SynchFrame(uint8_t slaveAddr);
Expand Down
2 changes: 1 addition & 1 deletion projects/app_thermal_camera/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ append_srcs_dir(ADD_SRCS "app" "assets")
###############################################

###### Add required/dependent components ######
list(APPEND ADD_REQUIREMENTS basic lvgl ext_dev)
list(APPEND ADD_REQUIREMENTS basic lvgl ext_dev_mlx90640)
###############################################

###### Add link search path for requirements/libs ######
Expand Down
2 changes: 1 addition & 1 deletion projects/app_thermal_camera/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int _main(int argc, char **argv)

float temp_min = 5.0f;
float temp_max = 45.0f;
float temp_cmap_oft = 2.0f;
// float temp_cmap_oft = 2.0f;


auto ret = find_device();
Expand Down

0 comments on commit bd99d58

Please sign in to comment.