def __init__(self, font):
     self.tft = tft.TFT("SSD1963", "LB04301", tft.LANDSCAPE)
     self.font = font
     self.g_width, height = self.tft.getScreensize()
     self.vert, self.hor, self.nchar, self.firstchar = font.get_properties()
     self.text_rows = height // self.vert  # determine text lines
     self.text_cols = self.g_width // self.hor  # determine tex cols
     self.g_height = self.text_rows * self.vert  # used height for text
     self.unused = height - self.g_height  # unused area at the bottom
     # set scroll area in relation to the font size, full size
     self.tft.setScrollArea(0, self.g_height, self.unused)
     self.tft.setTextStyle(fgcolor=(190, 190, 190),
                           bgcolor=(0, 0, 0),
                           font=self.font)
     self.fgcolor = [255, 255, 255]
     self.bgcolor = [0, 0, 0]
     self.scaling = 0.75
     self.inv = False
     self.underscore = False
     self.scroll_first = 1
     self.scroll_last = self.text_rows
     self.state = 0
     self.tft.printClrSCR()
     self.tft.backlight(100)  # Backlight on
     self.saved_row = self.saved_col = 1
Пример #2
0
def main(v_flip = False, h_flip = False):

    global PIR_flag

## The 9 inch board has X19/X20 swapped. For this board, use the alternative code
    if TFT_SIZE == 9:
        adc = pyb.ADC(pyb.Pin.board.X19)  # read battery voltage (large PCB)
    else:
        adc = pyb.ADC(pyb.Pin.board.X20)  # read battery voltage
    vbus = pyb.Pin('USB_VBUS')
    if vbus.value():
        USBSUPPLY = True
    else:
        USBSUPPLY = False

    usb = pyb.USB_VCP()

    batval = adc.read()
    if (TOOLOWBAT < batval < LOWBAT) and USBSUPPLY == False: # low battery, switch off
        while True: # stay there until reset
            pyb.stop()  # go to sleep. Only the PIR Sensor may wake me up
# Battery OK, or suppy by USB, start TFT.
    if TFT_SIZE == 7:
        mytft = tft.TFT("SSD1963", "AT070TN92", tft.PORTRAIT, v_flip, h_flip)
    elif TFT_SIZE == 4:
        mytft = tft.TFT("SSD1963", "LB04301", tft.LANDSCAPE, v_flip, h_flip)
    elif TFT_SIZE == 9:
        mytft = tft.TFT("SSD1963", "AT090TN10", tft.PORTRAIT, False, True)
    mytft.clrSCR()
    width, height = mytft.getScreensize()
    
    if TFT_SIZE == 9:
## The 9 inch board has X19/X20 swapped. For this board, use the alternative code
        extint = pyb.ExtInt(pyb.Pin.board.X20, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, callback) ## large PCB
    else:
        extint = pyb.ExtInt(pyb.Pin.board.X19, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, callback)
    extint.enable()

    total_cnt = 0

    if TFT_SIZE == 4:
        os.chdir("img_272x480")
    else:
        os.chdir("img_480x800")
    files = os.listdir(".")

    start = COUNTER  # reset timer once
    PIR_flag = False

    while True:
        TESTMODE = usb.isconnected()  # On USB, run test mode
        while True:  # get the next file name, but not banner.bmp
            myrng = pyb.rng()
            name = files[myrng % len(files)]
            if name != BANNER_NAME:
                break

        batval = adc.read()
        if TESTMODE:
            print("Battery: ", batval, ", Files: ", len(files), ", File: ", name, ", RNG: ", myrng)

