|
| 1 | +Power |
| 2 | +====== |
| 3 | + |
| 4 | +.. include:: ../refs/system.ref |
| 5 | +.. include:: ../refs/hardware.power.ref |
| 6 | + |
| 7 | +class Power |
| 8 | +------------ |
| 9 | + |
| 10 | +.. important:: |
| 11 | + |
| 12 | + Methods of the Power Class depend on ``M5.begin()`` |M5.begin.svg|. |
| 13 | + |
| 14 | + All methods calling the Power object need to be placed after ``M5.begin()`` |M5.begin.svg|. |
| 15 | + |
| 16 | +Methods |
| 17 | +------- |
| 18 | + |
| 19 | +.. method:: Power.setExtOutput(enable: bool, port: int=0xFF) -> None |
| 20 | + |
| 21 | + Set power output of the external ports. |
| 22 | + |
| 23 | + When ``enable`` is True, the power output of the external ports is in output |
| 24 | + mode. When ``enable`` is False, the power output of the external ports is |
| 25 | + in input mode. |
| 26 | + |
| 27 | + ``port`` is the port number, optional values are available in :ref:`class PORT`, |
| 28 | + only valid for M5Stack Station. |
| 29 | + |
| 30 | + UIFLOW2: |
| 31 | + |
| 32 | + |setExtOutput1.svg| |
| 33 | + |setExtOutput2.svg| |
| 34 | + |
| 35 | + |
| 36 | +.. method:: Power.getExtOutput() -> bool |
| 37 | + |
| 38 | + Get power output of the external ports. |
| 39 | + |
| 40 | + Returns ``True`` if the power output of the external ports is in output |
| 41 | + mode. Returns ``False`` if the power output of the external ports is in |
| 42 | + input mode. |
| 43 | + |
| 44 | + UIFLOW2: |
| 45 | + |
| 46 | + |getExtOutput.svg| |
| 47 | + |
| 48 | + |
| 49 | +.. method:: Power.setUsbOutput(enable: bool) -> None |
| 50 | + |
| 51 | + Set power output of the main USB port. |
| 52 | + |
| 53 | + When ``enable`` is True, the power output of the main USB port is in output |
| 54 | + mode. When ``enable`` is False, the power output of the main USB port is in |
| 55 | + input mode. |
| 56 | + |
| 57 | + UIFLOW2: |
| 58 | + |
| 59 | + |setUsbOutput.svg| |
| 60 | + |
| 61 | + |
| 62 | +.. method:: Power.getUsbOutput() -> bool |
| 63 | + |
| 64 | + Get power output of the main USB port. |
| 65 | + |
| 66 | + Returns ``True`` if the power output of the main USB port is in output mode. |
| 67 | + Returns ``False`` if the power output of the main USB port is in input mode. |
| 68 | + |
| 69 | + UIFLOW2: |
| 70 | + |
| 71 | + |getUsbOutput.svg| |
| 72 | + |
| 73 | + |
| 74 | +.. method:: Power.setLed(brightness=255) -> None |
| 75 | + |
| 76 | + Turn on/off the power LED. |
| 77 | + |
| 78 | + ``brightness`` is the brightness value, ranging from 0 to 255. 0 is off, |
| 79 | + 255 is the maximum brightness. |
| 80 | + |
| 81 | + UIFLOW2: |
| 82 | + |
| 83 | + |setLed.svg| |
| 84 | + |
| 85 | + |
| 86 | +.. method:: Power.powerOff() |
| 87 | + |
| 88 | + Turn off all power. |
| 89 | + |
| 90 | + UIFLOW2: |
| 91 | + |
| 92 | + |powerOff.svg| |
| 93 | + |
| 94 | + |
| 95 | +.. method:: Power.timerSleep(seconds) -> None |
| 96 | + Power.timerSleep(minutes, hours) -> None |
| 97 | + Power.timerSleep(minutes, hours, date, weekDay) -> None |
| 98 | + |
| 99 | + sleep and timer boot. The boot condition can be specified by the argument. |
| 100 | + |
| 101 | + ``seconds``: Range is 1 - 15300, in seconds. |
| 102 | + |
| 103 | + ``minutes``: Range is 0 - 59, in minutes. |
| 104 | + |
| 105 | + ``hours``: Range is 0 - 23, in hours. |
| 106 | + |
| 107 | + ``date``: Range is 1 - 31, in days. |
| 108 | + |
| 109 | + ``weekDay``: Range is 0 - 6. |
| 110 | + |
| 111 | + UIFLOW2: |
| 112 | + |
| 113 | + |timerSleep1.svg| |
| 114 | + |timerSleep2.svg| |
| 115 | + |timerSleep3.svg| |
| 116 | + |
| 117 | + |
| 118 | +.. method:: Power.deepSleep(micro_seconds: int=0, wakeup: bool=True) |
| 119 | + |
| 120 | + ESP32 deepsleep. |
| 121 | + |
| 122 | + ``micro_seconds``: Number of micro seconds to wakeup. |
| 123 | + |
| 124 | + ``wakeup``: Whether to wake up. |
| 125 | + |
| 126 | + UIFLOW2: |
| 127 | + |
| 128 | + |deepSleep.svg| |
| 129 | + |
| 130 | + |
| 131 | +.. method:: Power.lightSleep(micro_seconds: int=0, wakeup: bool=True) |
| 132 | + |
| 133 | + ESP32 lightsleep. |
| 134 | + |
| 135 | + ``micro_seconds``: Number of micro seconds to wakeup. |
| 136 | + |
| 137 | + ``wakeup``: Whether to wake up. |
| 138 | + |
| 139 | + UIFLOW2: |
| 140 | + |
| 141 | + |lightSleep.svg| |
| 142 | + |
| 143 | + |
| 144 | +.. method:: Power.getBatteryLevel() -> int |
| 145 | + |
| 146 | + Get the remaining battery power percentage. Returns a value between 0-100. |
| 147 | + |
| 148 | + UIFLOW2: |
| 149 | + |
| 150 | + |getBatteryLevel.svg| |
| 151 | + |
| 152 | + |
| 153 | +.. method:: Power.setBatteryCharge(enable: bool) -> None |
| 154 | + |
| 155 | + Set battery charging enable. |
| 156 | + |
| 157 | + UIFLOW2: |
| 158 | + |
| 159 | + |setBatteryCharge.svg| |
| 160 | + |
| 161 | + |
| 162 | +.. method:: Power.setChargeCurrent(max_mA: int) -> None |
| 163 | + |
| 164 | + Set battery charge current. |
| 165 | + |
| 166 | + ``max_mA``: Range is 0-2000, in milliamps. |
| 167 | + |
| 168 | + UIFLOW2: |
| 169 | + |
| 170 | + |setChargeCurrent.svg| |
| 171 | + |
| 172 | + |
| 173 | +.. method:: Power.setChargeVoltage(max_mV: int) -> None |
| 174 | + |
| 175 | + Set battery charge voltage. |
| 176 | + |
| 177 | + ``max_mV``: Range is 4100-4600, in millivolts. |
| 178 | + |
| 179 | + UIFLOW2: |
| 180 | + |
| 181 | + |setChargeVoltage.svg| |
| 182 | + |
| 183 | + |
| 184 | +.. method:: Power.isCharging() -> bool |
| 185 | + |
| 186 | + Get whether the battery is currently charging or not. |
| 187 | + |
| 188 | + UIFLOW2: |
| 189 | + |
| 190 | + |isCharging.svg| |
| 191 | + |
| 192 | + |
| 193 | +.. method:: Power.getBatteryVoltage() -> int |
| 194 | + |
| 195 | + Get battery voltage. Unit is millivolts. |
| 196 | + |
| 197 | + UIFLOW2: |
| 198 | + |
| 199 | + |getBatteryVoltage.svg| |
| 200 | + |
| 201 | + |
| 202 | +.. method:: Power.getBatteryCurrent() -> int |
| 203 | + |
| 204 | + Get battery current. Unit is milliamps. |
| 205 | + |
| 206 | + UIFLOW2: |
| 207 | + |
| 208 | + |getBatteryCurrent.svg| |
| 209 | + |
| 210 | + |
| 211 | +.. method:: Power.getKeyState() -> int |
| 212 | + |
| 213 | + Get Power Key Press condition. |
| 214 | + |
| 215 | + UIFLOW2: |
| 216 | + |
| 217 | + |getKeyState.svg| |
| 218 | + |
| 219 | +.. method:: Power.setVibration(level: int) -> None |
| 220 | + |
| 221 | + Operate the vibration motor. |
| 222 | + |
| 223 | + ``level``: Vibration intensity, ranging from 0-255. |
| 224 | + |
| 225 | + UIFLOW2: |
| 226 | + |
| 227 | + |setVibration.svg| |
| 228 | + |
| 229 | +.. _class PORT: |
| 230 | + |
| 231 | +class PORT |
| 232 | +---------- |
| 233 | + |
| 234 | +Constants |
| 235 | +--------- |
| 236 | + |
| 237 | +.. data:: PORT.A |
| 238 | + |
| 239 | + Port A. |
| 240 | + |
| 241 | +.. data:: PORT.B1 |
| 242 | + |
| 243 | + Port B1. |
| 244 | + |
| 245 | +.. data:: PORT.B2 |
| 246 | + |
| 247 | + Port B2. |
| 248 | + |
| 249 | +.. data:: PORT.C1 |
| 250 | + |
| 251 | + Port C1. |
| 252 | + |
| 253 | +.. data:: PORT.C2 |
| 254 | + |
| 255 | + Port C2. |
| 256 | + |
| 257 | +.. data:: PORT.USB |
| 258 | + |
| 259 | + USB Port. |
| 260 | + |
| 261 | +.. data:: PORT.HAT |
| 262 | + |
| 263 | + HAT Port. |
| 264 | + |
| 265 | +.. data:: PORT.ALL |
| 266 | + |
| 267 | + All Ports. |
0 commit comments