LibDriver MLX90614  1.0.0
MLX90614 full-featured driver
driver_mlx90614_advance.c
Go to the documentation of this file.
1 
38 
39 static mlx90614_handle_t gs_handle;
48 uint8_t mlx90614_advance_init(void)
49 {
50  uint8_t res;
51  uint16_t reg;
52 
53  /* link interface function */
63 
64  /* set address */
66  if (res != 0)
67  {
68  mlx90614_interface_debug_print("mlx90614: set addr failed.\n");
69 
70  return 1;
71  }
72 
73  /* mlx90614 init */
74  res = mlx90614_init(&gs_handle);
75  if (res != 0)
76  {
77  mlx90614_interface_debug_print("mlx90614: init failed.\n");
78 
79  return 1;
80  }
81 
82  /* pwm to smbus */
83  res = mlx90614_pwm_to_smbus(&gs_handle);
84  if (res != 0)
85  {
86  mlx90614_interface_debug_print("mlx90614: pwm to smbus failed.\n");
87  (void)(void)mlx90614_deinit(&gs_handle);
88 
89  return 1;
90  }
91 
92  /* exit sleep mode */
93  res = mlx90614_exit_sleep_mode(&gs_handle);
94  if (res != 0)
95  {
96  mlx90614_interface_debug_print("mlx90614: exit sleep mode failed.\n");
97  (void)(void)mlx90614_deinit(&gs_handle);
98 
99  return 1;
100  }
101 
102  /* set default fir length */
104  if (res != 0)
105  {
106  mlx90614_interface_debug_print("mlx90614: set fir length failed.\n");
107  (void)mlx90614_deinit(&gs_handle);
108 
109  return 1;
110  }
111 
112  /* set default iir */
114  if (res != 0)
115  {
116  mlx90614_interface_debug_print("mlx90614: set iir failed.\n");
117  (void)mlx90614_deinit(&gs_handle);
118 
119  return 1;
120  }
121 
122  /* set default mode */
124  if (res != 0)
125  {
126  mlx90614_interface_debug_print("mlx90614: set mode failed.\n");
127  (void)mlx90614_deinit(&gs_handle);
128 
129  return 1;
130  }
131 
132  /* set default ir sensor */
134  if (res != 0)
135  {
136  mlx90614_interface_debug_print("mlx90614: set ir sensor failed.\n");
137  (void)mlx90614_deinit(&gs_handle);
138 
139  return 1;
140  }
141 
142  /* set default ks */
143  res = mlx90614_set_ks(&gs_handle, MLX90614_ADVANCE_DEFAULT_KS);
144  if (res != 0)
145  {
146  mlx90614_interface_debug_print("mlx90614: set ks failed.\n");
147  (void)mlx90614_deinit(&gs_handle);
148 
149  return 1;
150  }
151 
152  /* set default kt2 */
154  if (res != 0)
155  {
156  mlx90614_interface_debug_print("mlx90614: set kt2 failed.\n");
157  (void)mlx90614_deinit(&gs_handle);
158 
159  return 1;
160  }
161 
162  /* set default gain */
164  if (res != 0)
165  {
166  mlx90614_interface_debug_print("mlx90614: set gain failed.\n");
167  (void)mlx90614_deinit(&gs_handle);
168 
169  return 1;
170  }
171 
172  /* set default sensor test */
174  if (res != 0)
175  {
176  mlx90614_interface_debug_print("mlx90614: set sensor test failed.\n");
177  (void)mlx90614_deinit(&gs_handle);
178 
179  return 1;
180  }
181 
182  /* set default repeat sensor test */
184  if (res != 0)
185  {
186  mlx90614_interface_debug_print("mlx90614: set repeat sensor test failed.\n");
187  (void)mlx90614_deinit(&gs_handle);
188 
189  return 1;
190  }
191 
192  /* convert emissivity correction coefficient */
195  (uint16_t *)&reg);
196  if (res != 0)
197  {
198  mlx90614_interface_debug_print("mlx90614: emissivity correction coefficient convert to register failed.\n");
199  (void)mlx90614_deinit(&gs_handle);
200 
201  return 1;
202  }
203 
204  /* set default emissivity correction coefficient */
205  res = mlx90614_set_emissivity_correction_coefficient(&gs_handle, reg);
206  if (res != 0)
207  {
208  mlx90614_interface_debug_print("mlx90614: set emissivity correction coefficient failed.\n");
209  (void)mlx90614_deinit(&gs_handle);
210 
211  return 1;
212  }
213 
214  return 0;
215 }
216 
225 {
226  uint8_t res;
227 
228  /* deinit */
229  res = mlx90614_deinit(&gs_handle);
230  if (res != 0)
231  {
232  return 1;
233  }
234  else
235  {
236  return 0;
237  }
238 }
239 
248 {
249  uint8_t res;
250 
251  /* enter sleep */
252  res = mlx90614_enter_sleep_mode(&gs_handle);
253  if (res != 0)
254  {
255  return 1;
256  }
257  else
258  {
259  return 0;
260  }
261 }
262 
271 {
272  uint8_t res;
273 
274  /* exit sleep */
275  res = mlx90614_exit_sleep_mode(&gs_handle);
276  if (res != 0)
277  {
278  return 1;
279  }
280  else
281  {
282  return 0;
283  }
284 }
285 
295 uint8_t mlx90614_advance_read(float *ambient, float *object)
296 {
297  uint8_t res;
298  uint16_t raw;
299 
300  /* read ambient */
301  res = mlx90614_read_ambient(&gs_handle, (uint16_t *)&raw, ambient);
302  if (res != 0)
303  {
304  return 1;
305  }
306 
307  /* read object1 */
308  res = mlx90614_read_object1(&gs_handle, (uint16_t *)&raw, object);
309  if (res != 0)
310  {
311  return 1;
312  }
313 
314  return 0;
315 }
316 
325 uint8_t mlx90614_advance_get_id(uint16_t id[4])
326 {
327  uint8_t res;
328 
329  /* read id */
330  res = mlx90614_get_id(&gs_handle, id);
331  if (res != 0)
332  {
333  return 1;
334  }
335  else
336  {
337  return 0;
338  }
339 }
driver mlx90614 advance header file
uint8_t mlx90614_set_gain(mlx90614_handle_t *handle, mlx90614_gain_t gain)
set the gain param
uint8_t mlx90614_set_fir_length(mlx90614_handle_t *handle, mlx90614_fir_length_t len)
set the ir sensor fir length
uint8_t mlx90614_set_repeat_sensor_test(mlx90614_handle_t *handle, mlx90614_bool_t enable)
enable or disable the repeat sensor test
uint8_t mlx90614_get_id(mlx90614_handle_t *handle, uint16_t id[4])
get the chip id
uint8_t mlx90614_set_mode(mlx90614_handle_t *handle, mlx90614_mode_t mode)
set the mode
uint8_t mlx90614_set_emissivity_correction_coefficient(mlx90614_handle_t *handle, uint16_t value)
set the emissivity correction coefficient
uint8_t mlx90614_set_iir(mlx90614_handle_t *handle, mlx90614_iir_t iir)
set the iir param
uint8_t mlx90614_set_ir_sensor(mlx90614_handle_t *handle, mlx90614_ir_sensor_t sensor)
set the ir sensor mode
uint8_t mlx90614_exit_sleep_mode(mlx90614_handle_t *handle)
exit from sleep mode
uint8_t mlx90614_set_ks(mlx90614_handle_t *handle, mlx90614_ks_t ks)
set the ks param
uint8_t mlx90614_pwm_to_smbus(mlx90614_handle_t *handle)
change pwm mode to smbus mode
uint8_t mlx90614_set_kt2(mlx90614_handle_t *handle, mlx90614_kt2_t kt2)
set the kt2 param
uint8_t mlx90614_set_sensor_test(mlx90614_handle_t *handle, mlx90614_bool_t enable)
enable or disable the sensor test
uint8_t mlx90614_enter_sleep_mode(mlx90614_handle_t *handle)
enter to sleep mode
uint8_t mlx90614_emissivity_correction_coefficient_convert_to_register(mlx90614_handle_t *handle, double s, uint16_t *reg)
convert the emissivity correction coefficient to the register raw data
uint8_t mlx90614_read_object1(mlx90614_handle_t *handle, uint16_t *raw, float *celsius)
read the object1
uint8_t mlx90614_init(mlx90614_handle_t *handle)
initialize the chip
uint8_t mlx90614_set_addr(mlx90614_handle_t *handle, uint8_t addr)
set the address
uint8_t mlx90614_read_ambient(mlx90614_handle_t *handle, uint16_t *raw, float *celsius)
read the ambient
uint8_t mlx90614_deinit(mlx90614_handle_t *handle)
close the chip
@ MLX90614_ADDRESS_DEFAULT
#define MLX90614_ADVANCE_DEFAULT_KS
#define MLX90614_ADVANCE_DEFAULT_MODE
#define MLX90614_ADVANCE_DEFAULT_GAIN
uint8_t mlx90614_advance_init(void)
advance example init
#define MLX90614_ADVANCE_DEFAULT_KT2
uint8_t mlx90614_advance_read(float *ambient, float *object)
advance example read
#define MLX90614_ADVANCE_DEFAULT_REPEAT_SENSOR_TEST
uint8_t mlx90614_advance_get_id(uint16_t id[4])
advance example get id
#define MLX90614_ADVANCE_DEFAULT_SENSOR_TEST
uint8_t mlx90614_advance_deinit(void)
advance example deinit
#define MLX90614_ADVANCE_DEFAULT_FIR_LENGTH
mlx90614 advance example default definition
#define MLX90614_ADVANCE_DEFAULT_EMISSIVITY_CORRECTION_COEFFICIENT
#define MLX90614_ADVANCE_DEFAULT_IR_SENSOR
#define MLX90614_ADVANCE_DEFAULT_IIR
uint8_t mlx90614_advance_enter_sleep(void)
advance example enter sleep
uint8_t mlx90614_advance_exit_sleep(void)
advance example exit sleep
uint8_t mlx90614_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t mlx90614_interface_iic_init(void)
interface iic bus init
void mlx90614_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t mlx90614_interface_iic_deinit(void)
interface iic bus deinit
uint8_t mlx90614_interface_sda_write(uint8_t value)
interface sda write
uint8_t mlx90614_interface_scl_write(uint8_t value)
interface scl write
uint8_t mlx90614_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void mlx90614_interface_debug_print(const char *const fmt,...)
interface print format data
mlx90614 handle structure definition