# test for low battery, switch off, or total count reached
        if (TOOLOWBAT < batval < LOWBAT) and USBSUPPLY == False:
            tft_standby(mytft)
            while True: # stay there until reset
                pyb.stop()

        if (total_cnt % BANNER_COUNTER) == 0:
            displayfile(mytft, BANNER_NAME, width, height)
            mytft.setTextPos(0, 0)
            if LOWBAT <= batval < WARNBAT:
                textcolor = (255,255,0)
            elif TOOLOWBAT < batval < LOWBAT:
                textcolor = (255,0,0)
            else: 
                textcolor = (0,255,0)
            mytft.setTextStyle(textcolor, None, 0, font14)
            mytft.printString("{:.3}V - {} - {}".format(((batval * 3.3 * SCALING) / 4096) + OFFSET, batval, total_cnt))
            pyb.delay(BANNER_TIME)

        total_cnt += 1
        displayfile(mytft, name, width, height)
        pyb.delay(PICT_TIME)

        if PIR_flag == False: ## For one picture activity, check inactivity counter
            start -= 1
            if start <= 0 or total_cnt > TOTAL_COUNTER:  # no activity,  long enough
                if TESTMODE == False:
                    tft_standby(mytft) # switch TFT off and ports inactive
                    pyb.delay(200)
                    pyb.stop()  # go to sleep Only PIR Sensor may wake me up
                    pyb.hard_reset() # will do all the re-init
                else:
                    print("Should switch off here for a second")
                    mytft.clrSCR()
                    mytft.setTextStyle((255,255,255), None, 0, font14)
                    mytft.setTextPos(0, 0)
                    pyb.delay(100)
                    batval = adc.read()
                    mytft.printString("{:.3}V - {}".format(((batval * 3.3 * SCALING) / 4096) + OFFSET, total_cnt))
                    mytft.printNewline()
                    mytft.printCR()
                    mytft.printString("Should switch off here for a second")
                    pyb.delay(3000)
                    if total_cnt > TOTAL_COUNTER:
                        total_cnt = 0
                PIR_flag = False
                start = COUNTER  # reset timer
        else: # activity. restart counter
            PIR_flag = False
            start = COUNTER  # reset timer
