Example #1
0
    def __init__(self, host="localhost"):
        self.subscribed_topic2method = {
            "scrolly/write_scroll": self.write_scroll,
            "scrolly/write": self.write,
            "scrolly/power": self.power,
            "scrolly/brightness": self.set_brightness
        }

        scroll.flip(x=True, y=True)
        scroll.set_brightness(0.2)
        scroll.clear()
        scroll.write_string("on")
        scroll.show()

        status_topic = "scrolly/status"
        self.mos = mosquitto.Mosquitto()
        self.mos.will_set(status_topic, "offline")
        self.mos.on_message = self.on_message
        self.debug("connecting to " + host)
        self.mos.connect(host)
        self.mos.publish("scrolly/power", 1)
        self.mos.publish(status_topic, "online")
        self.mos.subscribe("scrolly/#")

        self.stop_event = threading.Event()

        # start thread that is waiting for action in bluedot app
        th = threading.Thread(target=self._shutdown_on_bluedot_press_waiter)
        th.start()

        self.mos.loop_forever()
Example #2
0
def writeString():
    if request.is_json:
        schema = td["actions"]["writeString"]["input"]
        valid_input = Draft6Validator(schema).is_valid(request.json)

        if valid_input:
            dur = 5
            count = 0
            try:
                try:
                    dur = int(request.json["time"])
                except Exception as e:
                    print(e)
                Str = " " + str(request.json["string"])
                print(Str)
                x = int(request.json["x"])
                print(x)
                y = int(request.json["y"])
                print(y)
                bright = float(request.json["brightness"])

                scrollphathd.clear()
                scrollphathd.show()
                scrollphathd.write_string(Str,
                                          x,
                                          y,
                                          font=None,
                                          letter_spacing=1,
                                          brightness=bright,
                                          monospaced=True,
                                          fill_background=False)
                scrollphathd.flip(x=True, y=True)

                while count < dur * 10:
                    scrollphathd.show()
                    scrollphathd.scroll(1)
                    time.sleep(0.05)
                    count = count + 1
                scrollphathd.clear()
                scrollphathd.show()
                return "", 204
            except Exception as e:
                print(e)
                abort(400)
        else:
            abort(400)
            print("wrong input")
    else:
        abort(415)  # Wrong media type.
Example #3
0
def run():
    while True:
        action = api_queue.get(block=True)
        if action.action_type == "write":
            scrollphathd.write_string(action.data, font=font3x5)

        if action.action_type == "clear":
            scrollphathd.clear()

        if action.action_type == "scroll":
            scrollphathd.scroll(action.data[0], action.data[1])

        if action.action_type == "flip":
            scrollphathd.flip(x=action.data[0], y=action.data[1])

        scrollphathd.show()
Example #4
0
def getTime():
    r = requests.get("http://api.tfl.gov.uk/stopPoint/490013457N/Arrivals")
    json_result = r.json()
    my_stops = []
    for x in json_result:
        y = str(int(x['timeToStation']/60)).zfill(2)
        z = ' min ' + str(x['lineId'])
        my_stops.append(y)
        my_stops.sort()
        str1 = ', '.join(my_stops) +', '

    while True:
        scrollphathd.write_string(str1, y=1, font=font3x5, brightness=0.5)
        scrollphathd.flip(x,y)
        scrollphathd.scroll()    
        scrollphathd.show()
        print(str1)
Example #5
0
def clock():
    dur = 7
    count = 0
    while count < dur * (10):
        scrollphathd.clear()

        float_sec = (time.time() % 60) / 59.0
        seconds_progress = float_sec * 15

        if DISPLAY_BAR:
            # Step through 15 pixels to draw the seconds bar
            for y in range(15):

                current_pixel = min(seconds_progress, 1)
                scrollphathd.set_pixel(y + 1, 6, current_pixel * BRIGHTNESS)
                seconds_progress -= 1

                if seconds_progress <= 0:
                    break

        else:
            # Just display a simple dot
            scrollphathd.set_pixel(int(seconds_progress), 6, BRIGHTNESS)

    # Display the time (HH:MM) in a 5x5 pixel font
        scrollphathd.write_string(time.strftime("%H:%M"),
                                  x=0,
                                  y=0,
                                  font=font5x5,
                                  brightness=0.3)

        if int(time.time()) % 2 == 0:
            scrollphathd.clear_rect(8, 0, 1, 5)

        scrollphathd.show()
        scrollphathd.flip(x=True, y=True)
        time.sleep(0.1)
        count = count + 1

    return "", 204
    scrollphathd.clear()
    scrollphathd.show()
