Skip to content

Commit

Permalink
restructure layout for easy multi-file update
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVentura committed Jul 11, 2019
1 parent 5a59852 commit 1a93289
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 53 deletions.
1 change: 1 addition & 0 deletions firmware/curtains/HOSTNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALL_CURTAINS
1 change: 1 addition & 0 deletions firmware/curtains/common.py
39 changes: 10 additions & 29 deletions firmware/curtains_433.py → firmware/curtains/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import common
import time
from machine import Pin
from rfsocket import RFSocket

CLIENT_ID = 'ALL_CURTAINS'
TOPIC_PREFIX = "%s/set" % CLIENT_ID
SUBTOPICS = [b"ALL_CURTAINS/set/#" % TOPIC_PREFIX, b"RFPOWER/set/#"]
CLIENT_ID = common.get_client_id()
SUBTOPIC = b"%s/set/#" % CLIENT_ID

relay_up = Pin(16, Pin.OUT) # D0
relay_down = Pin(4, Pin.OUT) # D2

p = Pin(0, Pin.OUT)
s = RFSocket(p, remote_id=41203711, chann=RFSocket.NEXA)

def set_channel_state(channel, state):
if state:
s.on(channel)
else:
s.off(channel)
common.publish(PUBTOPIC+b"/%s" % channel, str(state))


def set_pin(pin, state):
PUBTOPIC = b"%s/state/pin_%s" % (CLIENT_ID, str(pin))
Expand Down Expand Up @@ -49,28 +38,20 @@ def sub_cb(topic, msg):
common.log(topic)
return

if stopic[0] == 'ALL_CURTAINS':
try:
_time = int(msg.decode())
_time = min(_time, 20)
except Exception as e:
common.log(e)
return
move_curtains(stopic[2], _time)
elif stopic[0] == 'RFPOWER':
channel = int(stopic[2])
print(stopic[2], channel)
if msg in (b'0', b'1'):
set_channel_state(channel, int(msg))
else:
common.log(msg.decode('ascii'))
try:
_time = int(msg.decode())
_time = min(_time, 20)
except Exception as e:
common.log(e)
return
move_curtains(stopic[2], _time)

def setup():
set_pin(relay_down, True)
set_pin(relay_up, True)

def main():
setup()
common.loop(setup_fn=None, loop_fn=[], callback=sub_cb, subtopic=SUBTOPICS)
common.loop(setup_fn=None, loop_fn=[], callback=sub_cb, subtopic=[SUBTOPIC])

main()
1 change: 1 addition & 0 deletions firmware/curtains/mqtt.py
1 change: 1 addition & 0 deletions firmware/hdmi_rf433/HOSTNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RFPOWER
1 change: 1 addition & 0 deletions firmware/hdmi_rf433/common.py
File renamed without changes.
1 change: 1 addition & 0 deletions firmware/hdmi_rf433/mqtt.py
1 change: 1 addition & 0 deletions firmware/hdmi_rf433/rfsocket.py
1 change: 1 addition & 0 deletions firmware/nightlamp/HOSTNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NIGHTLAMP
1 change: 1 addition & 0 deletions firmware/nightlamp/common.py
1 change: 1 addition & 0 deletions firmware/nightlamp.py → firmware/nightlamp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def handle_button(pin):
def setup():
button.irq(handler=handle_button, trigger=Pin.IRQ_RISING),
led(1) # Turn off LED, it is inverted

def main():
common.loop(setup_fn=setup, loop_fn=[read_dht], callback=sub_cb, subtopic=[SUBTOPIC])

Expand Down
1 change: 1 addition & 0 deletions firmware/nightlamp/mqtt.py
24 changes: 0 additions & 24 deletions firmware/temp.py

This file was deleted.

0 comments on commit 1a93289

Please sign in to comment.