Skip to content

Commit

Permalink
Defer measurement start.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 6, 2024
1 parent 567e250 commit 01d6470
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion as7343/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ def __init__(self, i2c_dev=None):
).upper()
locals()[name] = key

self.running = False

self.soft_reset()

auxid, revid, id = self.get_version()
Expand Down Expand Up @@ -484,7 +486,6 @@ def __init__(self, i2c_dev=None):
'ENABLE',
FDEN=False,
WEN=True,
SMUXEN=True,
SP_EN=True)

def bank_select(self, bank=0):
Expand Down Expand Up @@ -515,6 +516,20 @@ def set_channels(self, channel_count):
self._read_cycles = int(channel_count / 6)
self._as7343.set('CFG20', auto_SMUX=channel_count)

def start_measurement(self):
if self.running:
return
self.running = True
self._as7343.set(
'ENABLE',
SMUXEN=True)

def stop_measurement(self):
self.running = False
self._as7343.set(
'ENABLE',
SMUXEN=False)

def get_data(self, timeout=5.0):
results = list(self.read_fifo(timeout=timeout))

Expand All @@ -535,6 +550,8 @@ def get_data(self, timeout=5.0):
)

def read_fifo(self, timeout=5.0):
self.start_measurement()

t_start = time.time()
while self._as7343.get('FIFO_LVL').FIFO_LVL < self._read_cycles * 7:
time.sleep(0.001)
Expand Down

0 comments on commit 01d6470

Please sign in to comment.