ソースを参照

show led for charging

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 年 前
コミット
ae6d4d1d4b

+ 69 - 3
Application/app/keys.c → Application/app/key_leds.c

@@ -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)){

+ 4 - 1
Application/app/sox/state.c

@@ -366,6 +366,7 @@ static u32 _bms_main_task_handler(void){
 	return 0;
 }
 
+extern void show_leds_for_charging(uint8_t charging);
 static debounce_t _charging_detect = {.count = 0, .max_count = 10, .init_count = 0};
 static void check_charging(){
 	if ((measure_value()->load_current >= MIN_START_CHARGER_CURRENT)) {
@@ -373,6 +374,7 @@ static void check_charging(){
 			debounce_inc(_charging_detect);
 			if (debounce_reach_max(_charging_detect)){
 				_bms_state.charging = 1;
+				show_leds_for_charging(1);
 				debounce_reset(_charging_detect);
 			}
 		}else {
@@ -383,12 +385,13 @@ static void check_charging(){
 			debounce_inc(_charging_detect);
 			if (debounce_reach_max(_charging_detect)){
 				_bms_state.charging = 0;
+				show_leds_for_charging(0);
 				debounce_reset(_charging_detect);
 			}
 		}else {
 			debounce_reset(_charging_detect);
 		}
-	}	
+	}
 }
 
 /* if discharger mos and charger mos, one is open but other is closed.

+ 2 - 2
Project/SP600.uvoptx

@@ -303,8 +303,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\Application\app\keys.c</PathWithFileName>
-      <FilenameWithoutPath>keys.c</FilenameWithoutPath>
+      <PathWithFileName>..\Application\app\key_leds.c</PathWithFileName>
+      <FilenameWithoutPath>key_leds.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>

+ 2 - 2
Project/SP600.uvprojx

@@ -424,9 +424,9 @@
               <FilePath>..\Application\app\pcba_test.c</FilePath>
             </File>
             <File>
-              <FileName>keys.c</FileName>
+              <FileName>key_leds.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\Application\app\keys.c</FilePath>
+              <FilePath>..\Application\app\key_leds.c</FilePath>
             </File>
           </Files>
         </Group>

+ 2 - 2
Project/SP600_15AH.uvoptx

@@ -278,8 +278,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\Application\app\keys.c</PathWithFileName>
-      <FilenameWithoutPath>keys.c</FilenameWithoutPath>
+      <PathWithFileName>..\Application\app\key_leds.c</PathWithFileName>
+      <FilenameWithoutPath>key_leds.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>

+ 2 - 2
Project/SP600_15AH.uvprojx

@@ -424,9 +424,9 @@
               <FilePath>..\Application\app\pcba_test.c</FilePath>
             </File>
             <File>
-              <FileName>keys.c</FileName>
+              <FileName>key_leds.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\Application\app\keys.c</FilePath>
+              <FilePath>..\Application\app\key_leds.c</FilePath>
             </File>
           </Files>
         </Group>

+ 2 - 2
Project/SP700.uvoptx

@@ -323,8 +323,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\Application\app\keys.c</PathWithFileName>
-      <FilenameWithoutPath>keys.c</FilenameWithoutPath>
+      <PathWithFileName>..\Application\app\key_leds.c</PathWithFileName>
+      <FilenameWithoutPath>key_leds.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>

+ 2 - 2
Project/SP700.uvprojx

@@ -424,9 +424,9 @@
               <FilePath>..\Application\app\pcba_test.c</FilePath>
             </File>
             <File>
-              <FileName>keys.c</FileName>
+              <FileName>key_leds.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\Application\app\keys.c</FilePath>
+              <FilePath>..\Application\app\key_leds.c</FilePath>
             </File>
           </Files>
         </Group>