Fix code style: Z1 main examples

This commit is contained in:
George Oikonomou 2015-11-24 12:00:23 +00:00 committed by Antonio Lignan
parent afa5ab1ae4
commit e1f6d39857
10 changed files with 108 additions and 165 deletions

View File

@ -47,36 +47,27 @@
#include "shell-file.h"
#include "shell-text.h"
#include "dev/adxl345.h"
#define LED_INT_ONTIME CLOCK_SECOND/2
/*---------------------------------------------------------------------------*/
#define LED_INT_ONTIME (CLOCK_SECOND / 2)
#define ACCM_READ_INTERVAL CLOCK_SECOND
static process_event_t ledOff_event;
/*---------------------------------------------------------------------------*/
static process_event_t led_off_event;
static struct etimer led_etimer;
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS(accel_process, "Test Accel process");
PROCESS(led_process, "LED handling process");
AUTOSTART_PROCESSES(&accel_process, &led_process);
/*---------------------------------------------------------------------------*/
/* As several interrupts can be mapped to one interrupt pin, when interrupt
strikes, the adxl345 interrupt source register is read. This function prints
out which interrupts occurred. Note that this will include all interrupts,
even those mapped to 'the other' pin, and those that will always signal even if
not enabled (such as watermark). */
/* As several interrupts can be mapped to one interrupt pin, when interrupt
* strikes, the adxl345 interrupt source register is read. This function prints
* out which interrupts occurred. Note that this will include all interrupts,
* even those mapped to 'the other' pin, and those that will always signal even
* if not enabled (such as watermark).
*/
void
print_int(uint16_t reg){
#define ANNOYING_ALWAYS_THERE_ANYWAY_OUTPUT 0
#if ANNOYING_ALWAYS_THERE_ANYWAY_OUTPUT
if(reg & ADXL345_INT_OVERRUN) {
printf("Overrun ");
}
if(reg & ADXL345_INT_WATERMARK) {
printf("Watermark ");
}
if(reg & ADXL345_INT_DATAREADY) {
printf("DataReady ");
}
#endif
print_int(uint16_t reg)
{
if(reg & ADXL345_INT_FREEFALL) {
printf("Freefall ");
}
@ -94,74 +85,49 @@ print_int(uint16_t reg){
}
printf("\n");
}
/*---------------------------------------------------------------------------*/
/* accelerometer free fall detection callback */
void
accm_ff_cb(uint8_t reg){
accm_ff_cb(uint8_t reg)
{
L_ON(LEDS_B);
process_post(&led_process, ledOff_event, NULL);
printf("~~[%u] Freefall detected! (0x%02X) -- ", ((uint16_t) clock_time())/128, reg);
process_post(&led_process, led_off_event, NULL);
printf("~~[%u] Freefall detected! (0x%02X) -- ",
((uint16_t)clock_time()) / 128, reg);
print_int(reg);
}
/*---------------------------------------------------------------------------*/
/* accelerometer tap and double tap detection callback */
void
accm_tap_cb(uint8_t reg){
process_post(&led_process, ledOff_event, NULL);
if(reg & ADXL345_INT_DOUBLETAP){
accm_tap_cb(uint8_t reg)
{
process_post(&led_process, led_off_event, NULL);
if(reg & ADXL345_INT_DOUBLETAP) {
L_ON(LEDS_G);
printf("~~[%u] DoubleTap detected! (0x%02X) -- ", ((uint16_t) clock_time())/128, reg);
printf("~~[%u] DoubleTap detected! (0x%02X) -- ",
((uint16_t)clock_time()) / 128, reg);
} else {
L_ON(LEDS_R);
printf("~~[%u] Tap detected! (0x%02X) -- ", ((uint16_t) clock_time())/128, reg);
printf("~~[%u] Tap detected! (0x%02X) -- ",
((uint16_t)clock_time()) / 128, reg);
}
print_int(reg);
}
/*---------------------------------------------------------------------------*/
/* When posted an ledOff event, the LEDs will switch off after LED_INT_ONTIME.
static process_event_t ledOff_event;
ledOff_event = process_alloc_event();
process_post(&led_process, ledOff_event, NULL);
*/
static struct etimer ledETimer;
PROCESS_THREAD(led_process, ev, data) {
PROCESS_BEGIN();
while(1){
PROCESS_WAIT_EVENT_UNTIL(ev == ledOff_event);
etimer_set(&ledETimer, LED_INT_ONTIME);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ledETimer));
while(1) {
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);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/* Returns a string with the argument byte written in binary.
Example usage:
printf("Port1: %s\n", char2bin(P1IN));
*/
/*
static uint8_t b[9];
static uint8_t
*char2bin(uint8_t x) {
uint8_t z;
b[8] = '\0';
for (z = 0; z < 8; z++) {
b[7-z] = (x & (1 << z)) ? '1' : '0';
}
return b;
}
*/
/*---------------------------------------------------------------------------*/
/* Main process, setups */
static struct etimer et;
PROCESS_THREAD(accel_process, ev, data) {
PROCESS_BEGIN();
{
@ -169,11 +135,11 @@ PROCESS_THREAD(accel_process, ev, data) {
serial_shell_init();
shell_ps_init();
shell_file_init(); // for printing out files
shell_text_init(); // for binprint
shell_file_init(); /* for printing out files */
shell_text_init(); /* for binprint */
/* Register the event used for lighting up an LED when interrupt strikes. */
ledOff_event = process_alloc_event();
led_off_event = process_alloc_event();
/* Start and setup the accelerometer with default values, eg no interrupts enabled. */
accm_init();
@ -182,15 +148,15 @@ PROCESS_THREAD(accel_process, ev, data) {
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. */
/* 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 = 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);
etimer_set(&et, ACCM_READ_INTERVAL);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
@ -198,6 +164,5 @@ PROCESS_THREAD(accel_process, ev, data) {
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,30 +29,27 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Testing the internal MSP430 battery sensor on the Zolertia Z1 Platform.
* \author
* Enric M. Calvo <ecalvo@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/battery-sensor.h"
#include <stdio.h> /* For printf() */
#include <stdio.h>
/*---------------------------------------------------------------------------*/
float
floor(float x)
{
if(x >= 0.0f) {
return (float) ((int) x);
return (float)((int)x);
} else {
return (float) ((int) x - 1);
return (float)((int)x - 1);
}
}
/*---------------------------------------------------------------------------*/
PROCESS(test_battery_process, "Battery Sensor Test");
AUTOSTART_PROCESSES(&test_battery_process);
@ -67,13 +64,12 @@ PROCESS_THREAD(test_battery_process, ev, data)
while(1) {
uint16_t bateria = battery_sensor.value(0);
float mv = (bateria * 2.500 * 2) / 4096;
printf("Battery: %i (%ld.%03d mV)\n", bateria, (long) mv,
(unsigned) ((mv - floor(mv)) * 1000));
printf("Battery: %i (%ld.%03d mV)\n", bateria, (long)mv,
(unsigned)((mv - floor(mv)) * 1000));
}
SENSORS_DEACTIVATE(battery_sensor);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,32 +29,32 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A quick program for testing the light ziglet driver in the Z1 platform
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/i2cmaster.h"
#include "dev/light-ziglet.h"
#if 1
/*---------------------------------------------------------------------------*/
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 2)
/*---------------------------------------------------------------------------*/
PROCESS(test_process, "Test light ziglet process");
AUTOSTART_PROCESSES(&test_process);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_process, ev, data)
{
PROCESS_BEGIN();
@ -75,3 +75,4 @@ PROCESS_THREAD(test_process, ev, data)
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,7 +29,7 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* An example of how to use the button and light sensor on
@ -37,44 +37,41 @@
* \author
* Joakim Eriksson <joakime@sics.se>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include "dev/z1-phidgets.h"
/*---------------------------------------------------------------------------*/
PROCESS(test_button_process, "Test Button & Phidgets");
AUTOSTART_PROCESSES(&test_button_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_button_process, ev, data)
{
//static struct etimer et;
/* static struct etimer et; */
PROCESS_BEGIN();
SENSORS_ACTIVATE(phidgets);
SENSORS_ACTIVATE(button_sensor);
while(1) {
//etimer_set(&et, CLOCK_SECOND/2);
printf("Please press the User Button\n");
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);
//PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_toggle(LEDS_GREEN);
//printf("Button clicked\n");
printf("Phidget 5V 1:%d\n", phidgets.value(PHIDGET5V_1));
printf("Phidget 5V 2:%d\n", phidgets.value(PHIDGET5V_2));
printf("Phidget 3V 1:%d\n", phidgets.value(PHIDGET3V_1));
printf("Phidget 3V 2:%d\n", phidgets.value(PHIDGET3V_2));
if (phidgets.value(PHIDGET3V_1) < 100) {
if(phidgets.value(PHIDGET3V_1) < 100) {
leds_on(LEDS_RED);
} else {
leds_off(LEDS_RED);
}
}
PROCESS_END();
}

View File

@ -29,19 +29,17 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Testing the Potentiometer in Zolertia Z1 Starter Platform.
* \author
* Enric M. Calvo <ecalvo@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/potentiometer-sensor.h"
#include <stdio.h>
#include <stdio.h>
/*---------------------------------------------------------------------------*/
PROCESS(test_potent_process, "Testing Potentiometer in Z1SP");
AUTOSTART_PROCESSES(&test_potent_process);
@ -63,6 +61,4 @@ PROCESS_THREAD(test_potent_process, ev, data)
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,7 +29,7 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A quick program for testing a generic relay device connected in the
@ -37,25 +37,19 @@
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/relay-phidget.h"
#if 1
/*---------------------------------------------------------------------------*/
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
#if 0
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
#else
#define PRINTFDEBUG(...)
#endif
/*---------------------------------------------------------------------------*/
#define RELAY_INTERVAL (CLOCK_SECOND)
/*---------------------------------------------------------------------------*/
PROCESS(test_process, "Relay test process");
AUTOSTART_PROCESSES(&test_process);
/*---------------------------------------------------------------------------*/
@ -78,3 +72,4 @@ PROCESS_THREAD(test_process, ev, data)
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,7 +29,7 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Testing the SHT11 sensor on the Zolertia Z1 Platform.
@ -37,15 +37,15 @@
* Nicolas Tsiftes <nvt@sics.se>
* Enric M. Calvo <ecalvo@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/sht11/sht11.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
PROCESS(test_sht11_process, "SHT11 test");
AUTOSTART_PROCESSES(&test_sht11_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_sht11_process, ev, data)
{
static struct etimer et;
@ -54,14 +54,15 @@ PROCESS_THREAD(test_sht11_process, ev, data)
PROCESS_BEGIN();
sht11_init();
for (etimer_set(&et, CLOCK_SECOND);; etimer_reset(&et)) {
for(etimer_set(&et, CLOCK_SECOND);; etimer_reset(&et)) {
PROCESS_YIELD();
printf("Temperature: %u degrees Celsius\n",
(unsigned) (-39.60 + 0.01 * sht11_temp()));
(unsigned)(-39.60 + 0.01 * sht11_temp()));
rh = sht11_humidity();
printf("Rel. humidity: %u%%\n",
(unsigned) (-4 + 0.0405*rh - 2.8e-6*(rh*rh)));
(unsigned)(-4 + 0.0405 * rh - 2.8e-6 * (rh * rh)));
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,21 +29,23 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A quick program for testing the SHT25 temperature and humidity sensor
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/sht25.h"
/*---------------------------------------------------------------------------*/
PROCESS(test_sht25_process, "SHT25 test");
AUTOSTART_PROCESSES(&test_sht25_process);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_sht25_process, ev, data)
{
int16_t temperature, humidity;
@ -61,3 +63,4 @@ PROCESS_THREAD(test_sht25_process, ev, data)
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2013, Jelmer Tiete.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -12,8 +12,8 @@
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -25,11 +25,11 @@
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* This file is part of the Contiki operating system.
*
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A simple program for testing the TLC59116 I2C led driver.
@ -37,23 +37,21 @@
* \author
* Jelmer Tiete, VUB <jelmer@tiete.be>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/tlc59116.h"
#define BLINK_INTERVAL CLOCK_SECOND/25
/*---------------------------------------------------------------------------*/
#define BLINK_INTERVAL (CLOCK_SECOND / 25)
/*---------------------------------------------------------------------------*/
PROCESS(tlc59116_process, "Test tlc59116 process");
AUTOSTART_PROCESSES(&tlc59116_process);
/*---------------------------------------------------------------------------*/
/* Main process, setups */
static struct etimer et;
static uint8_t count = 0;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tlc59116_process, ev, data)
{
PROCESS_BEGIN();
@ -80,5 +78,4 @@ PROCESS_THREAD(tlc59116_process, ev, data)
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -29,41 +29,32 @@
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* A quick program for testing the tmp102 driver in the Z1 platform
* \author
* Enric M. Calvo <ecalvo@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/i2cmaster.h"
#include "dev/tmp102.h"
#if 1
/*---------------------------------------------------------------------------*/
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
#if 0
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
#else
#define PRINTFDEBUG(...)
#endif
#define TMP102_READ_INTERVAL (CLOCK_SECOND/2)
/*---------------------------------------------------------------------------*/
#define TMP102_READ_INTERVAL (CLOCK_SECOND / 2)
/*---------------------------------------------------------------------------*/
PROCESS(temp_process, "Test Temperature process");
AUTOSTART_PROCESSES(&temp_process);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(temp_process, ev, data)
{
PROCESS_BEGIN();
@ -86,14 +77,15 @@ PROCESS_THREAD(temp_process, ev, data)
PRINTFDEBUG("Reading Temp...\n");
raw = tmp102_read_temp_raw();
absraw = raw;
if(raw < 0) { // Perform 2C's if sensor returned negative data
if(raw < 0) { /* Perform 2C's if sensor returned negative data */
absraw = (raw ^ 0xFFFF) + 1;
sign = -1;
}
tempint = (absraw >> 8) * sign;
tempfrac = ((absraw >> 4) % 16) * 625; // Info in 1/10000 of degree
tempfrac = ((absraw >> 4) % 16) * 625; /* Info in 1/10000 of degree */
minus = ((tempint == 0) & (sign == -1)) ? '-' : ' ';
PRINTF("Temp = %c%d.%04d\n", minus, tempint, tempfrac);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/