Added interruption feature to the TSL2563 driver

This commit is contained in:
Antonio Lignan 2016-01-07 00:41:14 +01:00
parent 881e78cb60
commit a8a1ebf8b5
5 changed files with 146 additions and 50 deletions

View file

@ -39,6 +39,7 @@
#define PROJECT_CONF_H_
#define BROADCAST_CHANNEL 129
#define NETSTACK_CONF_RDC nullrdc_driver
#endif /* PROJECT_CONF_H_ */

View file

@ -48,16 +48,24 @@
#include <stdio.h>
#include "contiki.h"
#include "dev/i2c.h"
#include "dev/leds.h"
#include "dev/tsl2563.h"
/*---------------------------------------------------------------------------*/
/* Default sensor's integration cycle is 402ms */
#define SENSOR_READ_INTERVAL (CLOCK_SECOND/2)
#define SENSOR_READ_INTERVAL (CLOCK_SECOND)
/*---------------------------------------------------------------------------*/
PROCESS(remote_tsl2563_process, "TSL2563 test process");
AUTOSTART_PROCESSES(&remote_tsl2563_process);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
void
light_interrupt_callback(uint8_t value)
{
printf("* Light sensor interrupt!\n");
leds_toggle(LEDS_PURPLE);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(remote_tsl2563_process, ev, data)
{
PROCESS_BEGIN();
@ -66,16 +74,35 @@ PROCESS_THREAD(remote_tsl2563_process, ev, data)
/* Use Contiki's sensor macro to enable the sensor */
SENSORS_ACTIVATE(tsl2563);
/* Default integration time is 402ms with 1x gain, use the below call to
/* Default integration time is 402ms with 1x gain, use the below call to
* change the gain and timming, see tsl2563.h for more options
*/
// tsl2563.configure(TSL2563_TIMMING_CFG, TSL2563_G16X_402MS);
/* tsl2563.configure(TSL2563_TIMMING_CFG, TSL2563_G16X_402MS); */
/* Register the interrupt handler */
TSL2563_REGISTER_INT(light_interrupt_callback);
/* Enable the interrupt source for values over the threshold. The sensor
* compares against the value of CH0, one way to find out the required
* threshold for a given lux quantity is to enable the DEBUG flag and see
* the CH0 value for a given measurement. The other is to reverse the
* calculations done in the calculate_lux() function. The below value roughly
* represents a 2500 lux threshold, same as pointing a flashlight directly
*/
tsl2563.configure(TSL2563_INT_OVER, 0x15B8);
/* And periodically poll the sensor */
while(1) {
etimer_set(&et, SENSOR_READ_INTERVAL);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
light = tsl2563.value(TSL2563_VAL_READ);
printf("Light = %u\n", (uint16_t) light);
if(light != TSL2563_ERROR) {
printf("Light = %u\n", (uint16_t)light);
} else {
printf("Error, enable the DEBUG flag in the tsl2563 driver for info, ");
printf("or check if the sensor is properly connected\n");
}
}
PROCESS_END();
}