-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwr3223_modeValueDecoder.h
77 lines (67 loc) · 2.65 KB
/
wr3223_modeValueDecoder.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
namespace WR3223
{
enum WR3223EnumModus : char
{
AUS = 0b00000000,
SOMMER_BETRIEB = 0b00000001,
SOMMER_ABLUFT = 0b00000010,
WINTER_BETRIEB = 0b00000011,
HANBETRIEB_WINTERBETRIEB = 0b00000100,
ABSENKUNG_ON = 0b01000000,
NACHHEIZREGISTER_ON = 0b10000000
};
class WR3223ModusValueDecoder
{
static constexpr int STATUS_MASK = 0b11000111; // 1 + 2 + 4 + 64 + 128;
// für die Auswahl des Modus interessieren uns nur die erste 3 bit
static constexpr int MODE_MASK = 0b00000111;
public:
// Der aktuelle gesamtwert, welcher zuletzt gelesen wurde
int activeMode;
bool get_absenkung_on()
{
return static_cast<bool>(activeMode & WR3223EnumModus::ABSENKUNG_ON);
}
bool get_nachheizregister_on()
{
return static_cast<bool>(activeMode & WR3223EnumModus::NACHHEIZREGISTER_ON);
}
/// @brief Setzt den Status aus der Abfrag des Kommandos MD
/// @param read
bool publishValue(const char *read)
{
try
{
activeMode = WR3223Helper::to_int(read, false);
activeMode &= STATUS_MASK;
ModusSensor::absenkungSensor->publish_state(get_absenkung_on());
ModusSensor::nachheizregisterSensor->publish_state(get_nachheizregister_on());
return true;
}
catch(const std::exception& e)
{
ESP_LOGE("MODE DECODER", "Exception in publishValue: %s (SetValue: %s)",e.what(), read);
return false;
}
}
/// @brief Liefert nur die relevanten Bits für den Modus (also ohne nachheizregister und absenkung)
/// @return
int get_active_mode()
{
return activeMode & MODE_MASK;
}
std::string getModeDisplayValue(int pMode)
{
if(static_cast<bool>(pMode & WR3223EnumModus::WINTER_BETRIEB))
return "Winterbetrieb";
else if(static_cast<bool>(pMode & WR3223EnumModus::HANBETRIEB_WINTERBETRIEB))
return "Handbetrieb";
else if(static_cast<bool>(pMode & WR3223EnumModus::SOMMER_ABLUFT))
return "Sommer-Abluftbetrieb";
else if(static_cast<bool>(pMode & WR3223EnumModus::SOMMER_BETRIEB))
return "Sommerbetrieb";
else
return "AUS";
}
};
}