-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL3_2min_timer.cpp
More file actions
37 lines (29 loc) · 883 Bytes
/
L3_2min_timer.cpp
File metadata and controls
37 lines (29 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "L3_2min_timer.h"
#include <string.h>
bool getInputWithinTime(Serial& pc, char* buffer, int bufferSize, float timeLimitSec) {
Timer inputTimer;
inputTimer.start();
// 남은 개행 문자 제거
while (pc.readable()) {
char dump = pc.getc();
if (dump == '\n' || dump == '\r') break;
}
int index = 0;
while (inputTimer.read() < timeLimitSec) {
if (pc.readable()) {
char c = pc.getc();
if (c == '\r' || c == '\n') break;
if ((c == 0x7F || c == '\b') && index > 0) {
index--;
pc.printf("\b \b");
continue;
}
if (index < bufferSize - 1 && c >= 32 && c <= 126) {
buffer[index++] = c;
}
}
}
buffer[index] = '\0';
inputTimer.stop();
return strlen(buffer) > 0;
}