Skip to content

Commit 424e72c

Browse files
committed
Reducing memory footprint by using _naming for purely internal constants
1 parent c55da0d commit 424e72c

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

adafruit_apds9960/apds9960.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,52 +56,52 @@
5656
# GAIN_DEF = const(0x01)
5757

5858
# APDS9960_RAM = const(0x00)
59-
APDS9960_ENABLE = const(0x80)
60-
APDS9960_ATIME = const(0x81)
59+
_APDS9960_ENABLE = const(0x80)
60+
_APDS9960_ATIME = const(0x81)
6161
# APDS9960_WTIME = const(0x83)
6262
# APDS9960_AILTIL = const(0x84)
6363
# APDS9960_AILTH = const(0x85)
6464
# APDS9960_AIHTL = const(0x86)
6565
# APDS9960_AIHTH = const(0x87)
66-
APDS9960_PILT = const(0x89)
67-
APDS9960_PIHT = const(0x8B)
68-
APDS9960_PERS = const(0x8C)
66+
_APDS9960_PILT = const(0x89)
67+
_APDS9960_PIHT = const(0x8B)
68+
_APDS9960_PERS = const(0x8C)
6969
# APDS9960_CONFIG1 = const(0x8D)
7070
# APDS9960_PPULSE = const(0x8E)
71-
APDS9960_CONTROL = const(0x8F)
71+
_APDS9960_CONTROL = const(0x8F)
7272
# APDS9960_CONFIG2 = const(0x90)
73-
APDS9960_ID = const(0x92)
74-
APDS9960_STATUS = const(0x93)
75-
APDS9960_CDATAL = const(0x94)
73+
_APDS9960_ID = const(0x92)
74+
_APDS9960_STATUS = const(0x93)
75+
_APDS9960_CDATAL = const(0x94)
7676
# APDS9960_CDATAH = const(0x95)
7777
# APDS9960_RDATAL = const(0x96)
7878
# APDS9960_RDATAH = const(0x97)
7979
# APDS9960_GDATAL = const(0x98)
8080
# APDS9960_GDATAH = const(0x99)
8181
# APDS9960_BDATAL = const(0x9A)
8282
# APDS9960_BDATAH = const(0x9B)
83-
APDS9960_PDATA = const(0x9C)
83+
_APDS9960_PDATA = const(0x9C)
8484
# APDS9960_POFFSET_UR = const(0x9D)
8585
# APDS9960_POFFSET_DL = const(0x9E)
8686
# APDS9960_CONFIG3 = const(0x9F)
87-
APDS9960_GPENTH = const(0xA0)
87+
_APDS9960_GPENTH = const(0xA0)
8888
# APDS9960_GEXTH = const(0xA1)
89-
APDS9960_GCONF1 = const(0xA2)
90-
APDS9960_GCONF2 = const(0xA3)
89+
_APDS9960_GCONF1 = const(0xA2)
90+
_APDS9960_GCONF2 = const(0xA3)
9191
# APDS9960_GOFFSET_U = const(0xA4)
9292
# APDS9960_GOFFSET_D = const(0xA5)
9393
# APDS9960_GOFFSET_L = const(0xA7)
9494
# APDS9960_GOFFSET_R = const(0xA9)
95-
APDS9960_GPULSE = const(0xA6)
96-
APDS9960_GCONF3 = const(0xAA)
97-
APDS9960_GCONF4 = const(0xAB)
98-
APDS9960_GFLVL = const(0xAE)
99-
APDS9960_GSTATUS = const(0xAF)
95+
_APDS9960_GPULSE = const(0xA6)
96+
_APDS9960_GCONF3 = const(0xAA)
97+
_APDS9960_GCONF4 = const(0xAB)
98+
_APDS9960_GFLVL = const(0xAE)
99+
_APDS9960_GSTATUS = const(0xAF)
100100
# APDS9960_IFORCE = const(0xE4)
101101
# APDS9960_PICLEAR = const(0xE5)
102102
# APDS9960_CICLEAR = const(0xE6)
103-
APDS9960_AICLEAR = const(0xE7)
104-
APDS9960_GFIFO_U = const(0xFC)
103+
_APDS9960_AICLEAR = const(0xE7)
104+
_APDS9960_GFIFO_U = const(0xFC)
105105
# APDS9960_GFIFO_D = const(0xFD)
106106
# APDS9960_GFIFO_L = const(0xFE)
107107
# APDS9960_GFIFO_R = const(0xFF)
@@ -144,10 +144,10 @@ class APDS9960:
144144
145145
"""
146146

147-
_gesture_enable = RWBit(APDS9960_ENABLE, 6)
148-
_gesture_valid = RWBit(APDS9960_GSTATUS, 0)
149-
_gesture_mode = RWBit(APDS9960_GCONF4, 0)
150-
_proximity_persistance = RWBits(4, APDS9960_PERS, 4)
147+
_gesture_enable = RWBit(_APDS9960_ENABLE, 6)
148+
_gesture_valid = RWBit(_APDS9960_GSTATUS, 0)
149+
_gesture_mode = RWBit(_APDS9960_GCONF4, 0)
150+
_proximity_persistance = RWBits(4, _APDS9960_PERS, 4)
151151

152152
def __init__(
153153
self,
@@ -164,7 +164,7 @@ def __init__(
164164

165165
self.i2c_device = I2CDevice(i2c, address)
166166

167-
if self._read8(APDS9960_ID) != 0xAB:
167+
if self._read8(_APDS9960_ID) != 0xAB:
168168
raise RuntimeError()
169169

170170
self.enable_gesture = False
@@ -188,7 +188,7 @@ def __init__(
188188
self._reset_counts()
189189

190190
# gesture pulse length=0x2 pulse count=0x3
191-
self._write8(APDS9960_GPULSE, (0x2 << 6) | 0x3)
191+
self._write8(_APDS9960_GPULSE, (0x2 << 6) | 0x3)
192192

193193
## BOARD
194194
def _reset_counts(self) -> None:
@@ -198,20 +198,20 @@ def _reset_counts(self) -> None:
198198
self._saw_left_start = 0
199199
self._saw_right_start = 0
200200

201-
enable = RWBit(APDS9960_ENABLE, 0)
201+
enable = RWBit(_APDS9960_ENABLE, 0)
202202
"""Board enable. True to enable, False to disable"""
203-
enable_color = RWBit(APDS9960_ENABLE, 1)
203+
enable_color = RWBit(_APDS9960_ENABLE, 1)
204204
"""Color detection enable flag.
205205
True when color detection is enabled, else False"""
206-
enable_proximity = RWBit(APDS9960_ENABLE, 2)
206+
enable_proximity = RWBit(_APDS9960_ENABLE, 2)
207207
"""Enable of proximity mode"""
208-
gesture_fifo_threshold = RWBits(2, APDS9960_GCONF1, 6)
208+
gesture_fifo_threshold = RWBits(2, _APDS9960_GCONF1, 6)
209209
"""Gesture fifo threshold value: range 0-3"""
210-
gesture_gain = RWBits(2, APDS9960_GCONF2, 5)
210+
gesture_gain = RWBits(2, _APDS9960_GCONF2, 5)
211211
"""Gesture gain value: range 0-3"""
212-
color_gain = RWBits(2, APDS9960_CONTROL, 0)
212+
color_gain = RWBits(2, _APDS9960_CONTROL, 0)
213213
"""Color gain value"""
214-
enable_proximity_interrupt = RWBit(APDS9960_ENABLE, 5)
214+
enable_proximity_interrupt = RWBit(_APDS9960_ENABLE, 5)
215215
"""Proximity interrupt enable flag. True if enabled,
216216
False to disable"""
217217

@@ -256,7 +256,7 @@ def gesture(self) -> int: # pylint: disable-msg=too-many-branches
256256
self.buf129 = bytearray(129)
257257

258258
buffer = self.buf129
259-
buffer[0] = APDS9960_GFIFO_U
259+
buffer[0] = _APDS9960_GFIFO_U
260260
if not self._gesture_valid:
261261
return 0
262262

@@ -269,7 +269,7 @@ def gesture(self) -> int: # pylint: disable-msg=too-many-branches
269269
gesture_received = 0
270270
time.sleep(0.030) # 30 ms
271271

272-
n_recs = self._read8(APDS9960_GFLVL)
272+
n_recs = self._read8(_APDS9960_GFLVL)
273273
if n_recs:
274274

275275
with self.i2c_device as i2c:
@@ -336,25 +336,25 @@ def gesture(self) -> int: # pylint: disable-msg=too-many-branches
336336
@property
337337
def gesture_dimensions(self) -> int:
338338
"""Gesture dimension value: range 0-3"""
339-
return self._read8(APDS9960_GCONF3)
339+
return self._read8(_APDS9960_GCONF3)
340340

341341
@gesture_dimensions.setter
342342
def gesture_dimensions(self, dims: int) -> None:
343-
self._write8(APDS9960_GCONF3, dims & 0x03)
343+
self._write8(_APDS9960_GCONF3, dims & 0x03)
344344

345345
@property
346346
def color_data_ready(self) -> int:
347347
"""Color data ready flag. zero if not ready, 1 is ready"""
348-
return self._read8(APDS9960_STATUS) & 0x01
348+
return self._read8(_APDS9960_STATUS) & 0x01
349349

350350
@property
351351
def color_data(self) -> Tuple[int, int, int, int]:
352352
"""Tuple containing r, g, b, c values"""
353353
return (
354-
self._color_data16(APDS9960_CDATAL + 2),
355-
self._color_data16(APDS9960_CDATAL + 4),
356-
self._color_data16(APDS9960_CDATAL + 6),
357-
self._color_data16(APDS9960_CDATAL),
354+
self._color_data16(_APDS9960_CDATAL + 2),
355+
self._color_data16(_APDS9960_CDATAL + 4),
356+
self._color_data16(_APDS9960_CDATAL + 6),
357+
self._color_data16(_APDS9960_CDATAL),
358358
)
359359

360360
### PROXIMITY
@@ -366,17 +366,17 @@ def proximity_interrupt_threshold(self) -> Tuple[int, int, int]:
366366
zero to three values: low threshold, high threshold, persistance.
367367
persistance defaults to 4 if not provided"""
368368
return (
369-
self._read8(APDS9960_PILT),
370-
self._read8(APDS9960_PIHT),
369+
self._read8(_APDS9960_PILT),
370+
self._read8(_APDS9960_PIHT),
371371
self._proximity_persistance,
372372
)
373373

