Esempio n. 1
0
def reply_on_mention(message: Message):
    global Clock
    global Stop
    global Count
    global UwUMode
    global ImagePng
    global Vocal
    if random.randint(1, 100)<15:
         Vocal=True
    Count=50
    Stop=True
    Clock=False
    user_obj: TGUserModel = get_user_from_message(message)
    group: GroupSettings = get_group_from_message(message) if message.chat.type != 'private' else None
    if(group and group.override_settings):  # Use group's settings
        settings: TGUserModel = group.user
    else:
        group = None
        settings = user_obj
    generated_message = generate_markov(fetch_messages(settings, group))
    if (generated_message and not check_duplicated(generated_message, user_obj, group)):
            if UwUMode==True:
               generated_message=generated_message.replace("l", 'w')
               generated_message=generated_message.replace("r", 'w')
            width, height = lcd.dimensions()
            spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
            image = Image.new('1', (width, height),"black")
            image.paste(spritemap,(width-32,33))
            draw = ImageDraw.Draw(image)
            w, h = lcd.dimensions()
            font = ImageFont.truetype("/boot/TriggerBot-master/CCFONT.ttf", 12)
            lines = textwrap.wrap(generated_message, width=16)
            y_text = 0
            for line in lines:
                width, height = font.getsize(line)
                draw.text(((w- width)/4, y_text), line,1, font=font)
                y_text += height
            for x in range(128):
                for y in range(64):
                  pixel = image.getpixel((x, y))
                  lcd.set_pixel(x, y, pixel)
            backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
            backlight.show()
            lcd.show()
            ImagePng=image
            if Vocal==False:
                bot.reply_to(message, generated_message)
            else:
                message.text=generated_message
                audio(message)
            Stop=False
    else:
            Stop=False
    LedOnOff()
Esempio n. 2
0
 def init_screen(self):
     self.screen_width = lcd.dimensions()[0]
     self.screen_height = lcd.dimensions()[1]
     self.font = ImageFont.load_default()
     self.backlight = True
     self.start()
     # draw
     now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     self.initial_list = [
         now, "Hello Johan !", "Hello Nina !", "Go to Nice!"
     ]
     self.draw_object(self.initial_list)
Esempio n. 3
0
def Time():
    global Stop
    global ImagePng
    date=datetime.now()
    if Stop==True:
      return 0
    time = os.popen("date +%R").readline()
    font = ImageFont.truetype(fonts.FredokaOne, 26)
    width, height = lcd.dimensions()
    spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
    image = Image.new('1', (width, height),"black")
    image.paste(spritemap,(width-32,33))
    draw = ImageDraw.Draw(image)
    draw.line([(32,8),(96,8)],fill ="white",width=1)
    draw.line([(32,8),(64,56)],fill ="white",width=1)
    draw.line([(96,8),(64,56)],fill ="white",width=1)
    w, h = font.getsize(time)
    print(w,h)
    draw.text(((width-w+16)/2, 16), time,1, font=font)
    ImagePng=image
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    lcd.show()
    if date.hour>23 or date.hour<11:
      backlight.set_all(50,50,50)
    else:
      backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    backlight.show()
Esempio n. 4
0
def Msg(message: Message):
    global Clock
    global Stop
    global Count
    global ImagePng
    Count=10
    Stop=True
    Clock=False
    msg = message.text
    msg=msg.replace("/msg ", '')
    font = ImageFont.truetype("/boot/TriggerBot-master/CCFONT.ttf", 12)
    width, height = lcd.dimensions()
    spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
    image = Image.new('1', (width, height),"black")
    image.paste(spritemap,(width-32,33))
    draw = ImageDraw.Draw(image)
    lines = textwrap.wrap(msg, width=16)
    y_text = 16
    for line in lines:
        w, h = font.getsize(line)
        draw.text(((width-w)/2, y_text), line,1, font=font)
        y_text += h
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    backlight.show()
    lcd.show()
    ImagePng=image
    bot.reply_to(message, "✔�", parse_mode="Markdown")
    Stop=False
    LedOnOff()
Esempio n. 5
0
def creatImage():
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))

    image = displaySetup(image)

    return image
