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