-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pv-overrides): show solar and pv icons on hmi controller
- Loading branch information
Showing
10 changed files
with
357 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#ifndef AQUAMQTT_MAINSTATEPROXY_H | ||
#define AQUAMQTT_MAINSTATEPROXY_H | ||
|
||
#include "message/MainStatusMessage.h" | ||
#include "mqtt/IMQTTCallback.h" | ||
#include "state/DHWState.h" | ||
|
||
namespace aquamqtt | ||
{ | ||
|
||
struct AquaMqttMainOverrides | ||
{ | ||
bool pvState; | ||
bool solarState; | ||
}; | ||
|
||
/** | ||
* MainStateProxy accesses messages emitted by the main controller through DHW | ||
* state and applies overrides for customizing the HMI | ||
*/ | ||
|
||
class MainStateProxy : public mqtt::IMQTTCallback | ||
{ | ||
public: | ||
static MainStateProxy& getInstance(); | ||
|
||
virtual ~MainStateProxy() = default; | ||
|
||
MainStateProxy(const MainStateProxy&) = delete; | ||
|
||
private: | ||
MainStateProxy(); | ||
|
||
public: | ||
MainStateProxy& operator=(const MainStateProxy&) = delete; | ||
|
||
void setListener(TaskHandle_t handle); | ||
|
||
void applyMainOverrides(uint8_t* buffer); | ||
|
||
bool copyFrame(uint8_t frameId, uint8_t* buffer); | ||
|
||
void onOperationModeChanged(std::unique_ptr<message::HMIOperationMode> value) override; | ||
|
||
void onOperationTypeChanged(std::unique_ptr<message::HMIOperationType> type) override; | ||
|
||
void onInstallationModeChanged(std::unique_ptr<message::HMIInstallation> mode) override; | ||
|
||
void onWaterTempTargetChanged(std::unique_ptr<float> value) override; | ||
|
||
void onHeatingElementEnabledChanged(std::unique_ptr<bool> enabled) override; | ||
|
||
void onEmergencyModeEnabledChanged(std::unique_ptr<bool> enabled) override; | ||
|
||
void onPVModeHeatpumpEnabled(bool enabled) override; | ||
|
||
void onPVModeHeatElementEnabled(bool enabled) override; | ||
|
||
void onResetOverrides() override; | ||
|
||
AquaMqttMainOverrides getOverrides(); | ||
|
||
private: | ||
TaskHandle_t mNotify; | ||
SemaphoreHandle_t mMutex; | ||
|
||
bool mPVModeHeatPump; | ||
bool mPVModeHeatElement; | ||
}; | ||
|
||
} // namespace aquamqtt | ||
|
||
#endif // AQUAMQTT_MAINSTATEPROXY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#include "state/MainStateProxy.h" | ||
|
||
#include "config/Configuration.h" | ||
|
||
namespace aquamqtt | ||
{ | ||
|
||
MainStateProxy& MainStateProxy::getInstance() | ||
{ | ||
static MainStateProxy instance; | ||
return instance; | ||
} | ||
|
||
MainStateProxy::MainStateProxy() | ||
: IMQTTCallback() | ||
, mMutex(xSemaphoreCreateMutex()) | ||
, mNotify(nullptr) | ||
, mPVModeHeatPump(false) | ||
, mPVModeHeatElement(false) | ||
{ | ||
} | ||
|
||
void MainStateProxy::setListener(TaskHandle_t handle) | ||
{ | ||
if (!xSemaphoreTake(mMutex, portMAX_DELAY)) | ||
{ | ||
return; | ||
} | ||
|
||
mNotify = handle; | ||
|
||
xSemaphoreGive(mMutex); | ||
} | ||
|
||
void MainStateProxy::applyMainOverrides(uint8_t* buffer) | ||
{ | ||
if (!xSemaphoreTake(mMutex, portMAX_DELAY)) | ||
{ | ||
return; | ||
} | ||
|
||
message::MainStatusMessage message(buffer); | ||
|
||
// we only want to modify the message if a custom pv mode is active -> else leave state as it is | ||
if (mPVModeHeatElement) | ||
{ | ||
// let the hmi show the pv icon in case the heat element pv state is enabled | ||
message.enableStatePV(true); | ||
} | ||
|
||
if (mPVModeHeatPump) | ||
{ | ||
// let the hmi show the solar icon in case the heat element pv state is enabled | ||
message.enableStateSolar(true); | ||
} | ||
|
||
xSemaphoreGive(mMutex); | ||
} | ||
|
||
bool MainStateProxy::copyFrame(uint8_t frameId, uint8_t* buffer) | ||
{ | ||
if (frameId != aquamqtt::message::MAIN_MESSAGE_IDENTIFIER) | ||
{ | ||
return aquamqtt::DHWState::getInstance().copyFrame(frameId, buffer); | ||
} | ||
|
||
bool hasMainMessage = aquamqtt::DHWState::getInstance().copyFrame(frameId, buffer); | ||
if (hasMainMessage && aquamqtt::config::OPERATION_MODE == config::EOperationMode::MITM) | ||
{ | ||
applyMainOverrides(buffer); | ||
} | ||
return hasMainMessage; | ||
} | ||
|
||
void MainStateProxy::onOperationModeChanged(std::unique_ptr<message::HMIOperationMode> value) | ||
{ | ||
// noop | ||
} | ||
|
||
void MainStateProxy::onWaterTempTargetChanged(std::unique_ptr<float> value) | ||
{ | ||
// noop | ||
} | ||
|
||
void MainStateProxy::onHeatingElementEnabledChanged(std::unique_ptr<bool> enabled) | ||
{ | ||
// noop | ||
} | ||
|
||
void MainStateProxy::onEmergencyModeEnabledChanged(std::unique_ptr<bool> enabled) | ||
{ | ||
// noop | ||
} | ||
|
||
void MainStateProxy::onPVModeHeatpumpEnabled(bool enabled) | ||
{ | ||
|
||
if (!xSemaphoreTake(mMutex, portMAX_DELAY)) | ||
{ | ||
return; | ||
} | ||
|
||
mPVModeHeatPump = enabled; | ||
|
||
// message 193 has changed | ||
if (mNotify != nullptr) | ||
{ | ||
xTaskNotifyIndexed(mNotify, 0, (1UL << 7UL), eSetBits); | ||
} | ||
|
||
xSemaphoreGive(mMutex); | ||
} | ||
|
||
void MainStateProxy::onPVModeHeatElementEnabled(bool enabled) | ||
{ | ||
if (!xSemaphoreTake(mMutex, portMAX_DELAY)) | ||
{ | ||
return; | ||
} | ||
|
||
mPVModeHeatElement = enabled; | ||
|
||
// message 193 has changed | ||
if (mNotify != nullptr) | ||
{ | ||
xTaskNotifyIndexed(mNotify, 0, (1UL << 7UL), eSetBits); | ||
} | ||
|
||
xSemaphoreGive(mMutex); | ||
} | ||
|
||
void MainStateProxy::onOperationTypeChanged(std::unique_ptr<message::HMIOperationType> type) | ||
{ | ||
// noop | ||
} | ||
|
||
void MainStateProxy::onInstallationModeChanged(std::unique_ptr<message::HMIInstallation> mode) | ||
{ | ||
// noop | ||
} | ||
|
||
void MainStateProxy::onResetOverrides() | ||
{ | ||
// noop | ||
} | ||
AquaMqttMainOverrides MainStateProxy::getOverrides() | ||
{ | ||
if (!xSemaphoreTake(mMutex, portMAX_DELAY)) | ||
{ | ||
return AquaMqttMainOverrides{}; | ||
} | ||
|
||
AquaMqttMainOverrides retVal{}; | ||
|
||
if (mPVModeHeatPump) | ||
{ | ||
retVal.solarState = true; | ||
} | ||
|
||
if (mPVModeHeatElement) | ||
{ | ||
retVal.pvState = true; | ||
} | ||
|
||
xSemaphoreGive(mMutex); | ||
|
||
return retVal; | ||
} | ||
|
||
} // namespace aquamqtt |
Oops, something went wrong.