Example #6
0
def displayPacman(timeout):
    startTime = int(time.time())
    while startTime + timeout > time.time():
        sphd.flip(x=True, y=True)
        for x in range(0, 17):
            sphd.clear()

            # Draw the dots
            for i in range(3, 17, 3):
                if (x < i):
                    sphd.set_pixel(i, 3, brightSet)

            # Alternate mouth open/close
            if x % 2 == 0:
                pacmanOpen(x, 0, 0)
            else:
                pacmanClose(x, 0, 0)

            sphd.show()
            time.sleep(0.3)
Example #7
0
def run():
    while True:
        action = api_queue.get(block=True)

        if action.action_type == "write":
            cleanup()
            scrollphathd.write_string(action.data)

        if action.action_type == "clear":
            cleanup()

        if action.action_type == "scroll":
            scrollphathd.scroll(action.data[0], action.data[1])

        if action.action_type == "flip":
            scrollphathd.flip(x=action.data[0], y=action.data[1])

        if action.action_type == "autoscroll":
            autoscroll.config(action.data[0], action.data[1])

        scrollphathd.show()
Example #8
0
def send_image():
    if request.method == 'POST':
        try:
            print("headers")
            print(request.headers)
            print("data")
            print(request.data)
            print("headers")
            print(request.files)

            # uploaded_file = request.files['image']
            def get_pixel(x, y):
                p = img.getpixel((x, y))
                if img.getpalette() is not None:
                    r, g, b = img.getpalette()[p:p + 3]
                    p = max(r, g, b)
                return p / 255.0

            for x in request.files:
                print(x)
                uploaded_file = request.files[x]
                uploaded_file.save(x)
                print(uploaded_file.filename)
                img = Image.open(uploaded_file.filename)
                try:
                    for x in range(0, 17):
                        for y in range(0, 7):
                            brightness = get_pixel(x, y)
                            scrollphathd.pixel(x, 6 - y, brightness * 0.5)
                    scrollphathd.flip(x=True, y=False)
                    scrollphathd.show()

                except Exception as e:
                    print(e)
                    scrollphathd.clear()
                    scrollphathd.show()
            return "", 204
        except Exception as e:
            print(e)
            abort(501)
Example #9
0
def run():
    while True:
        action = api_queue.get(block=True)

        if action.action_type == "write":
            cleanup()
            state.set_current_action(action.data)
            scrollphathd.write_string(action.data)
            scrollphathd.scroll(0, -1)

        if action.action_type == "clear":
            cleanup()

        if action.action_type == "clearwater":
            cleanup()
            state.get_scheduler().remove_job('water_reminder')

        if action.action_type == "scroll":
            scrollphathd.scroll(action.data[0], action.data[1])

        if action.action_type == "flip":
            scrollphathd.flip(x=action.data[0], y=action.data[1])

        if action.action_type == "autoscroll":
            autoscroll.config(action.data[0], action.data[1])

        if action.action_type == "custom":
            cleanup()
            state.set_current_action('{}.py'.format(action.data))
            os.system('python ./patterns/{}.py &'.format(action.data))

        if action.action_type == "full":
            cleanup()
            full_board()

        if action.action_type == "water":
            set_reminder(action.data)

        scrollphathd.show()
