From 4dac94c7725883d8fa4057870a257875598560e0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 15 May 2020 00:00:42 +0200 Subject: [PATCH] clarify BUTTON macro usages --- armsrc/Standalone/hf_colin.c | 2 +- armsrc/Standalone/hf_msdsal.c | 4 ++-- armsrc/Standalone/hf_young.c | 8 ++++---- armsrc/Standalone/lf_em4100rswb.c | 3 +-- armsrc/Standalone/lf_em4100rwc.c | 16 ++++++++-------- armsrc/Standalone/lf_hidbrute.c | 12 ++++++------ armsrc/Standalone/lf_samyrun.c | 5 ----- armsrc/Standalone/lf_skeleton.c | 2 +- 8 files changed, 23 insertions(+), 29 deletions(-) diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index b1090a019..9752c66c3 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -501,7 +501,7 @@ failtag: LED_A_INV(); } - if (BUTTON_HELD(10) > 0) { + if (BUTTON_HELD(10) == BUTTON_HOLD) { WDT_HIT(); DbprintfEx(FLAG_NEWLINE, "\t\t\t[ READING FLASH ]"); ReadLastTagFromFlash(); diff --git a/armsrc/Standalone/hf_msdsal.c b/armsrc/Standalone/hf_msdsal.c index be66e39a6..e890818d2 100644 --- a/armsrc/Standalone/hf_msdsal.c +++ b/armsrc/Standalone/hf_msdsal.c @@ -222,9 +222,9 @@ void RunMod(void) { // Was our button held down or pressed? int button_pressed = BUTTON_HELD(1000); - if (button_pressed == 1) //Holding down the button + if (button_pressed == BUTTON_HOLD) //Holding down the button break; - else if (button_pressed == -1) { //Pressing one time change between reading & emulation + else if (button_pressed == BUTTON_SINGLE_CLICK) { //Pressing one time change between reading & emulation if (state == STATE_READ) { if (chktoken == true && token[0] != 0x00) { //Only change to emulation if it saved a track 2 in memory state = STATE_EMU; diff --git a/armsrc/Standalone/hf_young.c b/armsrc/Standalone/hf_young.c index d29aac220..193f124ed 100644 --- a/armsrc/Standalone/hf_young.c +++ b/armsrc/Standalone/hf_young.c @@ -222,8 +222,8 @@ void RunMod(void) { // exit from Standalone Mode, send a usbcommand. if (data_available()) return; - int button_action = BUTTON_HELD(1000); - if (button_action == 0) { // No button action, proceed with sim + int button_pressed = BUTTON_HELD(1000); + if (button_pressed == BUTTON_NO_CLICK) { // No button action, proceed with sim uint8_t flags = FLAG_4B_UID_IN_DATA; uint8_t data[PM3_CMD_DATA_SIZE] = {0}; // in case there is a read command received we shouldn't break @@ -259,12 +259,12 @@ void RunMod(void) { SimulateIso14443aTag(1, flags, data); } - } else if (button_action == BUTTON_SINGLE_CLICK) { + } else if (button_pressed == BUTTON_SINGLE_CLICK) { selected = (selected + 1) % OPTS; Dbprintf("Done playing. Switching to record mode on bank %d", selected); iGotoRecord = 1; break; - } else if (button_action == BUTTON_HOLD) { + } else if (button_pressed == BUTTON_HOLD) { Dbprintf("Playtime over. Begin cloning..."); iGotoClone = 1; break; diff --git a/armsrc/Standalone/lf_em4100rswb.c b/armsrc/Standalone/lf_em4100rswb.c index 559f85fee..dd9fafd6a 100644 --- a/armsrc/Standalone/lf_em4100rswb.c +++ b/armsrc/Standalone/lf_em4100rswb.c @@ -215,13 +215,12 @@ static int ButeEMTag(uint64_t originalCard, int slot) { direction = -1; } - uint64_t currentCard; while (cardnum > 1 && cardnum < 65535) { WDT_HIT(); if (data_available()) break; cardnum = cardnum + direction; - currentCard = PackEmID(originalCard, cardnum); + uint64_t currentCard = PackEmID(originalCard, cardnum); Dbprintf("[=] >> Simulating card id %"PRIx64" <<", currentCard); ConstructEM410xEmulBuf(ReversQuads(currentCard)); SimulateTagLowFrequencyEx(buflen, 0, 1, bruteforceSpeed[bruteforceSpeedCurrent] * 10000); diff --git a/armsrc/Standalone/lf_em4100rwc.c b/armsrc/Standalone/lf_em4100rwc.c index a7364bd81..ce96dd824 100644 --- a/armsrc/Standalone/lf_em4100rwc.c +++ b/armsrc/Standalone/lf_em4100rwc.c @@ -141,12 +141,12 @@ void RunMod(void) { switch (state) { case 0: // Select mode - if (button_pressed == 1) { + if (button_pressed == BUTTON_HOLD) { // Long press - switch to simulate mode SpinUp(100); LED_Slot(selected); state = 2; - } else if (button_pressed < 0) { + } else if (button_pressed == BUTTON_SINGLE_CLICK) { // Click - switch to next slot selected = (selected + 1) % slots_count; LED_Slot(selected); @@ -154,12 +154,12 @@ void RunMod(void) { break; case 1: // Read mode. - if (button_pressed > 0) { + if (button_pressed == BUTTON_HOLD) { // Long press - switch to read mode SpinUp(100); LED_Slot(selected); state = 3; - } else if (button_pressed < 0) { + } else if (button_pressed == BUTTON_SINGLE_CLICK) { // Click - exit to select mode CmdEM410xdemod(1, &high[selected], &low[selected], 0); FlashLEDs(100, 5); @@ -171,12 +171,12 @@ void RunMod(void) { break; case 2: // Simulate mode - if (button_pressed > 0) { + if (button_pressed == BUTTON_HOLD) { // Long press - switch to read mode SpinDown(100); LED_Slot(selected); state = 1; - } else if (button_pressed < 0) { + } else if (button_pressed == BUTTON_SINGLE_CLICK) { // Click - start simulating. Click again to exit from simulate mode LED_Slot(selected); ConstructEM410xEmulBuf(ReversQuads(low[selected])); @@ -188,12 +188,12 @@ void RunMod(void) { break; case 3: // Write tag mode - if (button_pressed > 0) { + if (button_pressed == BUTTON_HOLD) { // Long press - switch to select mode SpinDown(100); LED_Slot(selected); state = 0; - } else if (button_pressed < 0) { + } else if (button_pressed == BUTTON_SINGLE_CLICK) { // Click - write ID to tag WriteEM410x(0, (uint32_t)(low[selected] >> 32), (uint32_t)(low[selected] & 0xffffffff)); LED_Slot(selected); diff --git a/armsrc/Standalone/lf_hidbrute.c b/armsrc/Standalone/lf_hidbrute.c index 2b2b43718..8c4412ebe 100644 --- a/armsrc/Standalone/lf_hidbrute.c +++ b/armsrc/Standalone/lf_hidbrute.c @@ -85,7 +85,7 @@ void RunMod(void) { // so next button push begins playing what we recorded playing = 0; cardRead = 1; - } else if (button_pressed > 0 && cardRead == 1) { + } else if (button_pressed == BUTTON_HOLD && cardRead == 1) { LEDsoff(); LED(selected + 1, 0); LED(LED_A, 0); @@ -109,7 +109,7 @@ void RunMod(void) { } // Change where to record (or begin playing) - else if (button_pressed) { + else if (button_pressed != BUTTON_NO_CLICK) { // Next option if we were previously playing if (playing) selected = (selected + 1) % OPTS; @@ -131,7 +131,7 @@ void RunMod(void) { CmdHIDsimTAG(0, high[selected], low[selected], 0, 0); DbpString("[=] done playing"); - if (BUTTON_HELD(1000) > 0) + if (BUTTON_HELD(1000) == BUTTON_HOLD) goto out; /* We pressed a button so ignore it here with a delay */ @@ -169,7 +169,7 @@ void RunMod(void) { // Needed for exiting from proxbrute when button is pressed if (BUTTON_PRESS()) { - if (BUTTON_HELD(1000) > 0) { + if (BUTTON_HELD(1000) == BUTTON_HOLD) { goto out; } else { while (BUTTON_PRESS()) { @@ -199,7 +199,7 @@ void RunMod(void) { // Needed for exiting from proxbrute when button is pressed if (BUTTON_PRESS()) { - if (BUTTON_HELD(1000) > 0) { + if (BUTTON_HELD(1000) == BUTTON_HOLD) { goto out; } else { while (BUTTON_PRESS()) { WDT_HIT(); } @@ -220,7 +220,7 @@ void RunMod(void) { } DbpString("[=] done bruteforcing"); - if (BUTTON_HELD(1000) > 0) + if (BUTTON_HELD(1000) == BUTTON_HOLD) goto out; /* We pressed a button so ignore it here with a delay */ diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 579a06470..971304918 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -56,11 +56,6 @@ void RunMod(void) { int button_pressed = BUTTON_HELD(280); if (button_pressed != BUTTON_HOLD) continue; - /* - #define BUTTON_NO_CLICK 0 - #define BUTTON_SINGLE_CLICK -1 - #define BUTTON_DOUBLE_CLICK -2 - */ if (state == STATE_READ) { diff --git a/armsrc/Standalone/lf_skeleton.c b/armsrc/Standalone/lf_skeleton.c index 2f87e92c7..a2d566cb7 100644 --- a/armsrc/Standalone/lf_skeleton.c +++ b/armsrc/Standalone/lf_skeleton.c @@ -35,7 +35,7 @@ void RunMod(void) { Dbprintf("button %d", button_pressed); - if (button_pressed) + if (button_pressed != BUTTON_NO_CLICK) break; }