Skip to content

Commit

Permalink
[examples] Update nrfconnect pump examples (#11127)
Browse files Browse the repository at this point in the history
* Update pump-app and documentation removing old lock-app code.
Added dummy get functions for pressure and flow.
Added the possibility to factory reset the device with a longpress on one of the buttons.
Updated the .sysconfig file so it can be opened with sysconfig.

* Restyled

* Update pump-controller-app and documentation removing old lock-app references.
Added reset feature in the app.
Reduced target heap size to allow the project to build again.
Updated .sysconfig file so it loads correctly in SysConfig.

* Restyle changed files

* Restyled by whitespace

* Removed submodule added from bad merge.

* Reverted zap repo to correct version

* Corrected spelling

* Enabled extended discovery to support multiadmin on TI platform

* Restyled by whitespace

* pump-app: Replaced use of emberAfWriteServerAttribute calls with correct accessor methods

* Fixed a typo in the log output for UpdateClusterState

* Replaced usage of emberAf call's with correct accessors for nrfconnect pump examples.
Added update of on/off cluster when button is pressed in TI pump examples so they match the nrfconnect example behavior.

* Minor merge fixes. Built all pump examples (nrf + TI)

* Fixed bad merge of AppTask.cpp for TI Pump-app

* Fix bad merge of pump-manager for TI Pump App

* One more attempt to fix bad merge.

* Corrected type on maxSpeed attribute for pump-app

* Removed On/Off cluster update from pump-controller-apps as the attribute is no longer enabled

* revert submodule

* Restyled by whitespace

* Removed unused declarations from pump manager in pump-controller-app

* Regen ZAP

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 15, 2022
1 parent a550fb7 commit b53fb72
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 61 deletions.
39 changes: 23 additions & 16 deletions examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#define APP_TASK_PRIORITY 4
#define APP_EVENT_QUEUE_SIZE 10

#define PCC_CLUSTER_ENDPOINT 1
#define ONOFF_CLUSTER_ENDPOINT 1

using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
using namespace ::chip::app::Clusters;
Expand Down Expand Up @@ -279,7 +282,7 @@ void AppTask::ActionInitiated(PumpManager::Action_t aAction, int32_t aActor)
LED_startBlinking(sAppRedHandle, 110 /* ms */, LED_BLINK_FOREVER);
}

void AppTask::ActionCompleted(PumpManager::Action_t aAction)
void AppTask::ActionCompleted(PumpManager::Action_t aAction, int32_t aActor)
{
// if the action has been completed by the pump, update the pump trait.
// Turn on the pump state LED if in a STARTED state OR
Expand All @@ -300,6 +303,10 @@ void AppTask::ActionCompleted(PumpManager::Action_t aAction)
LED_stopBlinking(sAppRedHandle);
LED_setOff(sAppRedHandle);
}
if (aActor == AppEvent::kEventType_ButtonLeft)
{
sAppTask.UpdateClusterState();
}
}

void AppTask::DispatchEvent(AppEvent * aEvent)
Expand Down Expand Up @@ -368,102 +375,102 @@ void AppTask::UpdateClusterState()

ChipLogProgress(NotSpecified, "UpdateClusterState");

// write the new values
// Write the new values

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

status = OnOff::Attributes::OnOff::Set(1, 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);
}

int16_t maxPressure = PumpMgr().GetMaxPressure();
status = PumpConfigurationAndControl::Attributes::MaxPressure::Set(1, maxPressure);
status = PumpConfigurationAndControl::Attributes::MaxPressure::Set(PCC_CLUSTER_ENDPOINT, maxPressure);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxPressure %" PRIx8, status);
}

uint16_t maxSpeed = PumpMgr().GetMaxSpeed();
status = PumpConfigurationAndControl::Attributes::MaxSpeed::Set(1, maxSpeed);
status = PumpConfigurationAndControl::Attributes::MaxSpeed::Set(PCC_CLUSTER_ENDPOINT, maxSpeed);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxSpeed %" PRIx8, status);
}

uint16_t maxFlow = PumpMgr().GetMaxFlow();
status = PumpConfigurationAndControl::Attributes::MaxFlow::Set(1, maxFlow);
status = PumpConfigurationAndControl::Attributes::MaxFlow::Set(PCC_CLUSTER_ENDPOINT, maxFlow);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxFlow %" PRIx8, status);
}

int16_t minConstPress = PumpMgr().GetMinConstPressure();
status = PumpConfigurationAndControl::Attributes::MinConstPressure::Set(1, minConstPress);
status = PumpConfigurationAndControl::Attributes::MinConstPressure::Set(PCC_CLUSTER_ENDPOINT, minConstPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstPressure %" PRIx8, status);
}

int16_t maxConstPress = PumpMgr().GetMaxConstPressure();
status = PumpConfigurationAndControl::Attributes::MaxConstPressure::Set(1, maxConstPress);
status = PumpConfigurationAndControl::Attributes::MaxConstPressure::Set(PCC_CLUSTER_ENDPOINT, maxConstPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstPressure %" PRIx8, status);
}

