Skip to content

Commit

Permalink
[pump-app] Correct default state of On/Off cluster (#12986)
Browse files Browse the repository at this point in the history
* Addeded init routines to the pump app so the OnOff cluster state is set correctly at boot.
Added default timeout for extended discovery.

* Correct spacing as pr. review

* Removed blank line
  • Loading branch information
andersbangGF authored and pull[bot] committed Mar 22, 2023
1 parent 3ab735c commit 5367836
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
27 changes: 24 additions & 3 deletions examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "AppTask.h"
#include "AppConfig.h"
#include "AppEvent.h"
#include <app/server/Dnssd.h>
#include <app/server/Server.h>

#include <app-common/zap-generated/attribute-id.h>
Expand Down Expand Up @@ -52,6 +53,7 @@

#define PCC_CLUSTER_ENDPOINT 1
#define ONOFF_CLUSTER_ENDPOINT 1
#define EXTENDED_DISCOVERY_TIMEOUT_SEC 20

using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -140,6 +142,10 @@ int AppTask::Init()
;
}

#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(EXTENDED_DISCOVERY_TIMEOUT_SEC);
#endif

// Init ZCL Data Model and start server
PLAT_LOG("Initialize Server");
chip::Server::GetInstance().Init();
Expand Down Expand Up @@ -357,17 +363,32 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
}

void AppTask::InitOnOffClusterState()
{

EmberStatus status;

ChipLogProgress(NotSpecified, "Init On/Off clusterstate");

// Write false as pump always boots in stopped mode
status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, false);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Init On/Off state %" PRIx8, status);
}
}

void AppTask::InitPCCClusterState() {}

void AppTask::UpdateClusterState()
{
EmberStatus status;

ChipLogProgress(NotSpecified, "UpdateClusterState");

// Write the new values

bool onOffState = !PumpMgr().IsStopped();

status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, onOffState);
status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, onOffState);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating On/Off state %" PRIx8, status);
Expand Down
5 changes: 2 additions & 3 deletions examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
*/
void emberAfOnOffClusterInitCallback(EndpointId endpoint)
{
GetAppTask().UpdateClusterState();
GetAppTask().InitOnOffClusterState();
}

void emberAfPumpConfigurationAndControlClusterInitCallback(chip::EndpointId endpoint)
{
// TODO: Setup the default values in the cluster for this specific application
GetAppTask().UpdateClusterState();
GetAppTask().InitPCCClusterState();
}
2 changes: 2 additions & 0 deletions examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AppTask
void PostStartActionRequest(int32_t aActor, PumpManager::Action_t aAction);
void PostEvent(const AppEvent * event);
void UpdateClusterState();
void InitOnOffClusterState();
void InitPCCClusterState();

private:
friend AppTask & GetAppTask(void);
Expand Down

0 comments on commit 5367836

Please sign in to comment.