Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (60 loc) · 2.17 KB
/
Copy pathmain.py
File metadata and controls
78 lines (60 loc) · 2.17 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import json
import uasyncio as a
from py.wifi import connect
from py.esphub import ESPHub
from py.silversend import Silversend
sids = set()
with open("config.json") as f:
config = json.load(f)
wificonf = config["wifi"]
esphubconf = config["esphub"]
async def main():
wifi = await connect(**wificonf)
hub = ESPHub(**esphubconf, led_pin=config["led_pin"])
await hub.connect()
def rowstarting(row):
# print(f"now on row {row}")
# Socket IO send event "rowstart" with data=row to every client in array sids
hub.rowstart(sids, row)
def rowcomplete(row):
print(f"row {row} completed!")
# Socket IO send event "rowfinish" with data=row to every client in array sids
hub.rowfinish(sids, row)
s = Silversend(-20, 20, rowstarting=rowstarting, rowcomplete=rowcomplete)
pattern = [0, 1] * 20
s.loadrow(pattern)
print("we can do things and we're starting")
# Socket IO on event... this is also how you make more events
@hub.on("setcams")
async def row(data, sid):
s.setcams(*data)
print(f"we are resetting the cam positions to {data}. Dope!")
# Socket IO on event... this is also how you make more events
@hub.on("setrowindex")
async def row(data, sid):
s.setrowindex(data)
print(f"we are resetting the row counter to {data}. Dope!")
# Socket IO on event... this is also how you make more events
@hub.on("loadrow")
async def row(data, sid):
s.loadrow(data)
print(f"we got a row, which is {data}. Dope!")
# Socket IO on event... this is also how you make more events
@hub.on("subscribe")
async def subscribe(data, sid):
sids.add(sid)
print(f"we added {sid}, they are now all {sids}!")
# Socket IO on event... this is also how you make more events
@hub.on("unsubscribe")
async def subscribe(data, sid):
sids.remove(sid)
print(f"we removed {sid}, they are now all {sids}!")
while True:
try:
s.update()
await a.sleep(0)
except KeyboardInterrupt:
print("Received exit, exiting")
hub.close()
break
a.run(main())