Exemplo n.º 1
0
    def __init__(self, **kwargs):
        # define interface parameters
        self.screen_size = kwargs.get('screen_size', (800, 480))
        self.fill_color = kwargs.get('fill_color', (0, 0, 0))
        self.font_color = kwargs.get('font_color', (255, 255, 255))
        self.font_size = kwargs.get('font_size', 20)
        self.font = kwargs.get('font', "freesansbold.ttf")
        cmd = 'echo %d > /sys/class/backlight/rpi_backlight/brightness' % 64
        os.system(cmd)

        # define interface variables
        self.screen = None
        self.ts = Touchscreen()
        if not pygame.get_init():
            pygame.init()
        pygame.mouse.set_visible(0)
        self.screen = pygame.display.set_mode(self.screen_size)
        for touch in self.ts.touches:
            touch.on_press = self._touch_handler
            touch.on_release = self._touch_handler

        self.ts.run()
        self.screen.fill(self.fill_color)
        self.buttons = []
        self.texts = []
        self.button = []
        self.numpad = ''
Exemplo n.º 2
0
    def get_handler(self):
        """ Get either single or multi touch handler

        :return: event handler
        """
        handler = None
        if self.multi_touch:
            try:
                from ft5406 import Touchscreen
                self.multi_touch_screen = Touchscreen()
                handler = self.handle_multi_touch
            except Exception as e:
                logging.debug("%s", str(e))
        else:
            handler = self.handle_single_touch

        if not handler:
            os._exit(0)
        else:
            return handler
Exemplo n.º 3
0
            stateFile = open(screenState, 'r')
            state = stateFile.readline()
            state = str(state)
            stateFile.close()
            if (state == "lcd"):
                SP.call('echo "hdmi" > /home/pi/swipi-retro/assets/currentDisplayMode', shell=True)
                SP.call(['sudo','/home/pi/swipi-retro/assets/hdmi_out'])
            else :
                SP.call('echo "lcd" > /home/pi/swipi-retro/assets/currentDisplayMode', shell=True)
                SP.call(['sudo','/home/pi/swipi-retro/assets/lcd_out'])


if __name__ == "__main__":
    global shouldRun
    shouldRun = True
    ts = Touchscreen()

    for touch in ts.touches:
        touch.on_press = read_and_emulate_mouse
        touch.on_release = read_and_emulate_mouse
        touch.on_move = read_and_emulate_mouse

    ts.run()

    while shouldRun:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            ts.stop()
            exit()
Exemplo n.º 4
0
import pygame
import time
import os
import math
from pygame.locals import *
from ft5406 import Touchscreen
from gui import widgets, Button, Slider, Dial, render_widgets, touchscreen_event

pygame.init()

size = width, height = 800, 480
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)

pygame.mouse.set_visible(False)

ts = Touchscreen()

for touch in ts.touches:
    touch.on_press = touchscreen_event
    touch.on_release = touchscreen_event
    touch.on_move = touchscreen_event

def button_event(b, e, t):
    print(b.label)

def my_exit(b, e, t):
    global running
    running = False

Dial(
    (0, 100),
Exemplo n.º 5
0
gif_delay = 30  # How much time between frames in the animated gif
restart_delay = 5  # how long to display finished message before beginning a new session
test_server = 'www.google.com'

# full frame of v1 camera is 2592x1944. Wide screen max is 2592,1555
# if you run into resource issues, try smaller, like 1920x1152.
# or increase memory http://picamera.readthedocs.io/en/release-1.12/fov.html#hardware-limits
high_res_w = 2592  # width of high res image, if taken
high_res_h = 1944  # height of high res image, if taken
frame_rate = 15

# time stamp
now = time.strftime("%Y-%m-%d-%H-%M-%S")

# touch screen setup
ts = Touchscreen()

# set up camera

camera = picamera.PiCamera()
camera.vflip = False
camera.hflip = True  # flip for preview, showing users a mirror image
camera.resolution = (high_res_w, high_res_h)
camera.framerate = frame_rate

#############################
### Variables that Change ###
#############################
# Do not change these variables, as the code will change it anyway
transform_x = int(config.monitor_w)  # how wide to scale the jpg when replaying
transfrom_y = int(config.monitor_h)  # how high to scale the jpg when replaying
Exemplo n.º 6
0
import pygame
import time
import os
import math
from pygame.locals import *
from ft5406 import Touchscreen
from gui import widgets, Button, Slider, Dial, render_widgets, touchscreen_event

pygame.init()

size = width, height = 800, 480
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)

