Skip to content

Commit bdc569b

Browse files
Adding the level control to light switch and changing to dimmer switch (#37448)
* Moving the light switch app to dimmer switch app * adding the btn to light switch to control the level via switch * restyling the PR * restyling the PR with new line * fixing the build * restyling the PR * restyling the PR
1 parent af19062 commit bdc569b

11 files changed

+1512
-89
lines changed

examples/light-switch-app/light-switch-common/light-switch-app.matter

+127-1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,131 @@ cluster OnOff = 6 {
490490
command OnWithTimedOff(OnWithTimedOffRequest): DefaultSuccess = 66;
491491
}
492492

493+
/** Attributes and commands for controlling devices that can be set to a level between fully 'On' and fully 'Off.' */
494+
cluster LevelControl = 8 {
495+
revision 6;
496+
497+
enum MoveModeEnum : enum8 {
498+
kUp = 0;
499+
kDown = 1;
500+
}
501+
502+
enum StepModeEnum : enum8 {
503+
kUp = 0;
504+
kDown = 1;
505+
}
506+
507+
bitmap Feature : bitmap32 {
508+
kOnOff = 0x1;
509+
kLighting = 0x2;
510+
kFrequency = 0x4;
511+
}
512+
513+
bitmap OptionsBitmap : bitmap8 {
514+
kExecuteIfOff = 0x1;
515+
kCoupleColorTempToLevel = 0x2;
516+
}
517+
518+
readonly attribute nullable int8u currentLevel = 0;
519+
readonly attribute optional int16u remainingTime = 1;
520+
readonly attribute optional int8u minLevel = 2;
521+
readonly attribute optional int8u maxLevel = 3;
522+
readonly attribute optional int16u currentFrequency = 4;
523+
readonly attribute optional int16u minFrequency = 5;
524+
readonly attribute optional int16u maxFrequency = 6;
525+
attribute OptionsBitmap options = 15;
526+
attribute optional int16u onOffTransitionTime = 16;
527+
attribute nullable int8u onLevel = 17;
528+
attribute optional nullable int16u onTransitionTime = 18;
529+
attribute optional nullable int16u offTransitionTime = 19;
530+
attribute optional nullable int8u defaultMoveRate = 20;
531+
attribute access(write: manage) optional nullable int8u startUpCurrentLevel = 16384;
532+
readonly attribute command_id generatedCommandList[] = 65528;
533+
readonly attribute command_id acceptedCommandList[] = 65529;
534+
readonly attribute event_id eventList[] = 65530;
535+
readonly attribute attrib_id attributeList[] = 65531;
536+
readonly attribute bitmap32 featureMap = 65532;
537+
readonly attribute int16u clusterRevision = 65533;
538+
539+
request struct MoveToLevelRequest {
540+
int8u level = 0;
541+
nullable int16u transitionTime = 1;
542+
OptionsBitmap optionsMask = 2;
543+
OptionsBitmap optionsOverride = 3;
544+
}
545+
546+
request struct MoveRequest {
547+
MoveModeEnum moveMode = 0;
548+
nullable int8u rate = 1;
549+
OptionsBitmap optionsMask = 2;
550+
OptionsBitmap optionsOverride = 3;
551+
}
552+
553+
request struct StepRequest {
554+
StepModeEnum stepMode = 0;
555+
int8u stepSize = 1;
556+
nullable int16u transitionTime = 2;
557+
OptionsBitmap optionsMask = 3;
558+
OptionsBitmap optionsOverride = 4;
559+
}
560+
561+
request struct StopRequest {
562+
OptionsBitmap optionsMask = 0;
563+
OptionsBitmap optionsOverride = 1;
564+
}
565+
566+
request struct MoveToLevelWithOnOffRequest {
567+
int8u level = 0;
568+
nullable int16u transitionTime = 1;
569+
OptionsBitmap optionsMask = 2;
570+
OptionsBitmap optionsOverride = 3;
571+
}
572+
573+
request struct MoveWithOnOffRequest {
574+
MoveModeEnum moveMode = 0;
575+
nullable int8u rate = 1;
576+
OptionsBitmap optionsMask = 2;
577+
OptionsBitmap optionsOverride = 3;
578+
}
579+
580+
request struct StepWithOnOffRequest {
581+
StepModeEnum stepMode = 0;
582+
int8u stepSize = 1;
583+
nullable int16u transitionTime = 2;
584+
OptionsBitmap optionsMask = 3;
585+
OptionsBitmap optionsOverride = 4;
586+
}
587+
588+
request struct StopWithOnOffRequest {
589+
OptionsBitmap optionsMask = 0;
590+
OptionsBitmap optionsOverride = 1;
591+
}
592+
593+
request struct MoveToClosestFrequencyRequest {
594+
int16u frequency = 0;
595+
}
596+
597+
/** Command description for MoveToLevel */
598+
command MoveToLevel(MoveToLevelRequest): DefaultSuccess = 0;
599+
/** Command description for Move */
600+
command Move(MoveRequest): DefaultSuccess = 1;
601+
/** Command description for Step */
602+
command Step(StepRequest): DefaultSuccess = 2;
603+
/** Command description for Stop */
604+
command Stop(StopRequest): DefaultSuccess = 3;
605+
/** Command description for MoveToLevelWithOnOff */
606+
command MoveToLevelWithOnOff(MoveToLevelWithOnOffRequest): DefaultSuccess = 4;
607+
/** Command description for MoveWithOnOff */
608+
command MoveWithOnOff(MoveWithOnOffRequest): DefaultSuccess = 5;
609+
/** Command description for StepWithOnOff */
610+
command StepWithOnOff(StepWithOnOffRequest): DefaultSuccess = 6;
611+
/** Command description for StopWithOnOff */
612+
command StopWithOnOff(StopWithOnOffRequest): DefaultSuccess = 7;
613+
/** Change the currrent frequency to the provided one, or a close
614+
approximation if the exact provided one is not possible. */
615+
command MoveToClosestFrequency(MoveToClosestFrequencyRequest): DefaultSuccess = 8;
616+
}
617+
493618
/** The Descriptor Cluster is meant to replace the support from the Zigbee Device Object (ZDO) for describing a node, its endpoints and clusters. */
494619
cluster Descriptor = 29 {
495620
revision 2;
@@ -3158,10 +3283,11 @@ endpoint 0 {
31583283
}
31593284
}
31603285
endpoint 1 {
3161-
device type ma_onofflightswitch = 259, version 1;
3286+
device type ma_dimmerswitch = 260, version 1;
31623287

31633288
binding cluster Identify;
31643289
binding cluster OnOff;
3290+
binding cluster LevelControl;
31653291
binding cluster ScenesManagement;
31663292
binding cluster ColorControl;
31673293

examples/light-switch-app/light-switch-common/light-switch-app.zap

+85-11
Original file line numberDiff line numberDiff line change
@@ -4402,31 +4402,31 @@
44024402
},
44034403
{
44044404
"id": 2,
4405-
"name": "MA-onofflightswitch",
4405+
"name": "MA-dimmerswitch",
44064406
"deviceTypeRef": {
4407-
"code": 259,
4407+
"code": 260,
44084408
"profileId": 259,
4409-
"label": "MA-onofflightswitch",
4410-
"name": "MA-onofflightswitch",
4409+
"label": "MA-dimmerswitch",
4410+
"name": "MA-dimmerswitch",
44114411
"deviceTypeOrder": 0
44124412
},
44134413
"deviceTypes": [
44144414
{
4415-
"code": 259,
4415+
"code": 260,
44164416
"profileId": 259,
4417-
"label": "MA-onofflightswitch",
4418-
"name": "MA-onofflightswitch",
4417+
"label": "MA-dimmerswitch",
4418+
"name": "MA-dimmerswitch",
44194419
"deviceTypeOrder": 0
44204420
}
44214421
],
44224422
"deviceVersions": [
44234423
1
44244424
],
44254425
"deviceIdentifiers": [
4426-
259
4426+
260
44274427
],
4428-
"deviceTypeName": "MA-onofflightswitch",
4429-
"deviceTypeCode": 259,
4428+
"deviceTypeName": "MA-dimmerswitch",
4429+
"deviceTypeCode": 260,
44304430
"deviceTypeProfileId": 259,
44314431
"clusters": [
44324432
{
@@ -4737,6 +4737,80 @@
47374737
}
47384738
]
47394739
},
4740+
{
4741+
"name": "Level Control",
4742+
"code": 8,
4743+
"mfgCode": null,
4744+
"define": "LEVEL_CONTROL_CLUSTER",
4745+
"side": "client",
4746+
"enabled": 1,
4747+
"commands": [
4748+
{
4749+
"name": "MoveToLevel",
4750+
"code": 0,
4751+
"mfgCode": null,
4752+
"source": "client",
4753+
"isIncoming": 0,
4754+
"isEnabled": 1
4755+
},
4756+
{
4757+
"name": "Move",
4758+
"code": 1,
4759+
"mfgCode": null,
4760+
"source": "client",
4761+
"isIncoming": 0,
4762+
"isEnabled": 1
4763+
},
4764+
{
4765+
"name": "Step",
4766+
"code": 2,
4767+
"mfgCode": null,
4768+
"source": "client",
4769+
"isIncoming": 0,
4770+
"isEnabled": 1
4771+
},
4772+
{
4773+
"name": "Stop",
4774+
"code": 3,
4775+
"mfgCode": null,
4776+
"source": "client",
4777+
"isIncoming": 0,
4778+
"isEnabled": 1
4779+
},
4780+
{
4781+
"name": "MoveToLevelWithOnOff",
4782+
"code": 4,
4783+
"mfgCode": null,
4784+
"source": "client",
4785+
"isIncoming": 0,
4786+
"isEnabled": 1
4787+
},
4788+
{
4789+
"name": "MoveWithOnOff",
4790+
"code": 5,
4791+
"mfgCode": null,
4792+
"source": "client",
4793+
"isIncoming": 0,
4794+
"isEnabled": 1
4795+
},
4796+
{
4797+
"name": "StepWithOnOff",
4798+
"code": 6,
4799+
"mfgCode": null,
4800+
"source": "client",
4801+
"isIncoming": 0,
4802+
"isEnabled": 1
4803+
},
4804+
{
4805+
"name": "StopWithOnOff",
4806+
"code": 7,
4807+
"mfgCode": null,
4808+
"source": "client",
4809+
"isIncoming": 0,
4810+
"isEnabled": 1
4811+
}
4812+
]
4813+
},
47404814
{
47414815
"name": "Descriptor",
47424816
"code": 29,
@@ -5639,7 +5713,7 @@
56395713
"parentEndpointIdentifier": null
56405714
},
56415715
{
5642-
"endpointTypeName": "MA-onofflightswitch",
5716+
"endpointTypeName": "MA-dimmerswitch",
56435717
"endpointTypeIndex": 1,
56445718
"profileId": 259,
56455719
"endpointId": 1,

examples/light-switch-app/silabs/include/AppConfig.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
// state to another.
3232
#define ACTUATOR_MOVEMENT_PERIOS_MS 10
3333

34+
#define LONG_PRESS_TIMEOUT 3000
35+
3436
// APP Logo, boolean only. must be 64x64
3537
#define ON_DEMO_BITMAP \
3638
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \

examples/light-switch-app/silabs/include/AppEvent.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#pragma once
2121

22+
#include <cstdint>
23+
2224
struct AppEvent;
2325
typedef void (*EventHandler)(AppEvent *);
2426

@@ -30,6 +32,15 @@ struct AppEvent
3032
kEventType_Timer,
3133
kEventType_Light,
3234
kEventType_Install,
35+
kEventType_ResetWarning,
36+
kEventType_ResetCanceled,
37+
// Button events
38+
kEventType_ActionButtonPressed,
39+
kEventType_ActionButtonReleased,
40+
kEventType_FunctionButtonPressed,
41+
kEventType_FunctionButtonReleased,
42+
kEventType_TriggerLevelControlAction,
43+
kEventType_TriggerToggle,
3344
};
3445

3546
uint16_t Type;
@@ -46,9 +57,8 @@ struct AppEvent
4657
} TimerEvent;
4758
struct
4859
{
49-
uint8_t Action;
50-
int32_t Actor;
51-
} LightEvent;
60+
void * Context;
61+
} LightSwitchEvent;
5262
};
5363

