예제 #1
0
    def __init__(self, config, plugin_manager):
        self._pm = plugin_manager
        self._config = config

        # Create directories where pictures are saved
        for savedir in config.gettuple('GENERAL', 'directory', 'path'):
            if osp.isdir(savedir) and config.getboolean('GENERAL', 'debug'):
                shutil.rmtree(savedir)
            if not osp.isdir(savedir):
                os.makedirs(savedir)

        # Prepare the pygame module for use
        os.environ['SDL_VIDEO_CENTERED'] = '1'
        pygame.init()

        # Create window of (width, height)
        init_size = self._config.gettyped('WINDOW', 'size')
        init_debug = self._config.getboolean('GENERAL', 'debug')
        init_color = self._config.gettyped('WINDOW', 'background')
        init_text_color = self._config.gettyped('WINDOW', 'text_color')
        if not isinstance(init_color, (tuple, list)):
            init_color = self._config.getpath('WINDOW', 'background')

        title = 'Pibooth v{}'.format(pibooth.__version__)
        if not isinstance(init_size, str):
            self._window = PtbWindow(title,
                                     init_size,
                                     color=init_color,
                                     text_color=init_text_color,
                                     debug=init_debug)
        else:
            self._window = PtbWindow(title,
                                     color=init_color,
                                     text_color=init_text_color,
                                     debug=init_debug)

        self._menu = None
        self._multipress_timer = PoolingTimer(
            config.getfloat('CONTROLS', 'multi_press_delay'), False)

        # Define states of the application
        self._machine = StateMachine(self._pm, self._config, self,
                                     self._window)
        self._machine.add_state('wait')
        self._machine.add_state('choose')
        self._machine.add_state('chosen')
        self._machine.add_state('preview')
        self._machine.add_state('capture')
        self._machine.add_state('processing')
        self._machine.add_state('filter')
        self._machine.add_state('print')
        self._machine.add_state('finish')

        # ---------------------------------------------------------------------
        # Variables shared with plugins
        # Change them may break plugins compatibility
        self.capture_nbr = None
        self.capture_date = None
        self.capture_choices = (4, 1)
        self.previous_picture = None
        self.previous_animated = None
        self.previous_picture_file = None

        self.count = Counters(self._config.join_path("counters.pickle"),
                              taken=0,
                              printed=0,
                              forgotten=0,
                              remaining_duplicates=self._config.getint(
                                  'PRINTER', 'max_duplicates'))

        self.camera = camera.get_camera(
            config.getint('CAMERA', 'iso'),
            config.gettyped('CAMERA', 'resolution'),
            config.getint('CAMERA', 'rotation'),
            config.getboolean('CAMERA', 'flip'),
            config.getboolean('CAMERA', 'delete_internal_memory'))

        self.buttons = ButtonBoard(
            capture="BOARD" + config.get('CONTROLS', 'picture_btn_pin'),
            printer="BOARD" + config.get('CONTROLS', 'print_btn_pin'),
            hold_time=config.getfloat('CONTROLS', 'debounce_delay'),
            pull_up=True)
        self.buttons.capture.when_held = self._on_button_capture_held
        self.buttons.printer.when_held = self._on_button_printer_held

        self.leds = LEDBoard(
            capture="BOARD" + config.get('CONTROLS', 'picture_led_pin'),
            printer="BOARD" + config.get('CONTROLS', 'print_led_pin'))

        self.printer = Printer(config.get('PRINTER', 'printer_name'),
                               config.getint('PRINTER', 'max_pages'),
                               self.count)
예제 #2
0
#!/usr/bin/env python

print("Loading")

from gpiozero import ButtonBoard, Button
from time import sleep

btns = ButtonBoard(btn1=17, btn2=25, btn3=24, btn4=16)

print("""
Press any button, will print list of all button device values.
Would show device_0=1 if not named in ButtonBoard declaration
""")
while True:
    try:
        btns.wait_for_press()
        print(btns.value)
        sleep(0.3)

    except KeyboardInterrupt:
        print("\rExiting... TODO: print only keyword name")
        btns.close()  #  close each board button
        exit(0)
예제 #3
0
def inoroutchoice(selected_value):
    print('choice')
    global mode
    global mode_old
    global p_out
    global p_in
    if selected_value == "Input - pull-up" or selected_value == "Input - pull-down":
    
        mode = 'input'
        if mode_old == 'output':
            p_out.close()
        elif mode_old == 'input':
            p_in.close()
        mode_old = 'input'
        #p_out.close()
        if selected_value == "Input - pull-up":
            p_in = ButtonBoard(2,3,4,14,15,17,18,27,22,23,24,10,9,11,25,8,7,5,6,12,13,19,16,26,20,21)
            buttons[1].enable()
            buttons[1].bg = 'green'
            buttons[0].enable()
            buttons[0].bg = 'green'
        else:
            p_in = ButtonBoard(4,14,15,17,18,27,22,23,24,10,9,11,25,8,7,5,6,12,13,19,16,26,20,21,pull_up=False)
            buttons[1].disable()
            buttons[1].bg = 'light grey'
            buttons[0].disable()
            buttons[0].bg = 'light grey'
        #p_in = ButtonBoard(b2=2,b3=3,b20=20)
        p_in.when_pressed = pressed
        #p_in.when_released = released
        i=0
        floaters = []
        for p in p_in.value:
            print(p)
            if p == 1:
                floaters.append(i)
                print(i)
                if buttons[i].bg == 'grey':
                    buttons[i].bg = 'green'
                elif buttons[i].bg == 'light grey':
                    buttons[i].bg = 'light grey'
                else:
                    buttons[i].bg = 'grey'
            else:
                if buttons[i].bg == 'light grey':
                    buttons[i].bg = 'light grey'
                else:
                    buttons[i].bg = 'green'
                
            i+=1
        if len(floaters) > 0:
            app.warn("Possible floaters!", "Found " + str(len(floaters)) + " pins that may be floating high")
    elif selected_value == 'Output':
        mode = 'output'
        if mode_old == 'input':
            p_in.close()
        elif mode_old == 'output':
            p_out.close()
        mode_old = 'output'
        
        #p_in.close()
        p_out = LEDBoard(2,3,4,14,15,17,18,27,22,23,24,10,9,25,11,8,7,5,6,12,13,19,16,26,20,21)
        p_out.off()
        for b in buttons:

            if b.bg == 'grey':
                b.bg = 'green'
