Ejemplo n.º 1
0
    def decrease_interval(self):
        # set pixel to blue
        buttonshim.set_pixel(0, 0, 255)

        self.interval -= 5
        if self.interval < 5:
            self.interval = 5
Ejemplo n.º 2
0
def button_d(button, pressed):
    print("Button LOGOS")
    buttonshim.set_pixel(0, 255, 0)
    take_a_photo()
    led.on()
    os.system("mpg321 ana.mp3")
    detect_logos('/home/pi/CameraTell/image1.jpg')
Ejemplo n.º 3
0
def button_a(button, pressed):
    print("Button CONTENT of image")
    buttonshim.set_pixel(0, 255, 0)
    take_a_photo()
    led.on()
    os.system("mpg321 ana.mp3")
    image_content()
Ejemplo n.º 4
0
    def __init__(self):
        self.shutdownPin = 7

        # Define GPIO mode
        GPIO.setmode(GPIO.BOARD)

        # Initialize shutdown call back event
        GPIO.setup(self.shutdownPin, GPIO.IN,
                   pull_up_down=GPIO.PUD_UP)  # Shutdown Signal
        GPIO.add_event_detect(self.shutdownPin,
                              GPIO.FALLING,
                              callback=self.shutdownPinLow,
                              bouncetime=100)

        self.shutdownTimer = -100
        self.shutDownStop()

        try:
            buttonshim.set_pixel(0x00, 0x00, 0x00)
            self.buttonShimFound = True
        except:
            self.buttonShimFound = False

        try:
            self.sense = SenseHat()
        except:
            self.sense = False

        return
Ejemplo n.º 5
0
def play_track():
    global player
    global playList
    global starttime
    global direction
    global pausetime
    if direction == '':
        direction = 'next'
    try:
        status = player.playback_status()
        filename = player.get_filename()
        duration = player.duration()
        currtime = int(time.time())
        remaining = int(duration - (currtime - starttime + pausetime))
        print(filename + ' for ' + str(remaining))
    except:
        nextTrack = getNextTrack()
        if direction == 'resume':
            direction = 'next'
        starttime = int(time.time())
        try:
            for proc in psutil.process_iter():
                if 'omxplayer' in proc.name():
                    proc.kill()
            player = OMXPlayer(nextTrack)
        except:
            direction = 'next'
            nextTrack = getNextTrack()
        if buttons:
            buttonshim.set_pixel(0xff, 0xff, 0x00)
Ejemplo n.º 6
0
def button_a(button, pressed):
    for x in range(3):
        buttonshim.set_pixel(0xff, 0x00, 0x00)
        time.sleep(0.1)
        buttonshim.set_pixel(0x00, 0x00, 0x00)
    time.sleep(0.1)
    os.system("sudo halt")
Ejemplo n.º 7
0
def button_D(button, pressed):
    global headers
    global imagedir
    global pre
    # shut down motion service if started
    global motion_on
    global stream_on
    if stream_on:
        print("Shutting down Stream to start Motion Service.")
        subprocess.call(
            'sudo kill $(ps aux | grep "[f]fmpeg" | awk "{print $2}")',
            shell=True)
        stream_on = False
    if motion_on:
        motion_on = False
        subprocess.call('sudo service motion stop', shell=True)
        print("Shutting down Motion service before taking photo for upload.")
    buttonshim.set_pixel(255, 255, 0)
    # shut down the motion service if started

    print("Taking photo and sending to " + url)
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')
    fileName = imagedir + pre + st + '.jpg'
    subprocess.call('fswebcam ' + fileName, shell=True)
    print("Photo saved to " + fileName + ".  Uploading to Wordpress site at " +
          url)
    media = {'file': open(fileName, 'rb')}
    image = requests.post(url + '/media', headers=headers, files=media)
    link = json.loads(image.content.decode('utf-8'))['link']
    postid = json.loads(image.content.decode('utf-8'))['id']
    print('Your image is published on {} with ID {}'.format(link, postid))
    print('')
    buttonshim.set_pixel(0, 0, 0)
