Beispiel #1
0
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 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()
Beispiel #4
0
def display_state(rpi_id, pidi_status_dir):
    global last_state

    try:
        dir_file_list = os.listdir(pidi_status_dir)
    except FileNotFoundError:
        flp.scroll_print('ERROR - REMOTE DIR NOT FOUND!')
        return
    except PermissionError:
        flp.scroll_print('ERROR - REMOTE DIR NOT PERMITTED!')
        return

    instructions = get_device_instructions(rpi_id, dir_file_list)
    if not instructions:
        if last_state is None:
            flp.scroll_print('ERROR - FILE FOR THIS RASPBERRY NOT FOUND!')
            return
        else:
            instructions = [last_state]

    if len(instructions) > 1:
        flp.scroll_print('ERROR - TOO MANY INSTRUCTIONS')
        return

    instr = instructions[0]
    flp.print_str(instr)
    flp.show()

    rename_instruction(rpi_id, instr, pidi_status_dir)
    last_state = instr
Beispiel #5
0
def showtime():
    global debug
    global fourchar_flag
    global fourchar_payload

    # old logic actually worked, to a point
    fourchar_flag = False
    str_time = time.strftime("%H%M")
    flp.print_number_str(str_time)
    if int(time.time()) % 2 == 0:
        flp.set_decimal(1, 1)
    else:
        flp.set_decimal(1, 0)
    flp.show()
    time.sleep(0.1)
    # new logic
    #    flp.print_str("    ")
    #    flp.show
    #    float_temp = float(fourchar_payload)
    #    flp.print_float(float_temp, decimal_digits=1, justify_right=True)
    #    flp.show()
    #    time.sleep(2)

    # old logic
    if fourchar_flag == True:
        flp.print_str("    ")
        flp.show
        float_temp = float(fourchar_payload)
        flp.print_float(float_temp, decimal_digits=1, justify_right=True)
        flp.show()
        time.sleep(2)
    def _set_decimal(self, index, state):
        """ set decimal at given index """

        # should be called with _exec_with_lock
        lights_off = self._settings.get("_lights_off")
        if self._brightness > 0 and not lights_off:
            display.set_decimal(index, state)
            display.show()
Beispiel #7
0
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 __display_a(self):
        if self.display_id != self.__display_a:
            self.display_id = self.__display_a
            flp.print_str("LOGC")
            flp.show()
            time.sleep(2)

        flp.print_float(self.temp_a, decimal_digits=1)
        flp.set_blink(flp.HT16K33_BLINK_2HZ)
        flp.show()
    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 __display_f(self):
        if self.display_id != self.__display_f:
            flp.set_blink(flp.HT16K33_BLINK_OFF)
            self.display_id = self.__display_f
            #flp.scroll_print("FREEZER")
            flp.print_str("FRZR")
            flp.show()
            time.sleep(2)

        flp.print_float(self.temp_f, decimal_digits=1)
        flp.show()
        flp.glow()
Beispiel #11
0
def dprint(s):
    if len(s) > 4:
        s = "   " + s + "    "
        for i in range(len(s) - 4):
            flp.print_str(s[i:i + 4])
            flp.show()
            time.sleep(0.25)
    else:
        flp.print_str(s)
        flp.show()

    return
Beispiel #12
0
def scroll_print_float_str(strn, interval=0.3):
    if (len(strn) > 0):
        time.sleep(interval * 3.0)

        for ln in [
                strn[x:x + 5] if ('.' in strn[x:x + 5]) else strn[x:x + 4]
                for x in xrange(0,
                                len(strn) - 3)
        ]:
            if (ln[0] != '.'):
                flp.print_number_str(ln)
                flp.show()
                time.sleep(interval)

        time.sleep(interval * 2.0)
Beispiel #13
0
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()
Beispiel #16
0
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()
Beispiel #17
0
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 date_bin(currdate, currfulldate):
    firstLetter = ' '
    secondLetter = ' '
    match = False

    try:
        data = openJSON()
    except:
        binletters = "{}{}".format(firstLetter, secondLetter)
        fourletterphat.print_str("{}{}".format(currdate, binletters))
        fourletterphat.show()
        return

    for i in data:
        if i['bin'] == 'Grey Bin (General waste)':
            if i['date'] == currfulldate:
                firstLetter = 'G'
                match = True

    for i in data:
        if i['bin'] == '240Ltr Green Bin (Recycling)':
            if i['date'] == currfulldate:
                secondLetter = 'G'
                match = True

    for i in data:
        if i['bin'] == '240Ltr Brown Bin (Garden waste)':
            if i['date'] == currfulldate:
                secondLetter = 'B'
                match = True

    binletters = "{}{}".format(firstLetter, secondLetter)
    fourletterphat.print_str("{}{}".format(currdate, binletters))
    if match:
        binday = True
    else:
        binday = False

    fourletterphat.show()
Beispiel #19
0
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()
Beispiel #20
0
def on_message(client, userdata, msg):
    """The callback for when a PUBLISH message is received from the server."""
    global g_mqtt_data

    print(msg.topic + " -> " + str(msg.payload.decode('UTF-8')))
    message_data = json.loads(str(msg.payload.decode('UTF-8')))

    g_mqtt_data[msg.topic] = message_data

    # Flash the rightmost decimal to show receipt of a message
    flp.set_decimal(3, True)
    flp.show()
    time.sleep(.5)
    flp.set_decimal(3, False)
    flp.show()
    time.sleep(.25)
    flp.set_decimal(3, True)
    flp.show()
    time.sleep(.5)
    flp.set_decimal(3, False)
    flp.show()
Beispiel #21
0
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)
Beispiel #22
0
import time
import fourletterphat as flp
import button_shim
countdown = 10

while button_shim.button_A == True:
    str_time = time.strftime("%M%S")
    flp.print_number_str(countdown)
    flp.show()
    countdown -=1
    time.sleep(0.55)
    
    if  button_shim.button_A == True and  button_shim.button_B == True and button_shim.button_C == True:
        break
    
    if button_shim.button_E == True or button_shim.button_D == True:
        flp.print_str('BOOM')
        flp.show()
        break
    
    if countdown <= 0:
        flp.print_str('BOOM')
        flp.show()
        break
    
countdown_1 = 60
while button_shim.button_B == True:
    str_time = time.strftime("%M%S")
    flp.print_number_str(countdown_1)
    flp.show()
    countdown_1 -=1
Beispiel #23
0
#!/usr/bin/env python

import time
import fourletterphat

print("""
Four Letter pHAT: scroll.py

Scrolls a message across the display.

Press Ctrl+C to exit.
""")

message = "YARR PIRATES   "

while True:
    # Display the first four letters of the message
    fourletterphat.print_str(message[:4])

    # Take the first letter (position 0) of the message
    # and pop it onto the end of the string.
    message = message[1:] + message[0]

    fourletterphat.show()
    time.sleep(0.25)
def flp_print(msg):
    flp.print_str(str(msg))
    flp.show()
 def display(self, value):
     flp.print_str(value)
     flp.show()
     time.sleep(5)
Beispiel #26
0
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)