|
@@ -6,12 +6,12 @@
|
|
|
shark_charger_state_t shark_charger_state;
|
|
shark_charger_state_t shark_charger_state;
|
|
|
shark_bool shark_charger_enabled;
|
|
shark_bool shark_charger_enabled;
|
|
|
shark_bool shark_charger_valid;
|
|
shark_bool shark_charger_valid;
|
|
|
|
|
+shark_bool shark_battery_full;
|
|
|
shark_u16 shark_charge_times;
|
|
shark_u16 shark_charge_times;
|
|
|
shark_u16 shark_charge_skip;
|
|
shark_u16 shark_charge_skip;
|
|
|
|
|
|
|
|
static shark_u16 shark_charger_remove;
|
|
static shark_u16 shark_charger_remove;
|
|
|
static shark_u16 shark_charger_insert;
|
|
static shark_u16 shark_charger_insert;
|
|
|
-static shark_bool shark_battery_full;
|
|
|
|
|
|
|
|
|
|
void shark_charge_init(void)
|
|
void shark_charge_init(void)
|
|
|
{
|
|
{
|
|
@@ -23,6 +23,41 @@ void shark_charge_init(void)
|
|
|
gpio_init(GPIO_PORT_CHG_EN, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_CHG_EN);
|
|
gpio_init(GPIO_PORT_CHG_EN, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_CHG_EN);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+shark_bool shark_battery_charge_full(void)
|
|
|
|
|
+{
|
|
|
|
|
+ if (sub_bms_info_1.connected) {
|
|
|
|
|
+ if (sub_bms_info_2.connected) {
|
|
|
|
|
+ if (sub_bms_info_1.packet_common.m_percent > 99 && sub_bms_info_2.packet_common.m_percent > 99) {
|
|
|
|
|
+ shark_battery_full = shark_true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (sub_bms_info_1.packet_common.m_percent < 97 || sub_bms_info_2.packet_common.m_percent < 97) {
|
|
|
|
|
+ shark_battery_full = shark_false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (sub_bms_info_1.packet_common.m_percent > 99) {
|
|
|
|
|
+ shark_battery_full = shark_true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (sub_bms_info_1.packet_common.m_percent < 97) {
|
|
|
|
|
+ shark_battery_full = shark_false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (sub_bms_info_2.connected) {
|
|
|
|
|
+ if (sub_bms_info_2.packet_common.m_percent > 99) {
|
|
|
|
|
+ shark_battery_full = shark_true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (sub_bms_info_2.packet_common.m_percent < 97) {
|
|
|
|
|
+ shark_battery_full = shark_false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return shark_false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return shark_battery_full;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
shark_bool shark_charger_is_normal(void)
|
|
shark_bool shark_charger_is_normal(void)
|
|
|
{
|
|
{
|
|
|
return shark_charger_enabled && (shark_battery_charge_in1() || shark_battery_charge_in2());
|
|
return shark_charger_enabled && (shark_battery_charge_in1() || shark_battery_charge_in2());
|
|
@@ -30,6 +65,10 @@ shark_bool shark_charger_is_normal(void)
|
|
|
|
|
|
|
|
void shark_charger_set_state(shark_charger_state_t state)
|
|
void shark_charger_set_state(shark_charger_state_t state)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (shark_battery_charge_full()) {
|
|
|
|
|
+ state = SHARK_CHG_REMOVE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (shark_charger_state != state) {
|
|
if (shark_charger_state != state) {
|
|
|
shark_charger_state = state;
|
|
shark_charger_state = state;
|
|
|
println("charger: state%d", state);
|
|
println("charger: state%d", state);
|
|
@@ -38,15 +77,12 @@ void shark_charger_set_state(shark_charger_state_t state)
|
|
|
|
|
|
|
|
void shark_charger_set_enable(shark_bool enable)
|
|
void shark_charger_set_enable(shark_bool enable)
|
|
|
{
|
|
{
|
|
|
- if (sub_bms_info_1.packet_common.m_percent > 99 && sub_bms_info_2.packet_common.m_percent > 99) {
|
|
|
|
|
- shark_battery_full = shark_true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (sub_bms_info_1.packet_common.m_percent < 97 || sub_bms_info_2.packet_common.m_percent < 97) {
|
|
|
|
|
- shark_battery_full = shark_false;
|
|
|
|
|
|
|
+ if (shark_battery_charge_full()) {
|
|
|
|
|
+ shark_charger_set_state(SHARK_CHG_REMOVE);
|
|
|
|
|
+ enable = shark_false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (shark_battery_full || cb_operate_state == CB_BAT1_BAT2_SERIES) {
|
|
|
|
|
|
|
+ if (cb_operate_state == CB_BAT1_BAT2_SERIES) {
|
|
|
enable = shark_false;
|
|
enable = shark_false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -102,6 +138,7 @@ void shark_charge_tick(void)
|
|
|
|
|
|
|
|
if (shark_charger_remove > SHARK_CHG_REMOVE_MIN) {
|
|
if (shark_charger_remove > SHARK_CHG_REMOVE_MIN) {
|
|
|
shark_charger_set_state(SHARK_CHG_REMOVE);
|
|
shark_charger_set_state(SHARK_CHG_REMOVE);
|
|
|
|
|
+ shark_battery_full = shark_false;
|
|
|
} else {
|
|
} else {
|
|
|
shark_charger_remove++;
|
|
shark_charger_remove++;
|
|
|
}
|
|
}
|