-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreheating_interface.ino
More file actions
61 lines (55 loc) · 2.16 KB
/
preheating_interface.ino
File metadata and controls
61 lines (55 loc) · 2.16 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
#include <Arduino.h>
#include <ArduinoSTL.h>
#include <LibPreheatingInterface.hpp>
class MyRemote : public LibPreheatingInterface::PreheatingRemote {
private:
const int VALUE_THRESHOLD_MIN = 200; // analogRead value [0 .. 1023]
const int VALUE_THRESHOLD_MAX = 500; // analogRead value [0 .. 1023]
const uint8_t PIN_ON = 11;
const uint8_t PIN_OFF = 12;
const uint8_t PIN_GREEN = 1;
const uint8_t PIN_RED = 0;
bool IsEnabled(int value) {
return value < VALUE_THRESHOLD_MAX && value > VALUE_THRESHOLD_MIN;
}
public:
void PressOn() override { digitalWrite(PIN_ON, LOW); }
void PressOff() override { digitalWrite(PIN_OFF, LOW);}
void ReleaseOn() override { digitalWrite(PIN_ON, HIGH); }
void ReleaseOff() override { digitalWrite(PIN_OFF, HIGH); }
bool IsGreenLedOn() override { return IsEnabled(analogRead(PIN_GREEN)); }
bool IsRedLedOn() override { return IsEnabled(analogRead(PIN_RED)); }
void Boot() {
pinMode(PIN_ON, OUTPUT);
digitalWrite(PIN_ON, HIGH);
pinMode(PIN_OFF, OUTPUT);
digitalWrite(PIN_OFF, HIGH);
}
} myRemote;
class MyPlatform : public LibPreheatingInterface::Platform, public LibScheduling::Platform {
public:
virtual void Println(const char *text) override { Serial.println(text); }
virtual unsigned long Millis() override { return millis(); }
} myPlatform;
LibPreheatingInterface::CommandHelper commandHelper{myPlatform, myPlatform, myRemote};
void setup() {
Serial.begin(115200);
Serial.println("yolo");
myRemote.Boot();
}
void loop() {
if (Serial.available() > 0) {
String uart_in = Serial.readStringUntil('\n');
if (uart_in == "on") {
Serial.println("activate");
LibPreheatingInterface::PowerOnCommand cmd{commandHelper};
auto result = cmd.PowerOn();
Serial.println("was error: " + String(result.IsError()));
} else if (uart_in == "off") {
Serial.println("deactivate");
LibPreheatingInterface::PowerOffCommand cmd{commandHelper};
auto result = cmd.PowerOff();
Serial.println("was error: " + String(result.IsError()));
}
}
}