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

[Level Control] Added ability to disable transitioning and OnOff feature #23679

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ static EmberAfStatus moveToLevelHandler(EndpointId endpoint, CommandId commandId
actualStepSize = static_cast<uint8_t>(currentLevel.Value() - state->moveToLevel);
}

#ifndef IGNORE_LEVEL_CONTROL_CLUSTER_TRANSITION
// If the Transition time field takes the value null, then the time taken
// to move to the new level shall instead be determined by the On/Off
// Transition Time attribute. If On/Off Transition Time, which is an
Expand Down Expand Up @@ -723,6 +724,12 @@ static EmberAfStatus moveToLevelHandler(EndpointId endpoint, CommandId commandId
// Time) as tenths of a second, but we work in milliseconds.
state->transitionTimeMs = (transitionTimeDs.Value() * MILLISECOND_TICKS_PER_SECOND / 10);
}
#else
// Transition is not supported so always use fastest transition time and ignore
// both the provided transition time as well as OnOffTransitionTime.
emberAfLevelControlClusterPrintln("Device does not support transition, ignoring transition time");
state->transitionTimeMs = FASTEST_TRANSITION_TIME_MS;
#endif // IGNORE_LEVEL_CONTROL_CLUSTER_TRANSITION

// The duration between events will be the transition time divided by the
// distance we must move.
Expand Down Expand Up @@ -826,6 +833,7 @@ static void moveHandler(EndpointId endpoint, CommandId commandId, uint8_t moveMo
}
}

#ifndef IGNORE_LEVEL_CONTROL_CLUSTER_TRANSITION
// If the Rate field is null, the device should move at the default move rate, if available,
// Otherwise, move as fast as possible
if (rate.IsNull())
Expand All @@ -852,6 +860,12 @@ static void moveHandler(EndpointId endpoint, CommandId commandId, uint8_t moveMo
{
state->eventDurationMs = MILLISECOND_TICKS_PER_SECOND / rate.Value();
}
#else
// Transition/rate is not supported so always use fastest transition time and ignore
// both the provided transition time as well as OnOffTransitionTime.
emberAfLevelControlClusterPrintln("Device does not support transition, ignoring rate");
state->eventDurationMs = FASTEST_TRANSITION_TIME_MS;
#endif // IGNORE_LEVEL_CONTROL_CLUSTER_TRANSITION

state->transitionTimeMs = difference * state->eventDurationMs;
state->elapsedTimeMs = 0;
Expand Down Expand Up @@ -959,6 +973,7 @@ static void stepHandler(EndpointId endpoint, CommandId commandId, uint8_t stepMo
}
}

#ifndef IGNORE_LEVEL_CONTROL_CLUSTER_TRANSITION
// If the Transition Time field is null, the device should move as fast as
// it is able.
if (transitionTimeDs.IsNull())
Expand All @@ -978,6 +993,12 @@ static void stepHandler(EndpointId endpoint, CommandId commandId, uint8_t stepMo
state->transitionTimeMs = (state->transitionTimeMs * actualStepSize / stepSize);
}
}
#else
// Transition is not supported so always use fastest transition time and ignore
// both the provided transition time as well as OnOffTransitionTime.
emberAfLevelControlClusterPrintln("Device does not support transition, ignoring transition time");
state->transitionTimeMs = FASTEST_TRANSITION_TIME_MS;
#endif // IGNORE_LEVEL_CONTROL_CLUSTER_TRANSITION

// The duration between events will be the transition time divided by the
// distance we must move.
Expand Down Expand Up @@ -1042,6 +1063,13 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new
return;
}

// if the OnOff feature is not supported, the effect on LevelControl is ignored
if (!HasFeature(endpoint, chip::app::Clusters::LevelControl::LevelControlFeature::kOnOff))
{
emberAfLevelControlClusterPrintln("OnOff feature not supported, ignore LevelControlEffect");
return;
}

uint8_t minimumLevelAllowedForTheDevice = state->minLevel;

// "Temporarily store CurrentLevel."
Expand Down Expand Up @@ -1255,4 +1283,13 @@ static bool areStartUpLevelControlServerAttributesNonVolatile(EndpointId endpoin

void emberAfPluginLevelControlClusterServerPostInitCallback(EndpointId endpoint) {}

bool HasFeature(chip::EndpointId endpoint, chip::app::Clusters::LevelControl::LevelControlFeature feature)
{
bool success;
uint32_t featureMap;
success = (Attributes::FeatureMap::Get(endpoint, &featureMap) == EMBER_ZCL_STATUS_SUCCESS);

return success ? ((featureMap & to_underlying(feature)) != 0) : false;
}

void MatterLevelControlPluginServerInitCallback() {}
3 changes: 3 additions & 0 deletions src/app/clusters/level-control/level-control.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <stdint.h>

#include <app-common/zap-generated/cluster-objects.h>
#include <app/util/basic-types.h>

/** @brief On/off Cluster Server Post Init
Expand All @@ -36,3 +37,5 @@
* @param endpoint Endpoint that is being initialized Ver.: always
*/
void emberAfPluginLevelControlClusterServerPostInitCallback(chip::EndpointId endpoint);

bool HasFeature(chip::EndpointId endpoint, chip::app::Clusters::LevelControl::LevelControlFeature feature);