Skip to content

Commit 6253f44

Browse files
committed
[SenseAir] Keep SenseAir code in sync with PR letscontrolit#4550
1 parent 8e66d61 commit 6253f44

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

src/_P052_SenseAir.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,4 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
581581
return success;
582582
}
583583

584-
#endif // USES_P052
584+
#endif // USES_P052

src/src/PluginStructs/P052_data_struct.cpp

+55-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const __FlashStringHelper * P052_data_struct::Plugin_052_valuename(uint8_t value
2929
F("ABC period"), F("abc_per"),
3030
F("Error Status"), F("err")
3131
};
32-
const size_t index = (2* value_nr) + (displayString ? 0 : 1);
32+
const size_t index = 2 * value_nr + (displayString ? 0 : 1);
3333
constexpr size_t nrStrings = sizeof(strings) / sizeof(strings[0]);
3434

3535
if (index < nrStrings) {
@@ -38,5 +38,58 @@ const __FlashStringHelper * P052_data_struct::Plugin_052_valuename(uint8_t value
3838
return F("");
3939
}
4040

41+
void P052_data_struct::setABCperiod(int hours)
42+
{
43+
// Enable: write 1 ... 65534 to HR14 and bit1 set to 0 at HR19
44+
// Disable: write 0 or 65535 to HR14 and bit1 set to 1 at HR19
4145

42-
#endif // ifdef USES_P052
46+
47+
// Read HR19
48+
uint8_t errorcode = 0;
49+
int value = modbus.readHoldingRegister(P052_HR19_METER_CONTROL, errorcode);
50+
51+
// Clear bit 1 in register and write back HR19
52+
if (bitRead(value, 1)) {
53+
bitClear(value, 1);
54+
modbus.writeSingleRegister(P052_HR19_METER_CONTROL, value, errorcode);
55+
}
56+
57+
// Read HR14 and verify desired ABC period
58+
value = modbus.readHoldingRegister(P052_HR14_ABC_PERIOD, errorcode);
59+
60+
// If HR14 (ABC period) is not the desired period,
61+
// write desired ABC period to HR14
62+
if (value != hours) {
63+
modbus.writeSingleRegister(P052_HR14_ABC_PERIOD, hours, errorcode);
64+
}
65+
}
66+
67+
uint32_t P052_data_struct::getSensorID()
68+
{
69+
uint8_t errorcode = 0;
70+
const uint32_t sensorId = (modbus.readInputRegister(P052_IR30_SENSOR_ID_HIGH, errorcode) << 16) |
71+
modbus.readInputRegister(P052_IR31_SENSOR_ID_LOW, errorcode);
72+
73+
if (errorcode == 0) {
74+
return sensorId;
75+
}
76+
return 0;
77+
}
78+
79+
bool P052_data_struct::readInputRegister(short addr, int& value)
80+
{
81+
uint8_t errorcode = 0;
82+
83+
value = modbus.readInputRegister(addr, errorcode);
84+
return errorcode == 0;
85+
}
86+
87+
bool P052_data_struct::readHoldingRegister(short addr, int& value)
88+
{
89+
uint8_t errorcode = 0;
90+
91+
value = modbus.readHoldingRegister(addr, errorcode);
92+
return errorcode == 0;
93+
}
94+
95+
#endif // ifdef USES_P052

0 commit comments

Comments
 (0)