Exemplo n.º 1
0
def test_st7567_contrast(spidev):
    """Test that set_contrast tries to write over SPI."""
    from gfxhat import lcd, st7567

    lcd.contrast(11)

    spidev.SpiDev().writebytes.assert_has_calls(
        [mock.call([st7567.ST7567_SETCONTRAST, 11])])
Exemplo n.º 2
0
    def turn_off(self):
        self.clear()
        lcd.contrast(0)
        backlight.set_all(0, 0, 0)
        lcd.show()
        backlight.show()


#screen = Screen()
#screen.display("hello", "world")
#screen.turn_off()
Exemplo n.º 3
0
    def display(self, line1, line2):
        lcd.contrast(40)
        backlight.set_all(self.led_brightness, self.led_brightness,
                          self.led_brightness)
        backlight.show()
        self.draw.text((0, 1), line1, 1, self.font)
        self.draw.text((0, 30), 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()
Exemplo n.º 4
0
    def drawVolume(self, volume):
        """Draw box at right hand of screen to represent current volume"""
        self.volImage = Image.new('1', (self.volWidth, self.volHeight))
        self.volDraw = ImageDraw.Draw(self.volImage)
        print("volume = %d" % (volume))
        self.volDraw.polygon([(0, 0), (0, self.volHeight * volume / 100),
                              (self.volWidth, self.volHeight * volume / 100),
                              (self.volWidth, 0)],
                             fill="#ffffff")

        for x in range(self.volWidth):
            for y in range(self.volHeight):
                pixel = self.volImage.getpixel((x, y))
                print(x, y, pixel)
                lcd.set_pixel(self.volXoffset + x, self.volYoffset + y, pixel)
        lcd.contrast(38)
        lcd.show()
Exemplo n.º 5
0
def scan_contrast():
    for c in range(0, 64):
        im = Image.new("1", (128, 64), "black")
        im2 = ImageDraw.Draw(im)

        im2.text((19, 0), "Contrast: ", 1, font=lm)

        position = lm_big.getsize(str(c))
        im2.text((64 - (position[0] / 2), 10), str(c), 1, font=lm_big)
        for x in range(128):
            for y in range(64):
                pixel = im.getpixel((x, y))
                lcd.set_pixel(x, y, pixel)
        lcd.contrast(c)
        lcd.show()
        time.sleep(0.5)
    lcd.clear()
    lcd.show()
Exemplo n.º 6
0
def scan_contrast():
    for c in range(25, 64):
        draw.rectangle((0, 0, width, height), "black")

        message = "Contrast: {:02d}".format(c)

        w, h = font.getsize(message)
        left, top = (width - w) / 2, (height - h) / 2

        draw.text((left, top), message, 1, font=font)

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

        lcd.contrast(c)
        lcd.show()
        time.sleep(0.4)

    lcd.clear()
    lcd.show()
Exemplo n.º 7
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()
Exemplo n.º 8
0
    def drawTime(self):
        """Draw text showing current time on screen"""
        self.image = Image.new('1', (self.timeWidth, self.timeHeight))
        self.draw = ImageDraw.Draw(self.image)

        now = datetime.datetime.now()
        text = now.strftime("%H:%M")

        w, h = self.timeFont.getsize(text)

        #x = (self.timeWidth - w) // 2
        #y = (self.timeHeight - h) // 2
        x = 0
        y = 0

        self.draw.text((x, y), text, 1, self.timeFont)

        for x in range(self.timeWidth):
            for y in range(self.timeHeight):
                pixel = self.image.getpixel((x, y))
                lcd.set_pixel(x, y, pixel)
        lcd.contrast(38)
        lcd.show()
Exemplo n.º 9
0
        position = lm_big.getsize(str(c))
        im2.text((64 - (position[0] / 2), 10), str(c), 1, font=lm_big)
        for x in range(128):
            for y in range(64):
                pixel = im.getpixel((x, y))
                lcd.set_pixel(x, y, pixel)
        lcd.contrast(c)
        lcd.show()
        time.sleep(0.5)
    lcd.clear()
    lcd.show()


try:
    lcd.contrast(0)
    scan_contrast()

    lcd.contrast(0)
    backlight.set_all(255, 255, 255)
    backlight.show()

    scan_contrast()
    lcd.contrast(0)

    backlight.set_all(0, 0, 0)
    backlight.show()
    print("Done!")
except KeyboardInterrupt:
    lcd.contrast(0)
    backlight.set_all(0, 0, 0)
Exemplo n.º 10
0
        if ch == 1:
            self.screens[self.active].current_line -= 1
        if ch == 0:
            self.screens[self.active].current_line += 1


def cleanup():
    backlight.set_all(0, 0, 0)
    backlight.show()
    lcd.clear()
    lcd.show()


atexit.register(cleanup)

lcd.contrast(40)
lcd.rotation(180)

screen_collection = ScreenCollection()

# Create a stat screen
screen_collection.add(StatScreen())

# Create a network screen
screen_collection.add(
    NetworkScreen([
        "eth0", "wg0", "wlan0", "test0", "test1", "test2", "test3", "test4",
        "test5", "test6"
    ],
                  refresh_ticks=30))