Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ir_mlx.c
Go to the documentation of this file.
1 /*
2  * $Id: ir_mlx.c $
3  *
4  * Copyright (C) 2010 Martin Mueller
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
32 #include "modules/meteo/ir_mlx.h"
33 
34 #include "mcu_periph/sys_time.h"
35 #include "mcu_periph/i2c.h"
36 #include "led.h"
37 #include "mcu_periph/uart.h"
38 #include "messages.h"
40 
41 #ifndef DOWNLINK_DEVICE
42 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
43 #endif
44 
45 #ifndef MLX_I2C_DEV
46 #define MLX_I2C_DEV i2c0
47 #endif
48 
50 
58 
59 /* I2C address is set to 3 */
60 #ifndef MLX90614_ADDR
61 #define MLX90614_ADDR 0x06
62 #endif
63 
64 // printf("Ta = %2.2f°C (0x%04X)\n", (tp*0.02)-273.15, tp);
65 
66 
67 void ir_mlx_init( void ) {
69 }
70 
71 void ir_mlx_periodic( void ) {
72  if (cpu_time_sec > 1) {
73  if (ir_mlx_status >= IR_MLX_IDLE) {
74  /* start two byte case temperature */
78  /* send serial number every 30 seconds */
79  RunOnceEvery((8*30), DOWNLINK_SEND_MLX_SERIAL(DefaultChannel, DefaultDevice, &ir_mlx_id_01, &ir_mlx_id_23));
80  } else if (ir_mlx_status == IR_MLX_UNINIT) {
81  /* start two byte ID 0 */
85  }
86  }
87 }
88 
89 void ir_mlx_event( void ) {
90  if ((mlx_trans.status == I2CTransSuccess)) {
91  switch (ir_mlx_status) {
92 
93  case IR_MLX_RD_ID_0:
94  /* read two byte ID 0 */
96  ir_mlx_id_01 |= mlx_trans.buf[1] << 8;
97  /* start two byte ID 1 */
101  break;
102 
103  case IR_MLX_RD_ID_1:
104  /* read two byte ID 1 */
105  ir_mlx_id_01 |= mlx_trans.buf[0] << 16;
106  ir_mlx_id_01 |= mlx_trans.buf[1] << 24;
107  /* start two byte ID 2 */
111  break;
112 
113  case IR_MLX_RD_ID_2:
114  /* read two byte ID 2 */
116  ir_mlx_id_23 |= mlx_trans.buf[1] << 8;
117  /* start two byte ID 3 */
121  break;
122 
123  case IR_MLX_RD_ID_3:
124  /* read two byte ID 3 */
125  ir_mlx_id_23 |= mlx_trans.buf[0] << 16;
126  ir_mlx_id_23 |= mlx_trans.buf[1] << 24;
129  DOWNLINK_SEND_MLX_SERIAL(DefaultChannel, DefaultDevice, &ir_mlx_id_01, &ir_mlx_id_23);
130  break;
131 
132  case IR_MLX_RD_CASE_TEMP:
133  /* read two byte case temperature */
134  ir_mlx_itemp_case = mlx_trans.buf[1] << 8;
136  ir_mlx_temp_case = ir_mlx_itemp_case*0.02 - 273.15;
137 
138  /* start two byte obj temperature */
142  break;
143 
144  case IR_MLX_RD_OBJ_TEMP:
145  /* read two byte obj temperature */
146  ir_mlx_itemp_obj = mlx_trans.buf[1] << 8;
148  ir_mlx_temp_obj = ir_mlx_itemp_obj*0.02 - 273.15;
150 
151  DOWNLINK_SEND_MLX_STATUS(DefaultChannel, DefaultDevice,
155  &ir_mlx_temp_obj);
156  break;
157  default:
159  break;
160  }
161  }
162 }
#define MLX90614_ID_0
Definition: ir_mlx.h:8
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define MLX_I2C_DEV
Definition: ir_mlx.c:46
#define MLX90614_ID_3
Definition: ir_mlx.h:11
#define MLX90614_ID_1
Definition: ir_mlx.h:9
uint32_t ir_mlx_id_01
Definition: ir_mlx.c:56
#define MLX90614_TA
Definition: ir_mlx.h:6
void ir_mlx_event(void)
Definition: ir_mlx.c:89
#define MLX90614_TOBJ
Definition: ir_mlx.h:7
uint16_t ir_mlx_itemp_obj
Definition: ir_mlx.c:54
#define cpu_time_sec
Definition: sys_time.h:64
#define MLX90614_ADDR
Definition: ir_mlx.c:61
float ir_mlx_temp_case
Definition: ir_mlx.c:53
uint16_t ir_mlx_itemp_case
Definition: ir_mlx.c:52
Architecture independent timing functions.
unsigned long uint32_t
Definition: types.h:18
float ir_mlx_temp_obj
Definition: ir_mlx.c:55
struct i2c_transaction mlx_trans
Definition: ir_mlx.c:49
void ir_mlx_periodic(void)
Definition: ir_mlx.c:71
void ir_mlx_init(void)
Definition: ir_mlx.c:67
enum I2CTransactionStatus status
Definition: i2c.h:47
#define MLX90614_ID_2
Definition: ir_mlx.h:10
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
unsigned char uint8_t
Definition: types.h:14
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r)
Definition: i2c.h:156
uint8_t ir_mlx_status
Definition: ir_mlx.c:51
arch independent LED (Light Emitting Diodes) API
uint32_t ir_mlx_id_23
Definition: ir_mlx.c:57