Skip to content

Commit 795a7f9

Browse files
ci(pre-commit): Apply automatic fixes
1 parent a6054c4 commit 795a7f9

File tree

6 files changed

+86
-118
lines changed

6 files changed

+86
-118
lines changed

docs/en/matter/ep_window_covering.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,4 +558,3 @@ Window Covering
558558

559559
.. literalinclude:: ../../../libraries/Matter/examples/MatterWindowCovering/MatterWindowCovering.ino
560560
:language: arduino
561-

libraries/Matter/examples/MatterWindowCovering/MatterWindowCovering.ino

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
4242
// Button control
4343
uint32_t button_time_stamp = 0; // debouncing control
4444
bool button_state = false; // false = released | true = pressed
45-
const uint32_t debounceTime = 250; // button debouncing time (ms)
45+
const uint32_t debounceTime = 250; // button debouncing time (ms)
4646
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
4747

4848
// Window covering limits
4949
// Lift limits in centimeters (physical position)
5050
const uint16_t MAX_LIFT = 200; // Maximum lift position (fully open)
51-
const uint16_t MIN_LIFT = 0; // Minimum lift position (fully closed)
51+
const uint16_t MIN_LIFT = 0; // Minimum lift position (fully closed)
5252

5353
// Tilt limits (absolute values for conversion, not physical units)
5454
// Tilt is a rotation, not a linear measurement
55-
const uint16_t MAX_TILT = 90; // Maximum tilt absolute value
56-
const uint16_t MIN_TILT = 0; // Minimum tilt absolute value
55+
const uint16_t MAX_TILT = 90; // Maximum tilt absolute value
56+
const uint16_t MIN_TILT = 0; // Minimum tilt absolute value
5757

5858
// Current window covering state
5959
// These will be initialized in setup() based on installed limits and saved percentages
60-
uint16_t currentLift = 0; // Lift position in cm
60+
uint16_t currentLift = 0; // Lift position in cm
6161
uint8_t currentLiftPercent = 100;
6262
uint8_t currentTiltPercent = 0; // Tilt rotation percentage (0-100%)
6363

@@ -94,16 +94,16 @@ bool fullOpen() {
9494
currentLift = openLimit;
9595
currentLiftPercent = 100;
9696
Serial.printf("Opening window covering to full open (position: %d cm)\r\n", currentLift);
97-
97+
9898
// Update CurrentPosition to reflect actual position (setLiftPercentage now only updates CurrentPosition)
9999
WindowBlinds.setLiftPercentage(currentLiftPercent);
100-
100+
101101
// Set operational status to STALL when movement is complete
102102
WindowBlinds.setOperationalState(MatterWindowCovering::LIFT, MatterWindowCovering::STALL);
103-
103+
104104
// Store state
105105
matterPref.putUChar(liftPercentPrefKey, currentLiftPercent);
106-
106+
107107
return true;
108108
}
109109

@@ -114,16 +114,16 @@ bool fullClose() {
114114
currentLift = closedLimit;
115115
currentLiftPercent = 0;
116116
Serial.printf("Closing window covering to full close (position: %d cm)\r\n", currentLift);
117-
117+
118118
// Update CurrentPosition to reflect actual position (setLiftPercentage now only updates CurrentPosition)
119119
WindowBlinds.setLiftPercentage(currentLiftPercent);
120-
120+
121121
// Set operational status to STALL when movement is complete
122122
WindowBlinds.setOperationalState(MatterWindowCovering::LIFT, MatterWindowCovering::STALL);
123-
123+
124124
// Store state
125125
matterPref.putUChar(liftPercentPrefKey, currentLiftPercent);
126-
126+
127127
return true;
128128
}
129129

