hal_charge.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "app_chargerpin_conn_detect.h"
  2. #include "usr_config.h"
  3. #include "bsp_time.h"
  4. #include "system.h"
  5. #include "hal_led.h"
  6. #include "nrf_gpio.h"
  7. #include "hal_ble_client.h"
  8. #include "hal_ble_host.h"
  9. #include "app_flash.h"
  10. #include "hal_battery.h"
  11. #include "ble_comm.h"
  12. #include "app_pair_chargerpin.h"
  13. #include "hal_charge.h"
  14. #include "fml_adc.h"
  15. #include "drv_trigger.h"
  16. /************************ 函数声明 ***********************************/
  17. /************************ 变量 ***********************************/
  18. static uint8_t hal_charge_state = BLE_CHARGE_PULLOUT;
  19. //static uint8_t pair_state =0;
  20. //static void pair_start_cb(){
  21. // hal_charge_state = BLE_CHARGE_PULLOUT;
  22. // pair_state =1;
  23. //}
  24. //static void pair_done_cb(){
  25. // pair_state =0;
  26. //}
  27. //PAIR_START_REGISTER(pair_start_cb);
  28. //PAIR_DONE_REGISTER(pair_done_cb);
  29. /********************************************************/
  30. uint8_t hal_charge_Getstate(void)
  31. {
  32. return hal_charge_state;
  33. }
  34. static void hal_send_charge(void)
  35. {
  36. uint8_t sbuf[2]={0};
  37. uint8_t L = 0;
  38. if(mFlash.isHost) sbuf[L++] = 0;
  39. else sbuf[L++] = 1;
  40. sbuf[L++] = hal_charge_state;
  41. BLE_Client_Tx_Send(0,BLE_CHARGE,sbuf,L);
  42. }
  43. void cb_BLE_Client_R_CHARGE(void* handle)
  44. {
  45. BLE_Client_Rx_t* target = handle;
  46. DEBUG_LOG("!!!!!!!!cb_BLE_Client_R_CHARGE\n");
  47. hal_send_charge();
  48. BLE_Host_Tx_Send(0,BLE_CHARGE,target->pDat,target->datLen);
  49. }
  50. void cb_BLE_Host_R_CHARGE(void* handle)
  51. {
  52. BLE_Host_Rx_t* target = handle;
  53. BLE_Client_Tx_Send(0,BLE_CHARGE,target->pDat,target->datLen);
  54. // DEBUG_LOG("cb_BLE_Host_R_CHARGE:%d,%d,%d\n",target->pDat[0],target->pDat[1],target->datLen);
  55. }
  56. static void hal_charge_Process(void)
  57. {
  58. #if ONE_WIRE_ENABLE
  59. pair_line_t CHARGE_state = app_chargepin_pairline();
  60. if(CHARGE != CHARGE_state){ //没充电
  61. if(1 == pair_state)return;//配对不检测充电
  62. #else
  63. uint32_t ch = drv_GetChargeTrig();
  64. if(!ch){ //没充电
  65. #endif
  66. if(hal_charge_state!=BLE_CHARGE_PULLOUT){ DEBUG_LOG("charge out...\n");
  67. hal_charge_state = BLE_CHARGE_PULLOUT;
  68. Process_SetHoldOn(hal_charge_Process,0);
  69. hal_send_charge();
  70. }
  71. return;
  72. }
  73. // open_one_shel();
  74. if(GetBatteryPersent() >=100){
  75. if(hal_charge_state!=BLE_CHARGE_DONE){ DEBUG_LOG("charge done:...\n");
  76. hal_charge_state = BLE_CHARGE_DONE;
  77. Process_SetHoldOn(hal_charge_Process,1);
  78. hal_send_charge();
  79. }
  80. }else{ //正在充电
  81. if(hal_charge_state!=BLE_CHARGE_INSERT){ DEBUG_LOG("charge in...\n");
  82. hal_charge_state = BLE_CHARGE_INSERT;
  83. Process_SetHoldOn(hal_charge_Process,1);
  84. hal_send_charge();
  85. }
  86. }
  87. }
  88. void hal_charge_init(void)
  89. {
  90. BLE_Client_Rx_Regist(BLE_CHARGE,cb_BLE_Client_R_CHARGE);
  91. BLE_Host_Rx_Regist(BLE_CHARGE,cb_BLE_Host_R_CHARGE);
  92. Process_Start(1000,"charge",hal_charge_Process);
  93. hal_charge_Process();
  94. // Process_Start(10,"charge_monitor",hal_charge_monitor_process);
  95. }