Skip to content

Commit

Permalink
Updated the RVC example app to appropriatly handel the RvcOpState Pas…
Browse files Browse the repository at this point in the history
…ue and Resume commands for the new pause and resume compatible states.
  • Loading branch information
hicklin committed Dec 12, 2023
1 parent cce6c24 commit 9768632
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/rvc-app/rvc-common/include/rvc-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class RvcDevice
bool mDocked = false;
bool mCharging = false;

uint8_t mPausedState = 0;

public:
/**
* This class is responsible for initialising all the RVC clusters and manging the interactions between them as required by
Expand Down
33 changes: 32 additions & 1 deletion examples/rvc-app/rvc-common/src/rvc-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ void RvcDevice::HandleRvcCleanChangeToMode(uint8_t newMode, ModeBase::Commands::

void RvcDevice::HandleOpStatePauseCallback(Clusters::OperationalState::GenericOperationalError & err)
{
uint8_t tmpPausedState = mOperationalStateInstance.GetCurrentOperationalState();
auto error = mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
if (error == CHIP_NO_ERROR)
{
mPausedState = tmpPausedState;
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
}
else
Expand All @@ -104,7 +106,36 @@ void RvcDevice::HandleOpStatePauseCallback(Clusters::OperationalState::GenericOp

void RvcDevice::HandleOpStateResumeCallback(Clusters::OperationalState::GenericOperationalError & err)
{
auto error = mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
auto error = CHIP_NO_ERROR;
switch (mOperationalStateInstance.GetCurrentOperationalState())
{
case to_underlying(RvcOperationalState::OperationalStateEnum::kCharging):
case to_underlying(RvcOperationalState::OperationalStateEnum::kDocked):
{
if (mRunModeInstance.GetCurrentMode() == RvcRunMode::ModeCleaning || mRunModeInstance.GetCurrentMode() == RvcRunMode::ModeMapping) {
error = mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
}
else
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState));
return;
}
}
break;
case to_underlying(OperationalState::OperationalStateEnum::kPaused):
{
if (mPausedState == to_underlying(RvcOperationalState::OperationalStateEnum::kSeekingCharger)) {
error = mOperationalStateInstance.SetOperationalState(to_underlying(RvcOperationalState::OperationalStateEnum::kSeekingCharger));
}
else
{
error = mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
}
}
break;
}

// populate the response.
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
Expand Down

0 comments on commit 9768632

Please sign in to comment.