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

make touch sensor edge based to avoid approving >1 transaction #290

Merged
merged 1 commit into from
Aug 23, 2019
Merged
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
37 changes: 24 additions & 13 deletions targets/stm32l432/src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ static int is_touch_button_pressed()

int (*IS_BUTTON_PRESSED)() = is_physical_button_pressed;

static void edge_detect_touch_button()
{
static uint8_t last_touch = 0;
uint8_t current_touch = 0;
if (is_touch_button_pressed == IS_BUTTON_PRESSED)
{
current_touch = IS_BUTTON_PRESSED();

// 1 sample per 25 ms
if ((millis() - __last_button_bounce_time) > 25)
{
// Detect "touch / rising edge"
if (!last_touch && current_touch)
{
__last_button_press_time = millis();
}
__last_button_bounce_time = millis();
last_touch = current_touch;
}
}

}

void request_from_nfc(bool request_active) {
_RequestComeFromNFC = request_active;
}
Expand All @@ -78,19 +101,7 @@ void TIM6_DAC_IRQHandler()
}
}


if (is_touch_button_pressed == IS_BUTTON_PRESSED)
{
if (IS_BUTTON_PRESSED())
{
// Only allow 1 press per 25 ms.
if ((millis() - __last_button_bounce_time) > 25)
{
__last_button_press_time = millis();
}
__last_button_bounce_time = millis();
}
}
edge_detect_touch_button();

#ifndef IS_BOOTLOADER
// NFC sending WTX if needs
Expand Down