50 #include "lib/sensors.h" 54 #define PRINTF(...) printf(__VA_ARGS__) 60 void (*iaq_enable_callback)(uint16_t value);
62 static int16_t enabled;
65 static simple_iaq_data iaq_data;
66 static uint8_t iaq_buffer[IAQ_FRAME_SIZE+1];
68 PROCESS(iaq_process,
"IAQ process handler");
74 if (type == IAQ_STATUS) {
75 return (uint16_t)iaq_data.status;
76 }
else if (type == IAQ_DRIVER_STATUS) {
90 i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN,
91 I2C_SCL_NORMAL_BUS_SPEED);
99 I2C_MASTER_ERR_NONE) {
100 PRINTF(
"IAQ: Failed to retrieve data from IAQ\n");
102 iaq_data.status = IAQ_INTERNAL_ERROR;
105 PRINTF(
"IAQ: Buffer ");
107 PRINTF(
"[%d] %x, ", i-1, iaq_buffer[i-1]);
113 switch (iaq_buffer[2]) {
114 case IAQ_INTERNAL_SUCCESS:
115 enabled = IAQ_ACTIVE;
117 case IAQ_INTERNAL_RUNIN:
118 enabled = IAQ_INIT_STATE;
120 case IAQ_INTERNAL_BUSY:
121 case IAQ_INTERNAL_ERROR:
129 iaq_data.tvoc = ((uint16_t)iaq_buffer[0] << 8) + iaq_buffer[1];
130 iaq_data.co2 = ((uint16_t)iaq_buffer[7] << 8) + iaq_buffer[8];
131 iaq_data.status = iaq_buffer[2];
141 PRINTF(
"IAQ: Sensor not enabled\n");
144 if (enabled == IAQ_INIT_STATE) {
145 PRINTF(
"IAQ: Sensor initializing\n");
146 return IAQ_INIT_STATE;
148 if (type == IAQ_CO2_VALUE) {
151 if (type == IAQ_VOC_VALUE) {
152 return iaq_data.tvoc;
154 if (type == IAQ_STATUS) {
156 switch (iaq_data.status) {
157 case IAQ_INTERNAL_SUCCESS:
158 PRINTF(
"IAQ Status: SUCCESS\n");
160 case IAQ_INTERNAL_RUNIN:
161 PRINTF(
"IAQ Status: WARM UP\n");
163 case IAQ_INTERNAL_BUSY:
164 case IAQ_INTERNAL_ERROR:
165 PRINTF(
"IAQ Status: ERROR\n");
168 PRINTF(
"IAQ Status: UNKNOWN STATUS %d\n", iaq_data.status);
172 return iaq_data.status;
179 configure(
int type,
int value)
183 if ((enabled == IAQ_INIT_STATE) || (enabled == IAQ_ACTIVE)) {
188 enabled = IAQ_INIT_STATE;
197 SENSORS_SENSOR(iaq, IAQ_SENSOR, value, configure, status);
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_BEGIN()
Define the beginning of a process.
Header file with register and macro declarations for the cc2538 GPIO module.
#define PROCESS_END()
Define the end of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Timer library header file.
#define PROCESS_EXITHANDLER(handler)
Specify an action when a process exits.
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
uint8_t i2c_burst_receive(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to receive multiple bytes from a slave.
Header file for the RE-Mote Sensor IAQ.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
void process_start(struct process *p, process_data_t data)
Start a process.
void i2c_master_enable(void)
Enable master I2C module.