-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputManager.cpp
More file actions
58 lines (50 loc) · 1.2 KB
/
Copy pathInputManager.cpp
File metadata and controls
58 lines (50 loc) · 1.2 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
InputManager.h - Library for listening Serial Port and represent the word from it.
Created by Blindle, 17 September, 2017.
Released into the public domain.
*/
#include "Arduino.h"
#include "InputManager.h"
// MODES
const int InputManager::SERIAL_PORT_LISTENER = 1;
const int InputManager::MANUAL_MODE = 2;
// CONSTANTS STRINGS
const String INITIAL_VALUE = " ";
const String HARDCODES_WORDS[3] = {"AAAA", "BBBB", "CCCC"};
// DELAYS
const int DELAY_BETWEEN_WORDS = 2000;
const int POOLING_SERIAL_DELAY = 10;
InputManager::InputManager(int mode)
{
_mode = mode;
_hardcodedWordIndex = 0;
}
String InputManager::getInput()
{
switch (_mode)
{
case SERIAL_PORT_LISTENER:
return listenSerialPort();
case MANUAL_MODE:
default:
return getHardcodedWord();
}
}
String InputManager::listenSerialPort()
{
String result = INITIAL_VALUE;
while (result == INITIAL_VALUE)
{
if (Serial.available())
{
result = Serial.readString();
}
delay(POOLING_SERIAL_DELAY);
}
return result;
}
String InputManager::getHardcodedWord()
{
delay(DELAY_BETWEEN_WORDS);
return HARDCODES_WORDS[_hardcodedWordIndex++ % 3];
}