Esempio n. 6
0
    def __init__(self,
                 app: GfxApp,
                 screen_size: tuple = None,
                 enable_timing=False,
                 enable_reinit=False,
                 fps_limit=0,
                 orientation=ORIENT_DEFAULT,
                 modifiers=MODIFIER_NONE):
        if not screen_size:
            screen_size = lcd.dimensions()
        if orientation == ORIENT_PORTRAIT or orientation == ORIENT_PORTRAIT_INVERT:
            screen_size = (screen_size[1], screen_size[0])

        self._orientation = orientation
        self._modifiers = modifiers

        self._image_size = screen_size
        self._image = Image.new('P', self._image_size)
        self._draw = ImageDraw.Draw(self._image)

        self._last_image = Image.new('P', self._image_size)

        self._app: GfxApp = app

        self._current_timing: RenderPipelineTimings = None
        self._last_timing: RenderPipelineTimings = None

        self._use_reinit = enable_reinit
        self._frame_sleep_time = 0 if fps_limit <= 0 else 1 / fps_limit
        self._enable_timing = enable_timing or (fps_limit > 0)

        self._frame_counter = 0
Esempio n. 7
0
def displayIpOnGFX():
    led_states = [False for _ in range(6)]
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 22)
    text = getMyIp()

    w, h = font.getsize(text)
    x = (width - w) // 2
    y = (height - h) // 2

    draw.text((x, y), text, 1, font)

    backlight.set_all(120, 120, 120)

    backlight.show()

    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)

    lcd.show()
    time.sleep(10)
    #	input('< Hit a key >')
    lcd.clear()
    lcd.show()
    backlight.set_all(0, 0, 0)
    backlight.show()
Esempio n. 8
0
 def __init__(self):
     # led_states = [False for _ in range(6)]
     self.led_brightness = 127
     self.width, self.height = lcd.dimensions()
     self.image = Image.new('P', (self.width, self.height))
     self.draw = ImageDraw.Draw(self.image)
     self.font = ImageFont.truetype(fonts.FredokaOne, 20)
     self.fontLine2 = ImageFont.truetype(fonts.PressStart2P, 10)
     self.line1 = ""
     self.line2 = ""
Esempio n. 9
0
def eraseText(text, lcd, x, y):
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 38)
    w, h = font.getsize(text)
    draw.text((x, y), text, 1, font)
    for x1 in range(x, x + w):
        for y1 in range(y, y + h):
            lcd.set_pixel(x1, y1, 0)
    lcd.show()
Esempio n. 10
0
def displayText(text,lcd,x,y):
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.load_default()
    w, h = font.getsize(text)
    draw.text((x,y), text, 1, font)
    # print("display TEXT in terminal")
    for x1 in range(x,x+w):
        for y1 in range(y,y+h):
            pixel = image.getpixel((x1, y1))
            lcd.set_pixel(x1, y1, pixel)
    lcd.show()
Esempio n. 11
0
def displayText(text, lcd, x, y):
    lcd.clear()
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 24)
    w, h = font.getsize(text)
    draw.text((x, y), text, 1, font)
    for x1 in range(x, x + w):
        for y1 in range(y, y + h):
            pixel = image.getpixel((x1, y1))
            lcd.set_pixel(x1, y1, pixel)
    lcd.show()
Esempio n. 12
0
def displayText(text, x, y):
    from gfxhat import lcd, fonts, backlight
    from PIL import Image, ImageFont, ImageDraw
    lcd.clear()
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.BitbuntuFull, 10)
    w, h = font.getsize(text)
    draw.text((x, y), text, 1, font)
    for x1 in range(x, x + w):
        for y1 in range(y, y + h):
            pixel = image.getpixel((x1, y1))
            lcd.set_pixel(x1, y1, pixel)
    lcd.show()
Esempio n. 13
0
def displayText():
    lcd.clear()
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 24)
    text = "Etch a Sketch"
    w, h = font.getsize(text)
    x = (width - w) // 2
    y = (height - h) // 2
    draw.text((x,y), text, 1, font)
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    lcd.show() 
Esempio n. 14
0
def write(text):
    led_states = [False for _ in range(6)]
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 25)
    #Make sure to set the text variable
    w, h = font.getsize(text)
    x = (width - w) // 2
    y = (height - h) // 2
    draw.text((x, y), text, 1, font)
    ## Plot the pixels
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    #Display the pixels
    lcd.show()
Esempio n. 15
0
    def show(self):
        text= self.information
        width, height = lcd.dimensions()
        image = Image.new('P', (width, height))
        draw = ImageDraw.Draw(image)

        font = ImageFont.load_default()
        w, h = font.getsize(text)

        x = (width - w) // 2
        y = (height - h) // 2

        draw.text((x,y), text, 1, font)
        for x in range(128):
            for y in range(64):
                pixel = image.getpixel((x, y))
                lcd.set_pixel(x, y, pixel)

        lcd.show()
