mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-18 16:03:22 +08:00
修改了Web后台的部分界面,增加了HAmqtt中的总电量传感器,后台新增mqtt上报频率设置
This commit is contained in:
34
mico-os/libraries/drivers/MiCOKit_EXT2/MiCOKit_EXT2.mk
Normal file
34
mico-os/libraries/drivers/MiCOKit_EXT2/MiCOKit_EXT2.mk
Normal file
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# 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 := Lib_MiCOKit_EXT_$(PLATFORM)
|
||||
|
||||
$(NAME)_SOURCES := micokit_ext_mfg.c \
|
||||
micokit_ext.c \
|
||||
motion_sensor.c \
|
||||
temp_hum_sensor.c
|
||||
|
||||
|
||||
|
||||
GLOBAL_INCLUDES := . \
|
||||
..
|
||||
|
||||
$(NAME)_COMPONENTS += drivers/display/VGM128064 \
|
||||
drivers/keypad/gpio_button \
|
||||
drivers/motor/dc_motor \
|
||||
drivers/rgb_led/P9813 \
|
||||
drivers/sensor/BME280 \
|
||||
drivers/sensor/DHT11 \
|
||||
drivers/sensor/APDS9930 \
|
||||
drivers/sensor/light_adc \
|
||||
drivers/sensor/infrared_adc
|
||||
|
||||
|
||||
#(info $(COMPILER_SPECIFIC_PEDANTIC_CFLAGS))
|
||||
#$(NAME)_CFLAGS = $(COMPILER_SPECIFIC_PEDANTIC_CFLAGS)
|
||||
108
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext.c
Normal file
108
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board peripherals operations..
|
||||
******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "mico_platform.h"
|
||||
#include "micokit_ext.h"
|
||||
|
||||
#define micokit_ext_log(M, ...) custom_log("MICOKIT_EXT", M, ##__VA_ARGS__)
|
||||
#define micokit_ext_log_trace() custom_log_trace("MICOKIT_EXT")
|
||||
|
||||
extern void user_key1_clicked_callback(void);
|
||||
extern void user_key1_long_pressed_callback(void);
|
||||
extern void user_key2_clicked_callback(void);
|
||||
extern void user_key2_long_pressed_callback(void);
|
||||
|
||||
//------------------------------------- API ------------------------------------
|
||||
OSStatus user_modules_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; // max char each line
|
||||
#if defined(MICO_EXT_KEY1)||defined(MICO_EXT_KEY2)
|
||||
button_init_t init;
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CPU_MX1290
|
||||
// init DC Motor(GPIO)
|
||||
dc_motor_init();
|
||||
dc_motor_set(0); // off
|
||||
#endif
|
||||
|
||||
// init RGB LED(P9813)
|
||||
rgb_led_init();
|
||||
rgb_led_open(0, 0, 0); // off
|
||||
|
||||
// init OLED
|
||||
OLED_Init();
|
||||
OLED_Clear();
|
||||
snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", MODEL);
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_1, oled_show_line);
|
||||
memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1);
|
||||
snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", "MiCO ");
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, oled_show_line);
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Running... ");
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " ");
|
||||
|
||||
apds9930_sensor_init();
|
||||
|
||||
#ifndef CONFIG_CPU_MX1290
|
||||
// init Light sensor(ADC)
|
||||
light_sensor_init();
|
||||
|
||||
// init infrared sensor(ADC)
|
||||
infrared_reflective_init();
|
||||
|
||||
// init user key1 && key2
|
||||
#ifdef MICO_EXT_KEY1
|
||||
init.gpio = MICO_EXT_KEY1;
|
||||
init.pressed_func = user_key1_clicked_callback;
|
||||
init.long_pressed_func = NULL;
|
||||
init.long_pressed_timeout = 5000;
|
||||
button_init( IOBUTTON_USER_1, init);
|
||||
#endif
|
||||
|
||||
#ifdef MICO_EXT_KEY2
|
||||
init.gpio = MICO_EXT_KEY2;
|
||||
init.pressed_func = user_key2_clicked_callback;
|
||||
init.long_pressed_func = NULL;
|
||||
init.long_pressed_timeout = 5000;
|
||||
button_init( IOBUTTON_USER_2, init);
|
||||
#endif
|
||||
|
||||
err = temp_hum_sensor_init();
|
||||
#endif
|
||||
|
||||
// int32_t temperature;
|
||||
// uint32_t humidity;
|
||||
//
|
||||
// while(1){
|
||||
// err = temp_hum_sensor_read( &temperature, &humidity );
|
||||
// if( err == kNoErr ){
|
||||
// platform_log( "temperature: %d, humidity = %d ", temperature, humidity);
|
||||
// }
|
||||
// sleep(1);
|
||||
// }
|
||||
//exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus micokit_ext_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
err = user_modules_init();
|
||||
|
||||
return err;
|
||||
}
|
||||
94
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext.h
Normal file
94
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board peripherals operations..
|
||||
******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MICOKIT_EXT_H_
|
||||
#define __MICOKIT_EXT_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
//------------------------- MicoKit-EXT board modules drivers ------------------
|
||||
#include "rgb_led/P9813/rgb_led.h"
|
||||
#include "display/VGM128064/oled.h"
|
||||
#include "motor/dc_motor/dc_motor.h"
|
||||
#include "keypad/gpio_button/button.h"
|
||||
|
||||
#include "sensor/light_adc/light_sensor.h"
|
||||
#include "sensor/APDS9930/APDS9930.h"
|
||||
#include "sensor/infrared_adc/infrared_reflective.h"
|
||||
|
||||
|
||||
#include "motion_sensor.h"
|
||||
#include "temp_hum_sensor.h"
|
||||
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Driver MiCOKit Ext Driver
|
||||
* @brief Provide driver interface for MiCOKit Ext devices
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICOKIT_EXT_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Driver MiCOKit Ext Driver
|
||||
* @brief Provide device init driver interface for MiCOKit Ext or modules
|
||||
* @{
|
||||
*/
|
||||
|
||||
//--------------------------- MicoKit-EXT board info ---------------------------
|
||||
#define DEV_KIT_MANUFACTURER "MXCHIP"
|
||||
#define DEV_KIT_NAME "MiCOKit3288"
|
||||
|
||||
#define MFG_TEST_MAX_MODULE_NUM 3
|
||||
|
||||
|
||||
/**
|
||||
* @brief MicoKit-EXT board init
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus micokit_ext_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Init modules on MicoKit-EXT board.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus user_modules_init(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif // __MICOKIT_EXT_H_
|
||||
50
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext_def.h
Normal file
50
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext_def.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext_def.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 20-May-2015
|
||||
* @brief micokit extension board peripherals pin defines.
|
||||
******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MICOKIT_EXT_DEF_H_
|
||||
#define __MICOKIT_EXT_DEF_H_
|
||||
|
||||
//-------------------------- MicoKit-EXT board pin define ----------------------
|
||||
#ifdef CONFIG_CPU_MX1290
|
||||
#define SSD1106_USE_I2C
|
||||
#define OLED_I2C_PORT (Arduino_I2C)
|
||||
#else
|
||||
#define OLED_SPI_PORT (Arduino_SPI)
|
||||
#define OLED_SPI_SCK (Arduino_SCK)
|
||||
#define OLED_SPI_DIN (Arduino_SI)
|
||||
#define OLED_SPI_DC (Arduino_SO)
|
||||
#define OLED_SPI_CS (Arduino_CS)
|
||||
#endif
|
||||
|
||||
#define P9813_PIN_CIN (Arduino_SCL)
|
||||
#define P9813_PIN_DIN (Arduino_SDA)
|
||||
|
||||
#define DC_MOTOR (Arduino_D9)
|
||||
|
||||
#define MICO_EXT_KEY1 (Arduino_D4)
|
||||
#define MICO_EXT_KEY2 (Arduino_D5)
|
||||
|
||||
#define BME280_I2C_DEVICE (Arduino_I2C)
|
||||
#define DHT11_DATA (Arduino_D8)
|
||||
|
||||
#define APDS9930_I2C_DEVICE (Arduino_I2C)
|
||||
|
||||
#define LIGHT_SENSOR_ADC (Arduino_A2)
|
||||
#define INFARAED_REFLECTIVE_ADC (Arduino_A3)
|
||||
|
||||
|
||||
#endif // __MICOKIT_EXT_DEF_H_
|
||||
263
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext_mfg.c
Normal file
263
mico-os/libraries/drivers/MiCOKit_EXT2/micokit_ext_mfg.c
Normal file
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board manufacture test operations..
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, MXCHIP Inc. SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 MXCHIP Inc.</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "mico_platform.h"
|
||||
#include "micokit_ext.h"
|
||||
#include "mico_system.h"
|
||||
|
||||
#include "sensor/BME280/bme280_user.h"
|
||||
#include "sensor/DHT11/DHT11.h"
|
||||
|
||||
extern mico_semaphore_t mfg_test_state_change_sem;
|
||||
extern volatile int16_t mfg_test_module_number;
|
||||
|
||||
//---------------------------- user modules functions --------------------------
|
||||
|
||||
// Key1 clicked callback: previous test module in test mode
|
||||
WEAK void user_key1_clicked_callback( void )
|
||||
{
|
||||
if ( NULL != mfg_test_state_change_sem )
|
||||
{
|
||||
if ( 0 < mfg_test_module_number )
|
||||
{
|
||||
mfg_test_module_number = (mfg_test_module_number - 1) % (MFG_TEST_MAX_MODULE_NUM + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mfg_test_module_number = MFG_TEST_MAX_MODULE_NUM;
|
||||
}
|
||||
mico_rtos_set_semaphore( &mfg_test_state_change_sem ); // go back to previous module
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Key2 clicked callback: next test module in test mode
|
||||
WEAK void user_key2_clicked_callback( void )
|
||||
{
|
||||
if ( NULL != mfg_test_state_change_sem )
|
||||
{
|
||||
mfg_test_module_number = (mfg_test_module_number + 1) % (MFG_TEST_MAX_MODULE_NUM + 1);
|
||||
mico_rtos_set_semaphore( &mfg_test_state_change_sem ); // start next module
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//---------------------------- MFG TEST FOR EXT-BOARD --------------------------
|
||||
#define mfg_test_oled_test_string "abcdefghijklmnop123456789012345612345678901234561234567890123456"
|
||||
#define OLED_MFG_TEST_PREFIX "TEST:"
|
||||
|
||||
mico_semaphore_t mfg_test_state_change_sem = NULL;
|
||||
volatile int16_t mfg_test_module_number = 0;
|
||||
volatile bool scanap_done = false;
|
||||
extern void mico_wlan_get_mac_address( uint8_t *mac );
|
||||
|
||||
static void mf_printf( char *str )
|
||||
{
|
||||
OLED_Clear( );
|
||||
OLED_ShowString( 0, 0, (char*) str );
|
||||
}
|
||||
|
||||
static void mf_printf_pos( uint8_t x, uint8_t y, char *str )
|
||||
{
|
||||
//OLED_Clear();
|
||||
OLED_ShowString( x, y, (char*) str );
|
||||
}
|
||||
|
||||
void mico_notify_WifiScanCompleteHandler( ScanResult *pApList, void * inContext )
|
||||
{
|
||||
char str[32] = { '\0' };
|
||||
pApList->ApList[0].ssid[10] = '\0'; // truncate first 10 char
|
||||
sprintf( str, "SSID :%10s\r\nPOWER:%10d",
|
||||
pApList->ApList[0].ssid,
|
||||
pApList->ApList[0].rssi );
|
||||
mf_printf_pos( 0, 4, str );
|
||||
scanap_done = true;
|
||||
}
|
||||
|
||||
void micokit_ext_mfg_test( mico_Context_t *inContext )
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
char str[64] = { '\0' };
|
||||
uint8_t mac[6];
|
||||
|
||||
int rgb_led_hue = 0;
|
||||
int dc_motor = 0;
|
||||
|
||||
uint8_t dht11_ret = 0;
|
||||
uint8_t dht11_temp_data = 0;
|
||||
uint8_t dht11_hum_data = 0;
|
||||
int dht11_test_cnt = 0;
|
||||
|
||||
int light_ret = 0;
|
||||
uint16_t light_sensor_data = 0;
|
||||
|
||||
int infrared_ret = 0;
|
||||
uint16_t infrared_reflective_data = 0;
|
||||
|
||||
bool bme280_on = false;
|
||||
int32_t bme280_temp = 0;
|
||||
uint32_t bme280_hum = 0;
|
||||
uint32_t bme280_press = 0;
|
||||
|
||||
UNUSED_PARAMETER( inContext );
|
||||
|
||||
UNUSED_PARAMETER( dht11_ret );
|
||||
UNUSED_PARAMETER( light_ret );
|
||||
UNUSED_PARAMETER( infrared_ret );
|
||||
|
||||
mico_rtos_init_semaphore( &mfg_test_state_change_sem, 1 );
|
||||
err = mico_system_notify_register( mico_notify_WIFI_SCAN_COMPLETED, (void *) mico_notify_WifiScanCompleteHandler, inContext );
|
||||
require_noerr( err, exit );
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
switch ( mfg_test_module_number )
|
||||
{
|
||||
case 0: // mfg mode start
|
||||
{
|
||||
sprintf( str, "%s\r\nStart:\r\n%s\r\n%s", "TEST MODE", " Next: KEY2", " Prev: KEY1" );
|
||||
mf_printf( str );
|
||||
while ( kNoErr != mico_rtos_get_semaphore( &mfg_test_state_change_sem, MICO_WAIT_FOREVER ) )
|
||||
;
|
||||
break;
|
||||
}
|
||||
case 1: // OUTPUT: OLED & RGB & DC_MOTOR
|
||||
{
|
||||
while ( kNoErr != mico_rtos_get_semaphore( &mfg_test_state_change_sem, 0 ) )
|
||||
{
|
||||
// OLED display test info
|
||||
sprintf( str, "%s OUTPUT\r\nOLED\r\nRGB_LED\r\nDC_MOTOR", OLED_MFG_TEST_PREFIX );
|
||||
mf_printf( str );
|
||||
mico_thread_msleep( 500 );
|
||||
|
||||
// RGB_LED
|
||||
hsb2rgb_led_open( rgb_led_hue, 100, 50 );
|
||||
rgb_led_hue += 120;
|
||||
if ( rgb_led_hue >= 360 )
|
||||
{
|
||||
rgb_led_hue = 0;
|
||||
}
|
||||
|
||||
// DC MOTOR
|
||||
dc_motor = 1 - dc_motor;
|
||||
dc_motor_set( dc_motor );
|
||||
|
||||
// OLED
|
||||
mf_printf( mfg_test_oled_test_string );
|
||||
mico_thread_msleep( 500 );
|
||||
}
|
||||
|
||||
// exit, close modules
|
||||
dc_motor_set( 0 );
|
||||
hsb2rgb_led_open( 0, 0, 0 );
|
||||
OLED_Clear( );
|
||||
break;
|
||||
}
|
||||
case 2: // INPUT: infrared & light & T/H sensor
|
||||
{
|
||||
dht11_test_cnt = 0;
|
||||
bme280_on = false;
|
||||
while ( kNoErr != mico_rtos_get_semaphore( &mfg_test_state_change_sem, 0 ) )
|
||||
{
|
||||
// infrared
|
||||
infrared_ret = infrared_reflective_read( &infrared_reflective_data );
|
||||
|
||||
// light
|
||||
light_ret = light_sensor_read( &light_sensor_data );
|
||||
|
||||
// display infared/light on OLED line1~3
|
||||
sprintf( str, "%s INPUT\r\nInfrared: %6d\r\nLight: %9d",
|
||||
OLED_MFG_TEST_PREFIX,
|
||||
infrared_reflective_data, light_sensor_data );
|
||||
mf_printf_pos( 0, 0, str );
|
||||
|
||||
// T/H
|
||||
if ( dht11_test_cnt == 0 )
|
||||
{ // DHT11 interval must >= 1s
|
||||
// >>>DTH11
|
||||
dht11_ret = DHT11_Read_Data( &dht11_temp_data, &dht11_hum_data );
|
||||
// display T/H on OLED line4
|
||||
sprintf( str, "Humiture:%2dC %2d%%", dht11_temp_data, dht11_hum_data );
|
||||
mf_printf_pos( 0, 6, str );
|
||||
|
||||
// >>>BME280 check
|
||||
if ( false == bme280_on )
|
||||
{
|
||||
err = bme280_sensor_init( );
|
||||
if ( kNoErr == err )
|
||||
{
|
||||
bme280_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bme280_on )
|
||||
{
|
||||
// if has BME280
|
||||
err = bme280_data_readout( &bme280_temp, &bme280_press, &bme280_hum );
|
||||
if ( kNoErr == err )
|
||||
{
|
||||
//sprintf(str, "%s BME280\r\nT: %3.1fC\r\nH: %3.1f%%\r\nP: %5.2fkPa", OLED_MFG_TEST_PREFIX,
|
||||
// (float)bme280_temp/100, (float)bme280_hum/1024, (float)bme280_press/1000);
|
||||
// update T/H/P on OLED line4
|
||||
sprintf( str, "%3.1f/%3.1f/%5.2f",
|
||||
(float) bme280_temp / 100,
|
||||
(float) bme280_hum / 1024, (float) bme280_press / 1000 );
|
||||
mico_thread_sleep( 1 );
|
||||
mf_printf_pos( 0, 6, " " ); // clean line4
|
||||
mf_printf_pos( 0, 6, str );
|
||||
}
|
||||
}
|
||||
}
|
||||
dht11_test_cnt++;
|
||||
if ( 2 == dht11_test_cnt )
|
||||
{
|
||||
dht11_test_cnt = 0;
|
||||
}
|
||||
|
||||
mico_thread_msleep( 500 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: // wifi
|
||||
{
|
||||
wlan_get_mac_address( mac );
|
||||
sprintf( str, "%s Wi-Fi\r\nMAC:%02x%02x%02x%02x%02x%02x", OLED_MFG_TEST_PREFIX,
|
||||
mac[0],
|
||||
mac[1], mac[2], mac[3], mac[4], mac[5] );
|
||||
mf_printf( str );
|
||||
//mico_thread_msleep(500);
|
||||
|
||||
scanap_done = false;
|
||||
micoWlanStartScan( );
|
||||
while ( (!scanap_done) || (kNoErr != mico_rtos_get_semaphore( &mfg_test_state_change_sem, MICO_WAIT_FOREVER )) )
|
||||
;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
goto exit;
|
||||
// error
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
mico_thread_sleep( MICO_NEVER_TIMEOUT );
|
||||
}
|
||||
91
mico-os/libraries/drivers/MiCOKit_EXT2/motion_sensor.c
Normal file
91
mico-os/libraries/drivers/MiCOKit_EXT2/motion_sensor.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file motion_sensor.c
|
||||
* @author William Xu
|
||||
* @version V1.0.0
|
||||
* @date 21-May-2015
|
||||
* @brief motion sensor control demo.
|
||||
******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "sensor/BMA2x2/bma2x2_user.h"
|
||||
#include "sensor/BMG160/bmg160_user.h"
|
||||
#include "sensor/BMM050/bmm050_user.h"
|
||||
#include "motion_sensor.h"
|
||||
|
||||
OSStatus motion_sensor_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor init*/
|
||||
err = bma2x2_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor init*/
|
||||
err = bmg160_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor init*/
|
||||
err = bmm050_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus motion_sensor_readout(motion_data_t *motion_data)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor data read*/
|
||||
err = bma2x2_data_readout(&motion_data->accel_data.accel_datax,
|
||||
&motion_data->accel_data.accel_datay,
|
||||
&motion_data->accel_data.accel_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor data read*/
|
||||
err = bmg160_data_readout(&motion_data->gyro_data.gyro_datax,
|
||||
&motion_data->gyro_data.gyro_datay,
|
||||
&motion_data->gyro_data.gyro_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor data read*/
|
||||
err = bmm050_data_readout(&motion_data->mag_data.mag_dataz,
|
||||
&motion_data->mag_data.mag_datay,
|
||||
&motion_data->mag_data.mag_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus motion_sensor_deinit(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor deinit*/
|
||||
err = bma2x2_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor deinit*/
|
||||
err = bmg160_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor deinit*/
|
||||
err = bmm050_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
102
mico-os/libraries/drivers/MiCOKit_EXT2/motion_sensor.h
Normal file
102
mico-os/libraries/drivers/MiCOKit_EXT2/motion_sensor.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file motion_sensor.c
|
||||
* @author William Xu
|
||||
* @version V1.0.0
|
||||
* @date 21-May-2015
|
||||
* @brief motion sensor control header file.
|
||||
******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MOTION_SENSOR_H_
|
||||
#define __MOTION_SENSOR_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICOKIT_EXT_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Motion_Sensor_Driver MiCOKit Ext Motion Sensor Driver
|
||||
* @brief Provide driver interface for MiCOKit Ext motion sensor
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct _accel_data_t {
|
||||
int16_t accel_datax;
|
||||
int16_t accel_datay;
|
||||
int16_t accel_dataz;
|
||||
} accel_data_t;
|
||||
|
||||
typedef struct _gyro_data_t {
|
||||
int16_t gyro_datax;
|
||||
int16_t gyro_datay;
|
||||
int16_t gyro_dataz;
|
||||
} gyro_data_t;
|
||||
|
||||
typedef struct _mag_data_t {
|
||||
int16_t mag_datax;
|
||||
int16_t mag_datay;
|
||||
int16_t mag_dataz;
|
||||
} mag_data_t;
|
||||
|
||||
typedef struct _motion_data_t {
|
||||
accel_data_t accel_data;
|
||||
gyro_data_t gyro_data;
|
||||
mag_data_t mag_data;
|
||||
} motion_data_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize MiCOKit Ext - motion sensor Devices.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus motion_sensor_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read data from MiCOKit Ext - motion sensor Devices.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus motion_sensor_readout(motion_data_t *motion_data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deinitialize MiCOKit Ext - motion sensor Devices.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus motion_sensor_deinit(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#endif // __TEMP_HUM_SENSOR_H_
|
||||
|
||||
|
||||
|
||||
89
mico-os/libraries/drivers/MiCOKit_EXT2/temp_hum_sensor.c
Normal file
89
mico-os/libraries/drivers/MiCOKit_EXT2/temp_hum_sensor.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file temp_hum_sensor.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 1-May-2015
|
||||
* @brief user interfaces for temperature && humidity sensor operation,
|
||||
* use DHT11 if bme280 not found.
|
||||
******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "sensor/DHT11/DHT11.h"
|
||||
#include "sensor/BME280/bme280_user.h"
|
||||
#include "temp_hum_sensor.h"
|
||||
|
||||
static volatile temp_hum_sensor_type_t temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_NONE;
|
||||
|
||||
/*---------------------------------- function --------------------------------*/
|
||||
|
||||
OSStatus temp_hum_sensor_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
uint8_t ret = 0;
|
||||
|
||||
err = bme280_sensor_init();
|
||||
if(kNoErr != err){ // bme280 not work, use DHT11
|
||||
bme280_sensor_deinit();
|
||||
|
||||
ret = DHT11_Init();
|
||||
if(0 != ret){ // init error
|
||||
err = kNoResourcesErr;
|
||||
}
|
||||
else{
|
||||
temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_DHT11;
|
||||
err = kNoErr;
|
||||
}
|
||||
}
|
||||
else{ // use bme280
|
||||
temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_BME280;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus temp_hum_sensor_read(int32_t *temperature, uint32_t *humidity)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
uint8_t ret = 0;
|
||||
uint8_t dht11_temp = 0;
|
||||
uint8_t dht11_hum = 0;
|
||||
int32_t bme280_temp = 0;
|
||||
uint32_t bme280_hum = 0;
|
||||
uint32_t bme280_press = 0;
|
||||
|
||||
switch(temp_hum_sensor_type){
|
||||
case MICOKIT_TEMP_HUM_SENSOR_BME280:
|
||||
{
|
||||
err = bme280_data_readout(&bme280_temp, &bme280_press, &bme280_hum);
|
||||
*temperature = bme280_temp/100;
|
||||
*humidity = bme280_hum/1024;
|
||||
break;
|
||||
}
|
||||
case MICOKIT_TEMP_HUM_SENSOR_DHT11:
|
||||
{
|
||||
ret = DHT11_Read_Data(&dht11_temp, &dht11_hum);
|
||||
if(0 != ret || dht11_hum == 0 ){
|
||||
err = kReadErr;
|
||||
}
|
||||
else{
|
||||
*temperature = (int32_t)dht11_temp;
|
||||
*humidity = (uint32_t)dht11_hum;
|
||||
err = kNoErr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
err = kUnsupportedErr;
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
75
mico-os/libraries/drivers/MiCOKit_EXT2/temp_hum_sensor.h
Normal file
75
mico-os/libraries/drivers/MiCOKit_EXT2/temp_hum_sensor.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file temp_hum_sensor.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 1-May-2015
|
||||
* @brief DHT11 operation.
|
||||
******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __TEMP_HUM_SENSOR_H_
|
||||
#define __TEMP_HUM_SENSOR_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICOKIT_EXT_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Temp_Hum_Driver MiCOKit Ext Temp Hum Driver
|
||||
* @brief Provide driver interface for MiCOKit Ext Temp Hum Sensor
|
||||
* @{
|
||||
*/
|
||||
typedef enum {
|
||||
MICOKIT_TEMP_HUM_SENSOR_NONE = 0,
|
||||
MICOKIT_TEMP_HUM_SENSOR_BME280,
|
||||
MICOKIT_TEMP_HUM_SENSOR_DHT11
|
||||
}temp_hum_sensor_type_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize MiCOKit Ext - temp hum sensor Devices.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus temp_hum_sensor_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read tmperature and humidity from sensor device
|
||||
*
|
||||
* @param temperature: temperature data from sensor
|
||||
* @param humidity: humidity data from sensor
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus temp_hum_sensor_read(int32_t *temperature, uint32_t *humidity);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif // __TEMP_HUM_SENSOR_H_
|
||||
|
||||
Reference in New Issue
Block a user