Skip to content

Commit b471723

Browse files
committed
Simplify const() variable names
1 parent 02e24a7 commit b471723

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

adafruit_si1145.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,49 @@
3535
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SI1145.git"
3636

3737
# Registers
38-
SI1145_DEFAULT_ADDRESS = const(0x60)
39-
SI1145_PART_ID = const(0x00)
40-
SI1145_HW_KEY = const(0x07)
38+
_DEFAULT_ADDRESS = const(0x60)
39+
_PART_ID = const(0x00)
40+
_HW_KEY = const(0x07)
4141
_COEFF_0 = const(0x13)
4242
_COEFF_1 = const(0x14)
4343
_COEFF_2 = const(0x15)
4444
_COEFF_3 = const(0x16)
45-
SI1145_PARAM_WR = const(0x17)
46-
SI1145_COMMAND = const(0x18)
47-
SI1145_RESPONSE = const(0x20)
48-
SI1145_ALS_VIS_DATA0 = const(0x22)
49-
SI1145_UV_INDEX_DATA0 = const(0x2C)
50-
SI1145_PARAM_RD = const(0x2E)
45+
_PARAM_WR = const(0x17)
46+
_COMMAND = const(0x18)
47+
_RESPONSE = const(0x20)
48+
_ALS_VIS_DATA0 = const(0x22)
49+
_UV_INDEX_DATA0 = const(0x2C)
50+
_PARAM_RD = const(0x2E)
5151

5252
# Commands (for COMMAND register)
53-
SI1145_CMD_PARAM_QUERY = const(0b10000000)
54-
SI1145_CMD_PARAM_SET = const(0b10100000)
55-
SI1145_CMD_NOP = const(0b00000000)
56-
SI1145_CMD_RESET = const(0b00000001)
57-
SI1145_CMD_ALS_FORCE = const(0b00000110)
53+
_CMD_PARAM_QUERY = const(0b10000000)
54+
_CMD_PARAM_SET = const(0b10100000)
55+
_CMD_NOP = const(0b00000000)
56+
_CMD_RESET = const(0b00000001)
57+
_CMD_ALS_FORCE = const(0b00000110)
5858

5959
# RAM Parameter Offsets (use with PARAM_QUERY / PARAM_SET)
60-
SI1145_RAM_CHLIST = const(0x01)
60+
_RAM_CHLIST = const(0x01)
6161

6262

6363
class SI1145:
6464
"""Driver for the SI1145 UV, IR, Visible Light Sensor."""
6565

66-
_device_info = Struct(SI1145_PART_ID, "<BBB")
66+
_device_info = Struct(_PART_ID, "<BBB")
6767
_ucoeff_0 = Struct(_COEFF_0, "<B")
6868
_ucoeff_1 = Struct(_COEFF_1, "<B")
6969
_ucoeff_2 = Struct(_COEFF_2, "<B")
7070
_ucoeff_3 = Struct(_COEFF_3, "<B")
71-
_als_data = Struct(SI1145_ALS_VIS_DATA0, "<HH")
72-
_aux_data = Struct(SI1145_UV_INDEX_DATA0, "<H")
71+
_als_data = Struct(_ALS_VIS_DATA0, "<HH")
72+
_aux_data = Struct(_UV_INDEX_DATA0, "<H")
7373

74-
def __init__(self, i2c, address=SI1145_DEFAULT_ADDRESS):
74+
def __init__(self, i2c, address=_DEFAULT_ADDRESS):
7575
self.i2c_device = i2c_device.I2CDevice(i2c, address)
7676
dev_id, dev_rev, dev_seq = self.device_info
7777
if dev_id != 69 or dev_rev != 0 or dev_seq != 8:
7878
raise RuntimeError("Failed to find SI1145.")
7979
self.reset()
80-
self._write_register(SI1145_HW_KEY, 0x17)
80+
self._write_register(_HW_KEY, 0x17)
8181
self._als_enabled = True
8282
self._uv_index_enabled = True
8383
self.als_enabled = self._als_enabled
@@ -95,18 +95,18 @@ def als_enabled(self):
9595

9696
@als_enabled.setter
9797
def als_enabled(self, enable):
98-
chlist = self._param_query(SI1145_RAM_CHLIST)
98+
chlist = self._param_query(_RAM_CHLIST)
9999
if enable:
100100
chlist |= 0b00110000
101101
else:
102102
chlist &= ~0b00110000
103-
self._param_set(SI1145_RAM_CHLIST, chlist)
103+
self._param_set(_RAM_CHLIST, chlist)
104104
self._als_enabled = enable
105105

106106
@property
107107
def als(self):
108108
"""A two tuple of the Ambient Light System (ALS) visible and infrared raw sensor values."""
109-
self._send_command(SI1145_CMD_ALS_FORCE)
109+
self._send_command(_CMD_ALS_FORCE)
110110
return self._als_data
111111

112112
@property
@@ -116,12 +116,12 @@ def uv_index_enabled(self):
116116

117117
@uv_index_enabled.setter
118118
def uv_index_enabled(self, enable):
119-
chlist = self._param_query(SI1145_RAM_CHLIST)
119+
chlist = self._param_query(_RAM_CHLIST)
120120
if enable:
121121
chlist |= 0b01000000
122122
else:
123123
chlist &= ~0b01000000
124-
self._param_set(SI1145_RAM_CHLIST, chlist)
124+
self._param_set(_RAM_CHLIST, chlist)
125125
self._als_enabled = enable
126126

127127
self._ucoeff_0 = 0x00
@@ -136,31 +136,31 @@ def uv_index(self):
136136

137137
def reset(self):
138138
"""Perform a software reset of the firmware."""
139-
self._send_command(SI1145_CMD_RESET)
139+
self._send_command(_CMD_RESET)
140140
time.sleep(0.05) # doubling 25ms datasheet spec
141141

142142
def clear_error(self):
143143
"""Clear any existing error code."""
144-
self._send_command(SI1145_CMD_NOP)
144+
self._send_command(_CMD_NOP)
145145

146146
def _param_query(self, param):
147-
self._send_command(SI1145_CMD_PARAM_QUERY | (param & 0x1F))
148-
return self._read_register(SI1145_PARAM_RD)
147+
self._send_command(_CMD_PARAM_QUERY | (param & 0x1F))
148+
return self._read_register(_PARAM_RD)
149149

150150
def _param_set(self, param, value):
151-
self._write_register(SI1145_PARAM_WR, value)
152-
self._send_command(SI1145_CMD_PARAM_SET | (param & 0x1F))
151+
self._write_register(_PARAM_WR, value)
152+
self._send_command(_CMD_PARAM_SET | (param & 0x1F))
153153

154154
def _send_command(self, command):
155-
counter = self._read_register(SI1145_RESPONSE) & 0x0F
156-
self._write_register(SI1145_COMMAND, command)
157-
if command in (SI1145_CMD_NOP, SI1145_CMD_RESET):
155+
counter = self._read_register(_RESPONSE) & 0x0F
156+
self._write_register(_COMMAND, command)
157+
if command in (_CMD_NOP, _CMD_RESET):
158158
return 0
159-
response = self._read_register(SI1145_RESPONSE)
159+
response = self._read_register(_RESPONSE)
160160
while counter == response & 0x0F:
161161
if response & 0xF0:
162162
raise RuntimeError("SI1145 Error: 0x{:02x}".format(response & 0xF0))
163-
response = self._read_register(SI1145_RESPONSE)
163+
response = self._read_register(_RESPONSE)
164164
return response
165165

166166
def _read_register(self, register, length=1):

0 commit comments

Comments
 (0)