Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Refine the laundry-washer-control server implementation and add laundry-washer-controls-delegate-impl #28264

Merged
merged 9 commits into from
Aug 4, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h>
#include <app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h>
#include <app/util/af.h>
#include <app/util/config.h>
#include <cstring>

namespace chip {
namespace app {
namespace Clusters {
namespace LaundryWasherControls {

/**
* The application delegate to statically defines the options.
*/

class LaundryWasherControlDelegate : public Delegate
{
static const CharSpan spinSpeedsNameOptions[];
static const NumberOfRinsesEnum supportRinsesOptions[];
static LaundryWasherControlDelegate instance;

public:
CHIP_ERROR GetSpinSpeedAtIndex(size_t index, MutableCharSpan & spinSpeed);
CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse);

~LaundryWasherControlDelegate(){};
LaundryWasherControlDelegate(){};

static inline LaundryWasherControlDelegate & getLaundryWasherControlDelegate() { return instance; }
};

} // namespace LaundryWasherControls
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h>
#include <app/util/config.h>
#include <laundry-washer-controls-delegate-impl.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::LaundryWasherControls;
using chip::Protocols::InteractionModel::Status;

const CharSpan LaundryWasherControlDelegate::spinSpeedsNameOptions[] = {
CharSpan::fromCharString("Off"),
CharSpan::fromCharString("Low"),
CharSpan::fromCharString("Medium"),
CharSpan::fromCharString("High"),
};

const NumberOfRinsesEnum LaundryWasherControlDelegate::supportRinsesOptions[] = {
NumberOfRinsesEnum::kNormal,
NumberOfRinsesEnum::kExtra,
};

LaundryWasherControlDelegate LaundryWasherControlDelegate::instance;

CHIP_ERROR LaundryWasherControlDelegate::GetSpinSpeedAtIndex(size_t index, MutableCharSpan & spinSpeed)
{
if (index >= ArraySize(spinSpeedsNameOptions))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
return chip::CopyCharSpanToMutableCharSpan(LaundryWasherControlDelegate::spinSpeedsNameOptions[index], spinSpeed);
}

CHIP_ERROR LaundryWasherControlDelegate::GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse)
{
if (index >= ArraySize(supportRinsesOptions))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
supportedRinse = LaundryWasherControlDelegate::supportRinsesOptions[index];
return CHIP_NO_ERROR;
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-alarm-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/operational-state-delegate-impl.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/operational-state-delegates.cpp",
Expand Down
8 changes: 8 additions & 0 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
#include "WindowCoveringManager.h"
#include "dishwasher-mode.h"
#include "include/tv-callbacks.h"
#include "laundry-washer-controls-delegate-impl.h"
#include "laundry-washer-mode.h"
#include "rvc-modes.h"
#include "tcc-mode.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/CommandHandler.h>
#include <app/att-storage.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h>
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/server/Server.h>
#include <app/util/af.h>
Expand Down Expand Up @@ -205,6 +207,12 @@ void ApplicationShutdown()
}
}

using namespace chip::app::Clusters::LaundryWasherControls;
void emberAfLaundryWasherControlsClusterInitCallback(EndpointId endpoint)
{
LaundryWasherControlsServer::SetDefaultDelegate(1, &LaundryWasherControlDelegate::getLaundryWasherControlDelegate());
}

void emberAfLowPowerClusterInitCallback(EndpointId endpoint)
{
ChipLogProgress(NotSpecified, "Setting LowPower default delegate to global manager");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ class Delegate
virtual ~Delegate() = default;

/**
* Get the list of supported spin_speed list.
* Fills in the provided spin_speed at index `index` if there is one,
* or returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of spin_speed.
* @param index The index of the spin_speed, with 0 representing the first one.
* @param spinSpeed The spin speed is filled.
* Get the spin speed string at the given index in the list.
* @param index The index of the spin speed, with 0 representing the first one.
* @param spinSpeed The MutableCharSpan to copy the string data into. On success, the callee must update
* the length to the length of the copied data.
* @return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of spin speeds.
*/
virtual CHIP_ERROR GetSpinSpeedAtIndex(size_t index, MutableCharSpan & spinSpeed) = 0;

/**
* Get the list of supported rinses list.
* Fills in the provided rinses at index `index` if there is one,
* or returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of rinses.
* Get the supported rinses string at the given index in the list.
* @param index The index of the supported rinses with 0 representing the first one.
* @param supportedRinse The supported rinse is filled.
* @param supportedRinse The MutableCharSpan to copy the string data into. On success, the callee must update
* the length to the length of the copied data.
* @return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of spin speeds.
*/
virtual CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse) = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ LaundryWasherControlsServer & LaundryWasherControlsServer::Instance()
return sInstance;
}

EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpointId,
DataModel::Nullable<uint8_t> newSpinSpeedCurrent)
EmberAfStatus LaundryWasherControlsServer::SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable<uint8_t> spinSpeedCurrent)
{
DataModel::Nullable<uint8_t> spinSpeedCurrent;
EmberAfStatus res = SpinSpeedCurrent::Get(endpointId, spinSpeedCurrent);
if ((res == EMBER_ZCL_STATUS_SUCCESS) && (spinSpeedCurrent != newSpinSpeedCurrent))
DataModel::Nullable<uint8_t> spinSpeedCurrentNow;
EmberAfStatus res = SpinSpeedCurrent::Get(endpointId, spinSpeedCurrentNow);
if ((res == EMBER_ZCL_STATUS_SUCCESS) && (spinSpeedCurrentNow != spinSpeedCurrent))
{
res = SpinSpeedCurrent::Set(endpointId, newSpinSpeedCurrent);
res = SpinSpeedCurrent::Set(endpointId, spinSpeedCurrent);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,51 +42,19 @@ class LaundryWasherControlsServer : public AttributeAccessInterface
* Set the default delegate of laundry washer server at endpoint x
* @param endpoint ID of the endpoint
* @param delegate The default delegate at the endpoint
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code.
*/
static void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate);

/**
* Init the laundry washer server.
* @param void
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code.
*/
// CHIP_ERROR Init();

/**
* @brief Set the attribute newSpinSpeedCurrent
*
* @param endpointId ID of the endpoint
* @param newSpinSpeedCurrent attribute SpinSpeedCurrent
* @return true on success, false on failure
*/
EmberAfStatus SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable<uint8_t> newSpinSpeedCurrent);

/**
* @brief Get the attribute newSpinSpeedCurrent
*
* @param endpointId ID of the endpoint
* @param SpinSpeedCurrent attribute SpinSpeedCurrent
* @return true on success, false on failure
* API to set/get the SpinSpeedCurrent attribute
*/
EmberAfStatus SetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable<uint8_t> spinSpeedCurrent);
EmberAfStatus GetSpinSpeedCurrent(EndpointId endpointId, DataModel::Nullable<uint8_t> & spinSpeedCurrent);

/**
* @brief Set the attribute NumberOfRinses
*
* @param endpointId ID of the endpoint
* @param newNumberOfRinses attribute NumberOfRinses
* @return true on success, false on failure
* API to set/get the NumberOfRinses attribute
*/
EmberAfStatus SetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum newNumberOfRinses);

/**
* @brief Get the attribute NumberOfRinses
*
* @param endpointId ID of the endpoint
* @param NumberOfRinses attribute NumberOfRinses
* @return true on success, false on failure
*/
EmberAfStatus GetNumberOfRinses(EndpointId endpointId, NumberOfRinsesEnum & numberOfRinses);

private:
Expand Down