找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2993|回复: 3
收起左侧

STM32智能婴儿摇篮程序设计源码

[复制链接]
ID:535582 发表于 2019-5-12 08:17 | 显示全部楼层 |阅读模式
0.png
可以通过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内加入

单片机源程序如下:
  1. #include <string.h>
  2. #include "gizwits_product.h"
  3. #include "Hal_key/Hal_key.h"
  4. #include "Hal_Usart/hal_uart.h"
  5. #include "Hal_led/Hal_led.h"
  6. #include "Hal_motor/Hal_motor.h"
  7. #include "Hal_rgb_led/Hal_rgb_led.h"
  8. #include "Hal_temp_hum/Hal_temp_hum.h"
  9. #include "Hal_infrared/Hal_infrared.h"
  10. #include "Hal_Watchdog/hal_watchdog.h"
  11. #include "bsp_key.h"

  12. /**包头*/
  13. 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};

  14. u8 gesture=0;        
  15.         
  16. extern unsigned char feeder_rec;//暖奶器开关
  17. extern unsigned char eat_alert_rec;//喝奶闹钟开关
  18. extern unsigned char humidifier_rec;//加湿器开关
  19. extern unsigned char anion_rec;//负离子净化器开关
  20. extern unsigned char blanket_rec;//恒温床垫开关
  21. extern unsigned char swing_rec;//摇摆档位选择
  22. extern unsigned char eat_hour_rec;//定时喝奶时
  23. extern unsigned char eat_minute_rec;//定时喝奶分
  24. extern unsigned char pee_rec;//是否尿床
  25. extern unsigned char eat_status_rec;//上次是否喝奶
  26. extern unsigned char temperature_rec;//环境温度
  27. extern unsigned char humidity_rec;//环境湿度
  28. extern unsigned char baby_heat_rec;//婴儿体温
  29. extern unsigned char baby_weight_rec;//婴儿体重
  30. extern unsigned char co_value_rec;//CO浓度
  31. extern unsigned char bed_heat_rec;//床垫温度

  32. volatile gizwitsReport_t reportData;//dev_status包含在里面
  33. keyTypedef_t singleKey[2];
  34. keysTypedef_t keys;

  35. void userInit(void)
  36. {
  37.           Key_GPIO_Config();
  38.     delayInit(72);
  39.     uartxInit();
  40.     rgbLedInit();
  41.     ledGpioInit();
  42.     rgbKeyGpioInit();
  43.     motorInit();
  44.     dht11Init();
  45.     irInit();
  46.     watchdogInit(2);    //5,625看门狗复位时间2s

  47.     memset((uint8_t*)&reportData, 0, sizeof(gizwitsReport_t));
  48.     motorStatus(MOTOR_SPEED_DEFAULT);
  49. }

  50. void userHandle(void)
  51. {
  52.                 /**控制类数据点*/
  53.                 uint8_t curFeeder = 0;
  54.                 uint8_t curEat_Alert = 0;
  55.                 uint8_t curHumidifier = 0;
  56.                 uint8_t curAnion = 0;
  57.                 uint8_t curBlanket = 0;
  58.                 uint8_t curColor = 0;
  59.                 uint8_t curHour = 0;
  60.                 uint8_t curMin = 0;
  61.           static uint32_t feederLastTimer=0;
  62.                 static uint32_t eat_alertLastTimer=0;
  63.                 static uint32_t humidifierLastTimer=0;
  64.                 static uint32_t anionLastTimer=0;
  65.                 static uint32_t blanketLastTimer=0;
  66.                 static uint32_t colorLastTimer=0;
  67.                 static uint32_t hourLastTimer=0;
  68.                 static uint32_t minLastTimer=0;
  69.         
  70.                 /**传感器类数据点*/
  71.     int8_t curTem = 0;  //当前的温度
  72.     int8_t curHum = 0;  //当前的湿度
  73.     uint8_t curInfrared = 0;   //当前红外状态
  74.                 uint8_t curPee = 0;  //当前是否尿床
  75.                 uint8_t curEat = 0;  //当前的喝奶状态
  76.                 uint8_t curBaby_Heat = 0;  //当前婴儿的体温
  77.                 uint8_t curBaby_Weight = 0; //当前婴儿的体重
  78.                 uint8_t curCO_Value = 0; //当前CO的浓度
  79.                 uint8_t curBed_Heat = 0;  //当前被窝的温度
  80.     static int8_t lastTem = 0;  //上一次的温度,只有上次和这次的不一样才上传
  81.     static int8_t lastHum = 0;  //上一次的湿度,只有上次和这次的不一样才上传
  82.                 static uint32_t peeLastTimer=0;  //上一次尿床检测的TimerCount
  83.                 static uint32_t eatLastTimer=0;  //上一次喝奶状态的TimerCount
  84.                 static uint32_t babyhLastTimer=0;//上一次婴儿体温的TimerCount
  85.                 static uint32_t weiLastTimer=0;  //上一次婴儿体重的TimerCount
  86.                 static uint32_t COLastTimer=0;   //上一次CO浓度的TimerCount
  87.                 static uint32_t bedhLastTimer=0; //上一次被窝温度的TimerCount
  88.     static uint32_t irLastTimer = 0;  //上一次红外的TimerCount
  89.     static uint32_t thLastTimer = 0;  //上一次Dht11的TimerCount 只有超过2s以上才上传

  90.                 /**获取控制类数据*/
  91.                 curFeeder=feeder_rec;
  92.                 curEat_Alert=eat_alert_rec;
  93.                 curHumidifier=humidifier_rec;
  94.                 curAnion=anion_rec;
  95.                 curBlanket=blanket_rec;
  96.                 curColor=swing_rec;
  97.                 curHour=eat_hour_rec;
  98.                 curMin=gesture;

  99.                 /**获取传感器类数据*/
  100.     curInfrared = irHandle();
  101.                 curPee=pee_rec;
  102.                 curEat=eat_status_rec;
  103.                 curBaby_Heat=baby_heat_rec;
  104.                 curBaby_Weight=baby_weight_rec;
  105.                 curCO_Value=co_value_rec;
  106.                 curBed_Heat=bed_heat_rec;
  107.                 curTem=temperature_rec;
  108.                 curHum=humidity_rec;
  109.                
  110.                 /**控制类数据的更新*/
  111.     if(curFeeder != reportData.devStatus.LED_OnOff)//暖奶器
  112.     {
  113.         if((gizwitsGetTimerCount() - feederLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  114.         {
  115.             reportData.devStatus.LED_OnOff = curFeeder;

  116.             feederLastTimer = gizwitsGetTimerCount();
  117.             printf("LED_OnOff %d \r\n", feederLastTimer);
  118.         }
  119.     }
  120.                
  121.                 if(curEat_Alert != reportData.devStatus.Eat_Alert)//喝奶闹钟
  122.     {
  123.         if((gizwitsGetTimerCount() - eat_alertLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  124.         {
  125.             reportData.devStatus.Eat_Alert = curEat_Alert;

  126.             eat_alertLastTimer = gizwitsGetTimerCount();
  127.             printf("Eat_Alert %d \r\n", eat_alertLastTimer);
  128.         }
  129.     }

  130.                 if(curHumidifier != reportData.devStatus.Humidity_OnOff)//加湿器
  131.     {
  132.         if((gizwitsGetTimerCount() - humidifierLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  133.         {
  134.             reportData.devStatus.Humidity_OnOff = curHumidifier;

  135.             humidifierLastTimer = gizwitsGetTimerCount();
  136.             printf("Humidity_OnOff %d \r\n", humidifierLastTimer);
  137.         }
  138.     }               
  139.                
  140.                 if(curAnion != reportData.devStatus.Anion_OnOff)//负离子净化器
  141.     {
  142.         if((gizwitsGetTimerCount() - anionLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  143.         {
  144.             reportData.devStatus.Anion_OnOff = curAnion;

  145.             anionLastTimer = gizwitsGetTimerCount();
  146.             printf("Anion_OnOff %d \r\n", anionLastTimer);
  147.         }
  148.     }        
  149.                
  150.                 if(curBlanket != reportData.devStatus.Blanket_OnOff)//恒温床垫
  151.     {
  152.         if((gizwitsGetTimerCount() - blanketLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  153.         {
  154.             reportData.devStatus.Blanket_OnOff = curBlanket;

  155.             blanketLastTimer = gizwitsGetTimerCount();
  156.             printf("Blanket_OnOff %d \r\n", blanketLastTimer);
  157.         }
  158.     }        

  159.                 if(curColor != reportData.devStatus.LED_Color)//摇摆档位
  160.     {
  161.         if((gizwitsGetTimerCount() - colorLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  162.         {
  163.             reportData.devStatus.LED_Color = curColor;

  164.             colorLastTimer = gizwitsGetTimerCount();
  165.             printf("LED_Color %d \r\n", colorLastTimer);
  166.         }
  167.     }        
  168.                
  169.                 if(curHour != reportData.devStatus.LED_R)//喝奶时
  170.     {
  171.         if((gizwitsGetTimerCount() - hourLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  172.         {
  173.             reportData.devStatus.LED_R = curHour;

  174.             hourLastTimer = gizwitsGetTimerCount();
  175.             printf("LED_R %d \r\n", hourLastTimer);
  176.         }
  177.     }        
  178.                
  179.                 if(curMin != reportData.devStatus.LED_G)//喝奶分
  180.     {
  181.         if((gizwitsGetTimerCount() - minLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  182.         {
  183.             reportData.devStatus.LED_G = curMin;

  184.             minLastTimer = gizwitsGetTimerCount();
  185.             printf("LED_G %d \r\n", minLastTimer);
  186.         }
  187.     }        
  188.                
  189.                 /**传感器类数据状态更新*/
  190.     if(curInfrared != reportData.devStatus.Infrared)//红外反射
  191.     {
  192.         if((gizwitsGetTimerCount() - irLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  193.         {
  194.             reportData.devStatus.Infrared = curInfrared;

  195.             irLastTimer = gizwitsGetTimerCount();
  196.             printf("Infrared %d \r\n", irLastTimer);
  197.         }
  198.     }
  199.    
  200.     if(curPee != reportData.devStatus.Pee_OnOff)//尿床检测
  201.     {
  202.         if((gizwitsGetTimerCount() - peeLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  203.         {
  204.             reportData.devStatus.Pee_OnOff = curPee;

  205.             peeLastTimer = gizwitsGetTimerCount();
  206.             printf("Pee_OnOff %d \r\n", peeLastTimer);
  207.         }
  208.     }
  209.                
  210.     if(curEat != reportData.devStatus.Eat_Status)//上次是否喝奶
  211.     {
  212.         if((gizwitsGetTimerCount() - eatLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  213.         {
  214.             reportData.devStatus.Eat_Status = curEat;

  215.             eatLastTimer = gizwitsGetTimerCount();
  216.             printf("Eat_Status %d \r\n", eatLastTimer);
  217.         }
  218.     }               
  219.                
  220.     if(curBaby_Heat != reportData.devStatus.Baby_Heat)//婴儿体温
  221.     {
  222.         if((gizwitsGetTimerCount() - babyhLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  223.         {
  224.             reportData.devStatus.Baby_Heat = curBaby_Heat;

  225.             babyhLastTimer = gizwitsGetTimerCount();
  226.             printf("Baby_Heat %d \r\n", babyhLastTimer);
  227.         }
  228.     }                        
  229.                
  230.     if(curBaby_Weight != reportData.devStatus.Baby_Weight)//婴儿体重
  231.     {
  232.         if((gizwitsGetTimerCount() - weiLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  233.         {
  234.             reportData.devStatus.Baby_Weight = curBaby_Weight;

  235.             weiLastTimer = gizwitsGetTimerCount();
  236.             printf("Baby_Weight %d \r\n", weiLastTimer);
  237.         }
  238.     }               

  239.     if(curCO_Value != reportData.devStatus.CO_Value)//一氧化碳浓度
  240.     {
  241.         if((gizwitsGetTimerCount() - COLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  242.         {
  243.             reportData.devStatus.CO_Value = curCO_Value;

  244.             COLastTimer = gizwitsGetTimerCount();
  245.             printf("CO_Value %d \r\n", COLastTimer);
  246.         }
  247.     }                                
  248.                
  249.     if(curBed_Heat != reportData.devStatus.Bed_Heat)//被窝温度
  250.     {
  251.         if((gizwitsGetTimerCount() - bedhLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
  252.         {
  253.             reportData.devStatus.Bed_Heat = curBed_Heat;

  254.             bedhLastTimer = gizwitsGetTimerCount();
  255.             printf("Bed_Heat %d \r\n", bedhLastTimer);
  256.         }
  257.     }                        
  258.                
  259.     if((gizwitsGetTimerCount()-thLastTimer) > REPORT_TIME_MAX) //timeout = 2S
  260.     {
  261.                                 if((curTem != lastTem)||(curHum != lastHum))//温湿度
  262.                                 {            
  263.                                                 reportData.devStatus.Temperature = curTem;
  264.                                                 reportData.devStatus.Humidity = curHum;
  265.                                                 
  266.                                                 lastTem = curTem;
  267.                                                 lastHum = curHum;
  268.                                                 
  269.                                                 printf("Temperature&Humidity  [%d-%d] %d %d\r\n", gizwitsGetTimerCount(), thLastTimer, curTem, curHum);
  270.                                 }        
  271.         thLastTimer = gizwitsGetTimerCount();
  272.     }
  273. }

  274. void key1ShortPress(void)
  275. {
  276.     printf("KEY1 PRESS\r\n");
  277. }

  278. void key1LongPress(void)
  279. {
  280.     printf("KEY1 PRESS LONG ,Wifi Reset\r\n");
  281.     gizwitsSetDefault();

  282. }
  283. void key2ShortPress(void)
  284. {
  285.     printf("KEY2 PRESS ,Soft AP mode\r\n");

  286.     //Soft AP mode, RGB red
  287.     ledRgbControl(255, 0, 0);
  288.     gizwitsSetMode(SoftAp_Mode);
  289. }

  290. void key2LongPress(void)
  291. {
  292.     //AirLink mode, RGB Green
  293.     printf("KEY2 PRESS LONG ,AirLink mode\r\n");
  294.     ledRgbControl(0, 128, 0);
  295.     gizwitsSetMode(AirLink_Mode);
  296. }

  297. void gestureGet(void)
  298. {
  299.                 if(Key_Scan(GPIOA,GPIO_Pin_1)==1)
  300.                         gesture|=0x01;
  301.                 else
  302.                         gesture&=0xfe;
  303.                
  304.                 if(Key_Scan(GPIOA,GPIO_Pin_4)==1)
  305.                         gesture|=0x02;
  306.                 else
  307.                         gesture&=0xfd;
  308.                
  309.                 if(Key_Scan(GPIOA,GPIO_Pin_5)==1)
  310.                         gesture|=0x04;
  311.                 else
  312.                         gesture&=0xfb;
  313.                
  314.                 if(Key_Scan(GPIOA,GPIO_Pin_7)==1)
  315.                         gesture|=0x08;
  316.                 else
  317.                         gesture&=0xf7;
  318.                
  319.                 if(Key_Scan(GPIOB,GPIO_Pin_0)==1)
  320.                         gesture|=0x10;
  321.                 else
  322.                         gesture&=0xef;
  323.                
  324.                 if(Key_Scan(GPIOB,GPIO_Pin_6)==1)
  325. ……………………

  326. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
Gokit3智能摇篮 V1.3(+睡姿).7z (177.18 KB, 下载次数: 42)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:328014 发表于 2019-5-17 05:57 | 显示全部楼层
好资料,51黑有你更精彩!!!
回复

使用道具 举报

ID:543424 发表于 2020-11-2 20:59 来自手机 | 显示全部楼层
51hei团团 发表于 2019-5-17 05:57
好资料,51黑有你更精彩!!!

有原理图吗?学习一下
回复

使用道具 举报

ID:676437 发表于 2020-11-3 12:15 | 显示全部楼层
可以发下仿真嘛
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表