Example #10
0
def displayTemp(timeout):
    startTime = int(time.time())
    while startTime + timeout > time.time():
        sphd.flip(x=True, y=True)
        sphd.clear()
        if precise == 0:
            offset = 1
            len = sphd.write_string(str(int(read_temp())),
                                    x=offset,
                                    y=1,
                                    font=font3x5,
                                    brightness=brightSet)
            printDegree(len + offset, 1)
            sphd.write_string("C",
                              x=len + offset + 3,
                              y=1,
                              font=font3x5,
                              brightness=brightSet)
        else:
            value = str(read_temp())
            num = value.split('.')[0]
            point = value.split('.')[1]
            len = sphd.write_string(num,
                                    x=0,
                                    y=1,
                                    font=font3x5,
                                    brightness=brightSet)
            sphd.set_pixel(len, 5, brightSet)
            sphd.write_string(point,
                              x=len + 2,
                              y=1,
                              font=font3x5,
                              brightness=brightSet)

            tinyC(len + 7, 3)
            sphd.set_pixel(len + 6, 1, brightSet)
    #print (str(read_temp()))
        sphd.show()
        time.sleep(1)
Example #11
0
def writeChar():
    if request.is_json:
        schema = td["actions"]["writeChar"]["input"]
        valid_input = Draft6Validator(schema).is_valid(request.json)

        if valid_input:
            o_x = 5
            o_y = 0
            Char = str(request.json["char"])
            try:
                o_x = int(request.json["o_x"])
            except Exception as e:
                print(e)
            try:
                o_y = int(request.json["o_y"])
            except Exception as e:
                print(e)
            bright = float(request.json["brightness"])

            scrollphathd.clear()
            scrollphathd.show()
            scrollphathd.draw_char(o_x,
                                   o_y,
                                   Char,
                                   font=None,
                                   brightness=bright,
                                   monospaced=True)
            scrollphathd.flip(x=True, y=True)
            scrollphathd.show()
            time.sleep(5)
            scrollphathd.clear()
            scrollphathd.show()
            return "", 204
        else:
            abort(400)
            print("wrong input")
    else:
        abort(415)  # Wrong media type.
Example #12
0
def displayTime(timeout):
    startTime = int(time.time())
    while startTime + timeout > time.time():
        sphd.flip(x=True, y=True)
        sphd.clear()
        currentTime = datetime.datetime.now()

        # Flash the colon every other second
        secs = int(currentTime.strftime("%S"))
        if (secs % 2 == 0):
            sphd.write_string(":",
                              x=8,
                              y=0,
                              font=font3x5,
                              brightness=brightSet)

        stringHour = currentTime.strftime("%H")
        stringMins = currentTime.strftime("%M")

        sphd.write_string(stringHour,
                          x=0,
                          y=0,
                          font=font3x5,
                          brightness=brightSet)
        sphd.write_string(stringMins,
                          x=10,
                          y=0,
                          font=font3x5,
                          brightness=brightSet)

        secPixels = int(round((float(secs) / 60) * 17, 0))
        for s in range(secPixels):
            sphd.set_pixel(s, 6, brightSet)

        sphd.show()
        #sphd.scroll(1)
        time.sleep(0.05)
        sphd.clear()
Example #13
0
def submit_td(ip_addr, tdd_address):
    global td
    td = get_td(ip_addr)
    print("Uploading TD to directory ...")
    while True:
        try:
            r = requests.post("{}/td".format(tdd_address), json=td)
            r.close()
            print("Got response: ", r.status_code)
            if 200 <= r.status_code <= 299:
                print("TD uploaded!")
                return
            else:
                print(
                    "TD could not be uploaded. Will try again in 15 Seconds..."
                )
                time.sleep(15)
        except Exception as e:
            print(e)
            print("TD could not be uploaded. Will try again in 15 Seconds...")
            time.sleep(15)

    dur = 7
    count = 0
    while count < dur * (10):
        scrollphathd.clear()

        float_sec = (time.time() % 60) / 59.0
        seconds_progress = float_sec * 15

        if DISPLAY_BAR:
            # Step through 15 pixels to draw the seconds bar
            for y in range(15):

                current_pixel = min(seconds_progress, 1)
                scrollphathd.set_pixel(y + 1, 6, current_pixel * BRIGHTNESS)
                seconds_progress -= 1

                if seconds_progress <= 0:
                    break

        else:
            # Just display a simple dot
            scrollphathd.set_pixel(int(seconds_progress), 6, BRIGHTNESS)

    # Display the time (HH:MM) in a 5x5 pixel font
        scrollphathd.write_string(time.strftime("%H:%M"),
                                  x=0,
                                  y=0,
                                  font=font5x5,
                                  brightness=0.3)

        if int(time.time()) % 2 == 0:
            scrollphathd.clear_rect(8, 0, 1, 5)

        scrollphathd.show()
        scrollphathd.flip(x=True, y=True)
        time.sleep(0.1)
        count = count + 1

    return "", 204
    scrollphathd.clear()
    scrollphathd.show()
