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

[SL-UP] Add Dimmer-switch app #130

Open
wants to merge 6 commits into
base: release_2.5-1.4
Choose a base branch
from

Conversation

arun-silabs
Copy link
Contributor

JIRA : MATTER-3083

This PR adds the dimmer-switch application by extending the existing light-switch application.

The zap file of light-switch app is modified by adding level-control-cluster client. The level of the bounded lighting app can be controlled by using buttons (btn0 and btn1) or by sending commands from shell.

@arun-silabs arun-silabs changed the title Add Dimmer-switch app [SL-UP] Add Dimmer-switch app Nov 26, 2024
@arun-silabs arun-silabs marked this pull request as ready for review November 26, 2024 19:15
@arun-silabs arun-silabs requested a review from a team as a code owner November 26, 2024 19:15
@arun-silabs
Copy link
Contributor Author

Currently, the level of the bounded light app can only be changed using shell commands, the button implementation is not yet done.
Raising this PR to make dimmer-switch available by feature complete, button implementation will be done asap!

Copy link
Contributor

@mkardous-silabs mkardous-silabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR isn't ready to be merged yet. The structure of added code prevents mutliple commands of being easily supported.

We should also add more than a single level control command.

@@ -4400,29 +4400,29 @@
},
{
"id": 2,
"name": "MA-onofflightswitch",
"name": "MA-dimmablelight",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we use this is correct? it should be a dimmable light swithc iirc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is suggested in the design document that we'll make the endpoint1 type as dimmable light

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this sample app a dimmer switch or a dimmable light?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a dimmer-switch. I've named it as dimmable light as per the discussion in design page..
please let me know if it needs to be updated as dimmable light switch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside of the design page, is it logical for this device to be a dimmabe light?
Also, where in the design page does it say that the this device should be a dimmable light?

examples/light-switch-app/silabs/include/AppEvent.h Outdated Show resolved Hide resolved
Comment on lines +26 to +27
#define MIN_LEVEL 0
#define MAX_LEVEL 254
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work within the cluster functions. Level Control has two attributes that defines this. We cannot redefine arbitrary values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not add any attributes of Level Control cluster in the zap file. Since Level control cluster is added as a client(similar to On/Off cluster), i followed the same way to implement this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the level is changed by another controller? I still fail to see the usefulness of storing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the level is changed by another controller, the currentLevel attribute will store that value. I;ve declared these 2 variables just for the MIN and MAX values of level as i did not add any attributes in the level control cluster.
Let me know if i should remove this and add the cluster attributes and use them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that it doesn't make sense to hardcode these values since any light device can have a different value. You are assuming configuration and behaviors which will not work outside of a bulb with those configurations.

@@ -45,6 +48,8 @@ class LightSwitchMgr
void GenericSwitchOnShortRelease();

void TriggerLightSwitchAction(LightSwitchAction action, bool isGroupCommand = false);
void TriggerLevelControlAction(uint8_t level, bool isGroupCommand = false);
uint8_t currentLevel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to store a copy of the current level instead of using the attribute that is already persisted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add attributes to the Level Control cluster, should i include the current_level attribute of cluster and use that for storing level?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again like state in other comments, it doesn't make any sense for the light-switch to store a current level this way.

Comment on lines +146 to +147
LightSwitchMgr::GetInstance().currentLevel = mCurrentButtonState ? MAX_LEVEL : MIN_LEVEL;
LightSwitchMgr::GetInstance().TriggerLevelControlAction(LightSwitchMgr::GetInstance().currentLevel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the level of the light when turning it on or off? This doesn't seem right...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the light is Off, the level of the light is minimum.
When the light is On, the level of the light is maximum.
I'm changing the level here as it is mentioned in design doc that the level and on-off attributes will be adjusted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't integrate correctly with the level control - please check the level control implementation.

@@ -125,6 +125,20 @@ void LightSwitchMgr::TriggerLightSwitchAction(LightSwitchAction action, bool isG
DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast<intptr_t>(data));
}

void LightSwitchMgr::TriggerLevelControlAction(uint8_t level, bool isGroupCommand)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure and name of this function does not fit with the current implementation of the on off cluster commands.
The code needs to be structured in way that makes it coherent.

@@ -125,6 +125,20 @@ void LightSwitchMgr::TriggerLightSwitchAction(LightSwitchAction action, bool isG
DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast<intptr_t>(data));
}

void LightSwitchMgr::TriggerLevelControlAction(uint8_t level, bool isGroupCommand)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure of this function doesn't make it easy and straight forward to add new commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only used when button is pressed. This function will be modified with the button implementation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, please remove this function from this PR and add it when it will be used.

Comment on lines 146 to 153
if (LightSwitchMgr::GetInstance().currentLevel > MIN_LEVEL && data->level == MIN_LEVEL)
{
OffSwitchCommandHandler(0,NULL);
}
if (LightSwitchMgr::GetInstance().currentLevel == MIN_LEVEL && data->level > MIN_LEVEL)
{
OnSwitchCommandHandler(1,NULL);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make any sense. This is managed with the level control commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

As per the spec, if level is moved to MIN_LEVEL, the light should be OFF> If level is MAX_LEVEL, light should be ON. So, i've added this while handling MoveToLevel Command

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the Level Control implementation.

examples/light-switch-app/silabs/src/ShellCommands.cpp Outdated Show resolved Hide resolved
@mkardous-silabs mkardous-silabs added the sl-up This TAG indicates that this commit needs to be upstreamed to CSA before its next release. label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sl-up This TAG indicates that this commit needs to be upstreamed to CSA before its next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants