Skip to content

Commit

Permalink
Remove BarrierControlBarrierPosition and BarrierControlMovingState (
Browse files Browse the repository at this point in the history
#30523)

* Remove BarrierControlBarrierPosition and BarrierControlMovingState from the ember enum classes

* Make things compile

* Restyle

* Update comment text a bit to be more user friendly.

* Remove some static casts to make code nicer

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 19, 2024
1 parent 2867b71 commit c9ca2a5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 45 deletions.
54 changes: 39 additions & 15 deletions src/app/clusters/barrier-control-server/barrier-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ using namespace chip::app::Clusters;
using namespace chip::app::Clusters::BarrierControl;
using chip::Protocols::InteractionModel::Status;

// this is NOT in any spec (CHIP spec does not currently have BarrierControl)
// and XMLs do not attach these enums to clusters.
//
// This directly defines some constants. These could be replaced with real
// constants if we ever have some BarrierControl in the matter specification.
namespace chip {
namespace app {
namespace Clusters {
namespace BarrierControl {

namespace Position {
static constexpr uint8_t kClosed = 0;
static constexpr uint8_t kOpen = 100;
static constexpr uint8_t kUnknown = 255;
} // namespace Position

namespace MovingState {
static constexpr uint8_t kStopped = 0;
static constexpr uint8_t kClosing = 1;
static constexpr uint8_t kOpening = 2;
} // namespace MovingState

} // namespace BarrierControl
} // namespace Clusters
} // namespace app
} // namespace chip

typedef struct
{
uint8_t currentPosition;
Expand Down Expand Up @@ -220,9 +247,8 @@ static uint8_t getCurrentPosition(EndpointId endpoint)
// way of knowing the position of the barrier. Let's guess that the barrier is
// open so that we don't leave the barrier open when it should be closed.
uint8_t currentPositionFromAttribute = emAfPluginBarrierControlServerGetBarrierPosition(endpoint);
return ((currentPositionFromAttribute == EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN)
? static_cast<uint8_t>(EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN)
: currentPositionFromAttribute);
return ((currentPositionFromAttribute == BarrierControl::Position::kUnknown) ? BarrierControl::Position::kOpen
: currentPositionFromAttribute);
}

static uint32_t calculateDelayMs(EndpointId endpoint, uint8_t targetPosition, bool * opening)
Expand All @@ -249,7 +275,7 @@ void emberAfBarrierControlClusterServerTickCallback(EndpointId endpoint)
if (state.currentPosition == state.targetPosition)
{
emAfPluginBarrierControlServerSetBarrierPosition(endpoint, state.currentPosition);
setMovingState(endpoint, EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_STOPPED);
setMovingState(endpoint, BarrierControl::MovingState::kStopped);
cancelEndpointTimerCallback(endpoint);
}
else
Expand All @@ -270,14 +296,13 @@ void emberAfBarrierControlClusterServerTickCallback(EndpointId endpoint)
emAfPluginBarrierControlServerIncrementEvents(endpoint, false, false);
}
}
emAfPluginBarrierControlServerSetBarrierPosition(
endpoint,
(emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint)
? state.currentPosition
: static_cast<uint8_t>(EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN)));
setMovingState(
endpoint,
(state.increasing ? EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_OPENING : EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_CLOSING));
emAfPluginBarrierControlServerSetBarrierPosition(endpoint,
(emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint)
? state.currentPosition
: BarrierControl::Position::kUnknown));
setMovingState(endpoint,
(state.increasing ? BarrierControl::MovingState::kOpening : BarrierControl::MovingState::kClosing));

scheduleTimerCallbackMs(endpoint, state.delayMs);
}
}
Expand Down Expand Up @@ -307,8 +332,7 @@ bool emberAfBarrierControlClusterBarrierControlGoToPercentCallback(
}
else if (percentOpen > 100 // "100" means "100%", so greater than that is invalid
|| (!emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint) &&
percentOpen != EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_CLOSED &&
percentOpen != EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN))
percentOpen != BarrierControl::Position::kClosed && percentOpen != BarrierControl::Position::kOpen))
{
status = Status::ConstraintError;
}
Expand Down Expand Up @@ -342,7 +366,7 @@ bool emberAfBarrierControlClusterBarrierControlStopCallback(app::CommandHandler
{
EndpointId endpoint = commandPath.mEndpointId;
cancelEndpointTimerCallback(endpoint);
setMovingState(endpoint, EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_STOPPED);
setMovingState(endpoint, BarrierControl::MovingState::kStopped);
sendDefaultResponse(commandObj, commandPath, Status::Success);
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ DarwinForceWritable:
WeakEnums:
# Allow-list of enums that we generate as enums, not enum classes.
# The goal is to drive this down to 0.
- BarrierControlBarrierPosition
- BarrierControlMovingState
- ColorControlOptions
- ColorMode
- EnhancedColorMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ limitations under the License.
<field name="positionFailure" mask="0x08"/>
</bitmap>

<enum name="BarrierControlBarrierPosition" type="int8u">
<item name="Closed" value="0"/>
<item name="Open" value="100"/>
<item name="Unknown" value="0xFF"/>
</enum>

<enum name="BarrierControlMovingState" type="enum8">
<item name="Stopped" value="0x00"/>
<item name="Closing" value="0x01"/>
<item name="Opening" value="0x02"/>
</enum>

<cluster>
<name>Barrier Control</name>
<domain>Closures</domain>
Expand Down
16 changes: 0 additions & 16 deletions zzz_generated/app-common/app-common/zap-generated/enums.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9ca2a5

Please sign in to comment.