Example #14
0
def Main():
    # Setup signal handler so we can run in background.
    signal.signal(signal.SIGTERM, sig_term_handler)

    # Enable basic logging
    file_name = expand_file_name('server.log')
    logging.basicConfig(filename=file_name,
                        filemode='w',
                        level=logging.DEBUG)

    # Get socket infomration.
    server_address = get_server_address('socket.ini')

    # Create and intilize a TCP/IP socket.
    global sock
    sock = socket.socket()
    sock.bind(server_address)
    sock.settimeout(0.05)
    
    # Set defaults for scrolling display.
    scrollphathd.set_brightness(0.25)
    isFliped = False
    
    # Let the user know the server has started.
    logging.debug(str(datetime.datetime.now()) + " Server started")
    if os.getpgrp() == os.tcgetpgrp(sys.stdout.fileno()):
        print("Server started, ctrl-c to exit")
    else:
        print("Server started, 'kill {}' to exit".format(os.getpid()))

    # Listen for incomming connections.
    sock.listen(1)
    try:
        while True:
            # Wait for a connection.
            try:
                conn, addr = sock.accept()
                logging.debug(str(datetime.datetime.now()) +" Connection from: " + str(addr))
                while True:
                    data = conn.recv(1024).decode()
                    if not data:
                            conn.close()
                            break
                    command, junk, data = data.partition(':')
                    # Parse the command.
                    if command == "0":   # message
                        scrollphathd.clear()
                        scrollphathd.write_string(data, x=17) # 17 for scroll
                                                              # 0 for static
                    elif command == "1": # set brightness
                        scrollphathd.set_brightness(float(data))
                    elif command == "2": # invert display
                        if isFliped:
                            scrollphathd.flip(x=False, y=False)
                            isFliped = False
                        else:
                            scrollphathd.flip(x=True, y=True)
                            isFliped = True
            except socket.timeout:
                # On socket timeout, scroll the displayed message.
                scrollphathd.show()
                scrollphathd.scroll(1) # comment this out for static
    except KeyboardInterrupt:
        cleanup()
Example #15
0
                    '--scroll-x',
                    metavar='PIXELS',
                    type=int,
                    help='Scroll in the X axis.',
                    default=0)
parser.add_argument('-t',
                    '--scroll-y',
                    metavar='PIXELS',
                    type=int,
                    help='Scroll in the Y axis.',
                    default=0)
parser.add_argument('-m',
                    '--message',
                    metavar='MESSAGE',
                    type=str,
                    help='Message to display.',
                    default='Does it work? ')

args = parser.parse_args()

scrollphathd.set_brightness(0.5)
scrollphathd.clear()
scrollphathd.write_string(args.message, x=0, y=0, font=font3x5, brightness=0.5)

while True:
    scrollphathd.flip(args.flip_x, args.flip_y)
    scrollphathd.rotate(args.rotate)
    scrollphathd.scroll(args.scroll_x, args.scroll_y)
    scrollphathd.show()
    time.sleep(0.1)
Example #16
0
import scrollphathd as scroll
import sys
import time

scroll.set_brightness(0.2)
output = ' ' + ' '.join(sys.argv[1:]) + (5*' ')
scroll.clear()
scroll.flip(x=True, y=True)
scroll.write_string(output)
print("buffer shape", scroll.get_buffer_shape())

width, height = scroll.get_buffer_shape()
for _ in range(width):
    scroll.scroll()
    scroll.show()
    time.sleep(0.05)