def main(v_flip=False, h_flip=False):

    mytft = tft.TFT("SSD1963", "LB04301", tft.LANDSCAPE, v_flip, h_flip)
    width, height = mytft.getScreensize()
    mytft.setXY(0, 0, 479, 815)  # manual clear of the pyhsical frame buffer
    tft.TFT_io.fillSCR_AS(mytft.BGcolorvect, 480 * 816)

    mytft.backlight(100)
    bg_buf = bytearray(dejavu14.bits_horiz * dejavu14.bits_vert *
                       3)  # preallocate the buffer for transparency

    if True:
        drawpixel = mytft.drawPixel
        color = bytearray((0, 255, 0))
        start = pyb.millis()
        for i in range(0, 479):  # filling pixel-by-pixel
            for j in range(0, 271):
                drawpixel(i, j, color)
        time0 = pyb.elapsed_millis(start)
        print('DrawPixels: {} ms'.format(time0))
        pyb.delay(2000)

        start = pyb.millis()
        mytft.fillRectangle(0, 0, 479, 271,
                            bytes(b'\x00\xff\xff'))  # burst fill
        time0 = pyb.elapsed_millis(start)
        print('FillRectangle: {} ms'.format(time0))
        pyb.delay(2000)

    if False:
        mytft.clrSCR()
        font = dejavu10
        mytft.setTextStyle((240, 240, 240), None, 0, font, 0)
        mytft.setTextPos(0, 0, 200, False)
        print(mytft.printString("This text wil be cut after some characters"))
        mytft.drawHLine(0, 20, 200)
        pyb.delay(4000)

    if True:
        mytft.clrSCR()
        mytft.setTextPos(0, height * 0)
        mytft.setTextStyle((255, 0, 0), None, 0, font7hex)
        mytft.printString("This is text on Page 1")

        mytft.setTextPos(0, height * 1)
        mytft.setTextStyle((0, 255, 0), None, 0, font7hex)
        mytft.printString("This is text on Page 2")

        mytft.setTextPos(0, height * 2)
        mytft.setTextStyle((0, 0, 255), None, 0, font7hex)
        mytft.printString("This is text on Page 3")

        for i in range(3):
            mytft.setScrollStart(height * 0)
            pyb.delay(1000)
            mytft.setScrollStart(height * 1)
            pyb.delay(1000)
            mytft.setScrollStart(height * 2)
            pyb.delay(1000)
        mytft.setScrollStart(height * 0)

    if True:
        mytft.clrSCR()
        s = "0123456789"
        font = dejavu10
        mytft.setTextStyle((240, 240, 240), None, 0, font, 1)
        bfa = height % font.bits_vert + font.bits_vert
        vsa = height - bfa
        mytft.setScrollArea(0, vsa, bfa)
        mytft.setTextPos(0, height - font.bits_vert)
        mytft.printString("           This is the non-scrolling area")
        mytft.setTextPos(0, 0)
        for j in range(70):
            mytft.printString("Line {:4} ".format(j))
            for i in range(3):
                mytft.printString(s)
            mytft.printCR()  # No, then CR
            mytft.printNewline()  # NL: advance to the next line
            x, y = mytft.getTextPos()
            mytft.setTextPos(0, height - font.bits_vert)
            mytft.printString("Line {:4} ".format(j))
            mytft.setTextPos(x, y)
        mytft.printString(">")
        pyb.delay(2000)

    if True:
        mytft.clrSCR()
        mytft.setTextPos(0, 0)
        mytft.setTextStyle((255, 255, 255), None, 0, font7hex)
        mytft.printString("0123456789" * 5)
        mytft.setTextPos(0, 20)
        mytft.printString("abcdefghijklmnopqrstuvwxyz" * 2)
        pyb.delay(2000)

        mytft.setTextPos(0, 0)
        mytft.setTextStyle((0, 255, 0), None, KEEP_BG, dejavu14)
        mytft.printString("ABCDE        NOPQRSTUVWXYZ", bg_buf)
        mytft.setTextPos(0, 40)
        mytft.setTextStyle((0, 255, 0), None, 0, dejavu14)
        mytft.printString("abcdefghijklmnopqrstuvwxyz")
        mytft.setTextPos(0, 80)
        mytft.printString("0123456789!\"$%&/()=?")
        pyb.delay(2000)

        mytft.setColor((255, 255, 255))
        mytft.fillClippedRectangle(200, 150, 300, 250, (255, 0, 0))
        mytft.drawClippedRectangle(0, 150, 100, 250, (0, 255, 0))
        pyb.delay(2000)

    if True:
        mytft.clrSCR()
        cnt = 10
        mytft.setTextStyle((255, 255, 255), None, 0, sevensegnumfont)
        while cnt >= 0:
            mytft.setTextPos((width // 2) - 32, (height // 2) - 30)
            mytft.printString("{:2}".format(cnt))
            cnt -= 1
            pyb.delay(1000)

        gc.collect()
        mytft.clrSCR()
        buf = bytearray(5000)
        with open("logo50.raw", "rb") as f:
            n = f.readinto(buf)
        tft.TFT_io.swapbytes(buf, 5000)
        for i in range(10):
            mytft.clrSCR()
            for cnt in range(50):
                x = pyb.rng() % (width - 51)
                y = pyb.rng() % (height - 51)
                mytft.drawBitmap(x, y, 50, 50, buf, 16)
            pyb.delay(1000)

    files = "F0012.bmp", "F0010.raw", "F0013.data", "F0020_1.bmp", "F0020_2.bmp", "F0020_4.bmp", "F0020_8.bmp", "F0020.bmp", "F0013.bmp"

    mytft.setTextStyle((255, 255, 255), None, KEEP_BG | INV_FG, dejavu14)
    while True:
        for name in files:
            #            name = files[pyb.rng() % len(files)]
            displayfile(mytft, name, width, height)
            mytft.setTextPos(180, 230)
            mytft.printString(name, bg_buf)
            pyb.delay(6000)
Пример #4
0
def main(v_flip = False, h_flip = False):

    global PIR_flag

## The 9 inch board has X19/X20 swapped. For this board, use the alternative code
    if TFT_SIZE == 9:
        adc = pyb.ADC(pyb.Pin.board.X19)  # read battery voltage (large PCB)
    else:
        adc = pyb.ADC(pyb.Pin.board.X20)  # read battery voltage
    vbus = pyb.Pin('USB_VBUS')
    if vbus.value():
        USBSUPPLY = True
    else:
        USBSUPPLY = False

    usb = pyb.USB_VCP()

    batval = adc.read()
    if (TOOLOWBAT < batval < LOWBAT) and USBSUPPLY == False: # low battery, switch off
        while True: # stay there until reset
            pyb.stop()  # go to sleep. Only the PIR Sensor may wake me up
# Battery OK, or suppy by USB, start TFT.
    if TFT_SIZE == 7:
        mytft = tft.TFT("SSD1963", "AT070TN92", tft.PORTRAIT, v_flip, h_flip)
    elif TFT_SIZE == 4:
        mytft = tft.TFT("SSD1963", "LB04301", tft.LANDSCAPE, v_flip, h_flip)
    elif TFT_SIZE == 9:
        mytft = tft.TFT("SSD1963", "AT090TN10", tft.PORTRAIT, False, True)
    mytft.clrSCR()
    width, height = mytft.getScreensize()
    
    if TFT_SIZE == 9:
## The 9 inch board has X19/X20 swapped. For this board, use the alternative code
        extint = pyb.ExtInt(pyb.Pin.board.X20, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, callback) ## large PCB
    else:
        extint = pyb.ExtInt(pyb.Pin.board.X19, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, callback)
    extint.enable()

    files, has_banner, shuffle = get_files("/sd/serie", "/sd/zufall")

    start = COUNTER  # reset timer once
    PIR_flag = False

    file_index = 1  # 1: do not start with banner, 0: Start with banner
    while True:
        TESTMODE = usb.isconnected()  # On USB, run test mode
            # on every series start create a random shuffle
        if file_index == 0 and shuffle == True:
            files = list_shuffle(files)
        name = files[file_index]
        file_index = (file_index + 1) % len(files)
## on USB supply assume good battery
        if USBSUPPLY == False:
            batval = adc.read()
        else:
            batval = WARNBAT + 1
        if TESTMODE:
            print("Battery: ", batval, ", Files: ", len(files), ", File: ", name)

## test for low battery, switch off
        if (TOOLOWBAT < batval < LOWBAT) and USBSUPPLY == False:
            tft_standby(mytft)
            while True: # stay there until reset
                pyb.stop()

        if (file_index % BANNER_COUNTER) == 1 and has_banner == True:
            displayfile(mytft, BANNER_NAME, width, height)
            display_batlevel(mytft, batval)
            pyb.delay(BANNER_TIME)

        if displayfile(mytft, name, width, height):
            display_batlevel(mytft, batval)
            pyb.delay(PICT_TIME)

        if PIR_flag == False: ## For one picture activity, check inactivity counter
            start -= 1
            if start <= 0:  # no activity,  long enough
                if TESTMODE == False:
                    tft_standby(mytft) # switch TFT off and ports inactive
                    pyb.delay(200)
                    pyb.stop()  # go to sleep Only PIR Sensor may wake me up
                    pyb.hard_reset() # will do all the re-init
                else:
                    print("Should switch off here for a second")
                    mytft.clrSCR()
                    mytft.setTextStyle((255,255,255), None, 0, font14)
                    mytft.setTextPos(0, 0)
                    pyb.delay(100)
                    batval = adc.read()
                    mytft.printString("{:.3}V - {}".format(((batval * 3.3 * SCALING) / 4096) + OFFSET, file_index))
                    mytft.printNewline()
                    mytft.printCR()
                    mytft.printString("Should switch off here for a second")
                    pyb.delay(3000)
                PIR_flag = False
                start = COUNTER  # reset timer
        else: # activity. restart counter
            PIR_flag = False
            start = COUNTER  # reset timer
def main(v_flip=False, h_flip=False):

    mytft = tft.TFT("SSD1963", "LB04301", tft.LANDSCAPE, v_flip, h_flip)
    # mytft = tft.TFT("SSD1963", "AT070TN92", tft.PORTRAIT, v_flip, h_flip)
    width, height = mytft.getScreensize()
    print(width, height)
    mytft.setXY(0, 0, 479, 815)  # manual clear of the pyhsical frame buffer
    mytft.tft_io.fillSCR(mytft.BGcolorvect, 480 * 816)

    mytft.backlight(100)

    if True:
        drawpixel = mytft.drawPixel
        color = bytearray((0, 255, 0))
        start = time.ticks_ms()
        for i in range(0, 480):  # filling pixel-by-pixel
            mytft.drawVLine(i, 0, 272, color)
            # for j in range (0, 271):
            # drawpixel(i, j, color)
        time0 = time.ticks_ms() - start
        print('DrawPixels: {} ms'.format(time0))
        time.sleep_ms(2000)

        mytft.fillRectangle(0, 0, 479, 799,
                            bytes(b'\x00\x00\x00'))  # burst fill
        start = time.ticks_ms()
        for _ in range(2):
            mytft.clrSCR(b'\xff\xff\xff')
            # mytft.fillRectangle(0, 0, 479, 799, bytes(b'\xff\xff\xff')) # burst fill
            time.sleep_ms(500)
            mytft.clrSCR(b'\x00\x00\x00')
            # mytft.fillRectangle(0, 0, 479, 799, bytes(b'\x00\x00\x00')) # burst fill
            time.sleep_ms(500)
        time0 = time.ticks_ms() - start
        print('FillRectangle: {} ms'.format((time0 - 2000) / 4))
        time.sleep_ms(1000)

    if True:
        mytft.clrSCR()
        font = font10
        mytft.setTextStyle((240, 240, 240), None, 0, font, 0)
        mytft.setTextPos(0, 0, 200, False)
        print(mytft.printString("This text will be cut after some characters"))
        mytft.drawHLine(0, 20, 200)
        time.sleep_ms(4000)

    if False:
        mytft.clrSCR()
        mytft.setTextPos(0, height * 0)
        mytft.setTextStyle((255, 0, 0), None, 0, font7hex)
        mytft.printString("This is text on Page 1")

        mytft.setTextPos(0, height * 1)
        mytft.setTextStyle((0, 255, 0), None, 0, font7hex)
        mytft.printString("This is text on Page 2")

        mytft.setTextPos(0, height * 2)
        mytft.setTextStyle((0, 0, 255), None, 0, font7hex)
        mytft.printString("This is text on Page 3")

        for i in range(3):
            mytft.setScrollStart(height * 0)
            time.sleep_ms(1000)
            mytft.setScrollStart(height * 1)
            time.sleep_ms(1000)
            mytft.setScrollStart(height * 2)
            time.sleep_ms(1000)
        mytft.setScrollStart(height * 0)

    if True:
        mytft.clrSCR()
        s = "0123456789"
        font = font10
        mytft.setTextStyle((240, 240, 240), None, 0, font, 1)
        bfa = height % font.bits_vert + font.bits_vert
        vsa = height - bfa
        mytft.setScrollArea(0, vsa, bfa)
        mytft.setTextPos(0, height - font.bits_vert)
        mytft.printString("           This is the non-scrolling area")
        mytft.setTextPos(0, 0)
        for j in range(70):
            mytft.printString("Line {:4} ".format(j))
            for i in range(3):
                mytft.printString(s)
            mytft.printCR()  # No, then CR
            mytft.printNewline()  # NL: advance to the next line
            x, y = mytft.getTextPos()
            mytft.setTextPos(0, height - font.bits_vert)
            mytft.printString("Line {:4} ".format(j))
            mytft.setTextPos(x, y)
        mytft.printString(">")
        time.sleep_ms(2000)

    if True:
        mytft.clrSCR()
        mytft.setTextPos(0, 0)
        mytft.setTextStyle((255, 255, 255), None, 0, font7hex)
        mytft.printString("0123456789" * 5)
        mytft.setTextPos(0, 20)
        mytft.printString("abcdefghijklmnopqrstuvwxyz" * 2)
        time.sleep_ms(2000)

        mytft.setTextPos(0, 0)
        mytft.setTextStyle((0, 255, 0), None, KEEP_BG, font14)
        mytft.printString("ABCDE        NOPQRSTUVWXYZ")
        mytft.setTextPos(0, 40)
        mytft.setTextStyle((0, 255, 0), None, 0, font14)
        mytft.printString("abcdefghijklmnopqrstuvwxyz")
        mytft.setTextPos(0, 80)
        mytft.printString("0123456789!\"$%&/()=?")
        time.sleep_ms(2000)

        mytft.setColor((255, 255, 255))
        mytft.fillClippedRectangle(200, 150, 300, 250, (255, 0, 0))
        mytft.drawClippedRectangle(0, 150, 100, 250, (0, 255, 0))
        time.sleep_ms(2000)

    if True:
        mytft.clrSCR()
        cnt = 3
        mytft.setTextStyle((255, 255, 255), None, 0, sevensegnumfont)
        while cnt >= 0:
            mytft.setTextPos((width // 2) - 32, (height // 2) - 30)
            mytft.printString("{:2}".format(cnt))
            cnt -= 1
            time.sleep_ms(1000)

        gc.collect()
        mytft.clrSCR()
        buf = bytearray(5000)
        with open("logo50.raw", "rb") as f:
            n = f.readinto(buf)
        mytft.tft_io.swapbytes(buf, 5000)
        for i in range(3):
            mytft.clrSCR()
            for cnt in range(50):
                x = urandom.randint(0, width - 51)
                y = urandom.randint(0, height - 51)
                mytft.drawBitmap(x, y, 50, 50, buf, 16)
            time.sleep_ms(1000)


#    files = "F0012.bmp", "F0010.raw", "F0013.data","F0020_1.bmp", "F0020_2.bmp", "F0020_4.bmp", "F0020_8.bmp", "F0020.bmp", "F0013.bmp"
    files = "F0020_1.bmp", "F0020_2.bmp", "F0020_4.bmp", "F0020_8.bmp", "F0020.bmp"

    mytft.setTextStyle((255, 255, 255), None, DIM_BG, font14)
    while True:
        for name in files:
            # ## name = files[pyb.rng() % len(files)]
            start = time.ticks_ms()
            displayfile(mytft, name, width, height)
            time0 = time.ticks_ms() - start
            print("Display {}: {} ms".format(name, time0))
            mytft.setTextPos(180, 230)
            mytft.printString(name)
            time.sleep_ms(6000)
#
# test for icons

import tft
import checkbox
import radiobutton
import switch
import mdesign

mytft = tft.TFT()
mytft.backlight(100)
mytft.clrSCR((255, 255, 255))

if True:
    for color in range(4):
        mdesign.draw(color * 60 + 20, 20, 0, mytft.drawBitmap, color)
        mdesign.draw(color * 60 + 20, 60, 1, mytft.drawBitmap, color)
        mdesign.draw(color * 60 + 20, 100, 2, mytft.drawBitmap, color)
        mdesign.draw(color * 60 + 20, 140, 3, mytft.drawBitmap, color)

if False:
    mytft.clrSCR((255, 255, 255))

    checkbox.draw(20, 20, 0, mytft.drawBitmap)
    checkbox.draw(20, 60, 1, mytft.drawBitmap)
    checkbox.draw(20, 100, 2, mytft.drawBitmap)

    radiobutton.draw(20, 150, 1, mytft.drawBitmap)
    radiobutton.draw(60, 150, 0, mytft.drawBitmap)
    radiobutton.draw(100, 150, 0, mytft.drawBitmap)