-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbaseline.py
34 lines (27 loc) · 996 Bytes
/
baseline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Store and retreive environment baseline values for the ccs811 sensor."""
import uio
import uos
class Baseline:
"""Store and retreive environment baseline values for the ccs811 sensor."""
_BASELINE_FILE = 'ccs811_baseline.txt'
def exists(self):
"""Check if baseline exists."""
try:
with uio.open(self._BASELINE_FILE, mode='r'):
return True
except OSError:
return False
def store(self, value):
"""Store baseline integer value."""
with uio.open(self._BASELINE_FILE, mode='w') as baseline_file:
baseline_file.write('%s\n' % str(value))
def retrieve(self):
"""Retrieve baseline integer value."""
with uio.open(self._BASELINE_FILE, mode='r') as baseline_file:
return int(baseline_file.readline())
def delete(self):
"""Delete the baseline."""
try:
uos.remove(self._BASELINE_FILE)
except OSError:
pass