Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion 1.Firmware/src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ 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))
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if else 语句是否可以与整体项目一致,改为

if xxx {
   ...
} else {
  ...
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,不过我看这个工程的格式有点奇怪,有的地方是

void func(){
 ...;
}

有的是

void func()
{
...;
}

如果有别的代码提交,应该用什么格式?

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;
}
}