예제 #1
0
def program_main():
    ugfx.init()
    ugfx.clear(ugfx.WHITE)

    badge.leds_init()

    try:
        badge.eink_png(0, 0, logo_path)
    except:
        log('+ Failed to load graphics')

    # Name tag
    ugfx.string(ugfx.width() - ugfx.get_string_width(name, fonts[1]),
                ugfx.height() - 36, name, fonts[1], ugfx.BLACK)

    # Button info
    ugfx.string(0,
                ugfx.height() - 13, '[FLASH to update] [B to exit]', fonts[2],
                ugfx.BLACK)
    ugfx.flush()

    ugfx.input_init()
    ugfx.input_attach(ugfx.BTN_B, lambda pressed: exit_app())
    ugfx.input_attach(ugfx.BTN_FLASH, lambda pressed: start_self_update())

    HOST = "chat.freenode.net"
    PORT = 6667
    NICK = name + "[luv]"
    REALNAME = name + ' @ SHA2017'

    log('+ waiting for network...')
    wifi.init()
    while not wifi.sta_if.isconnected():
        time.sleep(0.1)

    s = socket.socket()
    s.connect((HOST, PORT))

    s.send(bytes("NICK %s\r\n" % NICK, "UTF-8"))
    s.send(bytes("USER %s 0 * :%s\r\n" % (NICK, REALNAME), "UTF-8"))
    s.send(bytes("JOIN #sha2017\r\n", "UTF-8"))

    # IRC Client
    while True:
        line = s.readline().rstrip()
        parts = line.split()

        if parts:
            if (parts[0] == b"PING"):
                s.send(bytes("PONG %s\r\n" % line[1], "UTF-8"))
                blink_led(green)
            if (parts[1] == b"PRIVMSG"):
                blink_led(red)
                msg = b' '.join(parts[3:])
                rnick = line.split(b'!')[0]
                log(b'%s: %s' % (rnick, msg))
예제 #2
0
def sendOverWifi(dataStringList: list):
    print(str(dataStringList))
    print(constructDataString(dataStringList))
    json = buildJSON(constructDataString(dataStringList))
    print(json)
    wifi.init()

    requests.request('POST',
                     'https://iot-web-app-2018.herokuapp.com/temperature',
                     json, None, {"Content-Type": "application/json"})
예제 #3
0
def main():

    import sys
    sys.modules.clear()

    from button_handler import Button
    from pins import Pins

    # Init device button IRQ:
    Pins.button_pin.irq(Button().irq_handler)

    from context import Context

    context = Context()

    import wifi
    wifi.init(context)
    del sys.modules['wifi']

    _RTC_KEY_RUN = 'run'
    _RUN_WEB_SERVER = 'web-server'
    _RUN_SOFT_OTA = 'soft-ota'

    from rtc import get_rtc_value
    if get_rtc_value(_RTC_KEY_RUN) == _RUN_WEB_SERVER:
        print('start webserver')

        from rtc import update_rtc_dict
        update_rtc_dict(data={_RTC_KEY_RUN:
                              _RUN_SOFT_OTA})  # run OTA client on next boot

        del update_rtc_dict
        del get_rtc_value
        del sys.modules['rtc']

        # init Watchdog timer
        from watchdog import Watchdog
        context.watchdog = Watchdog(context)

        from webswitch import WebServer

        WebServer(context=context, version=__version__).run()
    else:
        print('start "soft" OTA')
        Pins.power_led.off()
        from rtc import update_rtc_dict
        update_rtc_dict(data={_RTC_KEY_RUN:
                              _RUN_WEB_SERVER})  # run web server on next boot
        from ota_client import SoftOtaUpdate

        SoftOtaUpdate().run()

    from reset import ResetDevice
    ResetDevice(reason='unknown').reset()
예제 #4
0
def main():
    from context import Context

    context = Context()

    import wifi
    wifi.init(context)
    del sys.modules['wifi']
    gc.collect()

    server = WebServer()
    server.run()