Ejemplo n.º 8
0
def button_r_handler(button, pressed):
    color_scan()
    buttonshim.set_pixel(0x00, 0x00, 0x00)
    index = BUTTONS.index(button)
    if index > len(Users):
        return
    Users[BUTTONS.index(button)].display()
Ejemplo n.º 9
0
def button_e(button, hold_time=2):
    print("Button E SHUTDOWN")
    buttonshim.set_pixel(255, 0, 0)  #'''ADD THE SHUT DOWN FROM GPIO ZERO '''
    os.system("mpg321 bye.mp3")
    sleep(2)
    buttonshim.set_pixel(255, 0, 0)
    check_call(['sudo', 'poweroff'])
Ejemplo n.º 10
0
 def button_e_press(button, pressed):
     global player
     status = player.playback_status()
     if status == 'Playing':
         buttonshim.set_pixel(0xff, 0x00, 0x00)
     else:
         buttonshim.set_pixel(0xff, 0xff, 0x00)
     playorpause()
Ejemplo n.º 11
0
def hold_handler(button):
    global button_was_held
    button_was_held = True
    print("Long press detected!")

    buttonshim.set_pixel(0, 0, 255)
    exec(open("/usr/local/bin/status_check/PiholeControl.py").read())
    buttonshim.set_pixel(0, 0, 0)
Ejemplo n.º 12
0
 def loop(self):
     buttonshim.set_pixel(self.red, self.green, self.blue)
     if not self.pause:
         #self.smile_or_text()
         self.random_text()
         time.sleep(self.interval)
     else:
         time.sleep(0.01)
Ejemplo n.º 13
0
def button_e(button):
    print("Held for 2sec!")
    time.sleep(0.1)
    for x in range(3):
        buttonshim.set_pixel(0xff, 0x00, 0x00)
        time.sleep(0.1)
        buttonshim.set_pixel(0x00, 0x00, 0x00)
        time.sleep(0.1)
 def button_a_press(button, pressed):
     global volume
     volume = get_volume()
     volume = int(volume) + 1
     volume = min(100, volume)
     print("Volume: {}%".format(volume))
     set("{}%".format(volume))
     scale = volume / 100.0
     buttonshim.set_pixel(int(0xff * (1.0 - scale)), int(0xff * scale), 0x00)
Ejemplo n.º 15
0
def button_a(button, pressed):
    buttonshim.set_pixel(0x94, 0x00, 0xd3)  
    s=commands.getstatusoutput("raspistill -w 320 -h 240 -o IMG/snap.jpg")
    print s
    
    if s[0] != 0:
                self.output(s[1], s[0])
      else:
                self.output("error occured", status[0])
Ejemplo n.º 16
0
 def SuspendPihole():
     global pressId
     loopId = pressId
     print("Pi-Hole suspended")
     while (loopId == pressId):
         buttonshim.set_pixel(255, 0, 0)
         time.sleep(0.5)
         buttonshim.set_pixel(0, 0, 0)
         time.sleep(0.5)
Ejemplo n.º 17
0
 def EnablePihole():
     global pressId
     loopId = pressId
     print("Pi-Hole enabled")
     for i in range(0, 2):
         buttonshim.set_pixel(0, 255, 0)
         time.sleep(0.3)
         buttonshim.set_pixel(0, 0, 0)
         time.sleep(0.3)
Ejemplo n.º 18
0
def button_E_press(button, pressed):
    global buttonE_was_held
    global E_count
    buttonshim.set_pixel(0xff, 0x00, 0x00)
    buttonE_was_held = False
    E_count = E_count + 1
    if E_count > 2:
        E_count = 0
    print("E_press E_count=", E_count)
Ejemplo n.º 19
0
def button_a(button, pressed):
    global volume

    print("Status: Unmute")
    set("unmute")

    volume = get_volume()
    scale = volume / 100.0

    buttonshim.set_pixel(int(0xff * (1.0 - scale)), int(0xff * scale), 0x00)
