updating, sending values with write command no response
moving formatting around to reduce memory footprint handling eonotcon error by restarting network
This commit is contained in:
56
barrier.py
56
barrier.py
@@ -4,17 +4,23 @@ from machine import Pin
|
||||
|
||||
|
||||
class Barrier:
|
||||
moving = 0
|
||||
barrier_position = 0
|
||||
moving = b'\x00'
|
||||
barrier_position = b'\x00'
|
||||
ad0 = Pin("D0", Pin.IN, Pin.PULL_UP) #door
|
||||
ad1 = Pin("D1", Pin.IN, Pin.PULL_UP) #motor
|
||||
ad4 = Pin("D4", Pin.OUT, value=0)
|
||||
door = ad0.value()
|
||||
motor = ad1.value()
|
||||
update = False
|
||||
door = ad0.value().to_bytes(2,"big")
|
||||
motor = ad1.value().to_bytes(2, "big")
|
||||
update = True
|
||||
|
||||
def status(self, seq, payload):
|
||||
pass
|
||||
#moving state is x0001 enum8(0x30)
|
||||
#Barrierposition is 0x000A uint8(0x20)
|
||||
# 2 octets attribute identifier
|
||||
# 1 octet attribute data type
|
||||
# 1 octet attribute value
|
||||
return bytes([1,0,32,self.moving,10,0,20,self.barrier_position])
|
||||
|
||||
|
||||
def command(self, seq, payload):
|
||||
pass
|
||||
@@ -22,26 +28,28 @@ class Barrier:
|
||||
def watch(self):
|
||||
current_door = self.door
|
||||
current_motor = self.motor
|
||||
self.door = self.ad0.value()
|
||||
self.motor = self.ad1.value()
|
||||
self.door = self.ad0.value().to_bytes(2, "big")
|
||||
self.motor = self.ad1.value().to_bytes(2, "big")
|
||||
#print("door: "+str(self.door))
|
||||
#print("motor:" +str(self.motor))
|
||||
if (current_door != self.door) or (current_motor != self.motor):
|
||||
self.update = True
|
||||
else:
|
||||
self.update = False
|
||||
if self.door == 0:
|
||||
if self.motor == 1:
|
||||
self.moving = 0
|
||||
self.barrier_position = 100
|
||||
if self.motor == 0:
|
||||
if self.door == 1:
|
||||
self.moving = 0
|
||||
self.barrier_position = 0
|
||||
if self.motor == 0:
|
||||
if self.door == 0:
|
||||
if self.barrier_position == 100:
|
||||
self.barrier_position = 50
|
||||
self.moving = 1
|
||||
if self.barrier_position == 0:
|
||||
self.barrier_position = 50
|
||||
self.moving = 2
|
||||
if self.door == b'\x00':
|
||||
if self.motor == b'\x01':
|
||||
self.moving = b'\x00'
|
||||
self.barrier_position = b'\x64'
|
||||
if self.motor == b'\x00':
|
||||
if self.door == b'\x01':
|
||||
self.moving = b'\x00'
|
||||
self.barrier_position = b'\x00'
|
||||
if self.motor == b'\x00':
|
||||
if self.door == b'\x00':
|
||||
if self.barrier_position == b'\x64':
|
||||
self.barrier_position = b'\x32'
|
||||
self.moving = b'\x01'
|
||||
if self.barrier_position == b'\x00':
|
||||
self.barrier_position = b'\x32'
|
||||
self.moving = b'\x02'
|
||||
return self.update
|
||||
|
||||
Reference in New Issue
Block a user