Skip to content

Commit

Permalink
Add set Mode in each mode base clusters (#28827)
Browse files Browse the repository at this point in the history
* Add set Mode in each modebase clusters

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 12, 2023
1 parent f2c6c84 commit 1012272
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class DishwasherModeDelegate : public ModeBase::Delegate
~DishwasherModeDelegate() override = default;
};

ModeBase::Instance * Instance();

void Shutdown();

} // namespace DishwasherMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class LaundryWasherModeDelegate : public ModeBase::Delegate
~LaundryWasherModeDelegate() override = default;
};

ModeBase::Instance * Instance();

void Shutdown();

} // namespace LaundryWasherMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class RvcRunModeDelegate : public ModeBase::Delegate
~RvcRunModeDelegate() override = default;
};

ModeBase::Instance * Instance();

void Shutdown();

} // namespace RvcRunMode
Expand Down Expand Up @@ -109,6 +111,8 @@ class RvcCleanModeDelegate : public ModeBase::Delegate
~RvcCleanModeDelegate() override = default;
};

ModeBase::Instance * Instance();

void Shutdown();

} // namespace RvcCleanMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ CHIP_ERROR DishwasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mo
return CHIP_NO_ERROR;
}

ModeBase::Instance * DishwasherMode::Instance()
{
return gDishwasherModeInstance;
}

void DishwasherMode::Shutdown()
{
if (gDishwasherModeInstance != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ CHIP_ERROR LaundryWasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List
return CHIP_NO_ERROR;
}

ModeBase::Instance * LaundryWasherMode::Instance()
{
return gLaundryWasherModeInstance;
}

void LaundryWasherMode::Shutdown()
{
if (gLaundryWasherModeInstance != nullptr)
Expand Down
10 changes: 10 additions & 0 deletions examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTa
return CHIP_NO_ERROR;
}

ModeBase::Instance * RvcRunMode::Instance()
{
return gRvcRunModeInstance;
}

void RvcRunMode::Shutdown()
{
if (gRvcRunModeInstance != nullptr)
Expand Down Expand Up @@ -172,6 +177,11 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mode
return CHIP_NO_ERROR;
}

ModeBase::Instance * RvcCleanMode::Instance()
{
return gRvcCleanModeInstance;
}

void RvcCleanMode::Shutdown()
{
if (gRvcCleanModeInstance != nullptr)
Expand Down
70 changes: 70 additions & 0 deletions examples/all-clusters-app/linux/AllClustersCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <app/server/Server.h>
#include <platform/PlatformManager.h>

#include <dishwasher-mode.h>
#include <laundry-washer-mode.h>
#include <rvc-modes.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
Expand Down Expand Up @@ -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<uint8_t> mode;
if (!jsonMode.isNull())
{
mode = MakeNullable(static_cast<uint8_t>(jsonMode.asUInt()));
}
else
{
mode.SetNull();
}
self->OnModeChangeHandler(device, type, mode);
}
else
{
ChipLogError(NotSpecified, "Unhandled command: Should never happens");
Expand Down Expand Up @@ -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<uint8_t> 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);
Expand Down
5 changes: 5 additions & 0 deletions examples/all-clusters-app/linux/AllClustersCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> mode);
};

class AllClustersCommandDelegate : public NamedPipeCommandDelegate
Expand Down

0 comments on commit 1012272

Please sign in to comment.