Beispiel #1
0
import console, time

buttonSelect = console.Button(0)
display = console.Display()

def center_text(txt):
    return '{: ^{}}'.format(txt, display.max_char)

display.print_on_line(center_text("Wujuuu imported"), 0)
display.print_on_line(center_text("Press the"), 3)
display.print_on_line(center_text("button 0 to"), 4)
display.print_on_line(center_text("count presses"), 5)
intCounter = 0

while True:
    if not buttonSelect.isReleased():
        intCounter += 1
        display.clear(0, 1)
        display.print_on_line(center_text("IT IS WORKING!!!"), 0)
        display.print_on_line(center_text("Button presses"), 3)
        display.print_on_line(center_text(str(intCounter)), 5)
        time.sleep_ms(250)
Beispiel #2
0
import time
import os
import sys
import console

keys = console.Keypad()
oled = console.Display()


def print_menu(lstwords):
    """
    Function to print the menu when the script initializes.

    Returns:
        Nothing.
    """
    if isinstance(lstwords, list) and len(lstwords) <= 8:
        line = 0
        for script in lstwords:
            if line > len(oled.v_lines):
                time.sleep(2)
                line = 0
            oled.print_on_line(str(script), line)
            line += 1
    else:
        oled.print_wrapped(lstwords)
    time.sleep(3)


def print_selection(scripts, selection):
    """
Beispiel #3
0
def main():
    """
    Main logic is on this function
    """
    oled = console.Display()
    oled.print_wrapped("Checking messages file.")
    oled.clear(0, 1)
    time.sleep(1)
    check_file()
    html = """<!DOCTYPE html>
        <html lang="en">
        <head>
        <title>Message board</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
        body              { font-family: "Arial"; background: #fff;}
        .h1_div			  { background-color: #424242; height: 90px; text-align: center; font-family: "Arial";}
        .current_time     { vertical-align:middle; font-family:"Arial";}
        h1                { border-bottom: 1px; }
        h3                { font-family: "Arial"; color: #424242; text-align: center;}
        table             { table-layout: center;	font-family: "Arial";}
        th                { font-style: bold; text-align: center; height: 15px; border-bottom: 1px solid #ddd; padding: 5px}
        td                { border-bottom: 1px solid #ddd; text-align: left}
        input[type=text]  { border: 1px solid #424242; margin: 4px 2px; width:20em;}
        input[type=text]:focus { border: 3px solid #424242; margin: 4px 2px; -webkit-transition: width 0.4s ease-in-out; transition: width 0.4s ease-in-out;}
        input[type=submit]{ background-color: #424242; border: 3px; color: #ffffff; padding: 4px 8px; text-decoration: none; margin: 4px 2px; cursor: pointer; width:20em; font-weight: bold; font-family: "Arial";}
        form              {text-align: center;}
        </style>
        </head>
        <body>
        <div>
        <div class="h1_div">
        <h1 align="center" style="color:#ffffff;">Message board</h1>
        <h3 align="center" style="color:#ffffff;" class="current_time" id="humanTime"></h3>
        </div><div>
        <table align="center"><tr><th><h1>Messages</h1></th></tr>%s</table>
        <form>
        <br><h3>Type a message:</h3><br>
        <div><input type="text" name="messageinput"></input></div>
        <div><input type="submit" value="Send"></input></div>
        </form></div></div>
        <script>
        function currentTime()
        {
            var date = new Date();
            datestring = date.toDateString() + " " + date.toTimeString();
            document.getElementById("humanTime").innerHTML = datestring.split(" ").slice(0, 5).join(" ");
        }
        var element = document.getElementById("humanTime");
        if (typeof(element) != "undefined" && element != null)
        {
            window.load = setInterval(currentTime, 1000);
        }
        </script>
        </body>
        </html>
        """

    addr = socket.getaddrinfo("192.168.4.1", 80)[0][-1]
    s = socket.socket()
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(addr)
    s.listen(5)
    connection_count = 0

    while True:
        cl, addr = s.accept()
        oled.print_wrapped(
            str("Connection from : %s" % addr) +
            str("Free in: %d" % gc.mem_free()))
        time.sleep(0.1)
        oled.clear(0, 1)
        connection_count += 1
        cl_file = cl.makefile("rwb", 0)
        while True:
            h = cl_file.readline()
            gotten_msg = b"GET /?messageinput="
            if gotten_msg in h:
                msg = h.decode("utf-8").split("/?messageinput=")
                final_msg = msg[1][:(len(msg) - 12)]
                oled.clear(0, 1)
                oled.print_wrapped(final_msg)
                write_file(final_msg)
            if h == b"" or h == b"\r\n":
                break
        rows = linted_data()
        response = html % "\n".join(rows)
        try:
            cl.sendall(response)
        except OSError as error:
            print("Error trying to send all information. %s" % error)
            pass
        cl.close()
        oled.print_wrapped(str("Free out: %d" % gc.mem_free()))
        time.sleep(0.1)
        oled.clear(0, 1)