3 #include "libs/Kernel.h"
4 #include "libs/utils.h"
13 this->down_hook
= NULL
;
14 this->button_pin
= NULL
;
16 this->first_timer
= 0;
17 this->second_timer
= 0;
18 this->longpress_delay
= 0;
21 Button
*Button::pin(Pin
*passed_pin
)
23 this->button_pin
= passed_pin
;
27 void Button::check_signal()
29 check_signal(this->button_pin
->get() ? 1 : 0);
32 void Button::check_signal(int val
)
34 bool start_value
= this->value
;
36 if ( this->counter
< 5 ) {
39 if ( this->counter
== 5 ) {
43 if ( this->counter
> 0 ) {
46 if ( this->counter
== 0 ) {
51 if ( start_value
!= this->value
) {
53 if ( this->up_hook
!= NULL
) {
54 this->up_hook
->call();
55 this->first_timer
= 0;
56 this->second_timer
= 0;
60 if ( this->down_hook
!= NULL
) {
61 this->down_hook
->call();
65 //auto repeat button presses
66 if(this->longpress_delay
> 0) {
70 if(this->second_timer
== 10) {
71 this->up_hook
->call();
72 this->second_timer
= 0;
76 if(this->first_timer
== longpress_delay
) {
78 this->first_timer
= 0;
85 void Button::set_longpress_delay(int delay
)
87 this->longpress_delay
= delay
;