int16_t minCompPress = PumpMgr().GetMinCompPressure();
status = PumpConfigurationAndControl::Attributes::MinCompPressure::Set(1, minCompPress);
status = PumpConfigurationAndControl::Attributes::MinCompPressure::Set(PCC_CLUSTER_ENDPOINT, minCompPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinCompPressure %" PRIx8, status);
}

int16_t maxCompPress = PumpMgr().GetMaxCompPressure();
status = PumpConfigurationAndControl::Attributes::MaxCompPressure::Set(1, maxCompPress);
status = PumpConfigurationAndControl::Attributes::MaxCompPressure::Set(PCC_CLUSTER_ENDPOINT, maxCompPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxCompPressure %" PRIx8, status);
}

uint16_t minConstSpeed = PumpMgr().GetMinConstSpeed();
status = PumpConfigurationAndControl::Attributes::MinConstSpeed::Set(1, minConstSpeed);
status = PumpConfigurationAndControl::Attributes::MinConstSpeed::Set(PCC_CLUSTER_ENDPOINT, minConstSpeed);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstSpeed %" PRIx8, status);
}

uint16_t maxConstSpeed = PumpMgr().GetMaxConstSpeed();
status = PumpConfigurationAndControl::Attributes::MaxConstSpeed::Set(1, maxConstSpeed);
status = PumpConfigurationAndControl::Attributes::MaxConstSpeed::Set(PCC_CLUSTER_ENDPOINT, maxConstSpeed);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstSpeed %" PRIx8, status);
}

uint16_t minConstFlow = PumpMgr().GetMinConstFlow();
status = PumpConfigurationAndControl::Attributes::MinConstFlow::Set(1, minConstFlow);
status = PumpConfigurationAndControl::Attributes::MinConstFlow::Set(PCC_CLUSTER_ENDPOINT, minConstFlow);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstFlow %" PRIx8, status);
}

uint16_t maxConstFlow = PumpMgr().GetMaxConstFlow();
status = PumpConfigurationAndControl::Attributes::MaxConstFlow::Set(1, maxConstFlow);
status = PumpConfigurationAndControl::Attributes::MaxConstFlow::Set(PCC_CLUSTER_ENDPOINT, maxConstFlow);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstFlow %" PRIx8, status);
}

int16_t minConstTemp = PumpMgr().GetMinConstTemp();
status = PumpConfigurationAndControl::Attributes::MinConstTemp::Set(1, minConstTemp);
status = PumpConfigurationAndControl::Attributes::MinConstTemp::Set(PCC_CLUSTER_ENDPOINT, minConstTemp);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstTemp %" PRIx8, status);
}

int16_t maxConstTemp = PumpMgr().GetMaxConstTemp();
status = PumpConfigurationAndControl::Attributes::MaxConstTemp::Set(1, maxConstTemp);
status = PumpConfigurationAndControl::Attributes::MaxConstTemp::Set(PCC_CLUSTER_ENDPOINT, maxConstTemp);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstTemp %" PRIx8, status);
Expand Down
11 changes: 5 additions & 6 deletions examples/pump-app/cc13x2x7_26x2x7/main/PumpManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ bool PumpManager::InitiateAction(int32_t aActor, Action_t aAction)
if (mState == kState_StartCompleted && aAction == STOP_ACTION)
{
action_initiated = true;

new_state = kState_StopInitiated;
mCurrentActor = aActor;
new_state = kState_StopInitiated;
}
else if (mState == kState_StopCompleted && aAction == START_ACTION)
{
action_initiated = true;

new_state = kState_StartInitiated;
mCurrentActor = aActor;
new_state = kState_StartInitiated;
}

if (action_initiated)
Expand All @@ -113,7 +113,6 @@ bool PumpManager::InitiateAction(int32_t aActor, Action_t aAction)
mActionInitiated_CB(aAction, aActor);
}
}

return action_initiated;
}

Expand Down Expand Up @@ -188,7 +187,7 @@ void PumpManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)
{
if (pump->mActionCompleted_CB)
{
pump->mActionCompleted_CB(actionCompleted);
pump->mActionCompleted_CB(actionCompleted, pump->mCurrentActor);
}

if (pump->mAutoRestart && actionCompleted == STOP_ACTION)
Expand Down
2 changes: 1 addition & 1 deletion examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AppTask
int Init();

static void ActionInitiated(PumpManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(PumpManager::Action_t aAction);
static void ActionCompleted(PumpManager::Action_t aAction, int32_t aActor);

void DispatchEvent(AppEvent * event);

Expand Down
3 changes: 2 additions & 1 deletion examples/pump-app/cc13x2x7_26x2x7/main/include/PumpManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PumpManager
int16_t GetMaxConstTemp();

typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
typedef void (*Callback_fn_completed)(Action_t);
typedef void (*Callback_fn_completed)(Action_t, int32_t aActor);
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);

private:
Expand All @@ -82,6 +82,7 @@ class PumpManager
uint32_t mAutoStartDuration;
bool mAutoStartTimerArmed;
TimerHandle_t mTimerHandle;
int32_t mCurrentActor;

void CancelTimer(void);
void PumpTimer(uint32_t aTimeoutMs);
Expand Down
110 changes: 105 additions & 5 deletions examples/pump-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/util/attribute-storage.h>

Expand All @@ -44,6 +45,9 @@
#define BUTTON_PUSH_EVENT 1
#define BUTTON_RELEASE_EVENT 0

#define PCC_CLUSTER_ENDPOINT 1
#define ONOFF_CLUSTER_ENDPOINT 1

LOG_MODULE_DECLARE(app);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));

