def init(config={}): global cfg, printer, fd, num_axes, num_buttons, dead if cfg is not None: return configdata = { 'tick_time': .05, 'js': '/dev/input/js0', 'printer': '8000', 'dead': .1 } configdata.update(config) cfg = fhs.init(configdata) dead = float(cfg['dead']) printer = websocketd.RPC(cfg['printer'], tls=False) fd = os.open(cfg['js'], os.O_RDWR) version = ioctl(js.gversion, ctypes.c_uint32) if version != js.version: sys.stderr.write('version mismatch (%x != %x)' % (version, js.version)) num_axes = ioctl(js.gaxes, ctypes.c_uint8) num_buttons = ioctl(js.gbuttons, ctypes.c_uint8) axis_state[:] = [0.] * num_axes button_state[:] = [None] * num_buttons
and length should be set to 0. Make sure that the embroidery loop moves properly over the surface of the sewing machine. """ import websocketd import time import fhs config = fhs.init({'port': 8000, 'tls': 'False', 'motor': 3, 'sensor': 4}) motor = int(config['motor']) sensor = int(config['sensor']) tls = config['tls'].lower() != 'false' p = websocketd.RPC(config['port'], tls=tls) ''' Procedure: -> wait for confirm motor on needle down -> wait for gpio off needle up -> wait for gpio on motor off -> confirm Franklin moves repeat ''' while True: # Wait for confirm; pick up pending confirmation request, if any. id, message = p.wait_confirm()
Don't care about all the arguments, just check the last one.''' print_state = values[-1] if print_state == self.state: return print('State changed from {} to {}'.format(state_name[self.state], state_name[print_state])) self.state = print_state def __getattr__(self, attr): '''Anything else is requested. Return a function that can print the name and arguments when it is called.''' def call(*args, **kwargs): ## Uncomment the next line to see all the functions ## that are called. To handle any of them, define it ## like globals_update is defined above. #print('call', attr, 'args:', args, 'kwargs:', kwargs) pass return call # Open the connection to Franklin. p = websocketd.RPC('localhost:8000', monitor, tls=False) # Tell Franklin to inform us of updates. p.set_monitor(True) # Start the main loop (in the foreground), waiting for events. websocketd.fgloop()
l = l.strip() if l == '' or l.startswith('#') or not '=' in l: continue key, value = l.split('=', 1) if key == 'PORT': # Leave it as a string because it need not be numerical. port = value.strip() if key == 'TLS': tls = value.lower().strip() == 'true' if key == 'USER': credentials(0, value.strip()) if key == 'EXPERT': credentials(1, value.strip()) if key == 'ADMIN': credentials(2, value.strip()) try: p = websocketd.RPC(port, tls=tls, url='/admin', user=user, password=password) action = os.getenv('ACTION') dev = os.getenv('DEVNAME') if action == 'add': p.add_port(dev) elif action == 'remove': p.remove_port(dev) except: sys.stderr.write('Failed to handle serial port event for Franklin')
import websocketd import os import sys port = 8000 tls = True with open('/etc/default/franklin') as f: for l in f.readlines(): l = l.strip() if l == '' or l.startswith('#') or not '=' in l: continue key, value = l.split('=', 1) if key == 'PORT': # Leave it as a string because it need not be numerical. port = value.strip() if key == 'TLS': tls = value.lower().strip() == 'true' try: p = websocketd.RPC(port, tls=tls) action = os.getenv('ACTION') dev = os.getenv('DEVNAME') if action == 'add': p.add_port(dev) elif action == 'remove': p.remove_port(dev) except: sys.stderr.write('Failed to handle serial port event for Franklin')