Skip to content

Commit cb1ebcb

Browse files
committed
drivers: Standardize power on/off method naming.
1 parent 8c5600f commit cb1ebcb

24 files changed

Lines changed: 159 additions & 52 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ lib/<component>/
474474
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access.
475475
- **Device identification**: `device_id()` — returns the device/WHO_AM_I register value. All I2C drivers with an ID register must implement this method.
476476
- **Reset methods**: `reset()` for hardware reset (pin toggle), `soft_reset()` for software reset (register write), `reboot()` for memory reboot (reload trimming).
477+
- **Power methods**: `power_on()` / `power_off()`. Drivers with `_ensure_data()` auto-trigger don't need an explicit `power_on()`.
477478

478479
### Linting
479480

lib/apds9960/apds9960/device.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def set_mode(self, mode, enable=True):
111111
def enable_light_sensor(self, interrupts=True):
112112
self.set_ambient_light_gain(APDS9960_DEFAULT_AGAIN)
113113
self.set_ambient_light_int_enable(interrupts)
114-
self.enable_power()
114+
self.power_on()
115115
self.set_mode(APDS9960_MODE_AMBIENT_LIGHT, True)
116116

117117
# stop the light sensor
@@ -124,7 +124,7 @@ def enable_proximity_sensor(self, interrupts=True):
124124
self.set_proximity_gain(APDS9960_DEFAULT_PGAIN)
125125
self.set_led_drive(APDS9960_DEFAULT_LDRIVE)
126126
self.set_proximity_int_enable(interrupts)
127-
self.enable_power()
127+
self.power_on()
128128
self.set_mode(APDS9960_MODE_PROXIMITY, True)
129129

130130
# stop the proximity sensor
@@ -140,7 +140,7 @@ def enable_gesture_sensor(self, interrupts=True):
140140
self.set_led_boost(APDS9960_LED_BOOST_300)
141141
self.set_gesture_int_enable(interrupts)
142142
self.set_gesture_mode(True)
143-
self.enable_power()
143+
self.power_on()
144144
self.set_mode(APDS9960_MODE_WAIT, True)
145145
self.set_mode(APDS9960_MODE_PROXIMITY, True)
146146
self.set_mode(APDS9960_MODE_GESTURE, True)
@@ -213,10 +213,10 @@ def read_gesture(self):
213213
return motion
214214

215215
# turn the APDS-9960 on
216-
def enable_power(self):
216+
def power_on(self):
217217
self.set_mode(APDS9960_MODE_POWER, True)
218218

219-
def disable_power(self):
219+
def power_off(self):
220220
# turn the APDS-9960 off
221221
self.set_mode(APDS9960_MODE_POWER, False)
222222

