forked from BNoiZe/jura-esp32-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jura_uart.h
35 lines (29 loc) · 880 Bytes
/
jura_uart.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
#include "esphome.h"
class JuraUartReadLine : public Component, public UARTDevice, public TextSensor {
public:
JuraUartReadLine(UARTComponent *parent) : UARTDevice(parent) {}
void setup() override {
// nothing to do here
}
void loop() override {
int s = 0;
int w = 0;
char inbyte;
String inbytes;
while(!inbytes.endsWith("\r\n") && w <= 500) {
if (available()) {
byte rawbyte = read();
bitWrite(inbyte, s+ 0, bitRead(rawbyte, 2));
bitWrite(inbyte, s+ 1, bitRead(rawbyte, 5));
if ((s += 2) > 8) {
s = 0;
inbytes += inbyte;
}
} else {
delay(10);
}
w++;
}
ESP_LOGD("uart", "%s", inbytes.c_str());
}
};