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-file.h"
#include "shell-text.h" #include "shell-text.h"
#include "dev/adxl345.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 #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(accel_process, "Test Accel process");
PROCESS(led_process, "LED handling process"); PROCESS(led_process, "LED handling process");
AUTOSTART_PROCESSES(&accel_process, &led_process); AUTOSTART_PROCESSES(&accel_process, &led_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* As several interrupts can be mapped to one interrupt pin, when interrupt /* As several interrupts can be mapped to one interrupt pin, when interrupt
strikes, the adxl345 interrupt source register is read. This function prints * strikes, the adxl345 interrupt source register is read. This function prints
out which interrupts occurred. Note that this will include all interrupts, * 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 * even those mapped to 'the other' pin, and those that will always signal even
not enabled (such as watermark). */ * if not enabled (such as watermark).
*/
void void
print_int(uint16_t reg){ 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
if(reg & ADXL345_INT_FREEFALL) { if(reg & ADXL345_INT_FREEFALL) {
printf("Freefall "); printf("Freefall ");
} }
@ -94,74 +85,49 @@ print_int(uint16_t reg){
} }
printf("\n"); printf("\n");
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* accelerometer free fall detection callback */ /* accelerometer free fall detection callback */
void void
accm_ff_cb(uint8_t reg){ accm_ff_cb(uint8_t reg)
{
L_ON(LEDS_B); L_ON(LEDS_B);
process_post(&led_process, ledOff_event, NULL); process_post(&led_process, led_off_event, NULL);
printf("~~[%u] Freefall detected! (0x%02X) -- ", ((uint16_t) clock_time())/128, reg); printf("~~[%u] Freefall detected! (0x%02X) -- ",
((uint16_t)clock_time()) / 128, reg);
print_int(reg); print_int(reg);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* accelerometer tap and double tap detection callback */ /* accelerometer tap and double tap detection callback */
void void
accm_tap_cb(uint8_t reg){ accm_tap_cb(uint8_t reg)
process_post(&led_process, ledOff_event, NULL); {
if(reg & ADXL345_INT_DOUBLETAP){ process_post(&led_process, led_off_event, NULL);
if(reg & ADXL345_INT_DOUBLETAP) {
L_ON(LEDS_G); 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 { } else {
L_ON(LEDS_R); 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); 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_THREAD(led_process, ev, data) {
PROCESS_BEGIN(); PROCESS_BEGIN();
while(1){ while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == ledOff_event); PROCESS_WAIT_EVENT_UNTIL(ev == led_off_event);
etimer_set(&ledETimer, LED_INT_ONTIME); etimer_set(&led_etimer, LED_INT_ONTIME);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ledETimer)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&led_etimer));
L_OFF(LEDS_R + LEDS_G + LEDS_B); L_OFF(LEDS_R + LEDS_G + LEDS_B);
} }
PROCESS_END(); 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 */ /* Main process, setups */
static struct etimer et;
PROCESS_THREAD(accel_process, ev, data) { PROCESS_THREAD(accel_process, ev, data) {
PROCESS_BEGIN(); PROCESS_BEGIN();
{ {
@ -169,11 +135,11 @@ PROCESS_THREAD(accel_process, ev, data) {
serial_shell_init(); serial_shell_init();
shell_ps_init(); shell_ps_init();
shell_file_init(); // for printing out files shell_file_init(); /* for printing out files */
shell_text_init(); // for binprint shell_text_init(); /* for binprint */
/* Register the event used for lighting up an LED when interrupt strikes. */ /* 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. */ /* Start and setup the accelerometer with default values, eg no interrupts enabled. */
accm_init(); accm_init();
@ -182,15 +148,15 @@ PROCESS_THREAD(accel_process, ev, data) {
ACCM_REGISTER_INT1_CB(accm_ff_cb); ACCM_REGISTER_INT1_CB(accm_ff_cb);
ACCM_REGISTER_INT2_CB(accm_tap_cb); ACCM_REGISTER_INT2_CB(accm_tap_cb);
/* Set what strikes the corresponding interrupts. Several interrupts per pin is /* Set what strikes the corresponding interrupts. Several interrupts per pin is
possible. For the eight possible interrupts, see adxl345.h and adxl345 datasheet. */ possible. For the eight possible interrupts, see adxl345.h and adxl345 datasheet. */
accm_set_irq(ADXL345_INT_FREEFALL, ADXL345_INT_TAP + ADXL345_INT_DOUBLETAP); accm_set_irq(ADXL345_INT_FREEFALL, ADXL345_INT_TAP + ADXL345_INT_DOUBLETAP);
while (1) { while(1) {
x = accm_read_axis(X_AXIS); x = accm_read_axis(X_AXIS);
y = accm_read_axis(Y_AXIS); y = accm_read_axis(Y_AXIS);
z = accm_read_axis(Z_AXIS); z = accm_read_axis(Z_AXIS);
printf("x: %d y: %d z: %d\n", x, y, z); printf("x: %d y: %d z: %d\n", x, y, z);
etimer_set(&et, ACCM_READ_INTERVAL); etimer_set(&et, ACCM_READ_INTERVAL);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
@ -198,6 +164,5 @@ PROCESS_THREAD(accel_process, ev, data) {
} }
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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