Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions inc/mlx90632_depends.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
*/
extern int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value);

/** Read from two addresses from the mlx90632
*
* i2c read is processor specific and this function expects to have address of mlx90632 known, as it operates purely on
* register addresses.
*
* @note Needs to be implemented externally
* @param[in] register_address Address of the register to be read from
* @param[out] *value32 pointer to uint16_t array where read data can be written

* @retval 0 for success
* @retval <0 for failure
*
*/
extern int32_t mlx90632_i2c_read32(int16_t register_address, uint16_t* value32);

/** Write value to register_address of the mlx90632
*
* i2c write is processor specific and this function expects to have address of mlx90632 known, as it operates purely
Expand Down
25 changes: 9 additions & 16 deletions src/mlx90632.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,34 +188,27 @@ STATIC int32_t mlx90632_read_temp_object_raw(int32_t channel_position,
int16_t *object_new_raw, int16_t *object_old_raw)
{
int32_t ret;
uint16_t read_tmp;
uint16_t read_temp[2];
int16_t read;
uint8_t channel, channel_old;

ret = mlx90632_channel_new_select(channel_position, &channel, &channel_old);
if (ret != 0)
return -EINVAL;

ret = mlx90632_i2c_read(MLX90632_RAM_2(channel), &read_tmp);
ret = mlx90632_i2c_read32(MLX90632_RAM_1(channel), read_temp);
if (ret < 0)
return ret;
return ret;

read = (int16_t)read_tmp;

ret = mlx90632_i2c_read(MLX90632_RAM_1(channel), &read_tmp);
if (ret < 0)
return ret;
*object_new_raw = (read + (int16_t)read_tmp) / 2;
read = (int16_t)read_temp[1];
*object_new_raw = (read + (int16_t)read_temp[0]) >> 1;

ret = mlx90632_i2c_read(MLX90632_RAM_2(channel_old), &read_tmp);
ret = mlx90632_i2c_read32(MLX90632_RAM_1(channel_old), read_temp);
if (ret < 0)
return ret;
read = (int16_t)read_tmp;
return ret;

ret = mlx90632_i2c_read(MLX90632_RAM_1(channel_old), &read_tmp);
if (ret < 0)
return ret;
*object_old_raw = (read + (int16_t)read_tmp) / 2;
read = (int16_t)read_temp[1];
*object_old_raw = (read + (int16_t)read_temp[0]) >> 1;

return ret;
}
Expand Down