From f9b5d7c52c9d1fba47704c00e3ee830063a4aac8 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Thu, 16 Mar 2017 18:09:55 -0600 Subject: [PATCH] sht1x: move defines/register defs into separate header for SWIG Signed-off-by: Jon Trulson --- src/sht1x/CMakeLists.txt | 2 +- src/sht1x/javaupm_sht1x.i | 1 + src/sht1x/jsupm_sht1x.i | 1 + src/sht1x/pyupm_sht1x.i | 1 + src/sht1x/sht1x.h | 36 ++------------------- src/sht1x/sht1x_defs.h | 68 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 35 deletions(-) create mode 100644 src/sht1x/sht1x_defs.h diff --git a/src/sht1x/CMakeLists.txt b/src/sht1x/CMakeLists.txt index df60faa4..26c0e517 100644 --- a/src/sht1x/CMakeLists.txt +++ b/src/sht1x/CMakeLists.txt @@ -1,6 +1,6 @@ upm_mixed_module_init (NAME sht1x DESCRIPTION "Temperature and Humidity Sensor" - C_HDR sht1x.h + C_HDR sht1x.h sht1x_defs.h C_SRC sht1x.c CPP_HDR sht1x.hpp CPP_SRC sht1x.cxx diff --git a/src/sht1x/javaupm_sht1x.i b/src/sht1x/javaupm_sht1x.i index 0357042f..908100ff 100644 --- a/src/sht1x/javaupm_sht1x.i +++ b/src/sht1x/javaupm_sht1x.i @@ -4,6 +4,7 @@ %include "stdint.i" %include "typemaps.i" +%include "sht1x_defs.h" %include "sht1x.hpp" %{ #include "sht1x.hpp" diff --git a/src/sht1x/jsupm_sht1x.i b/src/sht1x/jsupm_sht1x.i index 52d82c1e..a9deb10e 100644 --- a/src/sht1x/jsupm_sht1x.i +++ b/src/sht1x/jsupm_sht1x.i @@ -2,6 +2,7 @@ %include "../upm.i" %include "std_string.i" +%include "sht1x_defs.h" %include "sht1x.hpp" %{ #include "sht1x.hpp" diff --git a/src/sht1x/pyupm_sht1x.i b/src/sht1x/pyupm_sht1x.i index 94337abc..7fe5448b 100644 --- a/src/sht1x/pyupm_sht1x.i +++ b/src/sht1x/pyupm_sht1x.i @@ -6,6 +6,7 @@ %feature("autodoc", "3"); +%include "sht1x_defs.h" %include "sht1x.hpp" %{ #include "sht1x.hpp" diff --git a/src/sht1x/sht1x.h b/src/sht1x/sht1x.h index 781d92df..cce4c2f0 100644 --- a/src/sht1x/sht1x.h +++ b/src/sht1x/sht1x.h @@ -28,6 +28,8 @@ #include "upm.h" #include "mraa/gpio.h" +#include "sht1x_defs.h" + #ifdef __cplusplus extern "C" { #endif @@ -67,40 +69,6 @@ extern "C" { float coeff_t2; } *sht1x_context; - // SHT1X commands. The first 3 msb's are the address, which are - // always 0. The following 5 bits are the actual command. - typedef enum { - SHT1X_CMD_MEAS_TEMPERATURE = 0x03, - SHT1X_CMD_MEAS_HUMIDITY = 0x05, - SHT1X_CMD_WRITE_STATUS = 0x06, - SHT1X_CMD_READ_STATUS = 0x07, - SHT1X_CMD_SOFT_RESET = 0x1e - } SHT1X_CMD_T; - - // status register bits - typedef enum { - SHT1X_STATUS_RESOLUTION_LOW = 0x01, // 0=12b RH/14b temp (dflt) - SHT1X_STATUS_NO_RELOAD_FROM_OTP = 0x02, - SHT1X_STATUS_HEATER_EN = 0x04, - - // 0x08-0x20 reserved - - SHT1X_STATUS_LOW_VOLT = 0x40 // low battery - - // 0x80 reserved - } SHT1X_STATUS_BITS_T; - - // The Vdd voltage can affect the temperature coefficients, so we - // provide a way to indicate the closest voltage and set up the - // compensation accordingly. - typedef enum { - SHT1X_VOLTS_5 = 0, // 5 volts - SHT1X_VOLTS_4 = 1, - SHT1X_VOLTS_3_5 = 2, // 3.5v - SHT1X_VOLTS_3 = 3, - SHT1X_VOLTS_2_5 = 4 - } SHT1X_VOLTS_T; - /** * SHT1X Initializer * diff --git a/src/sht1x/sht1x_defs.h b/src/sht1x/sht1x_defs.h new file mode 100644 index 00000000..f5a8e180 --- /dev/null +++ b/src/sht1x/sht1x_defs.h @@ -0,0 +1,68 @@ +/* + * Author: Jon Trulson + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + + + // SHT1X commands. The first 3 msb's are the address, which are + // always 0. The following 5 bits are the actual command. + typedef enum { + SHT1X_CMD_MEAS_TEMPERATURE = 0x03, + SHT1X_CMD_MEAS_HUMIDITY = 0x05, + SHT1X_CMD_WRITE_STATUS = 0x06, + SHT1X_CMD_READ_STATUS = 0x07, + SHT1X_CMD_SOFT_RESET = 0x1e + } SHT1X_CMD_T; + + // status register bits + typedef enum { + SHT1X_STATUS_RESOLUTION_LOW = 0x01, // 0=12b RH/14b temp (dflt) + SHT1X_STATUS_NO_RELOAD_FROM_OTP = 0x02, + SHT1X_STATUS_HEATER_EN = 0x04, + + // 0x08-0x20 reserved + + SHT1X_STATUS_LOW_VOLT = 0x40 // low battery + + // 0x80 reserved + } SHT1X_STATUS_BITS_T; + + // The Vdd voltage can affect the temperature coefficients, so we + // provide a way to indicate the closest voltage and set up the + // compensation accordingly. + typedef enum { + SHT1X_VOLTS_5 = 0, // 5 volts + SHT1X_VOLTS_4 = 1, + SHT1X_VOLTS_3_5 = 2, // 3.5v + SHT1X_VOLTS_3 = 3, + SHT1X_VOLTS_2_5 = 4 + } SHT1X_VOLTS_T; + +#ifdef __cplusplus +} +#endif