最新生成的SOC代码中,与原来的略有不同,特别是在DH11温度,湿度传感器的数据添加中,应特别注意,具体参考以一下文件及函数,原来网站上提供的相关PDF内容已不再适用。
1、user_main.c中添加如下内容:- #include "driver/hal_rgb_led.h" //RGB_LED头文件,新加内容
- #include "driver/hal_motor.h" //Motor头文件,新加内容
- #include "driver/hal_temp_hum.h" //Tempeture头文件,新加内容
- #include "driver/hal_infrared.h" //infrared头文件,新加内容
[color=rgb(0, 0, 0) !important]复制代码
- void ICACHE_FLASH_ATTR user_init(void)
- {
- uint32_t system_free_size = 0;
- wifi_station_set_auto_connect(1);
- wifi_set_sleep_type(NONE_SLEEP_T);//set none sleep mode
- espconn_tcp_set_max_con(10);
- uart_init_3(9600,115200);
- UART_SetPrintPort(1);
- GIZWITS_LOG( "---------------SDK version:%s--------------\n", system_get_sdk_version());
- GIZWITS_LOG( "system_get_free_heap_size=%d\n",system_get_free_heap_size());
- struct rst_info *rtc_info = system_get_rst_info();
- GIZWITS_LOG( "reset reason: %x\n", rtc_info->reason);
- if (rtc_info->reason == REASON_WDT_RST ||
- rtc_info->reason == REASON_EXCEPTION_RST ||
- rtc_info->reason == REASON_SOFT_WDT_RST)
- {
- if (rtc_info->reason == REASON_EXCEPTION_RST)
- {
- GIZWITS_LOG("Fatal exception (%d):\n", rtc_info->exccause);
- }
- GIZWITS_LOG( "epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n",
- rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);
- }
- if (system_upgrade_userbin_check() == UPGRADE_FW_BIN1)
- {
- GIZWITS_LOG( "---UPGRADE_FW_BIN1---\n");
- }
- else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2)
- {
- GIZWITS_LOG( "---UPGRADE_FW_BIN2---\n");
- }
- keyInit();
- /*RGB灯的初始化*/
- rgbGpioInit(); // 新加代码WHP
- rgbLedInit(); // 新加代码WHP
- /*电机的初始化*/
- motorInit(); // 新加代码WHP
- /*温度湿度传感器初始化*/
- dh11Init(); // 新加代码WHP
- /*红外初始化*/
- irInit(); //新加代码WHP
- gizwitsInit();
- GIZWITS_LOG("--- system_free_size = %d ---\n", system_get_free_heap_size());
- }
[color=rgb(0, 0, 0) !important]复制代码
2、gizwits_product.c中添加如下内容:- #define USER_TIME_MS 100//新添加代码:?更改定时器间隔为100ms
- #define TH_TIMEOUT (1000/USER_TIME_MS)//新添加代码:温湿度采集间隔为1S(1000ms)
- #define INF_TIMEOUT (500/USER_TIME_MS)//新添加代码:红外采集间隔为500ms
[color=rgb(0, 0, 0) !important]复制代码
- int8_t ICACHE_FLASH_ATTR gizwitsEventProcess(eventInfo_t *info, uint8_t *data, uint32_t len)
- {
- uint8_t i = 0;
- dataPoint_t * dataPointPtr = (dataPoint_t *)data;
- moduleStatusInfo_t * wifiData = (moduleStatusInfo_t *)data;
- if((NULL == info) || (NULL == data))
- {
- GIZWITS_LOG("!!! gizwitsEventProcess Error \n");
- return -1;
- }
- for(i = 0; i < info->num; i++)
- {
- switch(info->event)
- {
- case EVENT_LED_OnOff :
- currentDataPoint.valueLED_OnOff = dataPointPtr->valueLED_OnOff;
- GIZWITS_LOG("Evt: EVENT_LED_OnOff %d \n", currentDataPoint.valueLED_OnOff);
- if(0x01 == currentDataPoint.valueLED_OnOff)
- {
- //user handle
- rgbControl(255, 0, 0);//红灯亮,新加代码WHP
- }
- else
- {
- //user handle
- rgbControl(0, 0, 0);//灯灭,新加代码WHP;
- }
- break;
- case EVENT_LED_Color:
- currentDataPoint.valueLED_Color = dataPointPtr->valueLED_Color;
- GIZWITS_LOG("Evt: EVENT_LED_Color %d\n", currentDataPoint.valueLED_Color);
- switch(currentDataPoint.valueLED_Color)
- {
- case LED_Color_VALUE0:
- //user handle
- rgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, currentDataPoint.valueLED_B);
- break;
- case LED_Color_VALUE1:
- //user handle
- rgbControl(255, 165, 0);
- break;
- case LED_Color_VALUE2:
- //user handle
- rgbControl(160, 32, 240);
- break;
- case LED_Color_VALUE3:
- //user handle
- rgbControl(255, 110,180);
- break;
- default:
- break;
- }
- break;
- case EVENT_LED_R:
- currentDataPoint.valueLED_R= dataPointPtr->valueLED_R;
- GIZWITS_LOG("Evt:EVENT_LED_R %d\n",currentDataPoint.valueLED_R);
- //user handle
- rgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, currentDataPoint.valueLED_B);
- break;
- case EVENT_LED_G:
- currentDataPoint.valueLED_G= dataPointPtr->valueLED_G;
- GIZWITS_LOG("Evt:EVENT_LED_G %d\n",currentDataPoint.valueLED_G);
- //user handle
- rgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, currentDataPoint.valueLED_B);
- break;
- case EVENT_LED_B:
- currentDataPoint.valueLED_B= dataPointPtr->valueLED_B;
- GIZWITS_LOG("Evt:EVENT_LED_B %d\n",currentDataPoint.valueLED_B);
- //user handle
- rgbControl(currentDataPoint.valueLED_R, currentDataPoint.valueLED_G, currentDataPoint.valueLED_B);
- break;
- case EVENT_Motor_Speed:
- currentDataPoint.valueMotor_Speed= dataPointPtr->valueMotor_Speed;
- GIZWITS_LOG("Evt:EVENT_Motor_Speed %d\n",currentDataPoint.valueMotor_Speed);
- //user handle
- motorControl(currentDataPoint.valueMotor_Speed);
- break;
- case WIFI_SOFTAP:
- break;
- case WIFI_AIRLINK:
- break;
- case WIFI_STATION:
- break;
- case WIFI_CON_ROUTER:
- GIZWITS_LOG("@@@@ connected router\n");
- break;
- case WIFI_DISCON_ROUTER:
- GIZWITS_LOG("@@@@ disconnected router\n");
- break;
- case WIFI_CON_M2M:
- GIZWITS_LOG("@@@@ connected m2m\n");
- setConnectM2MStatus(0x01);
- break;
- case WIFI_DISCON_M2M:
- GIZWITS_LOG("@@@@ disconnected m2m\n");
- setConnectM2MStatus(0x00);
- break;
- case WIFI_RSSI:
- GIZWITS_LOG("@@@@ RSSI %d\n", wifiData->rssi);
- break;
- case TRANSPARENT_DATA:
- GIZWITS_LOG("TRANSPARENT_DATA \n");
- //user handle , Fetch data from [data] , size is [len]
- break;
- case MODULE_INFO:
- GIZWITS_LOG("MODULE INFO ...\n");
- break;
- default:
- break;
- }
- }
- system_os_post(USER_TASK_PRIO_2, SIG_UPGRADE_DATA, 0);
- return 0;
- }
[color=rgb(0, 0, 0) !important]复制代码
- void ICACHE_FLASH_ATTR userHandle(void)
- {
- /*
- currentDataPoint.valueInfrared = ;//Add Sensor Data Collection
- currentDataPoint.valueTemperature = ;//Add Sensor Data Collection
- currentDataPoint.valueHumidity = ;//Add Sensor Data Collection
- currentDataPoint.valueAlert_1 = ;//Add Sensor Data Collection
- currentDataPoint.valueAlert_2 = ;//Add Sensor Data Collection
- currentDataPoint.valueFault_LED = ;//Add Sensor Data Collection
- currentDataPoint.valueFault_Motor = ;//Add Sensor Data Collection
- currentDataPoint.valueFault_TemHum = ;//Add Sensor Data Collection
- currentDataPoint.valueFault_IR = ;//Add Sensor Data Collection
- */
- uint8_t ret=0;
- uint8_t curTemperature=0;
- uint8_t curHumidity=0;
- uint8_t curIr=0;
- static uint8_t thCtime=0;
- static uint8_t irCtime=0;
- thCtime++;
- irCtime++;
- /*新添加代码:红外传感器数据获取*/
- if(INF_TIMEOUT<irCtime)
- {
- irCtime=0;
- curIr=irUpdateStatus();
- currentDataPoint.valueInfrared=curIr;
- }
- /*新添加代码:温湿度传感器数据获取*/
- if(TH_TIMEOUT<thCtime)
- {
- thCtime=0;
- ret=dh11Read(&curTemperature,&curHumidity);
- if(0==ret)
- {
- currentDataPoint.valueTemperature=curTemperature;
- currentDataPoint.valueHumidity=curHumidity;
- }
- else
- {
- os_printf("@@@ dh11Read error! \n");
- }
- }
- system_os_post(USER_TASK_PRIO_2, SIG_UPGRADE_DATA, 0);
- }
[color=rgb(0, 0, 0) !important]复制代码
以上代码已经下载到gokit3功能板上已经验证,可以从APP端正常与设备连接,并操控,温度,湿度数据均能正常上传。
|
|
|