pygame.mouse.set_visible(False)

ts = Touchscreen(device="Goodix Capacitive TouchScreen")

for touch in ts.touches:
    touch.on_press = touchscreen_event
    touch.on_release = touchscreen_event
    touch.on_move = touchscreen_event


def button_event(b, e, t):
    print(b.label)


def my_exit(b, e, t):
    global running
    running = False
Exemplo n.º 7
0
class Interface:
    def __init__(self, **kwargs):
        # define interface parameters
        self.screen_size = kwargs.get('screen_size', (800, 480))
        self.fill_color = kwargs.get('fill_color', (0, 0, 0))
        self.font_color = kwargs.get('font_color', (255, 255, 255))
        self.font_size = kwargs.get('font_size', 20)
        self.font = kwargs.get('font', "freesansbold.ttf")
        cmd = 'echo %d > /sys/class/backlight/rpi_backlight/brightness' % 64
        os.system(cmd)

        # define interface variables
        self.screen = None
        self.ts = Touchscreen()
        if not pygame.get_init():
            pygame.init()
        pygame.mouse.set_visible(0)
        self.screen = pygame.display.set_mode(self.screen_size)
        for touch in self.ts.touches:
            touch.on_press = self._touch_handler
            touch.on_release = self._touch_handler

        self.ts.run()
        self.screen.fill(self.fill_color)
        self.buttons = []
        self.texts = []
        self.button = []
        self.numpad = ''

    def _draw_button(self, button, color=None):
        if not color:
            color = button.color
        self.draw(button.name, button.x, button.y, button.w, button.h,
                  button.font_color, button.font_size, color)

    def _numpad_input(self, digit):
        if any(digit):
            self.numpad += digit
        else:
            self.numpad = self.numpad[0:-1]
        self.draw(self.numpad, 500, 0, 300, 100, (255, 255, 255), 40,
                  (0, 0, 0))

    def _touch_handler(self, event, touch):
        if event == TS_PRESS:
            self.button = []
            for button in self.buttons:
                if button.x + button.w > touch.x > button.x and button.y + button.h > touch.y > button.y:
                    self.button = button
                    self._draw_button(button, button.push_color)
                    return
        if event == TS_RELEASE:
            button = self.button
            if button:
                self._draw_button(button)
                button.pressed = True
                if isinstance(button.action, str):
                    exec(button.action)
                else:
                    button.action()

    def add_button(self, **kwargs):
        button = Button(**kwargs)
        self.buttons.append(button)
        self._draw_button(button)
        return button

    def remove_button(self, button):
        self.buttons.remove(button)

    def add_numpad(self):
        for i in range(1, 10):
            self.add_button(name=str(i),
                            x=numpy.mod(i - 1, 3) * 100 + 400,
                            y=numpy.floor((i - 1) / 3) * 100 + 100,
                            action='self._numpad_input("' + str(i) + '")')
        self.add_button(name='0',
                        x=700,
                        y=200,
                        action='self._numpad_input("0")')
        self.add_button(name='<-',
                        x=700,
                        y=300,
                        action='self._numpad_input("")')
        self.add_button(name='.',
                        x=700,
                        y=100,
                        action='self._numpad_input(".")')

    def add_esc(self):
        self.add_button(name='Esc',
                        x=750,
                        y=0,
                        w=50,
                        h=50,
                        action='self.exit()')

    def draw(self,
             text,
             x=0,
             y=0,
             w=800,
             h=480,
             color=(255, 255, 255),
             size=40,
             background=None):
        if background:
            pygame.draw.rect(self.screen, background, (x, y, w, h))
        font = pygame.font.Font(self.font, size)
        lines = []
        txt = ''
        line_width = 0
        nline = 0
        for word in text.split(' '):
            word_surface = font.render(word, True, color)
            word_width, word_height = word_surface.get_size()
            if line_width + word_width >= w:
                lines.append(txt)
                txt = ''
                line_width = 0
            txt += ' ' + word
            line_width += word_width + font.size(' ')[0]
        lines.append(txt)
        offset = (h - word_height * numpy.size(lines)) / 2
        for line in lines:
            nline += 1  # Start on new row.
            text_surf = font.render(line, True, color)
            text_rect = text_surf.get_rect()
            text_rect.center = ((x + (w / 2)), (y + offset + word_height *
                                                (nline - 1) + word_height / 2))
            self.screen.blit(text_surf, text_rect)
        pygame.display.update()

    def cleanup(self):
        self.screen.fill(self.fill_color)
        self.buttons = []
        self.button = []
        self.numpad = ''

    def exit(self):
        try:
            self.ts.stop()
        finally:
            if pygame.get_init():
                pygame.mouse.set_visible(1)
                pygame.quit()
