def show_text(self, text, duration=2, blink=True): """ show text for the given time """ # should be called with _exec_with_lock self._settings.log.msg("DisplayController: showing text: %s" % text) if self._brightness == 0: time.sleep(duration) return display.clear() # scroll long text if len(text) > 4: steps = len(text) - 3 sleep_time = float(duration) / steps for i in range(steps): display.print_str(text[:4], False) display.show() time.sleep(sleep_time) text = text[1:] else: display.print_str(text, False) if blink: display.set_blink(display.HT16K33_BLINK_2HZ) display.show() time.sleep(duration) if blink: display.set_blink(display.HT16K33_BLINK_OFF)
def show_clock(): str_time = time.strftime("%H%M") fourletterphat.clear() fourletterphat.print_str(str_time) fourletterphat.set_decimal(1, int(time.time() % 2)) fourletterphat.show()
def main(): flp.clear() flp.print_str("NSFW") flp.show() print(infotext) print("\nPress Ctrl-C to exit.\n") wait_for_internet_connection() stocks = get_stocks_from_config("stocks.conf") flp.glow(period=0.5, duration=4) flp.clear() flp.show() print("Watching Stocks:") print("\n".join([ sym + ": " + share.get_name() + " (" + str(own) + " owned)" for sym, own, share in stocks ])) while (len(stocks) > 0): show_latest(stocks) print("No stocks...")
def __init__(self): self.temp_f = 0.0 self.temp_a = 0.0 self.n = int(time.time()) flp.clear() flp.set_brightness(4) self.update_called = False self.display_id = object()
def scroll_message(message): m = " " + message fourletterphat.clear() while len(m) > 3: fourletterphat.print_str(m[:4]) m = m[1:] fourletterphat.show() time.sleep(float(1) / scrolling_speed) time.sleep(seconds_for_panel_display)
def _set_time(self): """ set the current time on the display """ # should be called with _exec_with_lock self._settings.log.msg("DisplayController: setting time to: %s" % self._current_time) lights_off = self._settings.get("_lights_off") display.clear() if self._brightness > 0 and not lights_off: t_string = self._current_time.replace(":", "") display.print_str(t_string) display.show()
def main(): global last_state last_state = None rpi_id = constants.rpi_id pidi_status_dir = constants.pidi_status_dir flp.clear() flp.scroll_print("START") time.sleep(2) while True: display_state(rpi_id, pidi_status_dir) time.sleep(2)
def monitor(url): response = requests.get(url) status_code = response.status_code fourletterphat.clear() fourletterphat.print_str(str(status_code)) fourletterphat.show() time.sleep(5) fourletterphat.scroll_print(str(status_code) + ' ' + url + ' ' + str(status_code), 0.1 if (200 == status_code) else 1 ) fourletterphat.print_number_str(str(status_code)) fourletterphat.show() time.sleep(5) fourletterphat.clear()
def set_brightness(self, value=None): """ Set the brightness of the display """ # we only use off and four levels, so scale new appropriately if not value is None and value != self._brightness: self._brightness = value self._settings.set("_display.brightness", self._brightness) self._settings.log.msg("DisplayController: setting brightness to: %d" % self._brightness) if not simulate: # can't set brightness during an alarm if self._lock.acquire(False): if self._brightness > 0: display.set_brightness( DisplayController.BNESS[self._brightness]) else: display.clear() display.show() self._lock.release()
def alarm_text(self, stop_me, duration=1, text=None, delay=0): """ show running text """ if not text: return duration = int(duration) self._settings.log.msg( "DisplayController: show alarm text '%s' for %s minutes" % (text, duration)) # honor delay delay = int(delay) if delay > 0: self._settings.log.msg( "DisplayController: delaying alarm for %d minutes" % delay) if stop_me.wait(60 * delay): return if simulate: stop_me.wait(60 * duration) self._settings.log.msg( "DisplayController: show alarm text finished") return start_time = time.time() end_time = start_time + 60 * duration now = start_time with self._lock: display.clear() display.set_brightness(15) while now <= end_time: display.print_str(text[:4]) display.show() if stop_me.wait(0.35): break text = text[1:] + text[0] now = time.time() # reset display to standard self._settings.log.msg("DisplayController: show alarm text finished") self.set_time() self.set_brightness()
def cupToPi(data): if data is None: print(data) flp.print_str("BREW") flp.show() flp.glow(period=1, duration=10) else: if data is 0: flp.clear() flp.print_str("0CUP") flp.show() else: num = int(data) if num > 9: flp.print_str(data + "CP") flp.show() else: flp.print_str(data + "CUP") flp.show()
def dispTemp(): #establish location, if city is two words use and underscore between them #state use two letter abbreviation city = "New_York" state = "NY" #build the url url = "http://api.wunderground.com/api/API_KEY_HERE/conditions/q/" + state + "/" + city + ".json" #request our url f = urllib.request.urlopen(url) #open and read the url json_string = f.read() #encode the url into strings instead of bytes encoding = f.info().get_content_charset('utf-8') #parse the encoded data into something we can use JSON with parsed_json = json.loads(json_string.decode(encoding)) #grabbing specific datum with parsed JSON temp_f = parsed_json['current_observation']['temp_f'] strTemp_f = (str)(temp_f) #FourLetterPhat wasn't printing decimal so we are removing it strippedTemp = strTemp_f.replace(".", "") fourletterphat.clear() #printing what we grabbed fourletterphat.print_str(strippedTemp + "F") #setting the decimal at 1 works for double digit temps/looking into how to get to to lineup for single or triple digit temps fourletterphat.set_decimal(1, True) fourletterphat.show() #closing the url f.close()
def display_message(titles, numbers, show_title_at_end=False, number_type='str', float_decimal_digits=1, number_sleep=1, title_sleep=.5): """Display messaages with different timings for titles vs numbers.""" for title in titles: flp.clear() flp.print_str(title) flp.show() time.sleep(title_sleep) for number in numbers: flp.clear() flp.print_number_str(str(number)) flp.show() time.sleep(number_sleep) if (show_title_at_end): for title in titles: flp.clear() flp.print_str(title) flp.show() time.sleep(title_sleep)
def show_latest(stocks): folio = defaultdict(float) # {'USD':'123.45'}, e.g. for symbol, owned, share in stocks: flp.clear() flp.print_str(symbol) flp.show() pstr = symbol try: share.refresh() except Exception as e: time.sleep(0.5) pstr += " $" + share.get_price() + " " + share.get_currency() if (owned > 0): # Append folio info if any stocks owned total = float(share.get_price()) * float(owned) pstr += ", " + str(round(owned, 3)) + " OWNED, VAL $" + str( round(total, 2)) + " " + share.get_currency() folio[share.get_currency()] += total scroll_print_float_str(pstr, interval=0.2) flp.clear() flp.show() time.sleep(1) # If any stocks were owned if (len(folio) > 0): # Print a value for every currency folio_str = " FOLIO VAL" for currency, val in folio.items(): folio_str += " $" + str(round(val, 2)) + " " + currency scroll_print_float_str(folio_str, interval=0.25) flp.clear() flp.show() time.sleep(1)
import fourletterphat as flp import time while True: flp.clear() str_time = time.strftime("%H%M") flp.print_number_str(str_time) if int(time.time() % 2 == 0): flp.set_decimal(1, 0) else: flp.set_decimal(1, 0) flp.show() time.sleep(0.1)
#!/usr/bin/env python import time import fourletterphat from subprocess import Popen, PIPE print(""" Four Letter pHAT: cpu-temp.py This example will display your Pi's CPU temperature in degrees celsius. Press Ctrl+C to exit. """) while True: # Get temp forom vcgencmd in the format: "temp=XY.Z'C" # and reduce to the format "XYZC" for display temp = Popen(["vcgencmd", "measure_temp"], stdout=PIPE) temp = temp.stdout.read().decode('utf-8') temp = temp[5:].replace(".", "").replace("'", "").strip() fourletterphat.clear() fourletterphat.print_str(temp) fourletterphat.set_decimal(1, 1) fourletterphat.show() time.sleep(1)
def main(stdscr): # Clear screen s = State() seq = 0 x = None stdscr.clear() stdscr.nodelay(1) # set getch() non-blocking s.message = "Tea?" quit = False flp.clear() flp.print_number_str('OHIO') flp.show() while not quit: v = stdscr.getch() if v != -1: if v >= ord('0') and v <= ord('9') and v-ord('0') in lookup: s.current_tea_index = v-ord('0') tea = lookup[s.current_tea_index] s.message = "{} ready in ????".format(tea) s.message_timeout = 120 s.time_brewing_started = time.localtime() s.brewing = True s.reset_scroll() if v == curses.KEY_BACKSPACE: # Cancel s.message = "CANC" s.current_tea_index = None s.message_timeout = 20 s.time_brewing_started = None s.brewing = False s.reset_scroll() x = v # Update curses display for debugging stdscr.addstr(0,0,"Last keypress: {}".format(x)) stdscr.addstr(1,0,"Scrolling message: >{}<".format(s.message)) stdscr.addstr(2,0,"Scroll position: >{}<".format(s.get_scroll_pos())) stdscr.addstr(3,0,"Message timeout: {}".format(s.message_timeout)) if s.time_brewing_started: stdscr.addstr(4,0,"Brewing started: {}:{}:{}".format(s.time_brewing_started.tm_hour, s.time_brewing_started.tm_min, s.time_brewing_started.tm_sec)) stdscr.addstr(5,0,"Brewing started: {}s".format(time.mktime(s.time_brewing_started))) else: stdscr.addstr(4,0,"Nothign brewing") stdscr.addstr(6,0,"Time now : {}s".format(time.mktime(time.localtime()))) # Update tea time, if currently brewing if s.time_brewing_started: elapsed = time.mktime(time.localtime()) - time.mktime(s.time_brewing_started) remaining = int(TEA_BREWING_TIME-elapsed) if remaining > 0: s.message = s.message [:-4] + "{:1d}m{:02d}".format(int(remaining/60), remaining%60) else: if s.brewing: s.reset_scroll() s.brewing = False tea = lookup[s.current_tea_index] s.message = "{} {:3d}m".format(tea, int((elapsed - TEA_BREWING_TIME)/60)) if elapsed > MAX_TEA_AGE: s.time_brewing_started = None s.current_tea_index = None s.brewing = False s.message = "Tea?" s.reset_scroll() # Update four-letter display if s.message_timeout > 0: flp.clear() if s.message: flp.print_str(s.message[s.get_scroll_pos():]) if seq % 5 == 0 and s.scroll_position < len(s.message)-4: s.scroll_position += 1 flp.show() s.message_timeout -= 1 else: if s.current_tea_index: s.reset_scroll() s.message_timeout = 120 else: flp.clear() s.message = "Tea?" flp.print_str(s.message) flp.show() seq += 1 time.sleep(0.1)
def clearHats(): scrollphat.clear() fourletterphat.clear()