Skip to content

Commit cbbb8c8

Browse files
committed
Add a property setter for baseline
1 parent 3d65d3b commit cbbb8c8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

adafruit_ccs811.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
__version__ = "0.0.0-auto.0"
4545
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CCS811.git"
4646

47-
_BASELINE_PACKING_FORMAT = "<H"
4847

4948
_ALG_RESULT_DATA = const(0x02)
5049
_RAW_DATA = const(0x03)
@@ -161,7 +160,7 @@ def _update_data(self):
161160
@property
162161
def baseline(self):
163162
"""
164-
The function read and return the current baseline value.
163+
The propery reads and returns the current baseline value.
165164
The returned value is packed into an integer.
166165
Later the same integer can be passed `set_baseline` function
167166
in order to set a new baseline.
@@ -170,16 +169,17 @@ def baseline(self):
170169
buf[0] = _BASELINE
171170
with self.i2c_device as i2c:
172171
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)
173-
return struct.unpack(_BASELINE_PACKING_FORMAT, buf[1:])[0]
172+
return struct.unpack("<H", buf[1:])[0]
174173

175-
def set_baseline(self, baseline_int):
174+
@baseline.setter
175+
def baseline(self, baseline_int):
176176
"""
177-
The function lets you set a new baseline. As an argument accepts
177+
The property lets you set a new baseline. As a value accepts
178178
integer which represents packed baseline 2 bytes value.
179179
"""
180180
buf = bytearray(3)
181181
buf[0] = _BASELINE
182-
struct.pack_into(_BASELINE_PACKING_FORMAT, buf, 1, baseline_int)
182+
struct.pack_into("<H", buf, 1, baseline_int)
183183
with self.i2c_device as i2c:
184184
i2c.write(buf)
185185

0 commit comments

Comments
 (0)