コード例 #1
0
def touch_handler(channel, event):
    if channel == 1:
        cfg.blue = not cfg.blue
        if cfg.blue:
            hw.light_blue_on()
            hw.output_one_on()
        else:
            hw.light_blue_off()
            hw.output_one_off()
    if channel == 2:
        cfg.yellow = not cfg.yellow
        if cfg.yellow:
            hw.light_yellow_on()
            hw.output_two_on()
        else:
            hw.light_yellow_off()
            hw.output_two_off()
    if channel == 3:
        cfg.chocks = not cfg.chocks
        if cfg.chocks:
            cfg.watchdog_running = False
            chocks_on()
        else:
            cfg.watchdog_running = True
            chocks_off()
    if channel == 4:
        hw.light_green_blink(0.1)
        cfg.green = True
        time.sleep(5)
        if cfg.chocks:
            hw.light_green_on()
            os.system("sudo -s shutdown -h now")
        else:
            hw.light_green_off()
            cfg.green = False
コード例 #2
0

# URL for single frame feed
@app.route('/single_frame.jpg')
def single_frame():
    if cfg.camera_detected:
        jpeg = cam.single_frame()
        return Response(jpeg, mimetype='image/jpeg; boundary=frame')
    else:
        return 'no video'


if __name__ == '__main__':
    hw.light_green_blink(0.1)
    time.sleep(1)
    hw.light_green_off()
    cfg.camera_detected, cfg.camera = cam.init_camera()

    # register signal handler for a clean exit
    signal.signal(signal.SIGINT, signal_handler)

    # register handler for touchpads
    if hw.explorerhat:
        hw.xhat.touch.released(touch_handler)

    # prepare and start watchdog
    wd = threading.Thread(name='watchdog_timer', target=watchdog_timer)
    wd.start()

    #app.run(host='0.0.0.0', debug=False, threaded=True)
    http_server = WSGIServer(('', 5000), app)