Ejemplo n.º 20
0
 def release_handler(button, pressed):
     global button_was_held
     button_name = buttonshim.NAMES[button].lower()
     press_type = "long_" if button_was_held else ""
     if not app.busy:
         button_handler = "handle_{}{}".format(press_type, button_name)
         app.set_busy()
         buttonshim.set_pixel(*app.led)
         getattr(app.state.currentState, button_handler)()
         app.set_idle()
Ejemplo n.º 21
0
 def shutdownNow(self):
     print("Shutdown down now.")
     if self.buttonShimFound: buttonshim.set_pixel(0x00, 0x00, 0x00)
     if self.sense: self.sense.clear()
     if self.sense:
         self.sense.show_letter("S", (0xff, 0x00, 0x00), (0xf, 0xf, 0xf))
     self.shutdownCleanup()
     if self.sense: self.sense.clear()
     call("sudo shutdown now", shell=True)
     # Just incase th call is not executed
     self.shutDownStop()
     return
Ejemplo n.º 22
0
def do(func):
	global last_func
	if(busy()):
		#print("busy: " + func.__name__)
		return
	#print("free: " + func.__name__)
	blink()
	btn.set_pixel(0, 0, 127)
	last_func = func
	func()
	btn.set_pixel(0, 0, 0)
	free()
Ejemplo n.º 23
0
    def hit_pause(self):
        if self.pause:
            self.pause = False
            self.red = 0
            self.green = 0
            self.blue = 0
        else:
            self.pause = True
            self.red = 255
            self.green = 0
            self.blue = 0

        buttonshim.set_pixel(self.red, self.green, self.blue)
Ejemplo n.º 24
0
 def shutdownBody(self):
     print("    " + repr(self.shutdownTimer))
     if self.sense:
         self.sense.show_letter(repr(self.shutdownTimer),
                                (0xff, 0x00, 0x00), (0xf, 0xf, 0xf))
     self.shutdownTimer -= 1
     for count in range(0, 4):
         if self.shutdownTimer < 0:
             return self.shutdownAbort()
         if self.buttonShimFound: buttonshim.set_pixel(0xff, 0x00, 0x00)
         time.sleep(.125)
         if self.buttonShimFound: buttonshim.set_pixel(0x00, 0x00, 0xff)
         time.sleep(.125)
     return
Ejemplo n.º 25
0
def draw():
    for chan, val in enumerate([val for val in CHANS for _ in (0, 1)]):
        switcher = {
            "a": (LED_OFF if chan % 2 == 1 else LED_WHITE),
            "b": (LED_OFF if chan % 2 == 0 else LED_WHITE),
            "d": LED_OFF,
            "m": LED_WHITE,
            "s": LED_RED
        }
        rgb = switcher.get(val, LED_OFF)
        blinkt.set_pixel(chan, rgb[0], rgb[1], rgb[2])
    blinkt.show()
    if RECORDING:
        buttonshim.set_pixel(255, 0, 0)
    else:
        buttonshim.set_pixel(0, 0, 0)
Ejemplo n.º 26
0
def hold_handler(button):
    buttonshim.set_pixel(244, 66, 66)
    time.sleep(.5)
    buttonshim.set_pixel(0, 0, 0)
    time.sleep(.5)
    buttonshim.set_pixel(244, 66, 66)
    time.sleep(.5)
    buttonshim.set_pixel(0, 0, 0)
    subprocess.call('sudo shutdown -h now', shell=True)
Ejemplo n.º 27
0
def button_C(button, pressed):
    buttonshim.set_pixel(0, 0, 255)
    global motion_on
    global stream_on
    global streamurl
    global heightwidth
    if stream_on:
        print("Stream is already running.")
    if motion_on:
        motion_on = False
        subprocess.call('sudo service motion stop', shell=True)
        print("Shutting down Motion service before starting stream.")
    time.sleep(.5)
    print("Starting stream to " + streamurl)
    subprocess.call(
        'ffmpeg -f video4linux2 -s ' + heightwidth +
        ' -framerate 16 -i /dev/video0 -c:v h264_omx -threads 0 -an -ar 0 -f flv "'
        + streamurl + '"')
    buttonshim.set_pixel(0, 0, 0)
