Skip to content

Commit

Permalink
fix: Verifying keyboard input stops when write() before release()
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeLayer committed Oct 20, 2024
1 parent b738251 commit 0cedbdf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion controller_verify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define SERIAL_SPEED 9600 // 시리얼 통신 속도
#define INPUT_CHAR_ON_VERIFY_KEYBOARD 'a' // 키보드 입력 검증 시 누를 키
#define PRESSING_TICK_ON_VERIFY_KEYBOARD 500 // 키보드 입력 검증 시 키 누르는 시간
#define PRESSING_MILLISECONDS_ON_VERIFY_KEYBOARD 3000 // 키보드 입력 검증 시 키 누르는 시간
#define COMMAND_INVOKE_VERIFY_KEYBOARD 'k' // 키보드 입력 검증 명령어
#define COMMAND_INVOKE_VERIFY_EEPROM 'e' // 저장 검증 명령어
```
26 changes: 19 additions & 7 deletions controller_verify/controller_verify.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define VERIFY_KEYBOARD true

#define INPUT_CHAR_ON_VERIFY_KEYBOARD 'a'
#define PRESSING_TICK_ON_VERIFY_KEYBOARD 500
#define PRESSING_MILLISECONDS_ON_VERIFY_KEYBOARD 3000
#define COMMAND_INVOKE_VERIFY_KEYBOARD 'k'
#define COMMAND_INVOKE_VERIFY_EEPROM 'e'

Expand All @@ -30,7 +30,8 @@
#include <Keyboard.h>
#endif

int pressingTick = 0;
bool pressingInvoked = false;
unsigned long pressingInvokedAt = -1;

void setup() {
#if VERIFY_KEYBOARD
Expand All @@ -53,8 +54,16 @@ void setup() {

void loop() {
#if VERIFY_KEYBOARD
if (pressingTick--) {
Keyboard.release(INPUT_CHAR_ON_VERIFY_KEYBOARD);
if (pressingInvoked) {
unsigned long now = millis();
if (millis() - pressingInvokedAt > PRESSING_MILLISECONDS_ON_VERIFY_KEYBOARD) {
Keyboard.release(INPUT_CHAR_ON_VERIFY_KEYBOARD);
Serial.print("[Keyboard] Pressing done. (Released at: ");
Serial.print(now);
Serial.println(")");
pressingInvoked = false;
} else {
}
}
#endif

Expand All @@ -78,17 +87,20 @@ void loop() {

void invokeVerifyKeyboard() {
#if VERIFY_KEYBOARD
pressingInvoked = true;
Keyboard.write(INPUT_CHAR_ON_VERIFY_KEYBOARD);
Serial.print("[Keyboard] `");
Serial.print(INPUT_CHAR_ON_VERIFY_KEYBOARD);
Serial.println("` has been wrote.");

pressingTick = PRESSING_TICK_ON_VERIFY_KEYBOARD;
pressingInvokedAt = millis();
Serial.print("[Keyboard] `");
Serial.print(INPUT_CHAR_ON_VERIFY_KEYBOARD);
Serial.print("` will be pressed for ");
Serial.print(pressingTick);
Serial.println("ticks.");
Serial.print(PRESSING_MILLISECONDS_ON_VERIFY_KEYBOARD);
Serial.print(" milliseconds. (Started at: ");
Serial.print(pressingInvokedAt);
Serial.println(")");
Keyboard.press(INPUT_CHAR_ON_VERIFY_KEYBOARD);
#else
Serial.println("[Keyboard] Keyboard verification has been disabled.");
Expand Down

0 comments on commit 0cedbdf

Please sign in to comment.