374374
@proximity_interrupt_threshold.setter
375375
def proximity_interrupt_threshold(self, setting_tuple: Tuple[int, ...]) -> None:
376376
if setting_tuple:
377-
self._write8(APDS9960_PILT, setting_tuple[0])
377+
self._write8(_APDS9960_PILT, setting_tuple[0])
378378
if len(setting_tuple) > 1:
379-
self._write8(APDS9960_PIHT, setting_tuple[1])
379+
self._write8(_APDS9960_PIHT, setting_tuple[1])
380380
persist = 4 # default 4
381381
if len(setting_tuple) > 2:
382382
persist = min(setting_tuple[2], 7)
@@ -385,29 +385,29 @@ def proximity_interrupt_threshold(self, setting_tuple: Tuple[int, ...]) -> None:
385385
@property
386386
def gesture_proximity_threshold(self) -> int:
387387
"""Proximity threshold value: range 0-255"""
388-
return self._read8(APDS9960_GPENTH)
388+
return self._read8(_APDS9960_GPENTH)
389389

390390
@gesture_proximity_threshold.setter
391391
def gesture_proximity_threshold(self, thresh: int) -> None:
392-
self._write8(APDS9960_GPENTH, thresh & 0xFF)
392+
self._write8(_APDS9960_GPENTH, thresh & 0xFF)
393393

394394
@property
395395
def proximity(self) -> int:
396396
"""Proximity value: range 0-255"""
397-
return self._read8(APDS9960_PDATA)
397+
return self._read8(_APDS9960_PDATA)
398398

399399
def clear_interrupt(self) -> None:
400400
"""Clear all interrupts"""
401-
self._writecmdonly(APDS9960_AICLEAR)
401+
self._writecmdonly(_APDS9960_AICLEAR)
402402

403403
@property
404404
def integration_time(self) -> int:
405405
"""Proximity integration time: range 0-255"""
406-
return self._read8(APDS9960_ATIME)
406+
return self._read8(_APDS9960_ATIME)
407407

408408
@integration_time.setter
409409
def integration_time(self, int_time: int) -> None:
410-
self._write8(APDS9960_ATIME, int_time & 0xFF)
410+
self._write8(_APDS9960_ATIME, int_time & 0xFF)
411411

412412
# method for reading and writing to I2C
413413
def _write8(self, command: int, abyte: int) -> None:

0 commit comments

Comments
 (0)