|
|
@@ -1,21 +1,27 @@
|
|
|
#include "bsp/gpio.h"
|
|
|
#include "bsp/mcu_power_sleep.h"
|
|
|
+#include "bsp/ml5238.h"
|
|
|
#include "libs/shark_task.h"
|
|
|
#include "libs/logger.h"
|
|
|
#include "app/sox/soc.h"
|
|
|
+#include "app/sox/state.h"
|
|
|
|
|
|
static uint8_t led_on_mask = 0;
|
|
|
static void gpio_key_timer_handler(shark_timer_t *timer);
|
|
|
+static void led_charging_timer_handler(shark_timer_t *timer);
|
|
|
void gpio_key_irq_handler(void);
|
|
|
static shark_timer_t _led_timer = {.handler = gpio_key_timer_handler};
|
|
|
static shark_timer_t _led_stop_timer = {.handler = gpio_key_timer_handler};
|
|
|
-
|
|
|
+static shark_timer_t _led_charging_timer = {.handler = led_charging_timer_handler};
|
|
|
void gpio_key_init(void){
|
|
|
shark_timer_post(&_led_stop_timer, 2000);
|
|
|
enable_gpio_key_irq(1);
|
|
|
}
|
|
|
|
|
|
void gpio_key_irq_handler(void){
|
|
|
+ if (bms_state_get()->charging) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
LED0_ON(1);
|
|
|
LED1_ON(1);
|
|
|
LED2_ON(1);
|
|
|
@@ -27,6 +33,37 @@ void gpio_key_irq_handler(void){
|
|
|
mcu_sleep_set_wakeup_source(WAKEUP_SOURCE_KEY);
|
|
|
}
|
|
|
|
|
|
+static void led_show_by_mask(uint8_t mask) {
|
|
|
+ for (int m = 0; m < 5; m++){
|
|
|
+ if (mask & (1 << m)){
|
|
|
+ if (m == 0) {
|
|
|
+ LED4_ON(1);
|
|
|
+ }else if(m == 1) {
|
|
|
+ LED3_ON(1);
|
|
|
+ }else if (m == 2) {
|
|
|
+ LED2_ON(1);
|
|
|
+ }else if (m == 3) {
|
|
|
+ LED1_ON(1);
|
|
|
+ }else {
|
|
|
+ LED0_ON(1);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (m == 0) {
|
|
|
+ LED4_ON(0);
|
|
|
+ }else if(m == 1) {
|
|
|
+ LED3_ON(0);
|
|
|
+ }else if (m == 2) {
|
|
|
+ LED2_ON(0);
|
|
|
+ }else if (m == 3) {
|
|
|
+ LED1_ON(0);
|
|
|
+ }else {
|
|
|
+ LED0_ON(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
static uint8_t _led_mask(uint8_t capacity){
|
|
|
uint8_t mask = 0x1F;
|
|
|
if (capacity >= 80) {
|
|
|
@@ -37,12 +74,37 @@ static uint8_t _led_mask(uint8_t capacity){
|
|
|
mask = 0x1C;
|
|
|
}else if (capacity >= 20) {
|
|
|
mask = 0x18;
|
|
|
- }else {
|
|
|
+ }else { //< 20
|
|
|
mask = 0x10;
|
|
|
}
|
|
|
return mask;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+static uint8_t show_next = 0;
|
|
|
+static void led_charging_timer_handler(shark_timer_t *timer) {
|
|
|
+ uint8_t mask = _led_mask(get_soc()->capacity);
|
|
|
+ if (show_next) {
|
|
|
+ if (get_soc()->capacity < 20) {
|
|
|
+ mask = 0;
|
|
|
+ }else {
|
|
|
+ mask = _led_mask(get_soc()->capacity - 20);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ led_show_by_mask(mask);
|
|
|
+ show_next = (show_next + 1) % 2;
|
|
|
+ shark_timer_post(&_led_charging_timer, 300);
|
|
|
+}
|
|
|
+
|
|
|
+void show_leds_for_charging(uint8_t charging){
|
|
|
+ if (charging){
|
|
|
+ show_next = 0;
|
|
|
+ shark_timer_post(&_led_charging_timer, 300);
|
|
|
+ }else if (!charging){
|
|
|
+ shark_timer_cancel(&_led_charging_timer);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void gpio_key_timer_handler(shark_timer_t *timer) {
|
|
|
if (timer == &_led_stop_timer) {
|
|
|
LED0_ON(0);
|
|
|
@@ -55,7 +117,11 @@ static void gpio_key_timer_handler(shark_timer_t *timer) {
|
|
|
|
|
|
uint8_t want_mask = _led_mask(get_soc()->capacity);
|
|
|
if (want_mask == led_on_mask) {
|
|
|
- shark_timer_post(&_led_stop_timer, 2000);
|
|
|
+ if (ml5238_is_discharging()) {
|
|
|
+ shark_timer_post(&_led_stop_timer, 30 * 000);
|
|
|
+ }else {
|
|
|
+ shark_timer_post(&_led_stop_timer, 2000);
|
|
|
+ }
|
|
|
}else {
|
|
|
for (int m = 0; m < 5; m++){
|
|
|
if (led_on_mask & (1 << m)){
|