123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #include "app_chargerpin_conn_detect.h"
- #include "usr_config.h"
- #include "bsp_time.h"
- #include "system.h"
- #include "hal_led.h"
- #include "nrf_gpio.h"
- #include "hal_ble_client.h"
- #include "hal_ble_host.h"
- #include "app_flash.h"
- #include "hal_battery.h"
- #include "ble_comm.h"
- #include "app_pair_chargerpin.h"
- #include "hal_charge.h"
- #include "fml_adc.h"
- #include "drv_trigger.h"
- /************************ 函数声明 ***********************************/
- /************************ 变量 ***********************************/
- static uint8_t hal_charge_state = BLE_CHARGE_PULLOUT;
- //static uint8_t pair_state =0;
- //static void pair_start_cb(){
- // hal_charge_state = BLE_CHARGE_PULLOUT;
- // pair_state =1;
- //}
- //static void pair_done_cb(){
- // pair_state =0;
- //}
- //PAIR_START_REGISTER(pair_start_cb);
- //PAIR_DONE_REGISTER(pair_done_cb);
- /********************************************************/
- uint8_t hal_charge_Getstate(void)
- {
- return hal_charge_state;
- }
- static void hal_send_charge(void)
- {
- uint8_t sbuf[2]={0};
- uint8_t L = 0;
- if(mFlash.isHost) sbuf[L++] = 0;
- else sbuf[L++] = 1;
- sbuf[L++] = hal_charge_state;
- BLE_Client_Tx_Send(0,BLE_CHARGE,sbuf,L);
- }
- void cb_BLE_Client_R_CHARGE(void* handle)
- {
- BLE_Client_Rx_t* target = handle;
- DEBUG_LOG("!!!!!!!!cb_BLE_Client_R_CHARGE\n");
- hal_send_charge();
- BLE_Host_Tx_Send(0,BLE_CHARGE,target->pDat,target->datLen);
- }
- void cb_BLE_Host_R_CHARGE(void* handle)
- {
- BLE_Host_Rx_t* target = handle;
- BLE_Client_Tx_Send(0,BLE_CHARGE,target->pDat,target->datLen);
- // DEBUG_LOG("cb_BLE_Host_R_CHARGE:%d,%d,%d\n",target->pDat[0],target->pDat[1],target->datLen);
- }
- static void hal_charge_Process(void)
- {
- #if ONE_WIRE_ENABLE
- pair_line_t CHARGE_state = app_chargepin_pairline();
- if(CHARGE != CHARGE_state){ //没充电
- if(1 == pair_state)return;//配对不检测充电
- #else
-
- uint32_t ch = drv_GetChargeTrig();
- if(!ch){ //没充电
- #endif
- if(hal_charge_state!=BLE_CHARGE_PULLOUT){ DEBUG_LOG("charge out...\n");
- hal_charge_state = BLE_CHARGE_PULLOUT;
- Process_SetHoldOn(hal_charge_Process,0);
- hal_send_charge();
- }
- return;
- }
-
- // open_one_shel();
- if(GetBatteryPersent() >=100){
- if(hal_charge_state!=BLE_CHARGE_DONE){ DEBUG_LOG("charge done:...\n");
- hal_charge_state = BLE_CHARGE_DONE;
- Process_SetHoldOn(hal_charge_Process,1);
- hal_send_charge();
- }
- }else{ //正在充电
- if(hal_charge_state!=BLE_CHARGE_INSERT){ DEBUG_LOG("charge in...\n");
- hal_charge_state = BLE_CHARGE_INSERT;
- Process_SetHoldOn(hal_charge_Process,1);
- hal_send_charge();
-
- }
- }
- }
- void hal_charge_init(void)
- {
- BLE_Client_Rx_Regist(BLE_CHARGE,cb_BLE_Client_R_CHARGE);
- BLE_Host_Rx_Regist(BLE_CHARGE,cb_BLE_Host_R_CHARGE);
- Process_Start(1000,"charge",hal_charge_Process);
- hal_charge_Process();
-
- // Process_Start(10,"charge_monitor",hal_charge_monitor_process);
- }
|