From 101227203ba55dbd3fec97b3cc236c11e889324f Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Fri, 25 Aug 2023 22:05:59 +0900 Subject: [PATCH] Add set Mode in each mode base clusters (#28827) * Add set Mode in each modebase clusters * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../include/dishwasher-mode.h | 2 + .../include/laundry-washer-mode.h | 2 + .../all-clusters-common/include/rvc-modes.h | 4 ++ .../src/dishwasher-mode.cpp | 5 ++ .../src/laundry-washer-mode.cpp | 5 ++ .../all-clusters-common/src/rvc-modes.cpp | 10 +++ .../linux/AllClustersCommandDelegate.cpp | 70 +++++++++++++++++++ .../linux/AllClustersCommandDelegate.h | 5 ++ 8 files changed, 103 insertions(+) diff --git a/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h b/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h index 54d78c56b23132..b05b92dcba21e8 100644 --- a/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h +++ b/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h @@ -69,6 +69,8 @@ class DishwasherModeDelegate : public ModeBase::Delegate ~DishwasherModeDelegate() override = default; }; +ModeBase::Instance * Instance(); + void Shutdown(); } // namespace DishwasherMode diff --git a/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h b/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h index f8acce69295f46..4c935a9d43ab61 100644 --- a/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h +++ b/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h @@ -74,6 +74,8 @@ class LaundryWasherModeDelegate : public ModeBase::Delegate ~LaundryWasherModeDelegate() override = default; }; +ModeBase::Instance * Instance(); + void Shutdown(); } // namespace LaundryWasherMode diff --git a/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h b/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h index b8e7e13cf2c6ee..af8313fa285385 100644 --- a/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h +++ b/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h @@ -66,6 +66,8 @@ class RvcRunModeDelegate : public ModeBase::Delegate ~RvcRunModeDelegate() override = default; }; +ModeBase::Instance * Instance(); + void Shutdown(); } // namespace RvcRunMode @@ -109,6 +111,8 @@ class RvcCleanModeDelegate : public ModeBase::Delegate ~RvcCleanModeDelegate() override = default; }; +ModeBase::Instance * Instance(); + void Shutdown(); } // namespace RvcCleanMode diff --git a/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp index 65de4f9dc6e85e..607bb5578787f2 100644 --- a/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp @@ -76,6 +76,11 @@ CHIP_ERROR DishwasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List #include +#include +#include +#include + using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; @@ -143,6 +147,23 @@ void AllClustersAppCommandHandler::HandleCommand(intptr_t context) { self->OnRebootSignalHandler(BootReasonType::kSoftwareReset); } + else if (name == "ModeChange") + { + using chip::app::DataModel::MakeNullable; + std::string device = self->mJsonValue["Device"].asString(); + std::string type = self->mJsonValue["Type"].asString(); + Json::Value jsonMode = self->mJsonValue["Mode"]; + DataModel::Nullable mode; + if (!jsonMode.isNull()) + { + mode = MakeNullable(static_cast(jsonMode.asUInt())); + } + else + { + mode.SetNull(); + } + self->OnModeChangeHandler(device, type, mode); + } else { ChipLogError(NotSpecified, "Unhandled command: Should never happens"); @@ -344,6 +365,55 @@ void AllClustersAppCommandHandler::OnSwitchMultiPressCompleteHandler(uint8_t pre Clusters::SwitchServer::Instance().OnMultiPressComplete(endpoint, previousPosition, count); } +void AllClustersAppCommandHandler::OnModeChangeHandler(std::string device, std::string type, DataModel::Nullable mode) +{ + ModeBase::Instance * modeInstance = nullptr; + if (device == "DishWasher") + { + modeInstance = DishwasherMode::Instance(); + } + else if (device == "LaundryWasher") + { + modeInstance = LaundryWasherMode::Instance(); + } + else if (device == "RvcClean") + { + modeInstance = RvcCleanMode::Instance(); + } + else if (device == "RvcRun") + { + modeInstance = RvcRunMode::Instance(); + } + else + { + ChipLogDetail(NotSpecified, "Invalid device type : %s", device.c_str()); + return; + } + + if (type == "Current") + { + if (mode.IsNull()) + { + ChipLogDetail(NotSpecified, "Invalid value : null"); + return; + } + modeInstance->UpdateCurrentMode(mode.Value()); + } + else if (type == "StartUp") + { + modeInstance->UpdateStartUpMode(mode); + } + else if (type == "On") + { + modeInstance->UpdateOnMode(mode); + } + else + { + ChipLogDetail(NotSpecified, "Invalid mode type : %s", type.c_str()); + return; + } +} + void AllClustersCommandDelegate::OnEventCommandReceived(const char * json) { auto handler = AllClustersAppCommandHandler::FromJSON(json); diff --git a/examples/all-clusters-app/linux/AllClustersCommandDelegate.h b/examples/all-clusters-app/linux/AllClustersCommandDelegate.h index 2036084a2fcc9b..20b2ab731b75d3 100644 --- a/examples/all-clusters-app/linux/AllClustersCommandDelegate.h +++ b/examples/all-clusters-app/linux/AllClustersCommandDelegate.h @@ -88,6 +88,11 @@ class AllClustersAppCommandHandler * sequence, after it has been detected that the sequence has ended. */ void OnSwitchMultiPressCompleteHandler(uint8_t previousPosition, uint8_t count); + + /** + * Should be called when it is necessary to change the mode to manual operation. + */ + void OnModeChangeHandler(std::string device, std::string type, chip::app::DataModel::Nullable mode); }; class AllClustersCommandDelegate : public NamedPipeCommandDelegate