def signal_handler(signal, frame): global is_active is_active = False backlight.set_graph(0) lcd.clear() backlight.off() exit(0)
def right(self): v_module = self.modules[self.selected_module] isRunning = self.getModuleStatus(self.modules[self.selected_module]) if isRunning == "Y": # module is running, stop it execute = "/module/" + v_module + "/stop" self.consoleMessages.show_info("Stoping module: " + str(v_module) + "") else: # module is not running, start it execute = "/module/" + v_module + "/start" self.consoleMessages.show_info("Starting module: " + str(v_module) + "") backlight.set_bar(0, 20) result = self.webclient.call_api(execute) # fire up bargraph leds! Wohoo for i in range(100): backlight.set_graph(i / 70.0) time.sleep(0.005) # disable leds =( backlight.set_graph(0) self.ready = True try: if result[0] == True: return "Y" else: return "N" except: return "E"
def on_print_progress(self, storage, path, progress): lcd.clear() start = path.rfind('/') end = path.rfind('.') # Just want the file name, no path or extension. # The rfind gets us the deepest directory so we can truncate that off the string # It also gets us the index of the file extension # The code below will substring any directories off the path, and remove the extention if (start == -1): start = 0 if (end == -1): end = path.len() - 1 lcd.write(path[start:end]) backlight.set_graph(progress / 100.0) backlight.rgb(0, 0, 255) backlight.update() lcd.set_cursor_position(0, 1) lcd.write('Completed: ' + str(progress) + '%') if progress == 1: self.start_date = time.time() if progress > 10 and progress < 100: now = time.time() elapsed = now - self.start_date average = elapsed / (progress - 1) remaining = int((100 - progress) * average) remaining = str(datetime.timedelta(seconds=remaining)) lcd.set_cursor_position(0, 2) lcd.write('ETC: ') lcd.write(remaining) if progress == 100: self.JobIsDone(lcd)
def JobIsDone(self, localLcd): lcd.clear() backlight.rgb(255, 255, 255) localLcd.write('Job is Done!') for i in range(0, 100): backlight.set_graph((100 - i) / 100.0) time.sleep(0.05) backlight.update() lcd.clear() lcd.write('Ready for the next job')
def execCommand(self, cmd): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) (output, err) = p.communicate() # fire up bargraph leds! Wohoo for i in range(100): backlight.set_graph(i / 70.0) time.sleep(0.005) # disable leds =( backlight.set_graph(0) return output.strip()
def redraw(self): volume = subprocess.check_output("mpc status | grep volume", shell=True, stderr=subprocess.STDOUT) volume = volume[7:volume.find("%")] lcd.clear() lcd.set_cursor_position(0, 0) lcd.write(self.channelName[self.selectedStation]) lcd.set_cursor_position(0, 1) lcd.write(time.strftime("%d.%m. %H:%M:%S")) lcd.set_cursor_position(0, 2) lcd.write('Volume:' + volume + ' %') cpu = psutil.cpu_percent() backlight.set_graph(float(cpu) / 100.0)
def loadingScreen(): lcd.clear() # set brigthness backlight.set_bar(0, 20) # write loading message to lcd lcd.set_cursor_position(3,1) lcd.write("Loading...") # fire up bargraph leds! Wohoo for i in range(100): backlight.set_graph(i / 70.0) time.sleep(0.005) # disable leds =( backlight.set_graph(0)
def doorbell(): GPIO.remove_event_detect(gpio_bell) # Ignore multiple clicks if debug: print("Start of Doorbell function\n") # If pushover is enabled, run as thread and continue if push_enabled: t_push = threading.Thread(target=pushover, args=()) t_push.start() # If taking pictures is enabled, run as thread and continue if pictures_enabled: t_snap = threading.Thread(target=snapper, args=()) t_snap.start() # Log the event in the databse if debug: print "Doorbell rang at "+ts() log("Someone was at your door.") if debug: print "Event logged" # ####### # # Phase 1 # Ringing. # ####### # # Clear LCD and adjust information lcd.clear() backlight.rgb(0,0,255) lcd.set_cursor_position(0,0) lcd.write(txt_security) lcd.set_cursor_position(0,1) lcd.write(txt_ring) lcd.set_cursor_position(0,2) lcd.write(txt_ring2) if debug: print("Text changed, entering wait_loop*2") wait_loop(200) if debug: print("Wait loop done") if debug: print("<< Next Phase >>\n") backlight.set_graph(0) # ####### # # Phase 2 # Trying to contact them. # ####### # # Clear LCD and adjust information lcd.clear() backlight.rgb(255,153,0) lcd.set_cursor_position(0,0) lcd.write(txt_wait1) lcd.set_cursor_position(0,1) lcd.write(txt_wait2) lcd.set_cursor_position(0,2) lcd.write(txt_wait3) if debug: print("Text changed, entering wait_loop*2") wait_loop(100) if debug: print("Wait loop done") if debug: print("<< Next Phase >>\n") backlight.set_graph(0) # ####### # # Phase 3 # No one is there. # ####### # # Clear LCD and adjust information lcd.clear() backlight.rgb(255,0,0) lcd.set_cursor_position(0,0) lcd.write(txt_away1) lcd.set_cursor_position(0,1) lcd.write(txt_away2) lcd.set_cursor_position(0,2) lcd.write(txt_away3) if debug: print("Text changed, entering wait_loop") wait_loop(80) if debug: print("<< Next Phase >>\n") backlight.set_graph(0) # ####### # # Phase 4 # Delivery to the neighbors. # ####### # # Clear LCD and adjust information lcd.clear() backlight.rgb(0,255,0) lcd.set_cursor_position(0,0) lcd.write(txt_package1) lcd.set_cursor_position(0,1) lcd.write(txt_package2) lcd.set_cursor_position(0,2) lcd.write(txt_package3) if debug: print("Text changed, entering sleep") wait_loop(150) if debug: print("Wait loop done") if debug: print("<< End of last Phase >>\n") backlight.set_graph(0) lcd.clear() if debug: print("End of Doorbell function\n") GPIO.add_event_detect(gpio_bell,GPIO.FALLING)
def rainWarning(): forecast = darksky.Forecast(api_key, latitude, longitude, units=units) hourly = forecast.hourly rain = hourly[1].precipProbability * 100 if rain == 0: backlight.set_graph(0) elif (rain > 1) and (rain <= 9): backlight.set_graph(0.1) elif (rain >= 10) and (rain <= 19): backlight.set_graph(0.2) elif (rain >= 20) and (rain <= 29): backlight.set_graph(0.3) elif (rain >= 30) and (rain <= 39): backlight.set_graph(0.4) elif (rain >= 40) and (rain <= 49): backlight.set_graph(0.5) elif (rain >= 50) and (rain <= 59): backlight.set_graph(0.6) elif (rain >= 60) and (rain <= 69): backlight.set_graph(0.7) elif (rain >= 70) and (rain <= 79): backlight.set_graph(0.8) elif (rain >= 80) and (rain <= 89): backlight.set_graph(0.9) else: backlight.set_graph(1.0)
lcd.write("Rain: " + rain + "%") print("UV Index: " + uv + "") except: lcd.write("Connection Error") # Press the button on the joystick to exit @nav.on(nav.BUTTON) def handle_button(pin): lcd.clear() backlight.rgb(0, 0, 0) backlight.set_graph(0) os._exit(1) try: while True: rainWarning() display() sleep(300) # 5 minutes except (KeyboardInterrupt, SystemExit): lcd.clear() lcd.set_cursor_position(0, 0) lcd.write("Exiting...") lcd.set_cursor_position(0, 1) lcd.write("Goodbye!") sleep(2) lcd.clear() backlight.rgb(0, 0, 0) backlight.set_graph(0) os._exit(1)
def clean_shutdown(): backlight.set_graph(0) backlight.rgb(0, 0, 0) lcd.clear()
def clean_shutdown(): backlight.set_graph(0) backlight.rgb(0, 0, 0) lcd.clear() # read current ip address for a given interface def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24]) atexit.register(clean_shutdown) backlight.set_graph(0) backlight.rgb(0, 0, 0) while True: ip = 'Kein WLAN :(' try: ip = get_ip_address('wlan0') except IOError: pass lcd.clear() lcd.set_cursor_position(0, 0) lcd.write('BathPi - PiRadio') lcd.set_cursor_position(0, 1) lcd.write('Standby...')
def off(self): os.system('mpc stop') backlight.set_graph(0) backlight.rgb(0, 0, 0) lcd.clear()
emit_event('Joystick', 'button') while True: data = json.loads(raw_input()) component = data['component'] command = data['command'] parameters = data['parameters'] if component == 'DisplayOTron': if command == 'kill': if parameters['performReset']: lcd.clear() backlight.off() backlight.set_graph(0.0) sys.exit() elif command == 'reset': lcd.clear() backlight.off() backlight.set_graph(0.0) elif component == 'LCD': if command == 'clear': lcd.clear() elif command == 'setContrast': lcd.set_contrast(parameters['contrast']) elif command == 'setCursorPosition': lcd.set_cursor_position(parameters['column'], parameters['row']) elif command == 'write': lcd.write(parameters['value'])
def set_size(self, temp): for i in range(int(temp)): backlight.set_graph(i / self.maxtemp)
def handle_button(pin): lcd.clear() backlight.rgb(0, 0, 0) backlight.set_graph(0) os._exit(1)
def ledZero(self): backlight.set_graph(0)
def getAnimFrame(char,fps): return char[ int(round(time.time()*fps) % len(char)) ] cpu_sample_count = 200 cpu_samples = [0] * cpu_sample_count hue = 0.0 while True: hue += 0.008 backlight.sweep(hue) cpu_samples.append(psutil.cpu_percent() / 100.0) cpu_samples.pop(0) cpu_avg = sum(cpu_samples) / cpu_sample_count backlight.set_graph(cpu_avg) lcd.create_char(0,getAnimFrame(eqlchar,2)) if hue > 1.0: hue = 0.0 lcd.set_cursor_position(0,1) t = datetime.now().strftime("%H:%M:%S.%f") deploy = datetime(2015, 7, 1, 0, 0) timestamp = time.mktime(deploy.timetuple()) deploy_utc = datetime.utcfromtimestamp(timestamp) elapsed = deploy_utc - datetime.utcnow() trunc_micros = timedelta(days=elapsed.days, seconds=elapsed.seconds) seconds = elapsed.days*86400 + elapsed.seconds minutes, seconds = divmod(seconds, 60)
import time, datetime, copy, math, psutil cpu_sample_count = 200 cpu_samples = [0] * cpu_sample_count hue = 0.0 while True: hue += 0.001 backlight.sweep(hue) cpu_samples.append(psutil.cpu_percent() / 100.0) cpu_samples.pop(0) cpu_avg = sum(cpu_samples) / cpu_sample_count backlight.set_graph(cpu_avg) #cpu = psutil.cpu_percent(interval=0, percpu=False) cake = int(cpu_avg) #backlight.rgb(0,125,200) if hue > 1.0: hue = 0.0 lcd.set_cursor_position(0, 0) useage = str(cpu_avg * 100) lcd.write('CPU: ' + useage) lcd.set_cursor_position(0, 1) t = datetime.datetime.now().strftime("%H:%M:%S")
#!/usr/bin/env python import dot3k.lcd as lcd import dot3k.backlight as backlight import time # Clear the LCD and display Hello World lcd.clear() lcd.write("Hello World") # Turn off the backlight backlight.rgb(0, 0, 0) """ set_graph accepts a float between 0.0 and 1.0 and lights up the LEDs accordingly """ for i in range(100): backlight.set_graph(i / 100.0) time.sleep(0.05) """ set_bar will set a specific bargraph LED to a brightness between 0 and 255 """ for i in range(256): backlight.set_bar(0, [255 - i] * 9) time.sleep(0.01) backlight.set_graph(0)
def handle_up(pin): emit_event('Joystick', 'button') while True: data = json.loads(raw_input()) component = data['component'] command = data['command'] parameters = data['parameters'] if component == 'DisplayOTron': if command == 'kill': if parameters['performReset']: lcd.clear() backlight.off() backlight.set_graph(0.0) sys.exit() elif command == 'reset': lcd.clear() backlight.off() backlight.set_graph(0.0) elif component == 'LCD': if command == 'clear': lcd.clear() elif command == 'setContrast': lcd.set_contrast(parameters['contrast']) elif command == 'setCursorPosition': lcd.set_cursor_position(parameters['column'], parameters['row']) elif command == 'write': lcd.write(parameters['value'])
#!/usr/bin/env python import dot3k.lcd as lcd import dot3k.backlight as backlight import time # Clear the LCD and display Hello World lcd.clear() lcd.write("Hello World") # Turn off the backlight backlight.rgb(0,0,0) """ set_graph accepts a float between 0.0 and 1.0 and lights up the LEDs accordingly """ for i in range(100): backlight.set_graph(i/100.0) time.sleep(0.05) """ set_bar will set a specific bargraph LED to a brightness between 0 and 255 """ for i in range(256): backlight.set_bar(0,[255-i]*9) time.sleep(0.01) backlight.set_graph(0)
def wait_loop(span): for i in range(span): backlight.set_graph(i/float(span)) time.sleep(0.05)