summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adxl.py12
-rw-r--r--baresp.py21
2 files changed, 15 insertions, 18 deletions
diff --git a/adxl.py b/adxl.py
index c5e5f61..c87781d 100644
--- a/adxl.py
+++ b/adxl.py
@@ -6,7 +6,6 @@ class ADXL():
def __init__(self, SCL, SDA):
self.SCL = SCL
self.SDA = SDA
-
self._i2c = machine.I2C(scl=self.SCL, sda=self.SDA, freq=100000)
self._last_x = 0.0
@@ -16,17 +15,18 @@ class ADXL():
self._last_act_y = 0.0
self._last_act_z = 0.0
+ self._is_active = False
+
self._timer = machine.Timer(-1)
self._timer.init(period=100, mode=machine.Timer.PERIODIC, callback=self._timer_cb)
- self._is_active = True
-
self._timer_cb(None)
def setup(self):
r = self._i2c.readfrom_mem(self.ADXL_ADDR, 0x2D, 1)
- if (not bool(r[0] & (1 << 3)) or True):
+ if (not bool(r[0] & (1 << 3))):
+ print('setup')
# OFFSET_{X,Y,Z}
#self._i2c.writeto_mem(self.ADXL_ADDR, 0x1E, bytes([25, 76, 183]))
self._i2c.writeto_mem(self.ADXL_ADDR, 0x1E, bytes([25, 75, 131]))
@@ -75,14 +75,14 @@ class ADXL():
def _timer_cb(self, t):
int_src = self._i2c.readfrom_mem(self.ADXL_ADDR, 0x30, 1)
- #print(int_src)
- #print(self.read_data())
if (bool(int_src[0] & (1 << 4))):
+ print('activity detected')
self._is_active = True
(self._last_act_x, self._last_act_y, self._last_act_z) = self.read_data()
if (bool(int_src[0] & (1 << 3))):
+ print('inactivity detected')
self._is_active = False
if (bool(int_src[0] & (1 << 7))):
diff --git a/baresp.py b/baresp.py
index 30d5001..b58c2e2 100644
--- a/baresp.py
+++ b/baresp.py
@@ -76,10 +76,10 @@ class BarESP():
if (not machine.reset_cause() == machine.DEEPSLEEP_RESET):
self._log.info('non DS reset')
- self.adxl.setup()
else:
self._log.info('DS Reset')
- self.adxl.setup()
+
+ self.adxl.setup()
self.adxl.activity_intr(False)
self.adxl.inactivity_intr(True)
@@ -96,9 +96,8 @@ class BarESP():
if (self.adxl.is_active()):
BCEN_PIN.on()
- self.bar.state = BarState.WAIT_FOR_BARCODE
-
self.connect()
+ self.bar.state = BarState.WAIT_FOR_BARCODE
self.esp.state = ESPState.IDLE_ON
else:
@@ -106,28 +105,28 @@ class BarESP():
self.deepsleep(0)
elif (self.esp.state == ESPState.IDLE_ON):
- #self._log.debug(b'IDLE_ON\n')
+ #self._log.debug(b'IDLE_ON')
if (not self.adxl.is_active()):
if (self.bar.state == BarState.WAIT_FOR_BARCODE):
BCEN_PIN.off()
self.bar.state = BarState.OFF
- self._log.debug(b'->BAR_OFF\n')
+ self._log.debug(b'->BAR_OFF')
if (len(self._cache) == 0):
if (not self.bar.state == BarState.READING_BARCODE):
self.esp.state = ESPState.WAIT_FOR_ACTIVITY
- self._log.debug(b'->WFA\n')
+ self._log.debug(b'->WFA')
if (len(self._cache) > 0):
self.esp.state = ESPState.PENDING_DATA
- self._log.debug(b'->PDb\n')
+ self._log.debug(b'->PDb')
elif (self.esp.state == ESPState.PENDING_DATA):
if (len(self._cache) == 0):
self.esp.state = ESPState.IDLE_ON
self.ack_data_sent()
- self._log.debug(b'->IO\n')
+ self._log.debug(b'->IO')
else:
if (not (self.wlan.active() and self.wlan.isconnected())):
@@ -138,7 +137,6 @@ class BarESP():
bc = self._cache.pop(0)
self._log.debug(b'PD.pop')
self._log.debug(bc)
- self._log.debug(b'\n')
try:
s = usocket.socket()
@@ -147,7 +145,7 @@ class BarESP():
s.close()
utime.sleep_ms(100)
except Exception as e:
- self._log.debug(b'Sending bc failed.\n')
+ self._log.debug(b'Sending bc failed.')
self._log.debug(e)
self._cache.append(bc)
break
@@ -162,7 +160,6 @@ class BarESP():
def run_bar(self):
if (self.bar.state == BarState.WAIT_FOR_BARCODE):
bc = self.try_barcode()
-
if (bc):
self._cache.append(bc)