
3 changed files with 113 additions and 0 deletions
@ -0,0 +1,17 @@
|
||||
APPLICATION = driver_jc42
|
||||
include ../Makefile.tests_common |
||||
|
||||
USEMODULE += jc42
|
||||
USEMODULE += xtimer
|
||||
|
||||
# set default device parameters in case they are undefined
|
||||
TEST_I2C ?= 0
|
||||
TEST_I2C_ADDR ?= 0x18
|
||||
TEST_I2C_SPEED ?= I2C_SPEED_NORMAL
|
||||
|
||||
# export parameters
|
||||
CFLAGS += -DTEST_I2C=$(TEST_I2C)
|
||||
CFLAGS += -DTEST_I2C_ADDR=$(TEST_I2C_ADDR)
|
||||
CFLAGS += -DTEST_I2C_SPEED=$(TEST_I2C_SPEED)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include |
@ -0,0 +1,14 @@
|
||||
# JC42 Driver Test |
||||
|
||||
## Introduction |
||||
This test will test if the jc42 compatible temperature sensor is working. |
||||
|
||||
## Configuration |
||||
There are three parameters to configure: |
||||
|
||||
* `TEST_I2C` — I2C device to use. |
||||
* `TEST_I2C_ADDR` — The sensor address (usually 0x18). |
||||
* `TEST_I2C_SPEED` — The sensor address (usually I2C_SPEED_NORMAL). |
||||
|
||||
## Expected result |
||||
The sensor should continuously (every 1 sec) output the temperature. The precision should be two digits. |
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Koen Zandberg <koen@bergzand.net> |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @ingroup tests |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief Test application for the jc42 sensor driver |
||||
* |
||||
* @author Koen Zandberg <koen@bergzand.net> |
||||
* |
||||
* @} |
||||
*/ |
||||
|
||||
#ifndef TEST_I2C |
||||
#error "TEST_I2C not defined" |
||||
#endif |
||||
|
||||
#ifndef TEST_I2C_ADDR |
||||
#error "TEST_I2C_ADDR not defined" |
||||
#endif |
||||
|
||||
#ifndef TEST_I2C_SPEED |
||||
#error "TEST_I2C_SPEED not defined" |
||||
#endif |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include "xtimer.h" |
||||
|
||||
#include "periph/i2c.h" |
||||
|
||||
#include "jc42.h" |
||||
|
||||
int main(void) |
||||
{ |
||||
jc42_t dev; |
||||
jc42_params_t params = { |
||||
.i2c = TEST_I2C, |
||||
.addr = TEST_I2C_ADDR, |
||||
.speed = TEST_I2C_SPEED, |
||||
}; |
||||
|
||||
puts("JC42 temperature sensor test application\n"); |
||||
|
||||
/* initialize the sensor */ |
||||
printf("Initializing sensor..."); |
||||
|
||||
if (jc42_init(&dev, ¶ms) == 0) { |
||||
puts("[OK]"); |
||||
} |
||||
else { |
||||
puts("[Failed]"); |
||||
return 1; |
||||
} |
||||
|
||||
/* read temperature every 1 seconds */ |
||||
int16_t temperature; |
||||
while (1) { |
||||
printf("Testing sensor communication..."); |
||||
if (jc42_get_temperature(&dev, &temperature) == 0) { |
||||
puts("[OK]"); |
||||
} |
||||
else { |
||||
puts("[Failed]"); |
||||
return 1; |
||||
} |
||||
/* display results */ |
||||
printf("temperature: %d.%02d C\n", temperature / 100, temperature % 100); |
||||
|
||||
/* sleep between measurements */ |
||||
xtimer_usleep(1000 * MS_IN_USEC); |
||||
} |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue