app_safe.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*********************************************************************
  2. * INCLUDES
  3. */
  4. #include "ble_comm.h"
  5. #include "app_flash.h"
  6. #include "app_safe.h"
  7. #include "hal_ble_client.h"
  8. #include "hal_ble_host.h"
  9. #include "hal_led.h"
  10. static void app_safe_Process(void)
  11. {
  12. static uint8_t cnt =0;
  13. if(mBackup.ErrStartCnt >0){
  14. cnt++;
  15. if(cnt >=60){//一分钟后清空标志位
  16. mBackup.ErrStartCnt =0;
  17. if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save ErrStartCnt fail");
  18. DEBUG_LOG("clear mBackup.ErrorStartFlag\n");
  19. }
  20. }
  21. if(mBackup.RestartCnt > 1){
  22. char buff[40]={0};
  23. memset(buff,0,sizeof(buff));
  24. if(mFlash.isHost){
  25. sprintf(buff,"left shoes restart:%d",mBackup.RestartCnt);
  26. }else{
  27. sprintf(buff,"right shoes restart:%d",mBackup.RestartCnt);
  28. }
  29. if(0 == Except_TxError(EXCEPT_Power,(const char*)buff)){
  30. mBackup.RestartCnt =0;
  31. }
  32. }
  33. }
  34. //恢复出厂设置
  35. static void cb_BLE_RESTSETTING(void* handle)
  36. {
  37. Flash_DeleteAllInfor();
  38. Flash_DeleteAllStep();
  39. Flash_DeleteAllBackup();
  40. BLE_Client_Rx_t* target = handle;
  41. uint8_t cmd = target->pDat[0];
  42. BLE_Host_Tx_Send(0,BLE_RESTSETTING,&cmd,1);
  43. nrf_delay_ms(500);
  44. NVIC_SystemReset();
  45. }
  46. static void app_CONNTED_LED_Process(void){
  47. static uint8_t lastconeted =0;
  48. static uint8_t BlinkTime =0;
  49. static uint8_t BlinkfLAG =0;
  50. uint8_t nowconeted =0;
  51. if(mFlash.isHost)
  52. nowconeted = host_isconnect();
  53. else
  54. nowconeted = slave_isconnect();
  55. // DEBUG_LOG("mFlash.isHost %d,nowconeted:%d,\n",mFlash.isHost,nowconeted);
  56. if(nowconeted != lastconeted){
  57. lastconeted = nowconeted;
  58. if(nowconeted){
  59. BlinkfLAG =1;
  60. BlinkTime =0;
  61. DEBUG_LOG("COLOR_PURPLE\r\n");
  62. LED_Start(LED_LRCHECK,COLOR_PURPLE);
  63. Process_SetHoldOn(app_CONNTED_LED_Process,1);
  64. }
  65. else{
  66. BlinkfLAG =0;
  67. BlinkTime =0;
  68. Process_SetHoldOn(app_CONNTED_LED_Process,0);
  69. LED_Stop(LED_LRCHECK);
  70. }
  71. }
  72. if(BlinkfLAG){BlinkTime++;
  73. if(BlinkTime <=30){
  74. BlinkfLAG =1;
  75. }
  76. else{
  77. BlinkfLAG =0;
  78. BlinkTime =0;
  79. LED_Stop(LED_LRCHECK);
  80. }
  81. }
  82. }
  83. void app_safe_Init(void)
  84. {
  85. mBackup.RestartCnt++;
  86. Process_Start(1000,"app_safe",app_safe_Process);
  87. // Process_Start(100,"app_CONNTED_LED",app_CONNTED_LED_Process);
  88. BLE_Client_Rx_Regist(BLE_RESTSETTING,cb_BLE_RESTSETTING);
  89. }