-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialComm.cpp
More file actions
80 lines (74 loc) · 1.89 KB
/
SerialComm.cpp
File metadata and controls
80 lines (74 loc) · 1.89 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <Arduino.h>
#include <HardwareSerial.h>
#include <string.h>
#include "SerialComm.h"
void SerialComm::init(TimerTrigger *eggTurner, Controller *tempController,
Controller *humidController)
{
_eggTurner = eggTurner;
_tempController = tempController;
_humidController = humidController;
}
void SerialComm::check()
{
char command;
if (Serial.available()) {
command = Serial.read();
if (command == 'G') {
getParameters();
} else if (command == 'S') {
setParameters();
}
}
}
void SerialComm::getParameters()
{
Serial.print(millis());
Serial.print(' ');
Serial.print(*_tempController->getSensor());
Serial.print(' ');
Serial.print(_tempController->getTarget());
Serial.print(' ');
Serial.print(_tempController->getPower());
Serial.print(' ');
Serial.print(_tempController->getStatus());
Serial.print(' ');
Serial.print(*_humidController->getSensor());
Serial.print(' ');
Serial.print(_humidController->getTarget());
Serial.print(' ');
Serial.print(_humidController->getPower());
Serial.print(' ');
Serial.print(_humidController->getStatus());
Serial.print(' ');
Serial.print(_eggTurner->getOnState());
Serial.print(' ');
Serial.print(_eggTurner->isActive());
Serial.print(' ');
Serial.print(_eggTurner->getTimeLeft());
Serial.print(' ');
Serial.print(_eggTurner->getStatus());
Serial.println();
Serial.flush();
}
void SerialComm::setParameters()
{
char parameter;
int intVal;
float floatVal;
if (Serial.available()) {
parameter = Serial.read();
if (parameter == 'T') {
if ((floatVal = Serial.parseFloat())) {
_tempController->setTarget(floatVal);
}
} else if (parameter == 'H') {
if ((floatVal = Serial.parseFloat())) {
_humidController->setTarget(floatVal);
}
} else if (parameter == 'E') {
intVal = Serial.parseInt();
_eggTurner->activate(intVal);
}
}
}