diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index f6c10412812dea..b275d08e21d474 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -29,11 +29,21 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER #include + +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER +#include +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + using namespace chip::app::Clusters::RvcRunMode; static std::unique_ptr gRvcRunModeDelegate; static std::unique_ptr gRvcRunModeInstance; +chip::app::Clusters::ModeBase::Instance * getRvcRunModeInstance() +{ + return gRvcRunModeInstance.get(); +} + CHIP_ERROR RvcRunModeDelegate::Init() { return CHIP_NO_ERROR; @@ -51,7 +61,35 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands: return; } +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + OperationalState::GenericOperationalError err(to_underlying(OperationalState::ErrorStateEnum::kNoError)); + if (NewMode == RvcRunMode::ModeIdle) + { + if (currentMode != RvcRunMode::ModeIdle) + { // Stop existing cycle when going from cleaning/mapping to idle. + ChipLogProgress(DeviceLayer, "Stopping RVC cycle: %d", currentMode); + getRvcOperationalStateDelegate()->HandleStopStateCallback(err); + } + } + else + { + if (currentMode == RvcRunMode::ModeIdle) + { // Start a new cycle when going from idle to clening/mapping. + ChipLogProgress(DeviceLayer, "Starting new RVC cycle: %d", NewMode); + getRvcOperationalStateDelegate()->HandleStartStateCallback(err); + } + } + if (err.IsEqual(OperationalState::GenericOperationalError(to_underlying(OperationalState::ErrorStateEnum::kNoError)))) + { + response.status = to_underlying(ModeBase::StatusCode::kSuccess); + } + else + { + response.status = to_underlying(ModeBase::StatusCode::kGenericFailure); + } +#else response.status = to_underlying(ModeBase::StatusCode::kSuccess); +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER } CHIP_ERROR RvcRunModeDelegate::GetModeLabelByIndex(uint8_t modeIndex, chip::MutableCharSpan & label) diff --git a/examples/chef/common/chef-rvc-mode-delegate.h b/examples/chef/common/chef-rvc-mode-delegate.h index 359c90c5a08162..f5b155cd718b79 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -42,6 +42,7 @@ class RvcRunModeDelegate : public ModeBase::Delegate using ModeTagStructType = detail::Structs::ModeTagStruct::Type; ModeTagStructType ModeTagsIdle[1] = { { .value = to_underlying(ModeTag::kIdle) } }; ModeTagStructType ModeTagsCleaning[1] = { { .value = to_underlying(ModeTag::kCleaning) } }; + ModeTagStructType ModeTagsMapping[1] = { { .value = to_underlying(ModeTag::kMapping) } }; const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = { detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Idle"), @@ -52,7 +53,7 @@ class RvcRunModeDelegate : public ModeBase::Delegate .modeTags = DataModel::List(ModeTagsCleaning) }, detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Mapping"), .mode = ModeMapping, - .modeTags = DataModel::List(ModeTagsIdle) }, + .modeTags = DataModel::List(ModeTagsMapping) }, }; CHIP_ERROR Init() override; @@ -122,6 +123,8 @@ void Shutdown(); } // namespace chip #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER +chip::app::Clusters::ModeBase::Instance * getRvcRunModeInstance(); + chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 9b4118732ee165..1a1cf0696c2074 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -28,9 +28,18 @@ using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::RvcOperationalState; using chip::Protocols::InteractionModel::Status; +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER +#include +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + static std::unique_ptr gRvcOperationalStateDelegate; static std::unique_ptr gRvcOperationalStateInstance; +RvcOperationalStateDelegate * getRvcOperationalStateDelegate() +{ + return gRvcOperationalStateDelegate.get(); +} + static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data); DataModel::Nullable RvcOperationalStateDelegate::GetCountdownTime() @@ -176,6 +185,11 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data OperationalState::OperationalStateEnum state = static_cast(instance->GetCurrentOperationalState()); + if (state == OperationalState::OperationalStateEnum::kStopped) // Do not continue the timer when RVC has stopped. + { + return; + } + if (gRvcOperationalStateDelegate->mCountdownTime.IsNull()) { if (state == OperationalState::OperationalStateEnum::kRunning) @@ -223,6 +237,10 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data gRvcOperationalStateDelegate->mRunningTime = 0; gRvcOperationalStateDelegate->mPausedTime = 0; gRvcOperationalStateDelegate->mCountdownTime.SetNull(); + +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + getRvcRunModeInstance()->UpdateCurrentMode(RvcRunMode::ModeIdle); +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER } } } diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.h b/examples/chef/common/chef-rvc-operational-state-delegate.h index f56b7979f3c1c3..d551182787dc36 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -122,6 +122,8 @@ void Shutdown(); } // namespace app } // namespace chip +chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate * getRvcOperationalStateDelegate(); + chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer);