-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputController.cpp
83 lines (70 loc) · 1.95 KB
/
InputController.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Created by Tristan Whitcher on 3/9/16.
//
#include <iostream>
#include <stdio.h>
#include <termios.h>
#include "InputController.h"
#include "SafeOutput.h"
#include "Application.h"
#include "IOPort.h"
InputController::InputController(Garage* garage) : garage(garage) {
enabled = true;
SafeOutput::safe_output("Initializing InputController");
garage->getMotor()->attach(this);
}
void InputController::forwardEvent(Event event) {
garage->queueEvent(event);
}
void InputController::update(Event event) {
forwardEvent(event);
}
void InputController::overcurrent() {
garage->getMotor()->overcurrent();
}
void InputController::ir_beam() {
forwardEvent(IR_BEAM);
}
void InputController::button_pressed() {
forwardEvent(BUTTON_PRESSED);
}
void InputController::run() {
if(Application::SIMULATION) {
while (enabled) {
char c;
std::cin >> c;
if (c == '\n') {
continue;
}
SafeOutput::safe_output(std::string(1, (char) c) + " received.");
switch ((char) c) {
case 'm':
this->overcurrent();
break;
case 'i':
this->ir_beam();
break;
case 'r':
this->button_pressed();
break;
default:
break;
}
}
} else {
while(enabled) {
if(IOPort::IS_OVERCURRENT()) {
SafeOutput::safe_output("Overcurrent input read.");
this->overcurrent();
}
if(IOPort::IS_IR_BROKEN()) {
SafeOutput::safe_output("Ir broken input read.");
this->ir_beam();
}
if(IOPort::IS_REMOTE_BUTTON()) {
SafeOutput::safe_output("Remote button input read.");
this->button_pressed();
}
}
}
}