Skip to content

Commit ed47deb

Browse files
authored
feat(matter_docs): improves event handling documentation for MatterWindowCovering
Updated callback descriptions and clarified command triggers for window covering events.
1 parent 10b77bb commit ed47deb

File tree

1 file changed

+53
-16
lines changed

1 file changed

+53
-16
lines changed

docs/en/matter/ep_window_covering.rst

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,32 @@ This function will return the operational state for the specified field (``STALL
430430
Event Handling
431431
**************
432432

433+
The ``MatterWindowCovering`` class automatically detects Matter commands and calls the appropriate callbacks when registered. There are two types of callbacks:
434+
435+
**Target Position Callbacks** (triggered when ``TargetPosition`` attributes change):
436+
* ``onOpen()`` - called when ``UpOrOpen`` command is received (sets target to 0% = fully open)
437+
* ``onClose()`` - called when ``DownOrClose`` command is received (sets target to 100% = fully closed)
438+
* ``onStop()`` - called when ``StopMotion`` command is received (sets target to current position)
439+
* ``onGoToLiftPercentage()`` - called when ``TargetPositionLiftPercent100ths`` changes (from any command, ``setTargetLiftPercent100ths()``, or direct attribute write)
440+
* ``onGoToTiltPercentage()`` - called when ``TargetPositionTiltPercent100ths`` changes (from any command, ``setTargetTiltPercent100ths()``, or direct attribute write)
441+
442+
**Current Position Callback** (triggered when ``CurrentPosition`` attributes change):
443+
* ``onChange()`` - called when ``CurrentPositionLiftPercent100ths`` or ``CurrentPositionTiltPercent100ths`` change (after ``setLiftPercentage()``/``setTiltPercentage()`` are called or when a Matter controller updates these attributes directly)
444+
445+
**Important:** ``onChange()`` is **not** automatically called when Matter commands are executed. Commands modify ``TargetPosition``, not ``CurrentPosition``. To trigger ``onChange()``, your ``onGoToLiftPercentage()`` or ``onGoToTiltPercentage()`` callback must call ``setLiftPercentage()`` or ``setTiltPercentage()`` when the physical device actually moves.
446+
447+
**Note:** All callbacks are optional. If a specific callback is not registered, only the generic ``onGoToLiftPercentage()`` or ``onGoToTiltPercentage()`` callbacks will be called (if registered).
448+
433449
onOpen
434450
^^^^^^
435451

436-
Sets a callback function to be called when the window covering is opened.
452+
Sets a callback function to be called when the ``UpOrOpen`` command is received from a Matter controller. This command sets the target position to 0% (fully open).
437453

438454
.. code-block:: arduino
439455
440456
void onOpen(EndPointOpenCB onChangeCB);
441457
442-
* ``onChangeCB`` - Function to call when window covering is opened
458+
* ``onChangeCB`` - Function to call when ``UpOrOpen`` command is received
443459

444460
The callback signature is:
445461

@@ -450,13 +466,13 @@ The callback signature is:
450466
onClose
451467
^^^^^^^
452468

453-
Sets a callback function to be called when the window covering is closed.
469+
Sets a callback function to be called when the ``DownOrClose`` command is received from a Matter controller. This command sets the target position to 100% (fully closed).
454470

455471
.. code-block:: arduino
456472
457473
void onClose(EndPointCloseCB onChangeCB);
458474
459-
* ``onChangeCB`` - Function to call when window covering is closed
475+
* ``onChangeCB`` - Function to call when ``DownOrClose`` command is received
460476

461477
The callback signature is:
462478

@@ -467,51 +483,65 @@ The callback signature is:
467483
onGoToLiftPercentage
468484
^^^^^^^^^^^^^^^^^^^^
469485

470-
Sets a callback function to be called when the lift percentage changes.
486+
Sets a callback function to be called when ``TargetPositionLiftPercent100ths`` changes. This is triggered by:
487+
* Matter commands: ``UpOrOpen``, ``DownOrClose``, ``StopMotion``, ``GoToLiftPercentage``
488+
* Calling ``setTargetLiftPercent100ths()``
489+
* Direct attribute writes to ``TargetPositionLiftPercent100ths``
490+
491+
This callback is always called when the target lift position changes, regardless of which command or method was used to change it.
492+
493+
**Note:** This callback receives the **target** position. To update the **current** position (which triggers ``onChange()``), call ``setLiftPercentage()`` when the physical device actually moves.
471494

472495
.. code-block:: arduino
473496
474497
void onGoToLiftPercentage(EndPointLiftCB onChangeCB);
475498
476-
* ``onChangeCB`` - Function to call when lift percentage changes
499+
* ``onChangeCB`` - Function to call when target lift percentage changes
477500

478501
The callback signature is:
479502

480503
.. code-block:: arduino
481504
482505
bool onChangeCallback(uint8_t liftPercent);
483506
484-
* ``liftPercent`` - New lift percentage (0-100)
507+
* ``liftPercent`` - Target lift percentage (0-100, where 0 is fully closed, 100 is fully open)
485508

486509
onGoToTiltPercentage
487510
^^^^^^^^^^^^^^^^^^^^
488511

489-
Sets a callback function to be called when the tilt percentage changes.
512+
Sets a callback function to be called when ``TargetPositionTiltPercent100ths`` changes. This is triggered by:
513+
* Matter commands: ``UpOrOpen``, ``DownOrClose``, ``StopMotion``, ``GoToTiltPercentage``
514+
* Calling ``setTargetTiltPercent100ths()``
515+
* Direct attribute writes to ``TargetPositionTiltPercent100ths``
516+
517+
This callback is always called when the target tilt position changes, regardless of which command or method was used to change it.
518+
519+
**Note:** This callback receives the **target** position. To update the **current** position (which triggers ``onChange()``), call ``setTiltPercentage()`` when the physical device actually moves.
490520

491521
.. code-block:: arduino
492522
493523
void onGoToTiltPercentage(EndPointTiltCB onChangeCB);
494524
495-
* ``onChangeCB`` - Function to call when tilt percentage changes
525+
* ``onChangeCB`` - Function to call when target tilt percentage changes
496526

497527
The callback signature is:
498528

499529
.. code-block:: arduino
500530
501531
bool onChangeCallback(uint8_t tiltPercent);
502532
503-
* ``tiltPercent`` - New tilt percentage (0-100)
533+
* ``tiltPercent`` - Target tilt percentage (0-100, where 0 is fully closed, 100 is fully open)
504534

505535
onStop
506536
^^^^^^
507537

508-
Sets a callback function to be called when the window covering movement is stopped.
538+
Sets a callback function to be called when the ``StopMotion`` command is received from a Matter controller. This command sets the target position to the current position, effectively stopping any movement.
509539

510540
.. code-block:: arduino
511541
512542
void onStop(EndPointStopCB onChangeCB);
513543
514-
* ``onChangeCB`` - Function to call when window covering is stopped
544+
* ``onChangeCB`` - Function to call when ``StopMotion`` command is received
515545

516546
The callback signature is:
517547

@@ -522,22 +552,28 @@ The callback signature is:
522552
onChange
523553
^^^^^^^^
524554

525-
Sets a callback function to be called when any parameter changes.
555+
Sets a callback function to be called when ``CurrentPositionLiftPercent100ths`` or ``CurrentPositionTiltPercent100ths`` attributes change. This is different from ``onGoToLiftPercentage()`` and ``onGoToTiltPercentage()``, which are called when ``TargetPosition`` attributes change.
556+
557+
**When ``onChange()`` is called:**
558+
* When ``CurrentPositionLiftPercent100ths`` changes (after ``setLiftPercentage()`` is called or when a Matter controller updates this attribute directly)
559+
* When ``CurrentPositionTiltPercent100ths`` changes (after ``setTiltPercentage()`` is called or when a Matter controller updates this attribute directly)
560+
561+
**Important:** ``onChange()`` is **not** automatically called when Matter commands are executed. Commands modify ``TargetPosition`` attributes, which trigger ``onGoToLiftPercentage()`` or ``onGoToTiltPercentage()`` callbacks instead. To trigger ``onChange()`` after a command, your ``onGoToLiftPercentage()`` or ``onGoToTiltPercentage()`` callback must call ``setLiftPercentage()`` or ``setTiltPercentage()`` to update the ``CurrentPosition`` attributes when the physical device actually moves.
526562

527563
.. code-block:: arduino
528564
529565
void onChange(EndPointCB onChangeCB);
530566
531-
* ``onChangeCB`` - Function to call when state changes
567+
* ``onChangeCB`` - Function to call when current position attributes change
532568

533569
The callback signature is:
534570

535571
.. code-block:: arduino
536572
537573
bool onChangeCallback(uint8_t liftPercent, uint8_t tiltPercent);
538574
539-
* ``liftPercent`` - New lift percentage (0-100)
540-
* ``tiltPercent`` - New tilt percentage (0-100)
575+
* ``liftPercent`` - Current lift percentage (0-100)
576+
* ``tiltPercent`` - Current tilt percentage (0-100)
541577

542578
updateAccessory
543579
^^^^^^^^^^^^^^^
@@ -558,3 +594,4 @@ Window Covering
558594

559595
.. literalinclude:: ../../../libraries/Matter/examples/MatterWindowCovering/MatterWindowCovering.ino
560596
:language: arduino
597+

0 commit comments

Comments
 (0)