|
44 | 44 | __version__ = "0.0.0-auto.0"
|
45 | 45 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CCS811.git"
|
46 | 46 |
|
| 47 | + |
47 | 48 | _ALG_RESULT_DATA = const(0x02)
|
48 | 49 | _RAW_DATA = const(0x03)
|
49 | 50 | _ENV_DATA = const(0x05)
|
50 | 51 | _NTC = const(0x06)
|
51 | 52 | _THRESHOLDS = const(0x10)
|
52 | 53 |
|
53 |
| -# _BASELINE = 0x11 |
| 54 | +_BASELINE = const(0x11) |
| 55 | + |
54 | 56 | # _HW_ID = 0x20
|
55 | 57 | # _HW_VERSION = 0x21
|
56 | 58 | # _FW_BOOT_VERSION = 0x23
|
@@ -106,7 +108,6 @@ def __init__(self, i2c_bus, address=0x5A):
|
106 | 108 | raise RuntimeError(
|
107 | 109 | "Device ID returned is not correct! Please check your wiring."
|
108 | 110 | )
|
109 |
| - |
110 | 111 | # try to start the app
|
111 | 112 | buf = bytearray(1)
|
112 | 113 | buf[0] = 0xF4
|
@@ -156,6 +157,32 @@ def _update_data(self):
|
156 | 157 | if self.error:
|
157 | 158 | raise RuntimeError("Error:" + str(self.error_code))
|
158 | 159 |
|
| 160 | + @property |
| 161 | + def baseline(self): |
| 162 | + """ |
| 163 | + The propery reads and returns the current baseline value. |
| 164 | + The returned value is packed into an integer. |
| 165 | + Later the same integer can be used in order |
| 166 | + to set a new baseline. |
| 167 | + """ |
| 168 | + buf = bytearray(3) |
| 169 | + buf[0] = _BASELINE |
| 170 | + with self.i2c_device as i2c: |
| 171 | + i2c.write_then_readinto(buf, buf, out_end=1, in_start=1) |
| 172 | + return struct.unpack("<H", buf[1:])[0] |
| 173 | + |
| 174 | + @baseline.setter |
| 175 | + def baseline(self, baseline_int): |
| 176 | + """ |
| 177 | + The property lets you set a new baseline. As a value accepts |
| 178 | + integer which represents packed baseline 2 bytes value. |
| 179 | + """ |
| 180 | + buf = bytearray(3) |
| 181 | + buf[0] = _BASELINE |
| 182 | + struct.pack_into("<H", buf, 1, baseline_int) |
| 183 | + with self.i2c_device as i2c: |
| 184 | + i2c.write(buf) |
| 185 | + |
159 | 186 | @property
|
160 | 187 | def tvoc(self): # pylint: disable=invalid-name
|
161 | 188 | """Total Volatile Organic Compound in parts per billion."""
|
|
0 commit comments