Expand All @@ -60,6 +64,7 @@ static k_timer sFunctionTimer;

using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
using namespace ::chip::app::Clusters;

AppTask AppTask::sAppTask;

Expand Down Expand Up @@ -505,13 +510,108 @@ void AppTask::DispatchEvent(AppEvent * aEvent)

void AppTask::UpdateClusterState()
{
uint8_t newValue = !PumpMgr().IsStopped();
EmberStatus status;

ChipLogProgress(NotSpecified, "UpdateClusterState");

// Write the new values

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

status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, onOffState);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating On/Off state %" PRIx8, status);
}

int16_t maxPressure = PumpMgr().GetMaxPressure();
status = PumpConfigurationAndControl::Attributes::MaxPressure::Set(PCC_CLUSTER_ENDPOINT, maxPressure);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxPressure %" PRIx8, status);
}

uint16_t maxSpeed = PumpMgr().GetMaxSpeed();
status = PumpConfigurationAndControl::Attributes::MaxSpeed::Set(PCC_CLUSTER_ENDPOINT, maxSpeed);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxSpeed %" PRIx8, status);
}

uint16_t maxFlow = PumpMgr().GetMaxFlow();
status = PumpConfigurationAndControl::Attributes::MaxFlow::Set(PCC_CLUSTER_ENDPOINT, maxFlow);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxFlow %" PRIx8, status);
}

int16_t minConstPress = PumpMgr().GetMinConstPressure();
status = PumpConfigurationAndControl::Attributes::MinConstPressure::Set(PCC_CLUSTER_ENDPOINT, minConstPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstPressure %" PRIx8, status);
}

int16_t maxConstPress = PumpMgr().GetMaxConstPressure();
status = PumpConfigurationAndControl::Attributes::MaxConstPressure::Set(PCC_CLUSTER_ENDPOINT, maxConstPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstPressure %" PRIx8, status);
}

int16_t minCompPress = PumpMgr().GetMinCompPressure();
status = PumpConfigurationAndControl::Attributes::MinCompPressure::Set(PCC_CLUSTER_ENDPOINT, minCompPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinCompPressure %" PRIx8, status);
}

int16_t maxCompPress = PumpMgr().GetMaxCompPressure();
status = PumpConfigurationAndControl::Attributes::MaxCompPressure::Set(PCC_CLUSTER_ENDPOINT, maxCompPress);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxCompPressure %" PRIx8, status);
}

uint16_t minConstSpeed = PumpMgr().GetMinConstSpeed();
status = PumpConfigurationAndControl::Attributes::MinConstSpeed::Set(PCC_CLUSTER_ENDPOINT, minConstSpeed);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstSpeed %" PRIx8, status);
}

uint16_t maxConstSpeed = PumpMgr().GetMaxConstSpeed();
status = PumpConfigurationAndControl::Attributes::MaxConstSpeed::Set(PCC_CLUSTER_ENDPOINT, maxConstSpeed);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstSpeed %" PRIx8, status);
}

uint16_t minConstFlow = PumpMgr().GetMinConstFlow();
status = PumpConfigurationAndControl::Attributes::MinConstFlow::Set(PCC_CLUSTER_ENDPOINT, minConstFlow);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstFlow %" PRIx8, status);
}

uint16_t maxConstFlow = PumpMgr().GetMaxConstFlow();
status = PumpConfigurationAndControl::Attributes::MaxConstFlow::Set(PCC_CLUSTER_ENDPOINT, maxConstFlow);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MaxConstFlow %" PRIx8, status);
}

int16_t minConstTemp = PumpMgr().GetMinConstTemp();
status = PumpConfigurationAndControl::Attributes::MinConstTemp::Set(PCC_CLUSTER_ENDPOINT, minConstTemp);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(NotSpecified, "ERR: Updating MinConstTemp %" PRIx8, status);
}

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &newValue,
ZCL_BOOLEAN_ATTRIBUTE_TYPE);
int16_t maxConstTemp = PumpMgr().GetMaxConstTemp();
status = PumpConfigurationAndControl::Attributes::MaxConstTemp::Set(PCC_CLUSTER_ENDPOINT, maxConstTemp);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating on/off %x", status);
ChipLogError(NotSpecified, "ERR: Updating MaxConstTemp %" PRIx8, status);
}
}
Loading

0 comments on commit b53fb72

Please sign in to comment.