diff --git a/examples/all-clusters-app/all-clusters-common/include/laundry-washer-controls-delegate-impl.h b/examples/all-clusters-app/all-clusters-common/include/laundry-washer-controls-delegate-impl.h new file mode 100644 index 00000000000000..15a72482726ba0 --- /dev/null +++ b/examples/all-clusters-app/all-clusters-common/include/laundry-washer-controls-delegate-impl.h @@ -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 define 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() = default; + ~LaundryWasherControlDelegate() = default; + + static inline LaundryWasherControlDelegate & getLaundryWasherControlDelegate() { return instance; } +}; + +} // namespace LaundryWasherControls +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp b/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp new file mode 100644 index 00000000000000..6c70ef98cb4736 --- /dev/null +++ b/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp @@ -0,0 +1,56 @@ +/* + * + * 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. + */ +#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 chip; +using namespace chip::app::Clusters::LaundryWasherControls; + +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; +} diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 72cd65ba55bc9e..766b482e5a4600 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -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", diff --git a/examples/all-clusters-app/linux/main-common.cpp b/examples/all-clusters-app/linux/main-common.cpp index 727bddb955056b..71e86397ce7120 100644 --- a/examples/all-clusters-app/linux/main-common.cpp +++ b/examples/all-clusters-app/linux/main-common.cpp @@ -20,6 +20,7 @@ #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" @@ -27,6 +28,7 @@ #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> @@ -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"); diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h index 5529413a40cb88..c90923c775e5f3 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-delegate.h @@ -35,20 +35,19 @@ 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 value 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 supported rinse at the given index + * @return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of supported rinses. */ virtual CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse) = 0; }; diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp index 76832e4c091eb8..f7cb0cd06d42a6 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.cpp @@ -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; diff --git a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h index ac9b4ca0b7f209..f01069135b3e7c 100644 --- a/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h +++ b/src/app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h @@ -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: