Skip to content

Commit

Permalink
Dev (#18)
Browse files Browse the repository at this point in the history
* Add retry

* missing UART_RETRY_MAX

* move device name setting

* Add MS8607 enviromental sensor

* Add MS8607 sensor

* Add MS8607 sensor

* Isn’t that obvious.
  • Loading branch information
Hoan Hoang authored and hnhoan committed May 25, 2017
1 parent 0906d17 commit 08141da
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 20 deletions.
18 changes: 16 additions & 2 deletions ARM/Nordic/exemples/PTHSensorTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ Modified by Date Description
#include "app_util_platform.h"
#include "app_scheduler.h"
#include "pth_bme280.h"
#include "pth_ms8607.h"

#define DEVICE_NAME "PTHSensorTag" /**< Name of device. Will be included in the advertising data. */

#define APP_ADV_INTERVAL MSEC_TO_UNITS(1000, UNIT_0_625_MS) /**< The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */
#define APP_ADV_TIMEOUT_IN_SECONDS 60 /**< The advertising timeout (in units of seconds). */

/*
__ALIGN(4) const uint8_t g_lesc_private_key[32] = {
0x9a, 0x58, 0xc0, 0xff, 0xeb, 0x7f, 0x4b, 0x89, 0x41, 0xc2, 0x05, 0xfc, 0x9c, 0xca, 0x3e, 0xe5,
0x66, 0x4f, 0xf8, 0x80, 0x1b, 0xe9, 0x56, 0x1d, 0xa3, 0x72, 0x82, 0x55, 0xb7, 0x4f, 0x47, 0xd0
};
*/
// Evironmental Sensor Data to advertise
PTHSENSOR_DATA g_PTHData;

Expand Down Expand Up @@ -96,8 +102,13 @@ const BLEAPP_CFG s_BleAppCfg = {
static const I2CCFG s_I2cCfg = {
0, // I2C device number
{
#if 0
{BLUEIO_TAG_BME280_I2C_SDA_PORT, BLUEIO_TAG_BME280_I2C_SDA_PIN, BLUEIO_TAG_BME280_I2C_SDA_PINOP, IOPINDIR_BI, IOPINRES_NONE, IOPINTYPE_NORMAL}, // RX
{BLUEIO_TAG_BME280_I2C_SCL_PORT, BLUEIO_TAG_BME280_I2C_SCL_PIN, BLUEIO_TAG_BME280_I2C_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_NONE, IOPINTYPE_NORMAL}, // TX
#else
{0, 4, 0, IOPINDIR_BI, IOPINRES_NONE, IOPINTYPE_NORMAL}, // RX
{0, 3, 0, IOPINDIR_OUTPUT, IOPINRES_NONE, IOPINTYPE_NORMAL}, // TX
#endif
},
100000, // Rate
I2CMODE_MASTER,
Expand All @@ -118,7 +129,10 @@ static PTHSENSOR_CFG s_PthSensorCfg = {
};

// Environmental sensor instance
PthBme280 g_PthSensor;
PthBme280 g_Bme280Sensor;
PthMS8607 g_MS8607Sensor;

PTHSensor &g_PthSensor = g_MS8607Sensor;

void BlePeriphEvtUserHandler(ble_evt_t * p_ble_evt)
{
Expand Down
5 changes: 5 additions & 0 deletions ARM/Nordic/nRF51/EHAL/.project
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/src/sensors/pth_bme280.cpp</locationURI>
</link>
<link>
<name>src/sensors/pth_ms8607.cpp</name>
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/src/sensors/pth_ms8607.cpp</locationURI>
</link>
<link>
<name>src/nRF5_SDK/ble/ble_advertising</name>
<type>2</type>
Expand Down
10 changes: 10 additions & 0 deletions ARM/Nordic/nRF52/EHAL/.project
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/include/sensors/pth_bme280.h</locationURI>
</link>
<link>
<name>include/sensors/pth_ms8607.h</name>
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/include/sensors/pth_ms8607.h</locationURI>
</link>
<link>
<name>include/sensors/pth_sensor.h</name>
<type>1</type>
Expand Down Expand Up @@ -430,6 +435,11 @@
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/src/sensors/pth_bme280.cpp</locationURI>
</link>
<link>
<name>src/sensors/pth_ms8607.cpp</name>
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/src/sensors/pth_ms8607.cpp</locationURI>
</link>
<link>
<name>src/nRF5_SDK/ble/ble_advertising</name>
<type>2</type>
Expand Down
1 change: 1 addition & 0 deletions ARM/Nordic/nRF52/exemples/PTHSensorTag/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Debug/
/Release/
2 changes: 1 addition & 1 deletion ARM/Nordic/src/ble_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static void BleAppGapParamInit(const BLEAPP_CFG *pBleAppCfg)
*/
memset(&gap_conn_params, 0, sizeof(gap_conn_params));

if (pBleAppCfg->SecType != BLEAPP_SECTYPE_NONE)
if (pBleAppCfg->AppMode != BLEAPP_MODE_NOCONNECT)
{
gap_conn_params.min_conn_interval = pBleAppCfg->ConnIntervalMin;// MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = pBleAppCfg->ConnIntervalMax;//MAX_CONN_INTERVAL;
Expand Down
17 changes: 17 additions & 0 deletions include/sensors/pth_bme280.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ class PthBme280 : public PTHSensor {
virtual void Disable();
virtual void Reset();
bool ReadPTH(PTHSENSOR_DATA &PthData);
float ReadTemperature() {
PTHSENSOR_DATA pthdata;
ReadPTH(pthdata);
return (float)pthdata.Temperature / 100.0;
}

float ReadPressure() {
PTHSENSOR_DATA pthdata;
ReadPTH(pthdata);
return (float)pthdata.Pressure / 100.0;
}

float ReadHumidity() {
PTHSENSOR_DATA pthdata;
ReadPTH(pthdata);
return (float)pthdata.Humidity / 100.0;
}

private:

Expand Down
122 changes: 122 additions & 0 deletions include/sensors/pth_ms8607.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*--------------------------------------------------------------------------
File : pth_ms8607.h
Author : Hoang Nguyen Hoan Feb. 12, 2017
Desc : MS8607 environment sensor implementation
- Temperature, Humidity, Barometric pressure
Copyright (c) 2017, I-SYST inc., all rights reserved
Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies, and none of the
names : I-SYST or its contributors may be used to endorse or
promote products derived from this software without specific prior written
permission.
For info or contributing contact : hnhoan at i-syst dot com
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, 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.
----------------------------------------------------------------------------
Modified by Date Description
----------------------------------------------------------------------------*/
#ifndef __PTH_MS8607_H__
#define __PTH_MS8607_H__

#include <stdint.h>
#include <string.h>

#ifndef __cplusplus
#include <stdbool.h>
#endif

#include "iopincfg.h"
#include "pth_sensor.h"

// Device address
#define MS8607_PTDEV_ADDR 0x76
#define MS8607_RHDEV_ADDR 0x40

#define MS8607_CMD_PT_RESET 0x1E
#define MS8607_CMD_ADC_READ 0
#define MS8607_CMD_P_CONVERT_D1_256 0x40
#define MS8607_CMD_P_CONVERT_D1_512 0x42
#define MS8607_CMD_P_CONVERT_D1_1024 0x44
#define MS8607_CMD_T_CONVERT_D2_256 0x50
#define MS8607_CMD_T_CONVERT_D2_512 0x52
#define MS8607_CMD_T_CONVERT_D2_1024 0x54

#define MS8607_CMD_RH_RESET 0xFE
#define MS8607_CMD_RH_HOLD_MASTER 0xE5
#define MS8607_CMD_RH_WRITE_USER 0xE6
#define MS8607_CMD_RH_READ_USER 0xE7

#define MS8607_PROM_START_ADDR 0xA0

#ifdef __cplusplus

class PthMS8607 : public PTHSensor {
public:
PthMS8607() {}
virtual ~PthMS8607() {}
virtual bool Init(const PTHSENSOR_CFG &CfgData, DeviceIntrf *pIntrf);
virtual bool Enable();
virtual void Disable();
virtual void Reset();

/**
* @brief Set operating mode
*
* @param OpMode : Operating mode
* - PTHSENSOR_OPMODE_SLEEP
* - PTHSENSOR_OPMODE_SINGLE
* - PTHSENSOR_OPMODE_CONTINUOUS
* @param Freq : Sampling frequency in Hz for continuous mode
*
* @return true- if success
*/
virtual bool SetMode(PTHSENSOR_OPMODE OpMode, uint32_t Freq);

/**
* @brief Start sampling data
*
* @return true - success
*/
virtual bool StartSampling();
bool ReadPTH(PTHSENSOR_DATA &PthData);
float ReadTemperature();
float ReadPressure();
float ReadHumidity();

private:

void ReadPtProm();

int32_t vCurTemp;
int32_t vCurBarPres;
int32_t vCurRelHum;
uint16_t vPTProm[8];
int32_t vCurDT;
};

extern "C" {
#endif // __cplusplus

#ifdef __cplusplus
}

#endif // __cplusplus

#endif // __PTH_MS8607_H__
38 changes: 21 additions & 17 deletions include/sensors/pth_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,27 @@ class PTHSensor : public Device {
*/
virtual bool StartSampling() = 0;

float ReadTemperature() {
PTHSENSOR_DATA pthdata;
ReadPTH(pthdata);
return (float)pthdata.Temperature / 100.0;
}

float ReadPressure() {
PTHSENSOR_DATA pthdata;
ReadPTH(pthdata);
return (float)pthdata.Pressure / 100.0;
}

float ReadHumidity() {
PTHSENSOR_DATA pthdata;
ReadPTH(pthdata);
return (float)pthdata.Humidity / 100.0;
}
/**
* @brief Read temperature
*
* @return Temperature in degree C
*/
virtual float ReadTemperature() = 0;

/**
* @brief Read barometric pressure
*
* @return Barometric pressure in Pascal
*/
virtual float ReadPressure() = 0;

/**
* @brief Read relative humidity
*
* @return Relative humidity in %
*/
virtual float ReadHumidity() = 0;

protected:
PTHSENSOR_OPMODE vOpMode;
uint32_t vSampFreq; // Sampling frequency in Hz
Expand Down
Loading

0 comments on commit 08141da

Please sign in to comment.