Пример #1
0
import time
from threading import Thread
from pylibcerebrum.serial_mux import SerialMux
from http.server import HTTPServer, BaseHTTPRequestHandler

PORT = "/dev/serial/by-id/usb-Arduino__www.arduino.cc__Arduino_Uno_649383232313512181A1-if00"
BAUDRATE = 115200

s = SerialMux(PORT, BAUDRATE)
print("discovering cerebrum devices")
results = []
while not results:
    results = s.discover()
print(results)
print("opening first device")
g = s.open(0)
print("initializing device")
print(dir(g))
for io in [g.digital3, g.digital5, g.digital6, g.digital9, g.digital10, g.digital11]:
    io.direction = 1
    io.pwm_enabled = 1
print("starting event loop")

barstatus = "closed"
lastchange = time.time()


def animate():
    global barstatus, lastchange
    while True:
        lookup = barstatus
Пример #2
0
	global GANGLION_ADAPTERS
	GANGLION_ADAPTERS[ganglion_type] = cls
	return cls

class GanglionRestAdapter:
	def __init__(self, g):
		with exitOnSerialException():
			self.name = g.config.get('name') or g.config.get('node_id')
			#Hardware discovery
			self.members = [GANGLION_ADAPTERS[m.type](self, g) for m in g]
	
	@property
	def base_url(self):
		return '/cerebrum'

# === Cerebrum serial port setup ===
with exitOnSerialException():
	s = SerialMux(PORT, BAUDRATE)
	time.sleep(1)
	print('Discovering cerebrum devices')
	results = []
	while not results:
		results = s.discover()
	print('Opening devices')
	adapters = [GanglionRestAdapter(s.open(i)) for _,i in results]

if __name__ == '__main__':
	app.debug = True
	app.run()