-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_component.h
77 lines (64 loc) · 1.66 KB
/
custom_component.h
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
#include "esphome.h"
#include <string>
#include "coffee.h"
//using namespace esphome;
class MyCustomTextSensor : public PollingComponent, public TextSensor {
private:
std::string val;
public:
// constructor
MyCustomTextSensor() : PollingComponent(1000) {}
std::string get_val() {
return this->val;
}
void setup() override {
// This will be called by App.setup()
}
void update() override {
// This will be called every "update_interval" milliseconds.
//publish_state(this->val);
publish_state(this->val);
}
void receive_value(std::string val) {
//this->val = val;
this->val = val;
}
};
class MyCustomComponent : public PollingComponent {
public:
MyCustomTextSensor *custom_sensor = new MyCustomTextSensor();
Coffee coffee = Coffee(30);
int count = 0;
MyCustomComponent() : PollingComponent(1000) { }
void setup() override {
pinMode(2, OUTPUT);
coffee.setup();
}
void loop() override {
coffee.loop();
}
void update() override {
// This is the actual sensor reading logic.
//ESP_LOGD("custom", "sensor %d", custom_sensor->get_val());
//if(count%2)
//custom_sensor->receive_value("Hello World");
//else
//custom_sensor->receive_value("Hello Henrique");
//count++;
int coffeeStatus = coffee.getStatus();
if(coffeeStatus == 1)
custom_sensor->receive_value("Idle");
else if(coffeeStatus == 2)
custom_sensor->receive_value("Filling");
else
custom_sensor->receive_value("Draining");
}
void set_level(int val) {
ESP_LOGD("custom", "cups %d", val);
coffee.setRequestCup(val);
//if(val % 2)
//digitalWrite(2, 1);
//else
//digitalWrite(2, 0);
}
};