Exemplo n.º 8
0
elif "TFT" in os.environ and os.environ["TFT"] == "2":
    # TFT screen with mouse
    SCREEN=2
    os.environ["SDL_FBDEV"] = "/dev/fb1"
elif "TFT" in os.environ and os.environ["TFT"] == "3":
    # HDMI touchscreen
    SCREEN=3
    os.environ["SDL_FBDEV"] = "/dev/fb0"
    os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
    os.environ["SDL_MOUSEDRV"] = "TSLIB"
elif "TFT" in os.environ and os.environ["TFT"] == "4":
    # Raspberry Pi 7" touchscreen
    SCREEN=4
    from ft5406 import Touchscreen
    os.environ["SDL_FBDEV"] = "/dev/fb0"
    ts = Touchscreen()
else:
    # TFT touchscreen
    SCREEN=1
    os.environ["SDL_FBDEV"] = "/dev/fb1"
    os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
    os.environ["SDL_MOUSEDRV"] = "TSLIB"

# Initialize pygame modules individually (to avoid ALSA errors) and hide mouse
pygame.font.init()
pygame.display.init()
pygame.mouse.set_visible(0)

# Initialise GPIO
GPIO.setwarnings(False)
Exemplo n.º 9
0
elif "TFT" in os.environ and os.environ["TFT"] == "2":
    # TFT screen with mouse
    SCREEN = "2"
    os.environ["SDL_FBDEV"] = "/dev/fb1"
elif "TFT" in os.environ and os.environ["TFT"] == "3":
    # HDMI touchscreen
    SCREEN = "3"
    os.environ["SDL_FBDEV"] = "/dev/fb0"
    os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
    os.environ["SDL_MOUSEDRV"] = "TSLIB"
elif "TFT" in os.environ and os.environ["TFT"] == "4":
    # Raspberry Pi 7" touchscreen
    SCREEN = "4"
    from ft5406 import Touchscreen
    os.environ["SDL_FBDEV"] = "/dev/fb0"
    ts = Touchscreen()
elif "TFT" in os.environ and os.environ["TFT"] == "5":
    # Pimoroni HyperPixel 4.0" touchscreen
    SCREEN = "5"
    from hp4ts import Touchscreen
    os.environ["SDL_FBDEV"] = "/dev/fb0"
    ts = Touchscreen()
else:
    # TFT touchscreen
    SCREEN=1
    os.environ["SDL_FBDEV"] = "/dev/fb1"
    os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
    os.environ["SDL_MOUSEDRV"] = "TSLIB"
if "KPUSER" in os.environ:
    KPUSER=os.environ["KPUSER"]
#####################################################
Exemplo n.º 10
0
    # Get size of screen and create main rendering surface.
    size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
    screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
    # Display splash screen.
    splash = pygame.image.load('freqshow_splash.png')
    screen.fill(MAIN_BG)
    screen.blit(splash, ui.align(splash.get_rect(), (0, 0, size[0], size[1])))
    pygame.display.update()
    splash_start = time.time()
    # Create model and controller.
    fsmodel = model.FreqShowModel(size[0], size[1])
    fscontroller = controller.FreqShowController(fsmodel)
    time.sleep(0.25)
    # Main loop to process events and render current view.

    ts = Touchscreen()

    def touch_handler(event, touch):
        fscontroller.current().click((touch.x, touch.y))

    for touch in ts.touches:
        touch.on_press = touch_handler

    while True:
        # Ignore pygame events
        for event in pygame.event.get():
            pass

        ts.poll()

        # Update and render the current view.