From a825e66134f79b3e7d3aa47e9409750065730c92 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 Dec 2023 00:21:03 +0800 Subject: [PATCH 1/2] fix power off failed --- 1.Firmware/src/hal/hal.cpp | 6 +++++- 1.Firmware/src/hal/hal.h | 1 + 1.Firmware/src/hal/knob.cpp | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/1.Firmware/src/hal/hal.cpp b/1.Firmware/src/hal/hal.cpp index 8e0e1ba..609b94c 100644 --- a/1.Firmware/src/hal/hal.cpp +++ b/1.Firmware/src/hal/hal.cpp @@ -13,10 +13,14 @@ void HAL::Init() disp_draw_buf = static_cast(malloc(DISP_BUF_SIZE * sizeof(lv_color_t))); if (disp_draw_buf == nullptr) Serial.printf("lv_port_disp_init malloc failed!\n"); + knob_init(); power_init(); + if(! knob_check_long_pressed(1000)) + { + power_off(); + } motor_init(); - knob_init(); // super_dial_init(); } diff --git a/1.Firmware/src/hal/hal.h b/1.Firmware/src/hal/hal.h index d2eab78..38f247f 100644 --- a/1.Firmware/src/hal/hal.h +++ b/1.Firmware/src/hal/hal.h @@ -24,6 +24,7 @@ namespace HAL void Init(); void Update(); + bool knob_check_long_pressed(int should_cnt); void knob_init(); void knob_update(void); bool encoder_is_pushed(void); diff --git a/1.Firmware/src/hal/knob.cpp b/1.Firmware/src/hal/knob.cpp index 049e668..bd674d1 100644 --- a/1.Firmware/src/hal/knob.cpp +++ b/1.Firmware/src/hal/knob.cpp @@ -67,4 +67,23 @@ void HAL::knob_init(void) // attachInterrupt(CONFIG_ENCODER_A_PIN, Encoder_A_IrqHandler, CHANGE); // push_button.EventAttach(button_handler); +} + +bool HAL::knob_check_long_pressed(int should_cnt) +{ + int press_cnt = 0; + for(int i = 0; i < should_cnt * 2; i++) + { + if (digitalRead(PUSH_BUTTON_PIN) == LOW) + { + press_cnt++; + } + } + if(press_cnt >= should_cnt) + { + return true; + }else + { + return false; + } } \ No newline at end of file From ef8f29371a1fcfb6cdf7c98dfc4fa4e019661bab Mon Sep 17 00:00:00 2001 From: lvniqi Date: Sat, 23 Dec 2023 01:56:54 +0800 Subject: [PATCH 2/2] Update hal.cpp --- 1.Firmware/src/hal/hal.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/1.Firmware/src/hal/hal.cpp b/1.Firmware/src/hal/hal.cpp index 609b94c..21846ae 100644 --- a/1.Firmware/src/hal/hal.cpp +++ b/1.Firmware/src/hal/hal.cpp @@ -15,8 +15,7 @@ void HAL::Init() Serial.printf("lv_port_disp_init malloc failed!\n"); knob_init(); power_init(); - if(! knob_check_long_pressed(1000)) - { + if(! knob_check_long_pressed(1000)){ power_off(); } motor_init();