Skip to content

Commit a80a11d

Browse files
committed
Start new cycle when RVC Run Mode is changed from idle to cleaning/mapping
1 parent 5fd96ed commit a80a11d

3 files changed

+39
-1
lines changed

examples/chef/common/chef-rvc-mode-delegate.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T
2929

3030
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
3131
#include <chef-rvc-mode-delegate.h>
32+
33+
#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
34+
#include <chef-rvc-operational-state-delegate.h>
35+
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
36+
3237
using namespace chip::app::Clusters::RvcRunMode;
3338

3439
static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate;
@@ -51,7 +56,35 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands:
5156
return;
5257
}
5358

59+
#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
60+
OperationalState::GenericOperationalError err(to_underlying(OperationalState::ErrorStateEnum::kNoError));
61+
if (NewMode == RvcRunMode::ModeIdle)
62+
{
63+
if (currentMode != RvcRunMode::ModeIdle)
64+
{ // Stop existing cycle when going from cleaning/mapping to idle.
65+
ChipLogProgress(DeviceLayer, "Stopping RVC cycle: %d", currentMode);
66+
gRvcOperationalStateDelegate->HandleStopStateCallback(err);
67+
}
68+
}
69+
else
70+
{
71+
if (currentMode == RvcRunMode::ModeIdle)
72+
{ // Start a new cycle when going from idle to clening/mapping.
73+
ChipLogProgress(DeviceLayer, "Starting new RVC cycle: %d", NewMode);
74+
gRvcOperationalStateDelegate->HandleStartStateCallback(err);
75+
}
76+
}
77+
if (err.IsEqual(OperationalState::GenericOperationalError(to_underlying(OperationalState::ErrorStateEnum::kNoError))))
78+
{
79+
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
80+
}
81+
else
82+
{
83+
response.status = to_underlying(ModeBase::StatusCode::kGenericFailure);
84+
}
85+
#else
5486
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
87+
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
5588
}
5689

5790
CHIP_ERROR RvcRunModeDelegate::GetModeLabelByIndex(uint8_t modeIndex, chip::MutableCharSpan & label)
@@ -296,3 +329,4 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
296329
gRvcCleanModeInstance->Init();
297330
}
298331
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
332+

examples/chef/common/chef-rvc-operational-state-delegate.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace chip::app::Clusters::OperationalState;
2828
using namespace chip::app::Clusters::RvcOperationalState;
2929
using chip::Protocols::InteractionModel::Status;
3030

31-
static std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
31+
std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
3232
static std::unique_ptr<RvcOperationalState::Instance> gRvcOperationalStateInstance;
3333

3434
static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data);
@@ -327,3 +327,4 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
327327
gRvcOperationalStateInstance->Init();
328328
}
329329
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
330+

examples/chef/common/chef-rvc-operational-state-delegate.h

+3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ void Shutdown();
121121
} // namespace app
122122
} // namespace chip
123123

124+
extern std::unique_ptr<chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
125+
124126
chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
125127
const EmberAfAttributeMetadata * attributeMetadata,
126128
uint8_t * buffer);
127129
chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
128130
const EmberAfAttributeMetadata * attributeMetadata,
129131
uint8_t * buffer, uint16_t maxReadLength);
130132
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
133+

0 commit comments

Comments
 (0)