예제 #4
0
from lcd import LCD_HD44780_I2C
from rgb import Color, RGBButton
from datetime import datetime
from pipelines import Pipelines, QueryResult, QueryResultStatus
from pprint import pprint

import socket

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/martinwoodward/DasDeployer.git"

TITLE = ">>> Das Deployer <<<"

# Define controls
switchLight = LEDBoard(red=4, orange=27, green=13, blue=26, pwm=True)
switch = ButtonBoard(red=6, orange=5, green=25, blue=24, hold_time=5)
toggleLight = LEDBoard(dev=12, stage=20, prod=19)
toggle = ButtonBoard(dev=16, stage=23, prod=22, pull_up=False)
leds = LEDBoard(switchLight, toggleLight)
lcd = LCD_HD44780_I2C()
rgbmatrix = RGBButton()
bigButton = Button(17)

global pipes
global buildNumber
global activeEnvironment
global last_result
pipes = Pipelines()
buildNumber = ""
activeEnvironment = "Dev"
last_result = QueryResult()
예제 #5
0
#!/usr/bin/env python

print("Loading gpiozero")

from gpiozero import LEDBoard, ButtonBoard
from signal import pause

leds = LEDBoard(4, 18, 6, 13)
btns = ButtonBoard(17, 25, 24, 16)

print("Press A button, closest LED will light...")
print("Ctrl-C to exit\n")

while True :
  try:
    leds.source = btns
    pause()
  except KeyboardInterrupt:
    print("\rExiting..")
    exit(0)


예제 #6
0
import configuration
from gpiozero import ButtonBoard, LEDBoard, LED

buttons = ButtonBoard(2, 3, 4)
leds = LEDBoard(14, 15, 18)

blinking_led = LED(10)
blinking_led.blink()

for button, led in zip(buttons, leds):
    led.source = button.values

import gui
예제 #7
0
#!/usr/bin/env python

import board
from busio import I2C
import adafruit_ssd1306
from gpiozero import ButtonBoard
from time import sleep

btns = ButtonBoard(17, 16)

display = adafruit_ssd1306.SSD1306_I2C(128,
                                       32,
                                       I2C(board.SCL, board.SDA),
                                       addr=0x3c)

display.fill(0)
display.show()

x = 64
y = 16
display.pixel(x, y, 1)
display.show()

print(
    "Pixel showing, press button 1 or button 4 to move it.\nCtrl-C to exit...")
try:
    while btns.wait_for_press:
        if btns[0].is_pressed:
            # turning off current pixel
            display.pixel(x, y, 0)
            x = x - 1
#!/usr/bin/env python3

# For '4btn-4led' adafruit perma-proto mini circut.

print("Loading gpiozero")

from gpiozero import LED, ButtonBoard
from time import sleep

led = LED(16)
btns = ButtonBoard(22, 24, 25, 5)


def flashTimes(number):
    x = 0
    print("Button " + str(number) + " pressed.")
    while x < number:
        led.on()
        sleep(0.2)
        led.off()
        sleep(0.2)
        x = x + 1


print("Press any button, LED 4 will light to show button number 1-4...")
print("Ctrl-C to exit\n")

while True:
    try:
        if btns[0].is_pressed:
            flashTimes(1)
예제 #9
0
#Sonic Pi can be running either on the Raspberry Pi,
#or on an external networked computer

#The program requires gpiozero (already in Raspbian) and python-osc to be installed

from gpiozero import ButtonBoard, LED, Button
from pythonosc import osc_message_builder
from pythonosc import udp_client
from pythonosc import dispatcher
from pythonosc import osc_server
from time import sleep
import argparse
import sys

bn = 20  #number of "buttons" in ButtonBoard
b = ButtonBoard(1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 19, 20, 21, 22, 23,
                24, 25)
reset = Button(27)  #dealt with separately from ButtonBoard
flag = False  #used in def pr to separate on/off messages
activate = False  #used to activate sender once it is declared in __init__
current = 0  #used to hold current activated button


def pr():
    global flag, current
    if activate:  #make sure sender has been defined and is active
        if flag == False:
            for i in range(0, bn):  #find which pin triggerd on
                if b.value[i] > 0:
                    print(i, b.value[i])
                    sender.send_message('/playOn', i)  #send OSC message for on
                    flag = True  #switch to looking for "off"
예제 #10
0
 def __init__(self):
     super().__init__() # Initialize base class first
     self.leds = LEDBoard(*LEDS)
     self.buttons = ButtonBoard(*BUTTONS)
     self.state = [0, 0, 0, 0]