예제 #5
0
def loop():
    print("> angelshifts loop")
    last_update = int(badge.nvs_get_str("engel", "update", "0"))
    print("last update: ", last_update)
    if api_key:
        # Perform update if update_interval has passed
        if last_update + update_interval < easyrtc.time.time():
            print("angelshifts: updating...")
            wifi.init()
            tries = 0
            while not wifi.sta_if.isconnected():
                time.sleep(0.1)
                tries += 1
                if tries >= wifi_tries:
                    return wakeup_interval
            next_shift = get_next_shift(api_key)
            if next_shift:
                badge.nvs_set_str("engel", "shift_name", next_shift["name"])
                badge.nvs_set_str("engel", "shift_loc", next_shift["Name"])
                badge.nvs_set_str("engel", "shift_start", next_shift["start"])
                badge.nvs_set_str("engel", "shift_end", next_shift["end"])
                badge.nvs_set_u8("engel", "notified", 0)
            else:
                badge.nvs_set_str("engel", "shift_name", "")
            badge.nvs_set_str("engel", "update", str(easyrtc.time.time()))
        else:
            print("angelshifts: no update needed")

        # Notify about upcoming shift if it starts in less than notify_time
        if badge.nvs_get_str("engel", "shift_name", "") and not bool(
                badge.nvs_get_u8("engel", "notified")):
            start = int(badge.nvs_get_str("engel", "shift_start", ""))
            now = easyrtc.time.time()
            if start > now and start < now + notify_time:
                global notified
                badge.vibrator_init()
                badge.vibrator_activate(200)
                ugfx.string(
                    0, 0,
                    "NEXT SHIFT IN {} MINUTES!".format(notify_time // 60),
                    "PermanentMarker22", ugfx.BLACK)
                ugfx.flush()

        return wakeup_interval
    else:
        print("no api key set up")
        return 0
예제 #6
0
def main():
    print("> Main")
    global api_key

    ugfx.init()
    ugfx.input_init()

    ugfx.clear(ugfx.BLACK)
    ugfx.flush()
    ugfx.clear(ugfx.WHITE)
    ugfx.flush()

    ugfx.input_attach(ugfx.BTN_B, appglue.home)
    ugfx.input_attach(ugfx.BTN_SELECT, prompt_api_key)
    wifi.init()
    while not wifi.sta_if.isconnected():
        time.sleep(0.1)
        pass

    api_key = badge.nvs_get_str("engel", "key", "")
    if not api_key:
        prompt_api_key()

    show_shift_list()
예제 #7
0
"""
    Connect to WiFi via saved settings in:
        /_config_wifi.json
"""
import wifi
from context import Context

if __name__ == '__main__':
    context = Context()
    wifi.init(context)
예제 #8
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()
예제 #9
0
def main():
    
    # PiTFT init#################
    os.putenv('SDL_VIDEODRIVER','fbcon')
    os.putenv('SDL_FBDEV','/dev/fb1')
    os.putenv('SDL_MOUSEDRV','TSLIB')
    os.putenv('SDL_MOUSEDEV','/dev/input/touchscreen')


    # Wifi port init#################
    wifi.init()
    UDP_IP = "192.168.4.9"
    UDP_PORT = 9008

    MESSAGE = "w"

    print "UDP target IP:", UDP_IP
    print "UDP target port:", UDP_PORT
    print "message:", MESSAGE
    sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    sock.bind(("192.168.4.1",8080))

    # GPIO init#################

    volume.volumechange(100)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    GPIO.add_event_detect(5,GPIO.BOTH,callback=GPIOinput.GPIO5_both)
    GPIO.add_event_detect(6,GPIO.BOTH,callback=GPIOinput.GPIO6_both)
    GPIO.add_event_detect(12,GPIO.BOTH,callback=GPIOinput.GPIO12_both)
    GPIO.add_event_detect(13,GPIO.BOTH,callback=GPIOinput.GPIO13_both)
    GPIO.add_event_detect(16,GPIO.BOTH,callback=GPIOinput.GPIO16_both)
    GPIO.add_event_detect(17,GPIO.BOTH,callback=GPIOinput.GPIO17_both)
    GPIO.add_event_detect(18,GPIO.BOTH,callback=GPIOinput.GPIO18_both)
    GPIO.add_event_detect(19,GPIO.BOTH,callback=GPIOinput.GPIO19_both)
    GPIO.add_event_detect(20,GPIO.BOTH,callback=GPIOinput.GPIO20_both)
    GPIO.add_event_detect(21,GPIO.BOTH,callback=GPIOinput.GPIO21_both)
    GPIO.add_event_detect(22,GPIO.BOTH,callback=GPIOinput.GPIO22_both)
    GPIO.add_event_detect(23,GPIO.BOTH,callback=GPIOinput.GPIO23_both)
    GPIO.add_event_detect(26,GPIO.BOTH,callback=GPIOinput.GPIO26_both)
    GPIO.add_event_detect(27,GPIO.BOTH,callback=GPIOinput.GPIO27_both) 
    
    # Parse command line arguments
    (args, parser) = parse_arguments.parse_arguments()
    if not args.verbose:
        warnings.simplefilter('ignore')

    # Generate sound #################
    fps, sound = wavfile.read(piano.wav)
    tones = range(-24, -12)
    tones_all = range(-48, 12)
    sys.stdout.write('Ready for the computation.. ')
    sys.stdout.flush()
    transposed_sounds = [shift_pitch.shift_pitch(sound, n) for n in tones]
    
    pygame.mixer.init(fps, -16, 1, 2048)
    
    # Pygame display init############################################################################
    screen = pygame.display.set_mode((320,240))
    keys = args.keyboard.read().split('\n')
    sounds = map(pygame.sndarray.make_sound, transposed_sounds)
    key_sound = dict(zip(keys, sounds))
       
    keys_all = args.keyall.read().split('\n')
    transposed_sounds_all = [shift_pitch.shift_pitch(sound, n) for n in tones_all]
    sounds_all = map(pygame.sndarray.make_sound, transposed_sounds_all)
    key_sound_all = dict(zip(keys_all, sounds_all))
    
    print(keys)
    playing = {k: 0 for k in keys}
    note_duration = 0
    former_duration = 0
    rest_duration = 0
    note_length = 0
    tune_length = 0
    pygame.init()
    pygame.mouse.set_visible(False)
    WHITE = 255,255,255
    BLACK = 0,0,0
    GPIO.setmode(GPIO.BCM)
    a = 0
    a_rest = 0
    b = 0
    b_rest = 0    
    start = 0
    current_status = 0
    KEYDOWN = 99
    KEYUP = 100
    genrestflag = 0
    needtogenerate  = 1
    needtogenrest = 1
    

    # Program starts here################
    
    while (welcome.welcomeinit() == 0):
	    a = time.time()
	    b = time.time()
        #print(1)
        #print ('Virtual Piano')
    screen.fill(WHITE)
    display.displaykey(screen)
    #timer = threading.Timer(1,listenbutton)
    #timer.start()
    #print (a,b,keys)

    # main loop ################
    while True:            
        key = str(globalname.n[1])
        event = globalname.n[0]
        pygame.display.flip()
        # detect virtual button press ################
        if event == KEYDOWN:
            if (key in key_sound.keys()) and (playing[key] == 0):

            	# Use UDP signal to change volume ################
                sock.sendto(MESSAGE, (UDP_IP,UDP_PORT))
                data, addr = sock.recvfrom(100)
                globalname.mainlocation = int(data) % 10 - 2
                if (globalname.mainlocation == 3):
                    pygame.quit()
                vol = int(data) / 10
                if vol > 100:
                    sound_vol = 100
                elif vol > 40:
                	sound_vol = 90
                elif vol > 20:
                    sound_vol = 80
                else:
                	sound_vol = 70
                volume.volumechange(sound_vol)

                # generate note sound ################
                if (globalname.mainlocation >= 0):
                    sear = (globalname.mainlocation*100 + int(key) )
                else:
                    sear = (globalname.mainlocation*100 - int(key) )
                key_sound_all[str(sear)].play(fade_ms=50)
                playing[key] = 1

                # calculate rest duration ################                
                b = time.time()
                note_duration = b - a
                a = time.time()           
                current_status = 1

        # detect virtual button release ################
        elif event == KEYUP and key in key_sound.keys():

        	# generate note fade out ################
            if (globalname.mainlocation >= 0):
                sear = (globalname.mainlocation*100 + int(key) )
            else:
                sear = (globalname.mainlocation*100 - int(key) )
            key_sound_all[str(sear)].fadeout(50)

            # calculate note duration ################    
            playing[key] = 0
            b = time.time()
            note_duration = b - a
            a = time.time()
            start = 1
            globalname.n[0] = 0
            current_status = 0

        # append a note/rest to the note list ################    
        if ( former_duration != note_duration ):
            if (current_status == 0):
                display.appendnote(key,note_duration,keys)
            else:
                display.appendrest(note_duration)

        # display all things ################    
        screen.fill(WHITE)
        if (current_status == 0):
            display.displaykey(screen)
        else:
            display.displaykeyboard(key,keys,screen)            
        display.displaybase(screen)
        if (start) :
            display.displaynote(screen)
        former_duration = note_duration
예제 #10
0
def init_wifi():
    import wifi
    wifi.init()
    wifi.disable_wifi_ap()
예제 #11
0
def main():
    UhPLC()
    UhPLu = UhPLy()
    UhPDL(UhPLu)
    remove_duplicate_initial_fragment()
    if UhPDf:
        UhPLE(UhPLe)
        UhPLn(0, 0, "Welcome, early bird!", "PermanentMarker22", UhPLO)
        UhPLn(0, 30, "Welcome to the SHA2017Game! You are in league",
              "Roboto_Regular12", UhPLO)
        UhPLn(
            0, 50, "%s, as your 'callsign' shows if you soldered on your" %
            leaguename(), "Roboto_Regular12", UhPLO)
        UhPLn(0, 70, "LEDs. The game starts when the oracle is on the field,",
              "Roboto_Regular12", UhPLO)
        UhPLn(0, 90, "keep an eye on https://twitter.com/SHA2017Game.",
              "Roboto_Regular12", UhPLO)
        UhPLn(5, 113, "B: Back to home", "Roboto_Regular12", UhPLO)
        UhPLT()
        UhPLk()
        UhPLB(UhPLq, lambda pressed: UhPLz() if pressed else 0)
        return
    UhPLW = get_fragments()
    print('number of fragments so far', UhPDu(UhPLW))
    UhPLi = UhPDf
    if UhPDu(UhPLW) >= 25:
        UhPLc('SHA2017Game', 'fragment_0', UhPLW[0].strip())
        UhPLE(UhPLe)
        try:
            import os
            os.stat('/lib/SHA2017game/sparkle.py')
            won()
        except:
            import wifi
            import urequests
            import shards
            wifi.init()
            while not wifi.sta_if.isconnected():
                UhPLS(1)
            UhPLd = []
            for UhPLv in UhPLW:
                UhPLd.append(UhPLv.replace('\n', '').replace('\r', ''))
            UhPLM = shards.key_from_shards(UhPLd)
            print('Collecting shards.py with key', UhPLM)
            r = urequests.get("http://pi.bzzt.net/%s/sparkle.py" % UhPLM)
            f = UhPDX('/lib/SHA2017game/sparkle.py', 'w')
            f.write(r.content)
            f.close()
            won()
    elif UhPDu(UhPLW) > 1:
        UhPLc('SHA2017Game', 'fragment_0', UhPLW[0].strip())
        UhPLE(UhPLe)
        UhPLn(0, 0, "Share your fragments!", "PermanentMarker22", UhPLO)
        UhPLn(0, 30,
              "By sharing you have now brought together %d" % UhPDu(UhPLW),
              "Roboto_Regular12", UhPLO)
        UhPLn(
            0, 50, "fragments of league %s. Sharing will send them all." %
            leaguename(), "Roboto_Regular12", UhPLO)
        UhPLn(0, 70,
              "Unlock your league %s key with 25 fragments!" % leaguename(),
              "Roboto_Regular12", UhPLO)
        UhPLn(
            5, 113,
            "B: Back to home                                A: Share fragments",
            "Roboto_Regular12", UhPLO)
        UhPLT()
        UhPLk()
        UhPLB(UhPLq, lambda pressed: UhPLz() if pressed else 0)
        UhPLB(UhPLR, lambda pressed: initiate_sharing() if pressed else 0)
    elif UhPDu(UhPLW) == 1:
        UhPLE(UhPLe)
        UhPLn(0, 0, "Share your fragments!", "PermanentMarker22", UhPLO)
        UhPLn(
            0, 30,
            "The oracle gave you a fragment of a relic of the " + leaguename(),
            "Roboto_Regular12", UhPLO)
        UhPLn(0, 50, "league. 25 such fragments must be brought together",
              "Roboto_Regular12", UhPLO)
        UhPLn(0, 70, "to unlock its potential. Find other league members to",
              "Roboto_Regular12", UhPLO)
        UhPLn(0, 90, "share fragments along with a story or Mate.",
              "Roboto_Regular12", UhPLO)
        UhPLn(
            5, 113,
            "B: Back to home                                A: Share fragments",
            "Roboto_Regular12", UhPLO)
        UhPLT()
        UhPLk()
        UhPLB(UhPLq, lambda pressed: UhPLz() if pressed else 0)
        UhPLB(UhPLR, lambda pressed: initiate_sharing() if pressed else 0)
    elif UhPLi:

        def oracle_selection_made(value):
            UhPDL(UhPLu)
            if value:
                listenForOracle(leaguename())
            else:
                UhPLz()

        def dialog_title():
            return "SHA2017Game - you are in league " + leaguename()

        UhPLg('Are you ready to start your quest?',
              title=dialog_title(),
              true_text='Search for the oracle',
              false_text='Back to home screen',
              height=100,
              cb=oracle_selection_made)
    else:
        UhPLE(UhPLe)
        UhPLn(0, 0, "Retrieving fragment!", "PermanentMarker22", UhPLO)
        UhPLn(0, 30, "Welcome player of league " + leaguename(),
              "Roboto_Regular12", UhPLO)
        UhPLn(0, 50, "Fetching your initial fragment!", "Roboto_Regular12",
              UhPLO)
        UhPLT()
        import wifi
        import urequests
        wifi.init()
        n = 0
        while not wifi.sta_if.isconnected() and n < 30:
            UhPLS(1)
            n = n + 1
        if n == 30:
            UhPLn(0, 70, "Failed! Press A.", "Roboto_Regular12", UhPLO)
            UhPLk()
            UhPLB(UhPLR, lambda pressed: UhPLQ('SHA2017Game')
                  if pressed else 0)
            return
        UhPLj = (UhPLm()[3] + UhPLm()[4] + UhPLm()[5]) % 700
        r = urequests.get("http://pi.bzzt.net/oracle/%d/%d" % (UhPLu, UhPLj))
        gotOracleData(r.content)
        UhPLQ('SHA2017Game')