Пример #1
0
def wifiCallback(state):
    global tasks_wifi
    if state and rtcRequired and time.time() < 1482192000:
        easyrtc.configure()
    for task in tasks_wifi:
        task(state)
Пример #2
0
#based on Working Clock without permission
#come at me, bro.
import easyrtc
import ugfx
import badge
import time
import wifi
import random

badge.init()
ugfx.init()
wifi.init()
easyrtc.configure()

first = ['Holy', 'Shitty', 'Jizzy', 'Still', 'F*****g', 'Jaevla', 'Moronic'];
second = [' wanking ', ' shagging ', ' f*****g ', ' hacking ', ' cunting ', ' unwashed ', 'Mac-using']
third = ['assballs!', 'dick!', 'anyway!', 'twat!', 'NetBSD!', 'buggery!', 'Mac users']

def cuss():
    t = easyrtc.string()
    ugfx.clear(ugfx.WHITE)

#ugfx.string(x, y, string, font, colour)
    ugfx.string(10, 5, str(random.choice(first)), "PermanentMarker36", ugfx.BLACK)
    ugfx.string(30, 30, str(random.choice(second)), "PermanentMarker36", ugfx.BLACK)
    ugfx.string(100, 55, str(random.choice(third)), "PermanentMarker36", ugfx.BLACK)
#    ugfx.string(110, 85, str(herp), "PermanentMarker22", ugfx.BLACK)
    ugfx.string(30, 85, " it's ", "PermanentMarker22", ugfx.BLACK)
    ugfx.string(140, 85, t, "PermanentMarker36", ugfx.BLACK)

    ugfx.flush()
Пример #3
0
def setup(drawCb=None):
    global services
    global drawCallbacks

    if drawCb:
        print("[SERVICES] Draw callback registered")
        global drawCallback
        drawCallback = drawCb  #This might need a better name...

    # Status of wifi
    wifiFailed = False

    #Check if lib folder exists and get application list, else stop
    try:
        apps = uos.listdir('lib')
    except OSError:
        return [False, False]

    #For each app...
    for app in apps:
        print("APP: " + app)
        try:
            #Try to open and read the json description
            fd = open('/lib/' + app + '/service.json')
            description = ujson.loads(fd.read())
            fd.close()
        except:
            print("[SERVICES] No description found for " + app)
            continue  #Or skip the app

        try:
            #Try to open the service itself
            fd = open('/lib/' + app + '/service.py')
            fd.close()
        except:
            print("[SERVICES] No script found for " + app)
            continue  #Or skip the app

        rtcRequired = False  # True if RTC should be set before starting service
        loopEnabled = False  # True if loop callback is requested
        drawEnabled = False  # True if draw callback is requested

        wifiInSetup = False  # True if wifi needed in setup
        wifiInLoop = False  # True if wifi needed in loop

        try:
            if description['apiVersion'] != 2:
                print("[SERVICES] Service for " + app +
                      " is not compatible with current firmware")
                continue  #Skip the app
            wifiInSetup = description['wifi']['setup']
            wifiInLoop = description['wifi']['setup']
            rtcRequired = description['rtc']
            loopEnabled = description['loop']
            drawEnabled = description['draw']
        except:
            print("[SERVICES] Could not parse description of app " + app)
            continue  #Skip the app

        print("[SERVICES] Found service for " + app)

        # Import the service.py script
        try:
            srv = __import__('lib/' + app + '/service')
        except BaseException as e:
            print("[SERVICES] Could not import service of app " + app + ": ")
            sys.print_exception(e)
            continue  #Skip the app

        if wifiInSetup or wifiInLoop:
            if wifiFailed:
                print(
                    "[SERVICES] Service of app " + app +
                    " requires wifi and wifi failed so the service has been disabled."
                )
                continue
            if not easywifi.status():
                if not easywifi.enable():
                    wifiFailed = True
                    print("[SERVICES] Could not connect to wifi!")
                    continue  # Skip the app

        if rtcRequired and time.time() < 1482192000:
            if not wifiFailed:
                print("[SERVICES] RTC required, configuring...")
                easyrtc.configure()
            else:
                print(
                    "[SERVICES] RTC required but not available. Skipping service."
                )
                continue  # Skip the app (because wifi failed and rtc not available)

        try:
            srv.setup()
        except BaseException as e:
            print("[SERVICES] Exception in service setup " + app + ":")
            sys.print_exception(e)
            continue

        if loopEnabled:
            try:
                virtualtimers.new(1, srv.loop)
            except:
                print("[SERVICES] Loop requested but not defined in service " +
                      app)

        if drawEnabled and drawCb:
            drawCallbacks.append(srv)

        # Add the script to the global service list
        services.append(srv)

    handleDraw = False
    if len(drawCallbacks) > 0 and drawCb:
        print("[SERVICES] The service subsystem now handles screen redraws")
        handleDraw = True
        virtualtimers.new(1, draw_task, True)
    return handleDraw
def init():
    badge.init()
    ugfx.init()
    easywifi.enable()
    easyrtc.configure()
    clear_screen()