mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
Clear interrupt and trigger callback if new data is generated
This commit is contained in:
parent
f5b52e8094
commit
426fa24e50
@ -98,6 +98,9 @@ PROCESS_THREAD(remote_grove_gyro_process, ev, data)
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
/* Register the interrupt handler */
|
||||
GROVE_GYRO_REGISTER_INT(gyro_interrupt_callback);
|
||||
|
||||
/* The gyroscope sensor should be on now but the three gyroscope axis should
|
||||
* be off, to enable a single axis or any combination of the 3 you can use as
|
||||
* argument either GROVE_GYRO_X, GROVE_GYRO_Y, GROVE_GYRO_Z. To enable or
|
||||
@ -105,8 +108,12 @@ PROCESS_THREAD(remote_grove_gyro_process, ev, data)
|
||||
*/
|
||||
grove_gyro.configure(GROVE_GYRO_POWER_ON, GROVE_GYRO_XYZ);
|
||||
|
||||
/* Register the interrupt handler */
|
||||
GROVE_GYRO_REGISTER_INT(gyro_interrupt_callback);
|
||||
/* Enabling the data interrupt will feed data directly to the extern data
|
||||
* structure and notify us about it, depending on the sampling rate and
|
||||
* divisor this could generate many interrupts/second. A zero argument would
|
||||
* disable the interrupts
|
||||
*/
|
||||
grove_gyro.configure(GROVE_GYRO_DATA_INTERRUPT, 1);
|
||||
|
||||
/* And periodically poll the sensor, values are in º/s */
|
||||
|
||||
@ -124,12 +131,12 @@ PROCESS_THREAD(remote_grove_gyro_process, ev, data)
|
||||
if(grove_gyro.value(GROVE_GYRO_XYZ) == GROVE_GYRO_SUCCESS) {
|
||||
|
||||
/* Converted values with a 2-digit precision */
|
||||
printf("Gyro: X %u.%u, Y %u.%u, Z %u.%u\n", gyro_values.x / 100,
|
||||
gyro_values.x % 100,
|
||||
gyro_values.y / 100,
|
||||
gyro_values.y % 100,
|
||||
gyro_values.z / 100,
|
||||
gyro_values.z % 100);
|
||||
printf("Gyro: X: %u.%u, Y: %u.%u, Z: %u.%u\n", gyro_values.x / 100,
|
||||
gyro_values.x % 100,
|
||||
gyro_values.y / 100,
|
||||
gyro_values.y % 100,
|
||||
gyro_values.z / 100,
|
||||
gyro_values.z % 100);
|
||||
} else {
|
||||
printf("Error, enable the DEBUG flag in the grove-gyro driver for info,");
|
||||
printf(" or check if the sensor is properly connected\n");
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "dev/grove-gyro.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG 1
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
@ -110,10 +110,19 @@ grove_gyro_sampdiv(uint8_t value)
|
||||
return GROVE_GYRO_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
static uint8_t
|
||||
grove_gyro_clear_interrupt(void)
|
||||
{
|
||||
/* FIXME */
|
||||
uint8_t aux = 0;
|
||||
|
||||
/* Clear interrupt */
|
||||
grove_gyro_read_reg(GROVE_GYRO_INT_STATUS, &aux, 1);
|
||||
|
||||
if(aux & GROVE_GYRO_INT_STATUS_DATA_RDY_MASK) {
|
||||
return GROVE_GYRO_INT_STATUS_DATA_RDY_MASK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
@ -199,7 +208,7 @@ grove_gyro_power_mgmt(uint8_t value, uint8_t type)
|
||||
|
||||
/* Power-up delay */
|
||||
if(type == GROVE_GYRO_POWER_ON) {
|
||||
// clock_delay_usec(50000);
|
||||
clock_delay_usec(25000);
|
||||
}
|
||||
|
||||
return GROVE_GYRO_SUCCESS;
|
||||
@ -345,10 +354,20 @@ PROCESS_THREAD(grove_gyro_int_process, ev, data)
|
||||
PROCESS_EXITHANDLER();
|
||||
PROCESS_BEGIN();
|
||||
|
||||
static uint8_t axis_to_read = 0;
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
||||
grove_gyro_clear_interrupt();
|
||||
grove_gyro_int_callback(0);
|
||||
if(grove_gyro_clear_interrupt() == GROVE_GYRO_INT_STATUS_DATA_RDY_MASK) {
|
||||
|
||||
axis_to_read += (power_mgmt & GROVE_GYRO_X) ? 0: GROVE_GYRO_X;
|
||||
axis_to_read += (power_mgmt & GROVE_GYRO_Y) ? 0: GROVE_GYRO_Y;
|
||||
axis_to_read += (power_mgmt & GROVE_GYRO_Z) ? 0: GROVE_GYRO_Z;
|
||||
|
||||
if(grove_gyro_read(axis_to_read) == GROVE_GYRO_SUCCESS) {
|
||||
grove_gyro_int_callback(GROVE_GYRO_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
@ -466,7 +485,6 @@ configure(int type, int value)
|
||||
|
||||
/* Enable interrupt and latch the pin until cleared */
|
||||
if(grove_gyro_interrupt(GROVE_GYRO_INT_CFG_RAW_READY_EN +
|
||||
GROVE_GYRO_INT_CFG_LATCH_CLR_ANY +
|
||||
GROVE_GYRO_INT_CFG_LATCH_EN) == GROVE_GYRO_ERROR) {
|
||||
PRINTF("Gyro: failed to enable the interrupt\n");
|
||||
return GROVE_GYRO_ERROR;
|
||||
|
Loading…
Reference in New Issue
Block a user