Ejemplo n.º 28
0
def release_handler(button, pressed):
    if not button_was_held:
        global instructions
        buttonshim.set_pixel(235, 66, 244)
        print("To start safe shutdown, hold button for 3 seconds.")
        time.sleep(.5)
        buttonshim.set_pixel(0, 0, 0)
        time.sleep(.5)
        buttonshim.set_pixel(188, 244, 66)
        print(instructions)
        time.sleep(1)
        buttonshim.set_pixel(0, 0, 0)
Ejemplo n.º 29
0
def button_d(button, pressed):
    buttonshim.set_pixel(0, 0, 255)
    if pingOk('192.168.195.112'):
        sys.argv = [0, "192.168.195.112"]
        exec(open("/usr/local/bin/status_check/all_pi_stats.py").read())
        buttonshim.set_pixel(0, 200, 0)
        time.sleep(10)
        exec(open("/usr/local/bin/status_check/inky_update.py").read())
    else:
        buttonshim.set_pixel(200, 0, 0)
        time.sleep(2)
    buttonshim.set_pixel(0, 0, 0)
Ejemplo n.º 30
0
 def DisablePiholeTimer(numSecs):
     global pressId
     loopId = pressId
     for i in range(0, numSecs):
         draw.rectangle((0, 0, width, height), outline=0, fill=0)
         # disp.fill(0)
         # disp.show()
         if (loopId != pressId):
             print("Ending loop with ID: " + str(loopId))
             return
         print("Pi-Hole disabled for " + str(numSecs - i))
         draw.text((x, top), "Pi-Hole disabled for:", font=font, fill=255)
         draw.text((x, top + 8), str(numSecs - i), font=font2, fill=255)
         disp.image(image)
         disp.show()
         buttonshim.set_pixel(255, 255, 0)
         time.sleep(0.5)
         buttonshim.set_pixel(255, 150, 0)
         time.sleep(0.5)
     buttonshim.set_pixel(0, 0, 0)
     disp.fill(0)
     disp.show()
     draw.rectangle((0, 0, width, height), outline=0, fill=0)
     draw.text((x, top + 8), "Enabled!", font=font2, fill=255)
     disp.image(image)
     disp.show()
     time.sleep(1)
     disp.fill(0)
     disp.show()
     print("Pi-Hole reenabled")
If you want to control more than one device, press and hold A button to switch between devices.

A="Pause"
B="Play"
C="Stop"
D="Volume Down"
E="Volume Up"

""")
selecteddevice=0
while True:
  if devices==[]:
     print("No Device Online")
  elif not devices==[]:
     if len(devices)==len(chromecasts_name) and len(devices)>1:
        buttonshim.set_pixel(0x94, 0x00, 0xd3)
        @buttonshim.on_hold(buttonshim.BUTTON_A, hold_time=2)
        def button_a(button):
           global selecteddevice
           selecteddevice^=1
           print("Value Changed")
        @buttonshim.on_press(buttonshim.BUTTON_A)
        def button_a(button, pressed):
           cast=pychromecast.Chromecast(chromecasts_ip[selecteddevice])
           mc = cast.media_controller
           cast.wait()
           time.sleep(1)
           mc.pause()
        @buttonshim.on_press(buttonshim.BUTTON_B)
        def button_b(button, pressed):
           cast=pychromecast.Chromecast(chromecasts_ip[selecteddevice])
Ejemplo n.º 32
0
def button_a(button, pressed):
    buttonshim.set_pixel(128, 0, 0)
	blinkt.set_all(128, 0, 0)
Ejemplo n.º 33
0
def button_b(button, pressed):
    buttonshim.set_pixel(0, 128, 0)
	blinkt.set_all(0, 128, 0)
Ejemplo n.º 34
0
def button_c(button, pressed):
	buttonshim.set_pixel(0, 0, 128)
	blinkt.set_all(0, 0, 128)
Ejemplo n.º 35
0
def button_e(button, pressed):
    buttonshim.set_pixel(0xff, 0x00, 0x00)
Ejemplo n.º 36
0
def button_e(button, pressed):
    buttonshim.set_pixel(0xff, 0x00, 0x00)
	os.system("sudo poweroff")