From 53edb044c0dfe82fd9d0a0e0d3444a51ebe358f4 Mon Sep 17 00:00:00 2001
From: wllm-rbnt <william.robinet@conostix.com>
Date: Mon, 10 Sep 2018 18:19:31 +0200
Subject: [PATCH 1/1] Allow clean Legic simulation exit without button press
 (#668)

---
 armsrc/legicrfsim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/armsrc/legicrfsim.c b/armsrc/legicrfsim.c
index 07a0a62d..34633f36 100644
--- a/armsrc/legicrfsim.c
+++ b/armsrc/legicrfsim.c
@@ -19,6 +19,7 @@
 #include "legic_prng.h"
 #include "legic.h"
 #include "crc.h"
+#include "usb_cdc.h"  // for usb_poll_validate_length
 
 static uint8_t* legic_mem;      /* card memory, used for sim */
 static legic_card_select_t card;/* metadata of currently selected card */
@@ -439,7 +440,7 @@ void LegicRfSimulate(uint8_t cardtype) {
 
   LED_A_ON();
   DbpString("Starting Legic emulator, press button to end");
-  while(!BUTTON_PRESS()) {
+  while(!BUTTON_PRESS() && !usb_poll_validate_length()) {
     WDT_HIT();
 
     // wait for carrier, restart after timeout
-- 
2.39.5