def onPie():
    while True:
        key = getchar()
        lcd.show()
        keys = list(weirdDictionary.keys())
        vals = list(weirdDictionary.values())
        value = vals[keys.index(key)]

        width, height = lcd.dimensions()
        image = Image.new('P', (width, height))
        draw = ImageDraw.Draw(image)
        font = ImageFont.truetype(fonts.AmaticSCBold, 20)
        w, h = font.getsize(value)
        draw.text((1, 1), value, 1, font)
        for x1 in range(1, 1 + w):
            for y1 in range(1, 1 + h):
                pixel = image.getpixel((x1, y1))
                lcd.set_pixel(x1, y1, pixel)
        lcd.show()
def display_character():
    ch = input("Enter a character: ")
    x = int(input("Enter an x coordinate: "))
    y = int(input("Enter a y coordinate: "))
    if ch in myDict:
        lcd.clear()
        width, height = lcd.dimensions()
        image = Image.new('P', (width, height))
        draw = ImageDraw.Draw(image)
        font = ImageFont.truetype(fonts.AmaticSCBold, 12)
        w, h = font.getsize(ch)
        draw.text((x, y), ch, 1, font)
        for x1 in range(x, x + w):
            for y1 in range(y, y + h):
                pixel = image.getpixel((x1, y1))
                lcd.set_pixel(x1, y1, pixel)
        lcd.show()

    else:
        print("Chosen Character not Present in Dictionary")
Esempio n. 18
0
    def clear(self):
        self.width, self.height = lcd.dimensions()
        self.image = Image.new('P', (self.width, self.height))
        self.draw = ImageDraw.Draw(self.image)
        self.font = ImageFont.truetype(fonts.FredokaOne, 20)
        self.fontLine2 = ImageFont.truetype(fonts.PressStart2P, 10)
        self.line1 = ""
        self.line2 = ""
        lcd.contrast(40)
        backlight.set_all(self.led_brightness, self.led_brightness,
                          self.led_brightness)
        backlight.show()
        self.draw.text((0, 1), self.line1, 1, self.font)
        self.draw.text((0, 30), self.line2, 1, self.fontLine2)
        self.w, self.h = self.font.getsize(self.line1)
        self.x = (self.width - self.w) // 2
        self.y = (self.height - self.h) // 2

        for self.x in range(128):
            for self.y in range(64):
                pixel = self.image.getpixel((self.x, self.y))
                lcd.set_pixel(self.x, self.y, pixel)
        lcd.show()
Esempio n. 19
0
    def __init__(self, isDebug=False):
        self.__debug = isDebug

        self.__paint_required = True
        self.__timer = Timer(self.__backlight_timeout, self.__switch_backlight_off)
        self.init_menus()

        width, height = lcd.dimensions()
        self.__lcdWidth = width
        self.__lcdHeight = height
        # A squarer pixel font
        self.__font = ImageFont.truetype(fonts.BitocraFull, 11)

        # A slightly rounded, Ubuntu-inspired version of Bitocra
        #self.__font = ImageFont.truetype(fonts.BitbuntuFull, 10)

        self.__image = Image.new('P', (width, height))

        self.__draw = ImageDraw.Draw(self.__image)
        atexit.register(self.cleanup)
        self.set_backlight(255, 255, 255)
        self.set_menu_options()
        self.init_screen()
Esempio n. 20
0
    def __init__(self, controller, options_dict):
        print("""menu-options.py
        This example shows how you might store a list of menu options associated
        with functions and navigate them on GFX HAT.
        Press Ctrl+C or select "Exit" to exit.
        """)

        self.width, self.height = lcd.dimensions()
        self.font = ImageFont.truetype(fonts.BitbuntuFull, 10)
        self.image = Image.new('P', (self.width, self.height))
        self.draw = ImageDraw.Draw(self.image)
        self.controller = controller
        self.slept = False
        self.sleep_timer = 0
        self.fade = 255
        self.is_playing = controller.get_playing_state()

        for x in range(6):
            touch.set_led(x, 0)
            self.set_backlight()
            touch.on(x, self.handler)

        backlight.show()

        atexit.register(self.cleanup)

        self.menu_options = []

        for key in options_dict:
            self.menu_options.append(
                MenuOption(key, controller.change_station, self.font,
                           (options_dict[key], True, key)))

        self.current_menu_option = 1

        self.trigger_action = False
