Merge pull request #1523 from Zolertia/pull/z1-apify-sensors
Adapt Z1 on-board sensors to Contiki's API
This commit is contained in:
commit
862e43d9b0
6 changed files with 442 additions and 511 deletions
|
@ -42,10 +42,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "serial-shell.h"
|
||||
#include "shell-ps.h"
|
||||
#include "shell-file.h"
|
||||
#include "shell-text.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/adxl345.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LED_INT_ONTIME (CLOCK_SECOND / 2)
|
||||
|
@ -91,7 +88,7 @@ print_int(uint16_t reg)
|
|||
void
|
||||
accm_ff_cb(uint8_t reg)
|
||||
{
|
||||
L_ON(LEDS_B);
|
||||
leds_on(LEDS_BLUE);
|
||||
process_post(&led_process, led_off_event, NULL);
|
||||
printf("~~[%u] Freefall detected! (0x%02X) -- ",
|
||||
((uint16_t)clock_time()) / 128, reg);
|
||||
|
@ -105,11 +102,11 @@ accm_tap_cb(uint8_t reg)
|
|||
{
|
||||
process_post(&led_process, led_off_event, NULL);
|
||||
if(reg & ADXL345_INT_DOUBLETAP) {
|
||||
L_ON(LEDS_G);
|
||||
leds_on(LEDS_GREEN);
|
||||
printf("~~[%u] DoubleTap detected! (0x%02X) -- ",
|
||||
((uint16_t)clock_time()) / 128, reg);
|
||||
} else {
|
||||
L_ON(LEDS_R);
|
||||
leds_on(LEDS_RED);
|
||||
printf("~~[%u] Tap detected! (0x%02X) -- ",
|
||||
((uint16_t)clock_time()) / 128, reg);
|
||||
}
|
||||
|
@ -122,46 +119,46 @@ PROCESS_THREAD(led_process, ev, data) {
|
|||
PROCESS_WAIT_EVENT_UNTIL(ev == led_off_event);
|
||||
etimer_set(&led_etimer, LED_INT_ONTIME);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&led_etimer));
|
||||
L_OFF(LEDS_R + LEDS_G + LEDS_B);
|
||||
leds_off(LEDS_RED + LEDS_GREEN + LEDS_BLUE);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Main process, setups */
|
||||
PROCESS_THREAD(accel_process, ev, data) {
|
||||
PROCESS_THREAD(accel_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
{
|
||||
int16_t x, y, z;
|
||||
|
||||
serial_shell_init();
|
||||
shell_ps_init();
|
||||
shell_file_init(); /* for printing out files */
|
||||
shell_text_init(); /* for binprint */
|
||||
int16_t x, y, z;
|
||||
|
||||
/* Register the event used for lighting up an LED when interrupt strikes. */
|
||||
led_off_event = process_alloc_event();
|
||||
/* Register the event used for lighting up an LED when interrupt strikes. */
|
||||
led_off_event = process_alloc_event();
|
||||
|
||||
/* Start and setup the accelerometer with default values, eg no interrupts enabled. */
|
||||
accm_init();
|
||||
/* Start and setup the accelerometer with default values, eg no interrupts
|
||||
* enabled.
|
||||
*/
|
||||
SENSORS_ACTIVATE(adxl345);
|
||||
|
||||
/* Register the callback functions for each interrupt */
|
||||
ACCM_REGISTER_INT1_CB(accm_ff_cb);
|
||||
ACCM_REGISTER_INT2_CB(accm_tap_cb);
|
||||
/* Register the callback functions for each interrupt */
|
||||
ACCM_REGISTER_INT1_CB(accm_ff_cb);
|
||||
ACCM_REGISTER_INT2_CB(accm_tap_cb);
|
||||
|
||||
/* Set what strikes the corresponding interrupts. Several interrupts per pin is
|
||||
possible. For the eight possible interrupts, see adxl345.h and adxl345 datasheet. */
|
||||
accm_set_irq(ADXL345_INT_FREEFALL, ADXL345_INT_TAP + ADXL345_INT_DOUBLETAP);
|
||||
/* Set what strikes the corresponding interrupts. Several interrupts per
|
||||
* pin is possible. For the eight possible interrupts, see adxl345.h and
|
||||
* adxl345 datasheet.
|
||||
*/
|
||||
accm_set_irq(ADXL345_INT_FREEFALL, ADXL345_INT_TAP + ADXL345_INT_DOUBLETAP);
|
||||
|
||||
while(1) {
|
||||
x = accm_read_axis(X_AXIS);
|
||||
y = accm_read_axis(Y_AXIS);
|
||||
z = accm_read_axis(Z_AXIS);
|
||||
printf("x: %d y: %d z: %d\n", x, y, z);
|
||||
while(1) {
|
||||
x = adxl345.value(X_AXIS);
|
||||
y = adxl345.value(Y_AXIS);
|
||||
z = adxl345.value(Z_AXIS);
|
||||
printf("x: %d y: %d z: %d\n", x, y, z);
|
||||
|
||||
etimer_set(&et, ACCM_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
}
|
||||
etimer_set(&et, ACCM_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* Copyright (c) 2010-2016, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -32,9 +32,10 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* A quick program for testing the tmp102 driver in the Z1 platform
|
||||
* A quick program for testing the tmp102 sensor in the Z1 platform
|
||||
* \author
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
|
@ -44,7 +45,7 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
#define TMP102_READ_INTERVAL (CLOCK_SECOND / 2)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(temp_process, "Test Temperature process");
|
||||
PROCESS(temp_process, "TMP102 Temperature sensor process");
|
||||
AUTOSTART_PROCESSES(&temp_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
|
@ -55,12 +56,12 @@ PROCESS_THREAD(temp_process, ev, data)
|
|||
|
||||
int16_t temp;
|
||||
|
||||
tmp102_init();
|
||||
SENSORS_ACTIVATE(tmp102);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, TMP102_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
temp = tmp102_read_temp_x100();
|
||||
temp = tmp102.value(TMP102_READ);
|
||||
printf("Temp = %d\n", temp);
|
||||
}
|
||||
PROCESS_END();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue