Skip to content

Commit

Permalink
Merge pull request #188 from MichaelDvP:dev
Browse files Browse the repository at this point in the history
Mode update for #183
  • Loading branch information
proddy authored Nov 11, 2021
2 parents 4f2da03 + 27bfc14 commit 409d382
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 19 deletions.
9 changes: 7 additions & 2 deletions interface/src/system/LogEventController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface LogEventControllerState {
compact: boolean;
level: number;
max_messages: number;
last_id: number;
}

type LogEventControllerProps = RestControllerProps<LogSettings>;
Expand All @@ -62,7 +63,8 @@ class LogEventController extends Component<
events: [],
compact: false,
level: 6,
max_messages: 25
max_messages: 25,
last_id: 0
};
}

Expand Down Expand Up @@ -157,7 +159,10 @@ class LogEventController extends Component<
const rawData = event.data;
if (typeof rawData === 'string' || rawData instanceof String) {
const event = JSON.parse(rawData as string) as LogEvent;
this.setState((state) => ({ events: [...state.events, event] }));
if (event.i > this.state.last_id) {
this.setState({ last_id: event.i });
this.setState((state) => ({ events: [...state.events, event] }));
}
}
};

Expand Down
5 changes: 0 additions & 5 deletions src/dallassensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ bool DallasSensor::temperature_convert_complete() {
#endif
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"

int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
#ifndef EMSESP_STANDALONE
if (!bus_.reset()) {
Expand Down Expand Up @@ -276,8 +273,6 @@ int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
#endif
}

#pragma GCC diagnostic pop

const std::vector<DallasSensor::Sensor> DallasSensor::sensors() const {
return sensors_;
}
Expand Down
69 changes: 57 additions & 12 deletions src/devices/thermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ void Thermostat::process_RC10Monitor(std::shared_ptr<const Telegram> telegram) {
return;
}

uint8_t mode = hc->mode * 2;
uint8_t mode = 1 << hc->mode;
has_update(telegram->read_value(mode, 0)); // 1: nofrost, 2: night, 4: day
hc->mode = mode / 2; // for enum 0, 1, 2
hc->mode = mode >> 1; // for enum 0, 1, 2
has_update(telegram->read_value(hc->setpoint_roomTemp, 1, 1)); // is * 2, force as single byte
has_update(telegram->read_value(hc->curr_roomTemp, 2)); // is * 10
has_update(telegram->read_value(hc->reduceminutes, 5));
Expand All @@ -680,9 +680,26 @@ void Thermostat::process_RC10Set(std::shared_ptr<const Telegram> telegram) {
has_update(telegram->read_value(hc->nighttemp, 3));
has_update(telegram->read_value(hc->daytemp, 4));
has_update(telegram->read_value(hc->reducehours, 5));
has_update(telegram->read_value(ibaBuildingType_, 6));
has_update(telegram->read_value(heatingpid_, 6));
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"

// type 0xB2, mode setting Data: 04 00
// not used, we read mode from monitor 0xB1
void Thermostat::process_RC10Set_2(std::shared_ptr<const Telegram> telegram) {
// std::shared_ptr<Thermostat::HeatingCircuit> hc = heating_circuit(telegram);
// if (hc == nullptr) {
// return;
// }
// uint8_t mode = 1 << hc->mode;
// has_update(telegram->read_value(mode, 0)); // 1: nofrost, 2: night, 4: day
// hc->mode = mode >> 1; // for enum 0, 1, 2
}

#pragma GCC diagnostic pop

// 0xA8 - for reading the mode from the RC20 thermostat (0x17)
void Thermostat::process_RC20Set(std::shared_ptr<const Telegram> telegram) {
std::shared_ptr<Thermostat::HeatingCircuit> hc = heating_circuit(telegram);
Expand Down Expand Up @@ -1326,16 +1343,28 @@ bool Thermostat::set_building(const char * value, const int8_t id) {
return false;
}
LOG_INFO(F("Setting building to %s"), value);
if (model() == EMS_DEVICE_FLAG_RC10) {
write_command(0xB0, 6, bd, 0xB0);
} else if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) {
if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) {
write_command(0x240, 9, bd + 1, 0x240);
} else {
write_command(EMS_TYPE_IBASettings, 6, bd, EMS_TYPE_IBASettings);
}
return true;
}

// 0xB0 - Set RC10 heating pid
bool Thermostat::set_heatingpid(const char * value, const int8_t id) {
uint8_t pid = 0;
if (!Helpers::value2enum(value, pid, FL_(enum_PID))) {
LOG_WARNING(F("Set heating pid: Invalid value"));
return false;
}
LOG_INFO(F("Setting heating pid to %s"), value);
if (model() == EMS_DEVICE_FLAG_RC10) {
write_command(0xB0, 6, pid, 0xB0);
}
return true;
}

// 0xA5 - Set the building settings
bool Thermostat::set_damping(const char * value, const int8_t id) {
bool dmp;
Expand Down Expand Up @@ -1765,6 +1794,9 @@ bool Thermostat::set_mode(const char * value, const int8_t id) {
if (value[0] >= '0' && value[0] <= '9') {
uint8_t num = value[0] - '0';
switch (model()) {
case EMSdevice::EMS_DEVICE_FLAG_RC10:
mode = uuid::read_flash_string(FL_(enum_mode6)[num]);
break;
case EMSdevice::EMS_DEVICE_FLAG_RC20:
case EMSdevice::EMS_DEVICE_FLAG_RC20_N:
mode = uuid::read_flash_string(FL_(enum_mode2)[num]);
Expand Down Expand Up @@ -1842,6 +1874,7 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) {
uint8_t set_mode_value, offset;
uint16_t validate_typeid = 0;
uint8_t hc_p = hc->hc_num() - 1;
uint16_t set_typeid = set_typeids[hc->hc_num() - 1];

// set the value to send via EMS depending on the mode type
switch (mode) {
Expand All @@ -1865,6 +1898,18 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) {
}

switch (model()) {
case EMSdevice::EMS_DEVICE_FLAG_RC10:
offset = 0;
validate_typeid = 0xB1;
set_typeid = 0xB2;
if (mode == HeatingCircuit::Mode::NOFROST) {
set_mode_value = 1;
} else if (mode == HeatingCircuit::Mode::NIGHT) {
set_mode_value = 2;
} else { // DAY
set_mode_value = 4;
}
break;
case EMSdevice::EMS_DEVICE_FLAG_RC20:
offset = EMS_OFFSET_RC20Set_mode;
validate_typeid = set_typeids[hc_p];
Expand Down Expand Up @@ -1918,7 +1963,7 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) {

// add the write command to the Tx queue
// post validate is the corresponding monitor or set type IDs as they can differ per model
write_command(set_typeids[hc->hc_num() - 1], offset, set_mode_value, validate_typeid);
write_command(set_typeid, offset, set_mode_value, validate_typeid);

return true;
}
Expand Down Expand Up @@ -2627,12 +2672,12 @@ void Thermostat::register_device_values() {
DeviceValueUOM::DEGREES,
MAKE_CF_CB(set_calinttemp));
register_device_value(TAG_THERMOSTAT_DATA,
&ibaBuildingType_,
&heatingpid_,
DeviceValueType::ENUM,
FL_(enum_ibaBuildingType),
FL_(ibaBuildingType),
FL_(enum_PID),
FL_(heatingPID),
DeviceValueUOM::NONE,
MAKE_CF_CB(set_building));
MAKE_CF_CB(set_heatingpid));
register_device_value(TAG_THERMOSTAT_DATA, &backlight_, DeviceValueType::BOOL, nullptr, FL_(backlight), DeviceValueUOM::NONE, MAKE_CF_CB(set_backlight));
register_device_value(TAG_DEVICE_DATA_WW, &wwMode_, DeviceValueType::ENUM, FL_(enum_wwMode3), FL_(wwMode), DeviceValueUOM::NONE, MAKE_CF_CB(set_wwmode));
break;
Expand Down Expand Up @@ -2843,7 +2888,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi

switch (model) {
case EMS_DEVICE_FLAG_RC10:
register_device_value(tag, &hc->mode, DeviceValueType::ENUM, FL_(enum_mode6), FL_(mode), DeviceValueUOM::NONE);
register_device_value(tag, &hc->mode, DeviceValueType::ENUM, FL_(enum_mode6), FL_(mode), DeviceValueUOM::NONE, MAKE_CF_CB(set_mode));
register_device_value(tag, &hc->daytemp, DeviceValueType::UINT, FL_(div2), FL_(daytemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_daytemp));
register_device_value(tag, &hc->nighttemp, DeviceValueType::UINT, FL_(div2), FL_(nighttemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_nighttemp));
register_device_value(tag, &hc->reducehours, DeviceValueType::UINT, nullptr, FL_(reducehours), DeviceValueUOM::HOURS, MAKE_CF_CB(set_reducehours));
Expand Down
3 changes: 3 additions & 0 deletions src/devices/thermostat.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Thermostat : public EMSdevice {
int8_t ibaClockOffset_; // offset (in sec) to clock, 0xff = -1 s, 0x02 = 2 s
uint8_t ibaDamping_; // damping 0-off, 0xff-on
uint8_t backlight_;
uint8_t heatingpid_;

int8_t dampedoutdoortemp_;
uint16_t tempsensor1_;
Expand Down Expand Up @@ -298,6 +299,7 @@ class Thermostat : public EMSdevice {
void process_RC20Set_2(std::shared_ptr<const Telegram> telegram);
void process_RC10Monitor(std::shared_ptr<const Telegram> telegram);
void process_RC10Set(std::shared_ptr<const Telegram> telegram);
void process_RC10Set_2(std::shared_ptr<const Telegram> telegram);
void process_CRFMonitor(std::shared_ptr<const Telegram> telegram);
void process_RC300Monitor(std::shared_ptr<const Telegram> telegram);
void process_RC300Set(std::shared_ptr<const Telegram> telegram);
Expand Down Expand Up @@ -384,6 +386,7 @@ class Thermostat : public EMSdevice {
bool set_heatingtype(const char * value, const int8_t id);
bool set_reducehours(const char * value, const int8_t id);
bool set_backlight(const char * value, const int8_t id);
bool set_heatingpid(const char * value, const int8_t id);
};

} // namespace emsesp
Expand Down
2 changes: 2 additions & 0 deletions src/locale_EN.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ MAKE_PSTR_LIST(enum_ibaMainDisplay,
MAKE_PSTR_LIST(enum_ibaLanguage, F_(german), F_(dutch), F_(french), F_(italian))
MAKE_PSTR_LIST(enum_floordrystatus, F_(off), F_(start), F_(heat), F_(hold), F_(cool), F_(end))
MAKE_PSTR_LIST(enum_ibaBuildingType, F_(light), F_(medium), F_(heavy))
MAKE_PSTR_LIST(enum_PID, F("fast"), F_(medium), F("slow"))
MAKE_PSTR_LIST(enum_wwMode, F_(off), F_(low), F_(high), F_(auto), F_(own_prog))
MAKE_PSTR_LIST(enum_wwCircMode, F_(off), F_(on), F_(auto), F_(own_prog))
MAKE_PSTR_LIST(enum_wwMode2, F_(off), F_(on), F_(auto))
Expand Down Expand Up @@ -541,6 +542,7 @@ MAKE_PSTR_LIST(ibaMainDisplay, F("display"), F("display"))
MAKE_PSTR_LIST(ibaLanguage, F("language"), F("language"))
MAKE_PSTR_LIST(ibaClockOffset, F("clockoffset"), F("clock offset"))
MAKE_PSTR_LIST(ibaBuildingType, F("building"), F("building"))
MAKE_PSTR_LIST(heatingPID, F("heatingpid"), F("heating PID"))
MAKE_PSTR_LIST(ibaCalIntTemperature, F("intoffset"), F("offset internal temperature"))
MAKE_PSTR_LIST(ibaMinExtTemperature, F("minexttemp"), F("minimal external temperature"))
MAKE_PSTR_LIST(backlight, F("backlight"), F("key backlight"))
Expand Down

0 comments on commit 409d382

Please sign in to comment.