Esempio n. 21
0
def Ball(message: Message):
    global Clock
    global Stop
    global Count
    global ImagePng
    Count=10
    Stop=True
    Clock=False
    Ball = ["🎱 As I see it, yes 🎱","🎱 It is certain 🎱","🎱 It is decidedly so 🎱","🎱 Most likely 🎱","🎱 Outlook good 🎱","🎱 Signs point to yes 🎱","🎱 Without a doubt 🎱","🎱 Yes,Yes – definitely 🎱","🎱 You may rely on it 🎱","🎱 Reply hazy, try again 🎱","🎱 Ask again later 🎱","🎱 Better not tell you now 🎱","🎱 Cannot predict now 🎱","🎱 Concentrate and ask again 🎱","🎱 Don't count on it 🎱","🎱 My reply is no 🎱","🎱 My sources say no 🎱","🎱 Outlook not so good 🎱","🎱 Very doubtful 🎱"]
    choose=random.choice(Ball)
    font = ImageFont.truetype("/boot/TriggerBot-master/CCFONT.ttf", 12)
    width, height = lcd.dimensions()
    spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
    image = Image.new('1', (width, height),"black")
    image.paste(spritemap,(width-32,33))
    draw = ImageDraw.Draw(image)
    draw.line([(32,8),(96,8)],fill ="white",width=1)
    draw.line([(32,8),(64,56)],fill ="white",width=1)
    draw.line([(96,8),(64,56)],fill ="white",width=1)
    lines = textwrap.wrap(choose, width=16)
    y_text = 16
    for line in lines:
        w, h = font.getsize(line)
        draw.text(((width-w)/2, y_text), line,1, font=font)
        y_text += h
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    backlight.show()
    lcd.show()
    bot.reply_to(message, choose, parse_mode="Markdown")
    ImagePng=image
    Stop=False
    LedOnOff()
Esempio n. 22
0
Micro Pinout! A tiny version of Pinout.xyz.

Ever wondered what your GPIO pins do? What their BCM/WiringPi numbers are?

Use - and + to navigate the header and find out!

To see alt modes, use ^ and v on the left.

Press Ctrl + C to exit.