lib/bq27441/bq27441/device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(
9090
self.gpout_pin = gpout_pin
9191
self.capacity_mAh = capacity_mAh
9292
self.configure_gpout_input()
93-
self.power_up()
93+
self.power_on()
9494

9595
def configure_gpout_input(self):
9696
if self.gpout_pin:
@@ -100,7 +100,7 @@ def configure_gpout_output(self):
100100
if self.gpout_pin:
101101
self.gpout = Pin(self.gpout_pin, mode=Pin.OUT)
102102

103-
def power_up(self):
103+
def power_on(self):
104104
"""Wake up fuel gauge ic if in shutdown mode"""
105105
self.disable_shutdown_mode()
106106
sleep_ms(10)
@@ -109,7 +109,7 @@ def power_up(self):
109109
except Exception:
110110
raise
111111

112-
def power_down(self):
112+
def power_off(self):
113113
"""Put fuel gauge ic in shutdown mode by sending shutdown i2c cmd"""
114114
self.enter_shutdown_mode()
115115

lib/ism330dl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Returns:
234234
## Power Down
235235

236236
```python
237-
imu.power_down()
237+
imu.power_off()
238238
```
239239

240240
Stops accelerometer and gyroscope.

lib/ism330dl/ism330dl/device.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def status(self):
263263
# Power
264264
# --------------------------------------------------
265265

266-
def power_down(self):
266+
def power_off(self):
267267
self._write_u8(REG_CTRL1_XL, 0)
268268
self._write_u8(REG_CTRL2_G, 0)
269+
270+
def power_on(self):
271+
self.configure_accel(self._accel_odr, self._accel_scale)
272+
self.configure_gyro(self._gyro_odr, self._gyro_scale)

lib/lis2mdl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ print("Register dump:", regs)
210210
| `heading_flat_only()` | Flat compass heading |
211211
| `heading_with_tilt_compensation()` | Tilt-corrected heading |
212212
| `read_temperature_c()` | Read relative temperature |
213-
| `power_down()` / `wake()` | Power management |
213+
| `power_on()` / `power_off()` | Power management |
214214
| `soft_reset()` / `reboot()` | Sensor reset functions |
215215

216216
---

lib/lis2mdl/examples/magnet_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def test_power_modes(dev):
518518
ok = True
519519

520520
# Wake in continuous
521-
dev.wake("continuous")
521+
dev.power_on("continuous")
522522
r = dev.read_reg(LIS2MDL_CFG_REG_A)
523523
md = _bits(r, 1, 0)
524524
print(
@@ -530,7 +530,7 @@ def test_power_modes(dev):
530530
ok &= md == 0b00
531531

532532
# Wake in single
533-
dev.wake("single")
533+
dev.power_on("single")
534534
r = dev.read_reg(LIS2MDL_CFG_REG_A)
535535
md = _bits(r, 1, 0)
536536
print(
@@ -542,11 +542,11 @@ def test_power_modes(dev):
542542
ok &= md == 0b01
543543

544544
# Power down
545-
dev.power_down()
545+
dev.power_off()
546546
r = dev.read_reg(LIS2MDL_CFG_REG_A)
547547
md = _bits(r, 1, 0)
548548
print(
549-
"power_down() => MD=",
549+
"power_off() => MD=",
550550
md,
551551
"expected 0b11 =>",
552552
"OK" if md == 0b11 else "FAIL",
@@ -561,7 +561,7 @@ def test_power_modes(dev):
561561
ok &= dev.is_idle()
562562

563563
# Back to continuous
564-
dev.wake("continuous")
564+
dev.power_on("continuous")
565565
r = dev.read_reg(LIS2MDL_CFG_REG_A)
566566
md = _bits(r, 1, 0)
567567
print(

lib/lis2mdl/lis2mdl/device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,14 @@ def get_mode(self) -> str:
584584
md = r & 0b11
585585
return {0b00: "continuous", 0b01: "single", 0b11: "idle"}.get(md, "idle")
586586

587-
def power_down(self):
587+
def power_off(self):
588588
"""Switches to IDLE mode (low power)."""
589589
r = self._read_reg(LIS2MDL_CFG_REG_A)
590590
r = (r & ~0b11) | 0b11 # MD1..0 = 11
591591
self._write_reg(LIS2MDL_CFG_REG_A, r)
592592

593-
def wake(self, mode: str = "continuous"):
594-
"""Wakes the sensor: 'continuous' (default) or 'single'."""
593+
def power_on(self, mode: str = "continuous"):
594+
"""Power on the sensor: 'continuous' (default) or 'single'."""
595595
md = {"continuous": 0b00, "single": 0b01}.get(mode, 0b00)
596596
r = self._read_reg(LIS2MDL_CFG_REG_A)
597597
r = (r & ~0b11) | md

lib/mcp23009e/mcp23009e/device.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def reset(self):
5858
self.reset_pin.value(1)
5959
sleep_ms(10)
6060

61+
def power_off(self):
62+
self.reset_pin.value(0)
63+
64+
def power_on(self):
65+
self.reset_pin.value(1)
66+
sleep_ms(10)
67+
6168
def _soft_reset(self):
6269
"""Réinitialise le composant avec les valeurs par défaut"""
6370
# Configuration par défaut : toutes les pins en entrée

lib/ssd1327/ssd1327/device.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, width=128, height=128):
2525
# 96x96 32
2626
# 128x128 0
2727

28-
self.poweron()
28+
self.power_on()
2929
self.init_display()
3030

3131
def init_display(self):
@@ -81,12 +81,12 @@ def init_display(self):
8181
self.fill(0)
8282
self.write_data(self.buffer)
8383

84-
def poweroff(self):
84+
def power_off(self):
8585
self.write_cmd(SET_FN_SELECT_A)
8686
self.write_cmd(0x00) # Disable internal VDD regulator, to save power
8787
self.write_cmd(SET_DISP)
8888

89-
def poweron(self):
89+
def power_on(self):
9090
self.write_cmd(SET_FN_SELECT_A)
9191
self.write_cmd(0x01) # Enable internal VDD regulator
9292
self.write_cmd(SET_DISP | 0x01)
@@ -96,12 +96,12 @@ def contrast(self, contrast):
9696
self.write_cmd(contrast) # 0-255
9797

9898
def rotate(self, rotate):
99-
self.poweroff()
99+
self.power_off()
100100
self.write_cmd(SET_DISP_OFFSET)
101101
self.write_cmd(self.height if rotate else self.offset)
102102
self.write_cmd(SET_SEG_REMAP)
103103
self.write_cmd(0x42 if rotate else 0x51)
104-
self.poweron()
104+
self.power_on()
105105

106106
def invert(self, invert):
107107
self.write_cmd(

0 commit comments

Comments
 (0)