|
| 1 | +#################### |
| 2 | +MatterDimmablePlugin |
| 3 | +#################### |
| 4 | + |
| 5 | +About |
| 6 | +----- |
| 7 | + |
| 8 | +The ``MatterDimmablePlugin`` class provides a dimmable plugin unit endpoint for Matter networks. This endpoint implements the Matter dimmable plugin standard for controlling power outlets, relays, and other dimmable devices with power level control. |
| 9 | + |
| 10 | +**Features:** |
| 11 | +* On/off control |
| 12 | +* Power level control (0-255) |
| 13 | +* State persistence support |
| 14 | +* Callback support for state and level changes |
| 15 | +* Integration with Apple HomeKit, Amazon Alexa, and Google Home |
| 16 | +* Matter standard compliance |
| 17 | + |
| 18 | +**Use Cases:** |
| 19 | +* Dimmable smart power outlets |
| 20 | +* Variable power control |
| 21 | +* Dimmable relay control |
| 22 | +* Smart dimmer plugs |
| 23 | +* Level-controlled device control |
| 24 | + |
| 25 | +API Reference |
| 26 | +------------- |
| 27 | + |
| 28 | +Constructor |
| 29 | +*********** |
| 30 | + |
| 31 | +MatterDimmablePlugin |
| 32 | +^^^^^^^^^^^^^^^^^^^^ |
| 33 | + |
| 34 | +Creates a new Matter dimmable plugin endpoint. |
| 35 | + |
| 36 | +.. code-block:: arduino |
| 37 | +
|
| 38 | + MatterDimmablePlugin(); |
| 39 | +
|
| 40 | +Initialization |
| 41 | +************** |
| 42 | + |
| 43 | +begin |
| 44 | +^^^^^ |
| 45 | + |
| 46 | +Initializes the Matter dimmable plugin endpoint with optional initial state and level. |
| 47 | + |
| 48 | +.. code-block:: arduino |
| 49 | +
|
| 50 | + bool begin(bool initialState = false, uint8_t level = 64); |
| 51 | +
|
| 52 | +* ``initialState`` - Initial on/off state (``true`` = on, ``false`` = off, default: ``false``) |
| 53 | +* ``level`` - Initial power level (0-255, default: 64 = 25%) |
| 54 | + |
| 55 | +This function will return ``true`` if successful, ``false`` otherwise. |
| 56 | + |
| 57 | +end |
| 58 | +^^^ |
| 59 | + |
| 60 | +Stops processing Matter plugin events. |
| 61 | + |
| 62 | +.. code-block:: arduino |
| 63 | +
|
| 64 | + void end(); |
| 65 | +
|
| 66 | +On/Off Control |
| 67 | +************** |
| 68 | + |
| 69 | +setOnOff |
| 70 | +^^^^^^^^ |
| 71 | + |
| 72 | +Sets the on/off state of the plugin. |
| 73 | + |
| 74 | +.. code-block:: arduino |
| 75 | +
|
| 76 | + bool setOnOff(bool newState); |
| 77 | +
|
| 78 | +* ``newState`` - New state (``true`` = on, ``false`` = off) |
| 79 | + |
| 80 | +This function will return ``true`` if successful, ``false`` otherwise. |
| 81 | + |
| 82 | +getOnOff |
| 83 | +^^^^^^^^ |
| 84 | + |
| 85 | +Gets the current on/off state of the plugin. |
| 86 | + |
| 87 | +.. code-block:: arduino |
| 88 | +
|
| 89 | + bool getOnOff(); |
| 90 | +
|
| 91 | +This function will return ``true`` if the plugin is on, ``false`` if off. |
| 92 | + |
| 93 | +toggle |
| 94 | +^^^^^^ |
| 95 | + |
| 96 | +Toggles the on/off state of the plugin. |
| 97 | + |
| 98 | +.. code-block:: arduino |
| 99 | +
|
| 100 | + bool toggle(); |
| 101 | +
|
| 102 | +This function will return ``true`` if successful, ``false`` otherwise. |
| 103 | + |
| 104 | +Level Control |
| 105 | +************** |
| 106 | + |
| 107 | +setLevel |
| 108 | +^^^^^^^^ |
| 109 | + |
| 110 | +Sets the power level of the plugin. |
| 111 | + |
| 112 | +.. code-block:: arduino |
| 113 | +
|
| 114 | + bool setLevel(uint8_t newLevel); |
| 115 | +
|
| 116 | +* ``newLevel`` - New power level (0-255, where 0 = off, 255 = maximum level) |
| 117 | + |
| 118 | +This function will return ``true`` if successful, ``false`` otherwise. |
| 119 | + |
| 120 | +getLevel |
| 121 | +^^^^^^^^ |
| 122 | + |
| 123 | +Gets the current power level of the plugin. |
| 124 | + |
| 125 | +.. code-block:: arduino |
| 126 | +
|
| 127 | + uint8_t getLevel(); |
| 128 | +
|
| 129 | +This function will return the power level (0-255). |
| 130 | + |
| 131 | +Constants |
| 132 | +********* |
| 133 | + |
| 134 | +MAX_LEVEL |
| 135 | +^^^^^^^^^^ |
| 136 | + |
| 137 | +Maximum power level value constant. |
| 138 | + |
| 139 | +.. code-block:: arduino |
| 140 | +
|
| 141 | + static const uint8_t MAX_LEVEL = 255; |
| 142 | +
|
| 143 | +Operators |
| 144 | +********* |
| 145 | + |
| 146 | +bool operator |
| 147 | +^^^^^^^^^^^^^ |
| 148 | + |
| 149 | +Returns the current on/off state of the plugin. |
| 150 | + |
| 151 | +.. code-block:: arduino |
| 152 | +
|
| 153 | + operator bool(); |
| 154 | +
|
| 155 | +Example: |
| 156 | + |
| 157 | +.. code-block:: arduino |
| 158 | +
|
| 159 | + if (myPlugin) { |
| 160 | + Serial.println("Plugin is on"); |
| 161 | + } |
| 162 | +
|
| 163 | +Assignment operator |
| 164 | +^^^^^^^^^^^^^^^^^^^ |
| 165 | + |
| 166 | +Turns the plugin on or off. |
| 167 | + |
| 168 | +.. code-block:: arduino |
| 169 | +
|
| 170 | + void operator=(bool state); |
| 171 | +
|
| 172 | +Example: |
| 173 | + |
| 174 | +.. code-block:: arduino |
| 175 | +
|
| 176 | + myPlugin = true; // Turn plugin on |
| 177 | + myPlugin = false; // Turn plugin off |
| 178 | +
|
| 179 | +Event Handling |
| 180 | +************** |
| 181 | + |
| 182 | +onChange |
| 183 | +^^^^^^^^ |
| 184 | + |
| 185 | +Sets a callback function to be called when any parameter changes. |
| 186 | + |
| 187 | +.. code-block:: arduino |
| 188 | +
|
| 189 | + void onChange(EndPointCB onChangeCB); |
| 190 | +
|
| 191 | +* ``onChangeCB`` - Function to call when state changes |
| 192 | + |
| 193 | +The callback signature is: |
| 194 | + |
| 195 | +.. code-block:: arduino |
| 196 | +
|
| 197 | + bool onChangeCallback(bool newState, uint8_t newLevel); |
| 198 | +
|
| 199 | +* ``newState`` - New on/off state (``true`` = on, ``false`` = off) |
| 200 | +* ``newLevel`` - New power level (0-255) |
| 201 | + |
| 202 | +onChangeOnOff |
| 203 | +^^^^^^^^^^^^^ |
| 204 | + |
| 205 | +Sets a callback function to be called when the on/off state changes. |
| 206 | + |
| 207 | +.. code-block:: arduino |
| 208 | +
|
| 209 | + void onChangeOnOff(EndPointOnOffCB onChangeCB); |
| 210 | +
|
| 211 | +* ``onChangeCB`` - Function to call when on/off state changes |
| 212 | + |
| 213 | +The callback signature is: |
| 214 | + |
| 215 | +.. code-block:: arduino |
| 216 | +
|
| 217 | + bool onChangeCallback(bool newState); |
| 218 | +
|
| 219 | +* ``newState`` - New on/off state (``true`` = on, ``false`` = off) |
| 220 | + |
| 221 | +onChangeLevel |
| 222 | +^^^^^^^^^^^^^ |
| 223 | + |
| 224 | +Sets a callback function to be called when the power level changes. |
| 225 | + |
| 226 | +.. code-block:: arduino |
| 227 | +
|
| 228 | + void onChangeLevel(EndPointLevelCB onChangeCB); |
| 229 | +
|
| 230 | +* ``onChangeCB`` - Function to call when level changes |
| 231 | + |
| 232 | +The callback signature is: |
| 233 | + |
| 234 | +.. code-block:: arduino |
| 235 | +
|
| 236 | + bool onChangeCallback(uint8_t newLevel); |
| 237 | +
|
| 238 | +* ``newLevel`` - New power level (0-255) |
| 239 | + |
| 240 | +updateAccessory |
| 241 | +^^^^^^^^^^^^^^^ |
| 242 | + |
| 243 | +Updates the state of the plugin using the current Matter Plugin internal state. |
| 244 | + |
| 245 | +.. code-block:: arduino |
| 246 | +
|
| 247 | + void updateAccessory(); |
| 248 | +
|
| 249 | +This function will call the registered callback with the current state. |
| 250 | + |
| 251 | +Example |
| 252 | +------- |
| 253 | + |
| 254 | +Dimmable Plugin |
| 255 | +*************** |
| 256 | + |
| 257 | +.. literalinclude:: ../../../libraries/Matter/examples/MatterDimmablePlugin/MatterDimmablePlugin.ino |
| 258 | + :language: arduino |
| 259 | + |
0 commit comments