im = random.choice(self.images.keys()) bg.blit(self.images[im], (x * cart_rect.get_width(), y * cart_rect.get_height())) return bg def load_fonts(self): fonts = {} bpath = __file__.replace(os.path.basename(__file__), '') bpath = os.path.join(bpath, 'gfx', 'fonts') font_filenames = os.listdir(bpath) sizes = [15, 18, 23, 25, 27, 28] for size in sizes: for font_filename in font_filenames: if font_filename.endswith('.ttf'): name = os.path.basename(font_filename).split( '.')[0].lower() path = "./" + os.path.join(bpath, font_filename) fonts[name] = {} fonts[name][size] = pygame.font.Font(path, size) self.fonts = fonts if __name__ == '__main__': cm = cell.Membrane("DISPLAY") cm.start() DisplayNerve(cm) cm.join()
self.pulse = Pulse() self.cm = cm self.pulse.event_mask_set('all') self.pulse.event_callback_set(self.state_change) self.pulse.event_listen(timeout=10) def run(self): while not self.quit: time.sleep(0.1) def state_change(self, ev): #psil = self.pulse.sink_input_list() #props = [i.proplist for i in psil] print(ev.index, dir(ev.facility), ev.t) #raise PulseLoopStop if __name__ == "__main__": name = os.path.basename(__file__) name = name.replace('_nerve.py', '') cm = cell.Membrane(name) cm.start() cm.talk("BOOT") pulse_nerve = PulseNerve(cm) pulse_nerve.run() cm.join()
clf = nfc.ContactlessFrontend('usb') msg = "REGISTER:%s" % str(clf) self.cm.talk(msg) initialized = True except: msg = "No nfc device found, retries: %i" % retries self.cm.talk(msg) retries += 1 time.sleep(1) if retries > 10: sys.exit(-1) quit = False while not quit: res = clf.connect(rdwr={'on-connect': self.connected}) msg = str(time.time()) msg = "HEARTBEAT:%s" % str(msg) def connected(self, tag): msg = "TAG:%s" % str(tag) self.cm.talk(msg) return False if __name__ == '__main__': cm = cell.Membrane("NFC") cm.start() cm.talk("BOOT") nfc_nerve = NFC_Nerve(cm)
light_name = obj.text.lower() url = lights.get(light_name).get('url') if lights.get(light_name) and lights.get(light_name).get('status'): url = url % 'on' response = cell.req(url) if response: lights[light_name]['status'] = not lights[light_name]['status'] else: url = url % 'off' response = cell.req(url) if response: lights[light_name]['status'] = not lights[light_name]['status'] if __name__ == '__main__': cm = cell.Membrane() cm.start() cm.talk("TOUCH:BOOT") touch_nerve = TouchNerve(cm) touch_nerve.run() ''' from kivy.app import App from kivy.lang import Builder from kivy.factory import Factory from kivy.animation import Animation from kivy.clock import Clock, mainthread from kivy.uix.gridlayout import GridLayout import threading import time Builder.load_string("""