mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-17 15:38:14 +08:00
修改了Web后台的部分界面,增加了HAmqtt中的总电量传感器,后台新增mqtt上报频率设置
This commit is contained in:
15
mico-os/libraries/drivers/sensor/UVIS25/UVIS25.mk
Normal file
15
mico-os/libraries/drivers/sensor/UVIS25/UVIS25.mk
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
# Copyright (c) 2016 MXCHIP Inc.
|
||||
#
|
||||
# The contents of this file may not be disclosed to third parties, copied or
|
||||
# duplicated in any form, in whole or in part, without the prior written
|
||||
# permission of MXCHIP Corporation.
|
||||
#
|
||||
|
||||
|
||||
NAME := Sensor_UVIS25_$(PLATFORM)
|
||||
|
||||
$(NAME)_SOURCES := uvis25.c
|
||||
|
||||
GLOBAL_INCLUDES := .
|
||||
150
mico-os/libraries/drivers/sensor/UVIS25/uvis25.c
Normal file
150
mico-os/libraries/drivers/sensor/UVIS25/uvis25.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file uvis25.c
|
||||
* @author William Xu
|
||||
* @version V1.0.0
|
||||
* @date 21-May-2015
|
||||
* @brief
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "uvis25.h"
|
||||
|
||||
#define uvis25_log(M, ...) custom_log("UVIS25", M, ##__VA_ARGS__)
|
||||
#define uvis25_log_trace() custom_log_trace("UVIS25")
|
||||
|
||||
static OSStatus UVIS25_Init(void);
|
||||
static OSStatus UVIS25_GetUXindex(float *pfData);
|
||||
|
||||
/* I2C device */
|
||||
mico_i2c_device_t uvis25_i2c_device = {
|
||||
UVIS25_I2C_PORT, 0x47, I2C_ADDRESS_WIDTH_7BIT, I2C_STANDARD_SPEED_MODE
|
||||
};
|
||||
|
||||
OSStatus UVIS25_IO_Init(void)
|
||||
{
|
||||
// I2C init
|
||||
MicoI2cFinalize(&uvis25_i2c_device); // in case error
|
||||
MicoI2cInitialize(&uvis25_i2c_device);
|
||||
|
||||
if( false == MicoI2cProbeDevice(&uvis25_i2c_device, 5) ){
|
||||
uvis25_log("UVI25S_ERROR: no i2c device found!");
|
||||
return kNotInitializedErr;
|
||||
}
|
||||
return kNoErr;
|
||||
}
|
||||
|
||||
|
||||
/* \Brief: The function is used as I2C bus write
|
||||
* \Return : Status of the I2C write
|
||||
* \param dev_addr : The device address of the sensor
|
||||
* \param reg_addr : Address of the first register, will data is going to be written
|
||||
* \param reg_data : It is a value hold in the array,
|
||||
* will be used for write the value into the register
|
||||
* \param cnt : The no of byte of data to be write
|
||||
*/
|
||||
OSStatus UVIS25_IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
|
||||
{
|
||||
mico_i2c_message_t uvis25_i2c_msg = {NULL, NULL, 0, 0, 0, false};
|
||||
OSStatus iError = kNoErr;
|
||||
uint8_t array[8];
|
||||
uint8_t stringpos;
|
||||
array[0] = RegisterAddr;
|
||||
for (stringpos = 0; stringpos < NumByteToWrite; stringpos++) {
|
||||
array[stringpos + 1] = *(pBuffer + stringpos);
|
||||
}
|
||||
|
||||
iError = MicoI2cBuildTxMessage(&uvis25_i2c_msg, array, NumByteToWrite + 1, 3);
|
||||
iError = MicoI2cTransfer(&uvis25_i2c_device, &uvis25_i2c_msg, 1);
|
||||
if(kNoErr != iError){
|
||||
iError = kWriteErr;
|
||||
}
|
||||
|
||||
return kNoErr;
|
||||
}
|
||||
|
||||
/* \Brief: The function is used as I2C bus read
|
||||
* \Return : Status of the I2C read
|
||||
* \param dev_addr : The device address of the sensor
|
||||
* \param reg_addr : Address of the first register, will data is going to be read
|
||||
* \param reg_data : This data read from the sensor, which is hold in an array
|
||||
* \param cnt : The no of byte of data to be read
|
||||
*/
|
||||
OSStatus UVIS25_IO_Read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
|
||||
{
|
||||
mico_i2c_message_t uvis25_i2c_msg = {NULL, NULL, 0, 0, 0, false};
|
||||
OSStatus iError = kNoErr;
|
||||
uint8_t array[8] = {0};
|
||||
array[0] = RegisterAddr;
|
||||
|
||||
iError = MicoI2cBuildCombinedMessage(&uvis25_i2c_msg, array, pBuffer, 1, NumByteToRead, 3);
|
||||
if(kNoErr != iError){
|
||||
return kReadErr;
|
||||
}
|
||||
iError = MicoI2cTransfer(&uvis25_i2c_device, &uvis25_i2c_msg, 1);
|
||||
if(kNoErr != iError){
|
||||
return kReadErr;
|
||||
}
|
||||
return kNoErr;
|
||||
}
|
||||
|
||||
|
||||
static OSStatus UVIS25_Init(void)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
uint8_t temp = 0x03;
|
||||
|
||||
if((err = UVIS25_IO_Init()) != kNoErr){
|
||||
return err;
|
||||
}
|
||||
|
||||
if((err = UVIS25_IO_Write(&temp, UVIS25_CTRL_REG1, 1)) != kNoErr){
|
||||
return err;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static OSStatus UVIS25_GetUXindex(float *pfData)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
uint8_t temp = 0x00;
|
||||
uint8_t data = 0;
|
||||
|
||||
do{
|
||||
UVIS25_IO_Read(&temp, UVIS25_STATUS_REG, 1);
|
||||
}while( temp != 0x01 );
|
||||
|
||||
if((err = UVIS25_IO_Read(&data, UVIS25_UV_OUT_REG, 1)) != kNoErr){
|
||||
return err;
|
||||
}
|
||||
|
||||
*pfData = (float)data/16;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus uvis25_sensor_init(void)
|
||||
{
|
||||
return UVIS25_Init();
|
||||
}
|
||||
|
||||
OSStatus uvis25_Read_Data(float *uv_index)
|
||||
{
|
||||
return UVIS25_GetUXindex(uv_index);
|
||||
}
|
||||
|
||||
OSStatus uvis25_sensor_deinit(void)
|
||||
{
|
||||
return MicoI2cFinalize(&uvis25_i2c_device);
|
||||
}
|
||||
|
||||
100
mico-os/libraries/drivers/sensor/UVIS25/uvis25.h
Normal file
100
mico-os/libraries/drivers/sensor/UVIS25/uvis25.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file uvis25.h
|
||||
* @author William Xu
|
||||
* @version V1.0.0
|
||||
* @date 21-May-2015
|
||||
* @brief
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __UVIS25_H
|
||||
#define __UVIS25_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "mico_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MiCO_Sensor_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup MiCO_uvis25_Driver MiCO uvis25 Driver
|
||||
* @brief Provide driver interface uvis25 Sensor
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef UVIS25_I2C_PORT
|
||||
#define UVIS25_I2C_PORT MICO_I2C_NONE
|
||||
#endif
|
||||
|
||||
#define UVIS25_WHO_AM_I 0x0F
|
||||
#define UVIS25_CTRL_REG1 0x20
|
||||
#define UVIS25_CTRL_REG2 0x21
|
||||
#define UVIS25_CTRL_REG3 0x22
|
||||
#define UVIS25_INT_CFG 0x23
|
||||
#define UVIS25_INT_SOURCE 0x24
|
||||
#define UVIS25_THS_UV 0x25
|
||||
#define UVIS25_STATUS_REG 0x27
|
||||
#define UVIS25_UV_OUT_REG 0x28
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize uvis25 sensor device
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus uvis25_sensor_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of uvis25 sensor device
|
||||
*
|
||||
* @param uv_index: ultraviolet rays value
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus uvis25_Read_Data(float *uv_index);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deinitialize uvis25 sensor device
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus uvis25_sensor_deinit(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __UVIS25_H */
|
||||
Reference in New Issue
Block a user