-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRobotAdmin.cpp
90 lines (56 loc) · 1.48 KB
/
RobotAdmin.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
84
85
86
87
88
#include "Arduino.h"
#include "RobotModel.h"
#include "LedRGBIndicator.h"
#include "RobotAdmin.h"
RobotAdmin::RobotAdmin()
{
}
void RobotAdmin::checkForSerialData()
{
if (Serial.available() > 0) {
_incomingData = Serial.readString();
if (_incomingData == "st") {
Serial.println("robot status");
Serial.println("-------------------------");
Serial.print("group : ");
Serial.print(_robotModel->getGroup());
Serial.print(" , id : ");
Serial.print(_robotModel->getID());
Serial.print(" , health : ");
Serial.print(_robotModel->getHealth());
Serial.print(" , hit points: ");
Serial.println(_robotModel->getHitPoints());
}
else {
/// try to decode command
String command = _incomingData.substring(0, 2);
byte param = _incomingData.substring(3, 6).toInt();
if (command == "gr") {
_robotModel->setGroup(param);
}
else if (command == "id") {
_robotModel->setID(param);
}
else if (command == "hl") {
_robotModel->setHealth(param);
}
else if (command == "hp") {
_robotModel->setHitPoints(param);
}
else if (command == "??") {
Serial.println("format : [command,param] or [command param]");
Serial.println("command list : st , gr , ip , hl , hp , ??");
}
_ledRGB->blink(PIN_BLUE);
Serial.println("ok");
}
}
}
void RobotAdmin::attachRobotModel(RobotModel & robotModel)
{
_robotModel = &robotModel;
}
void RobotAdmin::attachLedRGB(LedRGBIndicator & ledRGB)
{
_ledRGB = &ledRGB;
}