可以通过STM32直接上云的源码。
1、修复ST V2.1底板时温湿度不规则报0的问题[bug:45027];
2015-08-28 V2.3.1
1、支持GoKit2.2硬件(增加RGB灯使能引脚A0)
2015-07-27 V2.3.0
1、采用uVision V4.70.0.0软件
2、修改了软件结构,封装了串口协议部分,进一步提升扩展性;
3、解决了app上显示温度不准确的问题;
4、修改了入网配置方法;
长按key1恢复默认配置,短按key2进入Soft AP模式,RGB灯红色,长按key2进入AirLink模式,RGB灯绿色;
5、关掉了进入配置模式时电机转动操作;
6、解决了APP中自定义灯颜色切换不准确的问题;
7、完善了协议指令01、03、04、05指令;
8、解决了上电时RGB高亮一段时间的问题;
先在gizwits_protocol.h将所有数据点加入
搜寻custom
修改eventProcess,dataPoint2Event,checkReport函数
只可读数据点在userHandle内加入
单片机源程序如下:
- #include <string.h>
- #include "gizwits_product.h"
- #include "Hal_key/Hal_key.h"
- #include "Hal_Usart/hal_uart.h"
- #include "Hal_led/Hal_led.h"
- #include "Hal_motor/Hal_motor.h"
- #include "Hal_rgb_led/Hal_rgb_led.h"
- #include "Hal_temp_hum/Hal_temp_hum.h"
- #include "Hal_infrared/Hal_infrared.h"
- #include "Hal_Watchdog/hal_watchdog.h"
- #include "bsp_key.h"
- /**包头*/
- unsigned char datahead[32]={0xFE,0xFD,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,0xF5,0xF4,0xF3,0xF2,0xF1,0xF0,0xEF,0xEE,0xED,0xEC,0xEB,0xEA,0xE9,0xE8,0xE7,0xE6,0xE5,0xE4,0xE3,0xE2,0xE1,0xE0,0xDF};
- u8 gesture=0;
-
- extern unsigned char feeder_rec;//暖奶器开关
- extern unsigned char eat_alert_rec;//喝奶闹钟开关
- extern unsigned char humidifier_rec;//加湿器开关
- extern unsigned char anion_rec;//负离子净化器开关
- extern unsigned char blanket_rec;//恒温床垫开关
- extern unsigned char swing_rec;//摇摆档位选择
- extern unsigned char eat_hour_rec;//定时喝奶时
- extern unsigned char eat_minute_rec;//定时喝奶分
- extern unsigned char pee_rec;//是否尿床
- extern unsigned char eat_status_rec;//上次是否喝奶
- extern unsigned char temperature_rec;//环境温度
- extern unsigned char humidity_rec;//环境湿度
- extern unsigned char baby_heat_rec;//婴儿体温
- extern unsigned char baby_weight_rec;//婴儿体重
- extern unsigned char co_value_rec;//CO浓度
- extern unsigned char bed_heat_rec;//床垫温度
- volatile gizwitsReport_t reportData;//dev_status包含在里面
- keyTypedef_t singleKey[2];
- keysTypedef_t keys;
- void userInit(void)
- {
- Key_GPIO_Config();
- delayInit(72);
- uartxInit();
- rgbLedInit();
- ledGpioInit();
- rgbKeyGpioInit();
- motorInit();
- dht11Init();
- irInit();
- watchdogInit(2); //5,625看门狗复位时间2s
- memset((uint8_t*)&reportData, 0, sizeof(gizwitsReport_t));
- motorStatus(MOTOR_SPEED_DEFAULT);
- }
- void userHandle(void)
- {
- /**控制类数据点*/
- uint8_t curFeeder = 0;
- uint8_t curEat_Alert = 0;
- uint8_t curHumidifier = 0;
- uint8_t curAnion = 0;
- uint8_t curBlanket = 0;
- uint8_t curColor = 0;
- uint8_t curHour = 0;
- uint8_t curMin = 0;
- static uint32_t feederLastTimer=0;
- static uint32_t eat_alertLastTimer=0;
- static uint32_t humidifierLastTimer=0;
- static uint32_t anionLastTimer=0;
- static uint32_t blanketLastTimer=0;
- static uint32_t colorLastTimer=0;
- static uint32_t hourLastTimer=0;
- static uint32_t minLastTimer=0;
-
- /**传感器类数据点*/
- int8_t curTem = 0; //当前的温度
- int8_t curHum = 0; //当前的湿度
- uint8_t curInfrared = 0; //当前红外状态
- uint8_t curPee = 0; //当前是否尿床
- uint8_t curEat = 0; //当前的喝奶状态
- uint8_t curBaby_Heat = 0; //当前婴儿的体温
- uint8_t curBaby_Weight = 0; //当前婴儿的体重
- uint8_t curCO_Value = 0; //当前CO的浓度
- uint8_t curBed_Heat = 0; //当前被窝的温度
- static int8_t lastTem = 0; //上一次的温度,只有上次和这次的不一样才上传
- static int8_t lastHum = 0; //上一次的湿度,只有上次和这次的不一样才上传
- static uint32_t peeLastTimer=0; //上一次尿床检测的TimerCount
- static uint32_t eatLastTimer=0; //上一次喝奶状态的TimerCount
- static uint32_t babyhLastTimer=0;//上一次婴儿体温的TimerCount
- static uint32_t weiLastTimer=0; //上一次婴儿体重的TimerCount
- static uint32_t COLastTimer=0; //上一次CO浓度的TimerCount
- static uint32_t bedhLastTimer=0; //上一次被窝温度的TimerCount
- static uint32_t irLastTimer = 0; //上一次红外的TimerCount
- static uint32_t thLastTimer = 0; //上一次Dht11的TimerCount 只有超过2s以上才上传
- /**获取控制类数据*/
- curFeeder=feeder_rec;
- curEat_Alert=eat_alert_rec;
- curHumidifier=humidifier_rec;
- curAnion=anion_rec;
- curBlanket=blanket_rec;
- curColor=swing_rec;
- curHour=eat_hour_rec;
- curMin=gesture;
- /**获取传感器类数据*/
- curInfrared = irHandle();
- curPee=pee_rec;
- curEat=eat_status_rec;
- curBaby_Heat=baby_heat_rec;
- curBaby_Weight=baby_weight_rec;
- curCO_Value=co_value_rec;
- curBed_Heat=bed_heat_rec;
- curTem=temperature_rec;
- curHum=humidity_rec;
-
- /**控制类数据的更新*/
- if(curFeeder != reportData.devStatus.LED_OnOff)//暖奶器
- {
- if((gizwitsGetTimerCount() - feederLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_OnOff = curFeeder;
- feederLastTimer = gizwitsGetTimerCount();
- printf("LED_OnOff %d \r\n", feederLastTimer);
- }
- }
-
- if(curEat_Alert != reportData.devStatus.Eat_Alert)//喝奶闹钟
- {
- if((gizwitsGetTimerCount() - eat_alertLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Eat_Alert = curEat_Alert;
- eat_alertLastTimer = gizwitsGetTimerCount();
- printf("Eat_Alert %d \r\n", eat_alertLastTimer);
- }
- }
- if(curHumidifier != reportData.devStatus.Humidity_OnOff)//加湿器
- {
- if((gizwitsGetTimerCount() - humidifierLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Humidity_OnOff = curHumidifier;
- humidifierLastTimer = gizwitsGetTimerCount();
- printf("Humidity_OnOff %d \r\n", humidifierLastTimer);
- }
- }
-
- if(curAnion != reportData.devStatus.Anion_OnOff)//负离子净化器
- {
- if((gizwitsGetTimerCount() - anionLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Anion_OnOff = curAnion;
- anionLastTimer = gizwitsGetTimerCount();
- printf("Anion_OnOff %d \r\n", anionLastTimer);
- }
- }
-
- if(curBlanket != reportData.devStatus.Blanket_OnOff)//恒温床垫
- {
- if((gizwitsGetTimerCount() - blanketLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Blanket_OnOff = curBlanket;
- blanketLastTimer = gizwitsGetTimerCount();
- printf("Blanket_OnOff %d \r\n", blanketLastTimer);
- }
- }
- if(curColor != reportData.devStatus.LED_Color)//摇摆档位
- {
- if((gizwitsGetTimerCount() - colorLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_Color = curColor;
- colorLastTimer = gizwitsGetTimerCount();
- printf("LED_Color %d \r\n", colorLastTimer);
- }
- }
-
- if(curHour != reportData.devStatus.LED_R)//喝奶时
- {
- if((gizwitsGetTimerCount() - hourLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_R = curHour;
- hourLastTimer = gizwitsGetTimerCount();
- printf("LED_R %d \r\n", hourLastTimer);
- }
- }
-
- if(curMin != reportData.devStatus.LED_G)//喝奶分
- {
- if((gizwitsGetTimerCount() - minLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_G = curMin;
- minLastTimer = gizwitsGetTimerCount();
- printf("LED_G %d \r\n", minLastTimer);
- }
- }
-
- /**传感器类数据状态更新*/
- if(curInfrared != reportData.devStatus.Infrared)//红外反射
- {
- if((gizwitsGetTimerCount() - irLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Infrared = curInfrared;
- irLastTimer = gizwitsGetTimerCount();
- printf("Infrared %d \r\n", irLastTimer);
- }
- }
-
- if(curPee != reportData.devStatus.Pee_OnOff)//尿床检测
- {
- if((gizwitsGetTimerCount() - peeLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Pee_OnOff = curPee;
- peeLastTimer = gizwitsGetTimerCount();
- printf("Pee_OnOff %d \r\n", peeLastTimer);
- }
- }
-
- if(curEat != reportData.devStatus.Eat_Status)//上次是否喝奶
- {
- if((gizwitsGetTimerCount() - eatLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Eat_Status = curEat;
- eatLastTimer = gizwitsGetTimerCount();
- printf("Eat_Status %d \r\n", eatLastTimer);
- }
- }
-
- if(curBaby_Heat != reportData.devStatus.Baby_Heat)//婴儿体温
- {
- if((gizwitsGetTimerCount() - babyhLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Baby_Heat = curBaby_Heat;
- babyhLastTimer = gizwitsGetTimerCount();
- printf("Baby_Heat %d \r\n", babyhLastTimer);
- }
- }
-
- if(curBaby_Weight != reportData.devStatus.Baby_Weight)//婴儿体重
- {
- if((gizwitsGetTimerCount() - weiLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Baby_Weight = curBaby_Weight;
- weiLastTimer = gizwitsGetTimerCount();
- printf("Baby_Weight %d \r\n", weiLastTimer);
- }
- }
- if(curCO_Value != reportData.devStatus.CO_Value)//一氧化碳浓度
- {
- if((gizwitsGetTimerCount() - COLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.CO_Value = curCO_Value;
- COLastTimer = gizwitsGetTimerCount();
- printf("CO_Value %d \r\n", COLastTimer);
- }
- }
-
- if(curBed_Heat != reportData.devStatus.Bed_Heat)//被窝温度
- {
- if((gizwitsGetTimerCount() - bedhLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Bed_Heat = curBed_Heat;
- bedhLastTimer = gizwitsGetTimerCount();
- printf("Bed_Heat %d \r\n", bedhLastTimer);
- }
- }
-
- if((gizwitsGetTimerCount()-thLastTimer) > REPORT_TIME_MAX) //timeout = 2S
- {
- if((curTem != lastTem)||(curHum != lastHum))//温湿度
- {
- reportData.devStatus.Temperature = curTem;
- reportData.devStatus.Humidity = curHum;
-
- lastTem = curTem;
- lastHum = curHum;
-
- printf("Temperature&Humidity [%d-%d] %d %d\r\n", gizwitsGetTimerCount(), thLastTimer, curTem, curHum);
- }
- thLastTimer = gizwitsGetTimerCount();
- }
- }
- void key1ShortPress(void)
- {
- printf("KEY1 PRESS\r\n");
- }
- void key1LongPress(void)
- {
- printf("KEY1 PRESS LONG ,Wifi Reset\r\n");
- gizwitsSetDefault();
- }
- void key2ShortPress(void)
- {
- printf("KEY2 PRESS ,Soft AP mode\r\n");
- //Soft AP mode, RGB red
- ledRgbControl(255, 0, 0);
- gizwitsSetMode(SoftAp_Mode);
- }
- void key2LongPress(void)
- {
- //AirLink mode, RGB Green
- printf("KEY2 PRESS LONG ,AirLink mode\r\n");
- ledRgbControl(0, 128, 0);
- gizwitsSetMode(AirLink_Mode);
- }
- void gestureGet(void)
- {
- if(Key_Scan(GPIOA,GPIO_Pin_1)==1)
- gesture|=0x01;
- else
- gesture&=0xfe;
-
- if(Key_Scan(GPIOA,GPIO_Pin_4)==1)
- gesture|=0x02;
- else
- gesture&=0xfd;
-
- if(Key_Scan(GPIOA,GPIO_Pin_5)==1)
- gesture|=0x04;
- else
- gesture&=0xfb;
-
- if(Key_Scan(GPIOA,GPIO_Pin_7)==1)
- gesture|=0x08;
- else
- gesture&=0xf7;
-
- if(Key_Scan(GPIOB,GPIO_Pin_0)==1)
- gesture|=0x10;
- else
- gesture&=0xef;
-
- if(Key_Scan(GPIOB,GPIO_Pin_6)==1)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
Gokit3智能摇篮 V1.3(+睡姿).7z
(177.18 KB, 下载次数: 42)
|