""")

pinout = yaml.load(open("pinout.yaml").read())
src = Image.open("upinout.png").convert("P")

width, height = lcd.dimensions()

font = ImageFont.truetype(fonts.BitocraFull, 11)

current_pin = 0
current_page = 0
running = True

backlight.set_all(255, 255, 255)
backlight.show()


def handle_input(ch, evt):
    global current_pin, current_page, running

    if evt == 'press':
Esempio n. 23
0
    def __init__(self, cwd):
        if Lcd.__single:
            raise Lcd.__single
        Lcd.__single = self

        # GFX properties
        self.width, self.height = lcd.dimensions()
        self.height -= 1  # TODO figure out why this is needed
        self.num_leds = 6

        # Zone dimensions
        self.zone_height = {0: 12, 1: 8, 2: 2, 3: 13, 4: 2, 5: 13, 6: 2, 7: 12}

        self.footswitch_xy = {0: (0, 0), 1: (51, 0), 2: (101, 0)}

        # Menu (System menu, Parameter edit, etc.)
        self.menu_height = self.height - self.zone_height[
            0] + 1  # TODO figure out why +1
        self.menu_image_height = self.menu_height * 10  # 10 pages (~40 parameters) enough?
        self.menu_image = Image.new('L', (self.width, self.menu_image_height))
        self.menu_draw = ImageDraw.Draw(self.menu_image)
        self.graph_width = 127
        self.menu_y0 = 40

        # Element dimensions
        self.plugin_height = 11
        self.plugin_width = 24
        self.plugin_width_medium = 30
        self.plugin_bypass_thickness = 2
        self.plugin_label_length = 7
        self.footswitch_width = 26

        self.zones = 8
        self.images = [
            Image.new('L',
                      (self.width,
                       self.zone_height[0])),  # Pedalboard / Preset Title bar
            Image.new('L',
                      (self.width, self.zone_height[1])),  # Analog Controllers
            Image.new('L',
                      (self.width, self.zone_height[2])),  # Plugin selection
            Image.new('L', (self.width, self.zone_height[3])),  # Plugins Row 1
            Image.new('L',
                      (self.width, self.zone_height[4])),  # Plugin selection
            Image.new('L', (self.width, self.zone_height[5])),  # Plugins Row 2
            Image.new('L',
                      (self.width, self.zone_height[6])),  # Plugin selection
            Image.new('L', (self.width, self.zone_height[7]))
        ]  # Footswitch Plugins

        self.draw = [
            ImageDraw.Draw(self.images[0]),
            ImageDraw.Draw(self.images[1]),
            ImageDraw.Draw(self.images[2]),
            ImageDraw.Draw(self.images[3]),
            ImageDraw.Draw(self.images[4]),
            ImageDraw.Draw(self.images[5]),
            ImageDraw.Draw(self.images[6]),
            ImageDraw.Draw(self.images[7])
        ]

        # Load fonts
        self.splash_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 18)
        self.title_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 11)
        self.label_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 10)
        self.small_bold_font = ImageFont.truetype("DejaVuSansMono-Bold.ttf", 8)
        #self.small_font = ImageFont.truetype("DejaVuSansMono.ttf", 8)
        self.small_font = ImageFont.truetype(
            os.path.join(cwd, "fonts", "EtBt6001-JO47.ttf"), 6)

        # Splash
        text_im = Image.new('L', (103, 63))
        draw = ImageDraw.Draw(text_im)
        draw.text((7, 20), "pi Stomp!", True, self.splash_font)
        self.splash = Image.new('L', (self.width, self.height))
        self.splash.paste(text_im.rotate(24), (0, 0, 103, 63))
        self.splash_show()

        # Turn on Backlight
        self.enable_backlight()

        self.supports_toolbar = False
Esempio n. 24
0
def main():
    print("""display-temp.py""")

    print('Connecting to {}'.format(SENSORTAG_ADDRESS))
    tag = SensorTag(SENSORTAG_ADDRESS)
    print("Connection successfull!")

    print("Initializing GFX-HAT...")
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)

    for x in range(6):
        touch.set_led(x, 0)
        backlight.set_pixel(x, 255, 255, 255)
        # touch.on(x, handler)

    backlight.set_all(155, 155, 155)
    backlight.show()

    atexit.register(cleanup)

    print("Reporting started every {0} seconds".format(FREQUENCY_SECONDS))
    try:
        while True:
            image.paste(0, (0, 0, width, height))

            readings = get_readings(tag)
            if not readings:
                print("SensorTag disconnected. Reconnecting.")
                reconnect(tag)
                continue

            # print readings
            print("Time:\t{}".format(datetime.datetime.now()))
            print("IR reading:\t\t{}, temperature:\t{}".format(
                readings["ir"], readings["ir_temp"]))
            print("Humidity reading:\t{}, temperature:\t{}".format(
                readings["humidity"], readings["humidity_temp"]))
            print("Barometer reading:\t{}, temperature:\t{}".format(
                readings["pressure"], readings["baro_temp"]))
            print("Luxmeter reading:\t{}".format(readings["light"]))
            fields = [
                datetime.datetime.now(), readings['ir'], readings['ir_temp'],
                readings['humidity'], readings['humidity_temp'],
                readings['pressure'], readings['baro_temp'], readings['light']
            ]
            with open(r'data.csv', 'a') as f:
                writer = csv.writer(f)
                writer.writerow(fields)

            # Drawing IP and Hostname
            # draw.text((2,1), "IP: " + get_ip(), 1, font)
            # draw.text((2,10), "Hostname: " + get_hostname(), 1, font)

            now = datetime.datetime.now()
            current_time = now.strftime("%H:%M:%S")
            draw.text((2, 1), "Time      : " + str(current_time), 1, font)
            draw.text((2, 10), "IR  (temp): " + str(readings["ir_temp"]) + "C",
                      1, font)
            draw.text((2, 20),
                      "Hum (temp): " + str(readings["humidity_temp"]) + "C", 1,
                      font)
            draw.text((2, 30),
                      "Bar (temp): " + str(readings["baro_temp"]) + "C", 1,
                      font)
            draw.text((2, 40), "Luxometer : " + str(readings["light"]) + "lux",
                      1, font)
            draw.text((2, 50), "IP: " + get_ip(), 1, font)

            mean_temp = float(readings['ir_temp']) + float(
                readings['humidity_temp']) + float(readings['baro_temp'])
            mean_temp /= 3.0
            if mean_temp > 28.0:
                backlight.set_all(155, 0, 0)
            elif mean_temp > 27.0:
                backlight.set_all(155, 75, 75)
            elif mean_temp < 24.0:
                backlight.set_all(100, 100, 155)
            elif mean_temp < 23.0:
                backlight.set_all(50, 50, 155)
            elif mean_temp < 22.0:
                backlight.set_all(0, 0, 155)
            else:
                backlight.set_all(155, 155, 155)
            backlight.show()

            for x in range(width):
                for y in range(height):
                    pixel = image.getpixel((x, y))
                    lcd.set_pixel(x, y, pixel)

            lcd.show()
            # time.sleep(1.0 / 30)
            time.sleep(FREQUENCY_SECONDS)

    except KeyboardInterrupt:
        cleanup()
Esempio n. 25
0
PIPETIME_COMPLETE = 10

ORIENT_LANDSCAPE = 0b00
ORIENT_PORTRAIT = 0b10

ORIENT_INVERT = 0b01
ORIENT_LANDSCAPE_INVERT = ORIENT_LANDSCAPE | ORIENT_INVERT
ORIENT_PORTRAIT_INVERT = ORIENT_PORTRAIT | ORIENT_INVERT

ORIENT_DEFAULT = ORIENT_LANDSCAPE

MODIFIER_NONE = 0b0
MODIFIER_COLOR_INVERTED = 0b1
MODIFIER_DRAW_IN_DIFF_MODE = 0b10

LCD_SIZE = lcd.dimensions()

PT = ([0] + ([255] * 255))


def is_portrait(orient: int) -> bool:
    return not (not orient & ORIENT_PORTRAIT)


def is_landscape(orient: int) -> bool:
    return not (not orient & ORIENT_LANDSCAPE)


def is_inverted(orient: int) -> bool:
    return not (not orient & ORIENT_INVERT)
Esempio n. 26
0
def test_st7567_dimensions(spidev):
    """Test that lcd.dimensions returns the constants defined in st7567."""
    from gfxhat import lcd, st7567

    assert lcd.dimensions() == (st7567.WIDTH, st7567.HEIGHT)
Esempio n. 27
0
def clear():
    lcd.clear()
    lcd.show()


def render(SCR, SIZ):
    for x in range(SIZ[0]):
        for y in range(SIZ[1]):
            lcd.set_pixel(x, y, SCR.getpixel((x, y)))

        lcd.show()


clear()

SIZ = lcd.dimensions()

SCR = Image.new('P', SIZ)
SCD = ImageDraw.Draw(SCR)
SCD.line((0, 0, SIZ[0] - 1, SIZ[1] - 1), fill=True)
SCD.line((SIZ[0] - 1, 0, 0, SIZ[1] - 1), fill=True)
render(SCR, SIZ)

IMG: Image.Image = Image.open("res/seat64.png")
for x in range(IMG.size[0]):
    for y in range(IMG.size[1]):
        p = IMG.getpixel((x, y))
        if p[3] > 128:
            SCD.point((x + 32, y), fill=True)

#SCR.paste(IMG.convert('P').copy(), (32, 0))
Esempio n. 28
0
from __future__ import division
import random
import time
from gfxhat import lcd, backlight, touch, fonts
from PIL import Image, ImageDraw, ImageFont

WIDTH, HEIGHT = lcd.dimensions()
BALL_RAD = 1
PAD_WIDTH = 2
PAD_HEIGHT = 12
HALF_PAD_WIDTH = PAD_WIDTH // 2
HALF_PAD_HEIGHT = PAD_HEIGHT // 2

ball_pos = [0, 0]
ball_vel = [0, 0]
paddle1_vel = 0
paddle2_vel = 0
l_score = 0
r_score = 0

font = ImageFont.truetype(fonts.BitocraFull, 11)

started = False
winner = 0
winning_score = 2
won = False


def ball_init(right):
    global ball_pos, ball_vel
    ball_pos = [WIDTH // 2, HEIGHT // 2]
Esempio n. 29
0
# Seyfullah Burul 040963942
# Last Modified: November 27, 2020
# Reading CSV file and displaying each line of the file as a Python list.

# Importing necessary libraries
from gfxhat import fonts, lcd, backlight
from os import system
from click import getchar

# Getting screen dimensions
scrWidth, scrHeight = lcd.dimensions()


# Screen back-lighting function
def setBacklight(light):
    if (light):
        backlight.set_all(0, 255, 0)
    else:
        backlight.set_all(0, 0, 0)
    backlight.show()


# Clear screen function
def clearScreen(lcd):
    lcd.clear()
    lcd.show()


# The function displays an object on the screen
def displayObject(obj, x, y, ignoreOutOfRangeError=True):
    if ignoreOutOfRangeError: