Skip to content

增加一个简单的消抖功能,以解决无法彻底关机的问题 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion 1.Firmware/src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ void HAL::Init()
disp_draw_buf = static_cast<lv_color_t*>(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();
}

Expand Down
1 change: 1 addition & 0 deletions 1.Firmware/src/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions 1.Firmware/src/hal/knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}