@@ -143,7 +143,7 @@ bool goToLiftPercentage(uint8_t liftPercent) {
143143
// Calculate absolute position based on installed limits
144144
uint16_t openLimit = WindowBlinds.getInstalledOpenLimitLift();
145145
uint16_t closedLimit = WindowBlinds.getInstalledClosedLimitLift();
146-
146+
147147
// Linear interpolation: 0% = openLimit, 100% = closedLimit
148148
if (openLimit < closedLimit) {
149149
currentLift = openLimit + ((closedLimit - openLimit) * liftPercent) / 100;
@@ -152,16 +152,16 @@ bool goToLiftPercentage(uint8_t liftPercent) {
152152
}
153153
currentLiftPercent = liftPercent;
154154
Serial.printf("Moving lift to %d%% (position: %d cm)\r\n", currentLiftPercent, currentLift);
155-
155+
156156
// Update CurrentPosition to reflect actual position (setLiftPercentage now only updates CurrentPosition)
157157
WindowBlinds.setLiftPercentage(currentLiftPercent);
158-
158+
159159
// Set operational status to STALL when movement is complete
160160
WindowBlinds.setOperationalState(MatterWindowCovering::LIFT, MatterWindowCovering::STALL);
161-
161+
162162
// Store state
163163
matterPref.putUChar(liftPercentPrefKey, currentLiftPercent);
164-
164+
165165
return true;
166166
}
167167

@@ -180,32 +180,32 @@ bool goToTiltPercentage(uint8_t tiltPercent) {
180180
// For simulation, we update instantly
181181
currentTiltPercent = tiltPercent;
182182
Serial.printf("Rotating tilt to %d%%\r\n", currentTiltPercent);
183-
183+
184184
// Update CurrentPosition to reflect actual position
185185
WindowBlinds.setTiltPercentage(currentTiltPercent);
186-
186+
187187
// Set operational status to STALL when movement is complete
188188
WindowBlinds.setOperationalState(MatterWindowCovering::TILT, MatterWindowCovering::STALL);
189-
189+
190190
// Store state
191191
matterPref.putUChar(tiltPercentPrefKey, currentTiltPercent);
192-
192+
193193
return true;
194194
}
195195

196196
bool stopMotor() {
197197
// Motor can be stopped while moving cover toward current target
198198
Serial.println("Stopping window covering motor");
199-
199+
200200
// Update CurrentPosition to reflect actual position when stopped
201201
// (setLiftPercentage and setTiltPercentage now only update CurrentPosition)
202202
WindowBlinds.setLiftPercentage(currentLiftPercent);
203203
WindowBlinds.setTiltPercentage(currentTiltPercent);
204-
204+
205205
// Set operational status to STALL for both lift and tilt
206206
WindowBlinds.setOperationalState(MatterWindowCovering::LIFT, MatterWindowCovering::STALL);
207207
WindowBlinds.setOperationalState(MatterWindowCovering::TILT, MatterWindowCovering::STALL);
208-
208+
209209
return true;
210210
}
211211

@@ -242,16 +242,16 @@ void setup() {
242242
uint8_t lastLiftPercent = matterPref.getUChar(liftPercentPrefKey, 100);
243243
// default tilt percentage is 0% if not stored before
244244
uint8_t lastTiltPercent = matterPref.getUChar(tiltPercentPrefKey, 0);
245-
245+
246246
// Initialize window covering with BLIND_LIFT_AND_TILT type
247247
WindowBlinds.begin(lastLiftPercent, lastTiltPercent, MatterWindowCovering::BLIND_LIFT_AND_TILT);
248-
248+
249249
// Configure installed limits for lift and tilt
250250
WindowBlinds.setInstalledOpenLimitLift(MIN_LIFT);
251251
WindowBlinds.setInstalledClosedLimitLift(MAX_LIFT);
252252
WindowBlinds.setInstalledOpenLimitTilt(MIN_TILT);
253253
WindowBlinds.setInstalledClosedLimitTilt(MAX_TILT);
254-
254+
255255
// Initialize current positions based on percentages and installed limits
256256
uint16_t openLimitLift = WindowBlinds.getInstalledOpenLimitLift();
257257
uint16_t closedLimitLift = WindowBlinds.getInstalledClosedLimitLift();
@@ -261,25 +261,25 @@ void setup() {
261261
} else {
262262
currentLift = openLimitLift - ((openLimitLift - closedLimitLift) * lastLiftPercent) / 100;
263263
}
264-
264+
265265
currentTiltPercent = lastTiltPercent;
266-
267-
Serial.printf("Window Covering limits configured: Lift [%d-%d cm], Tilt [%d-%d]\r\n",
268-
WindowBlinds.getInstalledOpenLimitLift(), WindowBlinds.getInstalledClosedLimitLift(),
269-
WindowBlinds.getInstalledOpenLimitTilt(), WindowBlinds.getInstalledClosedLimitTilt());
270-
Serial.printf("Initial positions: Lift=%d cm (%d%%), Tilt=%d%%\r\n",
271-
currentLift, currentLiftPercent, currentTiltPercent);
272-
266+
267+
Serial.printf(
268+
"Window Covering limits configured: Lift [%d-%d cm], Tilt [%d-%d]\r\n", WindowBlinds.getInstalledOpenLimitLift(),
269+
WindowBlinds.getInstalledClosedLimitLift(), WindowBlinds.getInstalledOpenLimitTilt(), WindowBlinds.getInstalledClosedLimitTilt()
270+
);
271+
Serial.printf("Initial positions: Lift=%d cm (%d%%), Tilt=%d%%\r\n", currentLift, currentLiftPercent, currentTiltPercent);
272+
273273
// Set callback functions
274274
WindowBlinds.onOpen(fullOpen);
275275
WindowBlinds.onClose(fullClose);
276276
WindowBlinds.onGoToLiftPercentage(goToLiftPercentage);
277277
WindowBlinds.onGoToTiltPercentage(goToTiltPercentage);
278278
WindowBlinds.onStop(stopMotor);
279-
279+
280280
// Generic callback for Lift or Tilt change
281281
WindowBlinds.onChange([](uint8_t liftPercent, uint8_t tiltPercent) {
282-
Serial.printf("Window Covering changed: Lift=%d%%, Tilt=%d%%\r\n", liftPercent, tiltPercent);
282+
Serial.printf("Window Covering changed: Lift=%d%%, Tilt=%d%%\r\n", liftPercent, tiltPercent);
283283
visualizeWindowBlinds(liftPercent, tiltPercent);
284284
return true;
285285
});

libraries/Matter/examples/MatterWindowCovering/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,3 @@ The MatterWindowCovering example consists of the following main components:
225225
## License
226226

227227
This example is licensed under the Apache License, Version 2.0.
228-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fqbn_append: PartitionScheme=huge_app
22

33
requires:
4-
- CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y
4+
- CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y

libraries/Matter/src/MatterEndpoints/MatterWindowCovering.cpp

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool MatterWindowCovering::begin(uint8_t liftPercent, uint8_t tiltPercent, Windo
7070
if (feature::lift::add(window_covering_cluster, &lift_config) != ESP_OK) {
7171
log_e("Failed to add Lift feature");
7272
}
73-
73+
7474
// Add Position Aware Lift feature
7575
feature::position_aware_lift::config_t position_aware_lift_config;
7676
position_aware_lift_config.current_position_lift_percentage = nullable<uint8_t>(0);
@@ -79,7 +79,7 @@ bool MatterWindowCovering::begin(uint8_t liftPercent, uint8_t tiltPercent, Windo
7979
if (feature::position_aware_lift::add(window_covering_cluster, &position_aware_lift_config) != ESP_OK) {
8080
log_e("Failed to add Position Aware Lift feature");
8181
}
82-
82+
8383
// Add Tilt feature if the covering type supports it
8484
bool supportsTilt = (coveringType == SHUTTER || coveringType == BLIND_TILT_ONLY || coveringType == BLIND_LIFT_AND_TILT);
8585
if (supportsTilt) {
@@ -88,7 +88,7 @@ bool MatterWindowCovering::begin(uint8_t liftPercent, uint8_t tiltPercent, Windo
8888
if (feature::tilt::add(window_covering_cluster, &tilt_config) != ESP_OK) {
8989
log_e("Failed to add Tilt feature");
9090
}
91-
91+
9292
// Add Position Aware Tilt feature
9393
feature::position_aware_tilt::config_t position_aware_tilt_config;
9494
position_aware_tilt_config.current_position_tilt_percentage = nullable<uint8_t>(0);
@@ -98,7 +98,7 @@ bool MatterWindowCovering::begin(uint8_t liftPercent, uint8_t tiltPercent, Windo
9898
log_e("Failed to add Position Aware Tilt feature");
9999
}
100100
}
101-
101+
102102
// Add Absolute Position feature (creates InstalledOpenLimitLift/ClosedLimitLift/Tilt attributes)
103103
// Must be added AFTER all lift and tilt features for all attributes to be created
104104
feature::absolute_position::config_t absolute_position_config;
@@ -109,7 +109,7 @@ bool MatterWindowCovering::begin(uint8_t liftPercent, uint8_t tiltPercent, Windo
109109
if (feature::absolute_position::add(window_covering_cluster, &absolute_position_config) != ESP_OK) {
110110
log_e("Failed to add Absolute Position feature");
111111
}
112-
112+
113113
// Create Window Covering commands
114114
create_up_or_open(window_covering_cluster);
115115
create_down_or_close(window_covering_cluster);
@@ -153,7 +153,8 @@ bool MatterWindowCovering::attributeChangeCB(uint16_t endpoint_id, uint32_t clus
153153
if (endpoint_id == getEndPointId() && cluster_id == WindowCovering::Id) {
154154
switch (attribute_id) {
155155
// Current position attributes (read-only to external Matter controllers; updated internally by device)
156-
case WindowCovering::Attributes::CurrentPositionLiftPercent100ths::Id: {
156+
case WindowCovering::Attributes::CurrentPositionLiftPercent100ths::Id:
157+
{
157158
uint16_t liftPercent100ths = val->val.u16;
158159
uint8_t liftPercent = (uint8_t)(liftPercent100ths / 100);
159160
log_d("Window Covering Lift Percentage changed to %d%%", liftPercent);
@@ -167,7 +168,8 @@ bool MatterWindowCovering::attributeChangeCB(uint16_t endpoint_id, uint32_t clus
167168
}
168169
break;
169170
}
170-
case WindowCovering::Attributes::CurrentPositionTiltPercent100ths::Id: {
171+
case WindowCovering::Attributes::CurrentPositionTiltPercent100ths::Id:
172+
{
171173
uint16_t tiltPercent100ths = val->val.u16;
172174
uint8_t tiltPercent = (uint8_t)(tiltPercent100ths / 100);
173175
log_d("Window Covering Tilt Percentage changed to %d%%", tiltPercent);
@@ -189,17 +191,14 @@ bool MatterWindowCovering::attributeChangeCB(uint16_t endpoint_id, uint32_t clus
189191
log_d("Window Covering Tilt Position changed to %d", val->val.u16);
190192
currentTiltPosition = val->val.u16;
191193
break;
192-
case WindowCovering::Attributes::CurrentPositionLiftPercentage::Id:
193-
log_d("Window Covering Lift Percentage (legacy) changed to %d%%", val->val.u8);
194-
break;
195-
case WindowCovering::Attributes::CurrentPositionTiltPercentage::Id:
196-
log_d("Window Covering Tilt Percentage (legacy) changed to %d%%", val->val.u8);
197-
break;
194+
case WindowCovering::Attributes::CurrentPositionLiftPercentage::Id: log_d("Window Covering Lift Percentage (legacy) changed to %d%%", val->val.u8); break;
195+
case WindowCovering::Attributes::CurrentPositionTiltPercentage::Id: log_d("Window Covering Tilt Percentage (legacy) changed to %d%%", val->val.u8); break;
198196

199197
// Target position attributes (writable, trigger movement)
200198
// Note: TargetPosition is where the device SHOULD go, not where it is.
201199
// CurrentPosition should only be updated when the physical device actually moves.
202-
case WindowCovering::Attributes::TargetPositionLiftPercent100ths::Id: {
200+
case WindowCovering::Attributes::TargetPositionLiftPercent100ths::Id:
201+
{
203202
if (!chip::app::NumericAttributeTraits<uint16_t>::IsNullValue(val->val.u16)) {
204203
uint16_t targetLiftPercent100ths = val->val.u16;
205204
uint8_t targetLiftPercent = (uint8_t)(targetLiftPercent100ths / 100);
@@ -214,7 +213,8 @@ bool MatterWindowCovering::attributeChangeCB(uint16_t endpoint_id, uint32_t clus
214213
}
215214
break;
216215
}
217-
case WindowCovering::Attributes::TargetPositionTiltPercent100ths::Id: {
216+
case WindowCovering::Attributes::TargetPositionTiltPercent100ths::Id:
217+
{
218218
if (!chip::app::NumericAttributeTraits<uint16_t>::IsNullValue(val->val.u16)) {
219219
uint16_t targetTiltPercent100ths = val->val.u16;
220220
uint8_t targetTiltPercent = (uint8_t)(targetTiltPercent100ths / 100);
@@ -235,55 +235,27 @@ bool MatterWindowCovering::attributeChangeCB(uint16_t endpoint_id, uint32_t clus
235235
log_d("Window Covering Type changed to %d", val->val.u8);
236236
coveringType = (WindowCoveringType_t)val->val.u8;
237237
break;
238-
case WindowCovering::Attributes::EndProductType::Id:
239-
log_d("Window Covering End Product Type changed to %d", val->val.u8);
240-
break;
241-
case WindowCovering::Attributes::ConfigStatus::Id:
242-
log_d("Window Covering Config Status changed to 0x%02X", val->val.u8);
243-
break;
244-
case WindowCovering::Attributes::Mode::Id:
245-
log_d("Window Covering Mode changed to 0x%02X", val->val.u8);
246-
break;
238+
case WindowCovering::Attributes::EndProductType::Id: log_d("Window Covering End Product Type changed to %d", val->val.u8); break;
239+
case WindowCovering::Attributes::ConfigStatus::Id: log_d("Window Covering Config Status changed to 0x%02X", val->val.u8); break;
240+
case WindowCovering::Attributes::Mode::Id: log_d("Window Covering Mode changed to 0x%02X", val->val.u8); break;
247241

248242
// Operational status attributes
249-
case WindowCovering::Attributes::OperationalStatus::Id:
250-
log_d("Window Covering Operational Status changed to 0x%02X", val->val.u8);
251-
break;
252-
case WindowCovering::Attributes::SafetyStatus::Id:
253-
log_d("Window Covering Safety Status changed to 0x%04X", val->val.u16);
254-
break;
243+
case WindowCovering::Attributes::OperationalStatus::Id: log_d("Window Covering Operational Status changed to 0x%02X", val->val.u8); break;
244+
case WindowCovering::Attributes::SafetyStatus::Id: log_d("Window Covering Safety Status changed to 0x%04X", val->val.u16); break;
255245

256246
// Limit attributes
257-
case WindowCovering::Attributes::PhysicalClosedLimitLift::Id:
258-
log_d("Window Covering Physical Closed Limit Lift changed to %d", val->val.u16);
259-
break;
260-
case WindowCovering::Attributes::PhysicalClosedLimitTilt::Id:
261-
log_d("Window Covering Physical Closed Limit Tilt changed to %d", val->val.u16);
262-
break;
263-
case WindowCovering::Attributes::InstalledOpenLimitLift::Id:
264-
log_d("Window Covering Installed Open Limit Lift changed to %d", val->val.u16);
265-
break;
266-
case WindowCovering::Attributes::InstalledClosedLimitLift::Id:
267-
log_d("Window Covering Installed Closed Limit Lift changed to %d", val->val.u16);
268-
break;
269-
case WindowCovering::Attributes::InstalledOpenLimitTilt::Id:
270-
log_d("Window Covering Installed Open Limit Tilt changed to %d", val->val.u16);
271-
break;
272-
case WindowCovering::Attributes::InstalledClosedLimitTilt::Id:
273-
log_d("Window Covering Installed Closed Limit Tilt changed to %d", val->val.u16);
274-
break;
247+
case WindowCovering::Attributes::PhysicalClosedLimitLift::Id: log_d("Window Covering Physical Closed Limit Lift changed to %d", val->val.u16); break;
248+
case WindowCovering::Attributes::PhysicalClosedLimitTilt::Id: log_d("Window Covering Physical Closed Limit Tilt changed to %d", val->val.u16); break;
249+
case WindowCovering::Attributes::InstalledOpenLimitLift::Id: log_d("Window Covering Installed Open Limit Lift changed to %d", val->val.u16); break;
250+
case WindowCovering::Attributes::InstalledClosedLimitLift::Id: log_d("Window Covering Installed Closed Limit Lift changed to %d", val->val.u16); break;
251+
case WindowCovering::Attributes::InstalledOpenLimitTilt::Id: log_d("Window Covering Installed Open Limit Tilt changed to %d", val->val.u16); break;
252+
case WindowCovering::Attributes::InstalledClosedLimitTilt::Id: log_d("Window Covering Installed Closed Limit Tilt changed to %d", val->val.u16); break;
275253

276254
// Actuation count attributes
277-
case WindowCovering::Attributes::NumberOfActuationsLift::Id:
278-
log_d("Window Covering Number of Actuations Lift changed to %d", val->val.u16);
279-
break;
280-
case WindowCovering::Attributes::NumberOfActuationsTilt::Id:
281-
log_d("Window Covering Number of Actuations Tilt changed to %d", val->val.u16);
282-
break;
255+
case WindowCovering::Attributes::NumberOfActuationsLift::Id: log_d("Window Covering Number of Actuations Lift changed to %d", val->val.u16); break;
256+
case WindowCovering::Attributes::NumberOfActuationsTilt::Id: log_d("Window Covering Number of Actuations Tilt changed to %d", val->val.u16); break;
283257

284-
default:
285-
log_d("Window Covering Unknown attribute %u changed", attribute_id);
286-
break;
258+
default: log_d("Window Covering Unknown attribute %u changed", attribute_id); break;
287259
}
288260
}
289261
return ret;
@@ -809,10 +781,10 @@ bool MatterWindowCovering::setOperationalState(OperationalStatusField_t field, O
809781
// 3. Recalculate Global based on priority: Lift (if not Stall) > Tilt
810782
uint8_t liftState = (currentStatus & LIFT) >> 2;
811783
uint8_t tiltState = (currentStatus & TILT) >> 4;
812-
784+
813785
// Global follows Lift by priority, or Tilt if Lift is not active (Stall = 0)
814786
uint8_t globalState = (liftState != STALL) ? liftState : tiltState;
815-
787+
816788
// Update Global field (bits 0-1)
817789
currentStatus = (currentStatus & ~GLOBAL) | (globalState << 0);
818790

@@ -855,4 +827,3 @@ void MatterWindowCovering::updateAccessory() {
855827
}
856828

857829
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */
858-

0 commit comments

Comments
 (0)