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

Make robotic vacuum cleaner spec compliant #37718

Merged
merged 9 commits into from
Feb 24, 2025
35 changes: 34 additions & 1 deletion examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T

#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>

#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
#include <chef-rvc-operational-state-delegate.h>
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER

using namespace chip::app::Clusters::RvcRunMode;

static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate;
static std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;
std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;

CHIP_ERROR RvcRunModeDelegate::Init()
{
Expand All @@ -51,7 +56,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);
gRvcOperationalStateDelegate->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);
gRvcOperationalStateDelegate->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)
Expand Down
2 changes: 2 additions & 0 deletions examples/chef/common/chef-rvc-mode-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void Shutdown();
} // namespace chip

#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
extern std::unique_ptr<chip::app::Clusters::ModeBase::Instance> gRvcRunModeInstance;

chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
Expand Down
15 changes: 14 additions & 1 deletion examples/chef/common/chef-rvc-operational-state-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ using namespace chip::app::Clusters::OperationalState;
using namespace chip::app::Clusters::RvcOperationalState;
using chip::Protocols::InteractionModel::Status;

static std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER

std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
static std::unique_ptr<RvcOperationalState::Instance> gRvcOperationalStateInstance;

static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data);
Expand Down Expand Up @@ -176,6 +180,11 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
OperationalState::OperationalStateEnum state =
static_cast<OperationalState::OperationalStateEnum>(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)
Expand Down Expand Up @@ -223,6 +232,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
gRvcRunModeInstance->UpdateCurrentMode(RvcRunMode::ModeIdle);
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions examples/chef/common/chef-rvc-operational-state-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void Shutdown();
} // namespace app
} // namespace chip

extern std::unique_ptr<chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate> gRvcOperationalStateDelegate;

chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
Expand Down
Loading