Merge pull request #1446 from alignan/pull/tsl2563-sensor

Enhanced TSL2563 driver for the Zoul module (RE-Mote/Firefly)
This commit is contained in:
George Oikonomou 2016-01-11 11:21:51 +00:00
commit c394302c44
7 changed files with 508 additions and 59 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,32 +48,62 @@
#include <stdio.h>
#include "contiki.h"
#include "dev/i2c.h"
#include "dev/leds.h"
#include "dev/tsl2563.h"
/*---------------------------------------------------------------------------*/
#if 1
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 2)
/* Default sensor's integration cycle is 402ms */
#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();
int light;
static uint16_t light;
/* 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
* change the gain and timming, see tsl2563.h for more options
*/
/* 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", 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_EXIT();
}
}
PROCESS_END();
}