5464
EventHandler Handler;

examples/light-switch-app/silabs/include/AppTask.h

-27
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ class AppTask : public BaseApplication
6666

6767
CHIP_ERROR StartAppTask();
6868

69-
/**
70-
* @brief Event handler when a button is pressed
71-
* Function posts an event for button processing
72-
*
73-
* @param buttonHandle APP_LIGHT_SWITCH or APP_FUNCTION_BUTTON
74-
* @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
75-
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
76-
*/
77-
static void ButtonEventHandler(uint8_t button, uint8_t btnAction);
78-
7969
private:
8070
static AppTask sAppTask;
8171

@@ -85,21 +75,4 @@ class AppTask : public BaseApplication
8575
* @return CHIP_ERROR
8676
*/
8777
CHIP_ERROR AppInit() override;
88-
89-
/**
90-
* @brief PB0 Button event processing function
91-
* Press and hold will trigger a factory reset timer start
92-
* Press and release will restart BLEAdvertising if not commisionned
93-
*
94-
* @param aEvent button event being processed
95-
*/
96-
static void ButtonHandler(AppEvent * aEvent);
97-
98-
/**
99-
* @brief PB1 Button event processing function
100-
* Function triggers a switch action sent to the CHIP task
101-
*
102-
* @param aEvent button event being processed
103-
*/
104-
static void SwitchActionEventHandler(AppEvent * aEvent);
10578
};

0 commit comments

Comments
 (0)