|
| 1 | +# ___ ___ _____ _________ ____ __. __ ___. .__ __ |
| 2 | +# / | \ / _ \ \_ ___ \ | |/ _|_/ |_ _____ \_ |__ | | ____ _/ |_ |
| 3 | +# / ~ \ / /_\ \ / \ \/ | < \ __\\__ \ | __ \ | | _/ __ \ \ __\ |
| 4 | +# \ Y // | \\ \____| | \ | | / __ \_ | \_\ \| |__\ ___/ | | |
| 5 | +# \___|_ / \____|__ / \______ /|____|__ \ |__| (____ / |___ /|____/ \___ > |__| |
| 6 | +# \/ \/ \/ \/ \/ \/ \/ |
| 7 | +# |
| 8 | +# Thank you for agreeing to hack on this HACKtablet! |
| 9 | +# I hope you enjoy exploring what you can achieve |
| 10 | +# this touchscreen CircuitPython device. |
| 11 | +# |
| 12 | +# - kmatch |
| 13 | +# |
| 14 | +# Resources |
| 15 | +# --------- |
| 16 | +# Background on the hardware, custom PCB schematic and layout: |
| 17 | +# https://hackaday.io/project/185831-hacktablet-crestron-tss-752-teardown-rebuild |
| 18 | +# |
| 19 | +# Datasheet for the touchscreen display panel: |
| 20 | +# https://cdn.hackaday.io/files/1858317950593504/ET070001DM6_Ver.6_20110520_201801111821.pdf |
| 21 | +# |
| 22 | +# The main github issue on the CircuitPython repository: |
| 23 | +# https://github.com/adafruit/circuitpython/issues/6049 |
| 24 | +# |
| 25 | +# The technical manual for the ESP32-S3, including information about its LCD peripheral: |
| 26 | +# https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf |
| 27 | +# |
| 28 | +# foamyguy's CircuitPython fork (the objective is to get this merged into the CircuitPython main repository) |
| 29 | +# The latest updates could eventually be put somewhere else, but at least this is a start. |
| 30 | +# https://github.com/foamyguy/circuitpython/tree/foamy_tablet |
| 31 | + |
| 32 | + |
| 33 | +import time |
| 34 | +import busio |
| 35 | +import board |
| 36 | +import adafruit_focaltouch |
| 37 | +import displayio |
| 38 | +import dotclockframebuffer |
| 39 | +import framebufferio |
| 40 | +import terminalio |
| 41 | +from rainbowio import colorwheel |
| 42 | +import adafruit_imageload |
| 43 | +from pydos_ui import Pydos_ui |
| 44 | + |
| 45 | + |
| 46 | +#SCL_pin = board.IO41 # set to a pin that you want to use for SCL |
| 47 | +#SDA_pin = board.IO42 # set to a pin that you want to use for SDA |
| 48 | + |
| 49 | +#IRQ_pin = board.IO40 # select a pin to connect to the display's interrupt pin ("IRQ") - not used in this code |
| 50 | + |
| 51 | + |
| 52 | +#i2c = busio.I2C(SCL_pin, SDA_pin) |
| 53 | + |
| 54 | + |
| 55 | +#ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False) |
| 56 | +ft = Pydos_ui.ft |
| 57 | + |
| 58 | +displayio.release_displays() |
| 59 | + |
| 60 | + |
| 61 | +# load the background "HACKtablet" image |
| 62 | + |
| 63 | +hack_bitmap, hack_palette = adafruit_imageload.load("HACKtablet.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) |
| 64 | + |
| 65 | +hack_tilegrid = displayio.TileGrid(hack_bitmap, |
| 66 | + pixel_shader=hack_palette, |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +# setup the display |
| 71 | + |
| 72 | +# create the list of 16 datapins (RGB565) |
| 73 | + |
| 74 | +# initialize the dotclock display. |
| 75 | +# Feel free to tweak these settings and see what |
| 76 | +# happens/ It may cause glitching depending upon what |
| 77 | +# settings you use. |
| 78 | + |
| 79 | +print('Creating DotClockFrameBuffer.') |
| 80 | + |
| 81 | + |
| 82 | +#fb=dotclockdisplay.DotClockFramebuffer( |
| 83 | +# width=800, height=480, |
| 84 | +# hsync=board.IO47, vsync=board.IO48, |
| 85 | +# de=board.IO45, |
| 86 | +# pclock=board.IO21, |
| 87 | +# data_pins=datapin_list, |
| 88 | +# pclock_frequency= 24*1000*1000, # 24000000 # 24 MHz |
| 89 | +# hsync_back_porch = 100, # 100 |
| 90 | +# hsync_front_porch = 40, # 40 |
| 91 | +# hsync_pulse_width = 5, # 5 |
| 92 | +# vsync_back_porch = 25, # 25 |
| 93 | +# vsync_front_porch = 10, # 10 |
| 94 | +# vsync_pulse_width = 1, # 1 |
| 95 | +# pclock_active_neg = 1, # 1 |
| 96 | +# bounce_buffer_size_px = 1000 * 15, # 15000 |
| 97 | +# ) |
| 98 | + |
| 99 | +fb=dotclockframebuffer.DotClockFramebuffer(**board.TFT,**board.TIMINGS800) |
| 100 | + |
| 101 | + |
| 102 | +print('Creating DotClockFrameBuffer Display.') |
| 103 | + |
| 104 | +display=framebufferio.FramebufferDisplay(fb) |
| 105 | +# force_refresh=True, |
| 106 | +# ) |
| 107 | + |
| 108 | +display.root_group = None |
| 109 | +display.refresh() |
| 110 | + |
| 111 | + |
| 112 | +# create the bouncing square |
| 113 | + |
| 114 | +box_size=50 |
| 115 | +corner_box_size=20 |
| 116 | +width=800 |
| 117 | +height=480 |
| 118 | + |
| 119 | +color_count=0 |
| 120 | + |
| 121 | +# Create a bitmap with two colors |
| 122 | +box_bitmap = displayio.Bitmap(box_size, box_size, 2) |
| 123 | +# Create a two color palette |
| 124 | +box_palette = displayio.Palette(2) |
| 125 | +box_palette[0] = 0x000000 |
| 126 | +box_palette[1] = colorwheel(color_count) |
| 127 | + |
| 128 | +box_bitmap.fill(1) |
| 129 | +box_tilegrid = displayio.TileGrid(box_bitmap, pixel_shader=box_palette) |
| 130 | + |
| 131 | +x_velocity = 2 |
| 132 | +y_velocity = 2 |
| 133 | + |
| 134 | + |
| 135 | +# Create a Group to hold the bouncing square |
| 136 | +box_group = displayio.Group() |
| 137 | +box_group.append(box_tilegrid) |
| 138 | + |
| 139 | +box_group.x=10 |
| 140 | +box_group.y=10 |
| 141 | + |
| 142 | +# Create the overall main display group |
| 143 | + |
| 144 | +main_group = displayio.Group() |
| 145 | + |
| 146 | +main_group.append(hack_tilegrid) |
| 147 | +main_group.append(box_group) |
| 148 | + |
| 149 | +display.root_group = main_group |
| 150 | + |
| 151 | +while True: |
| 152 | + |
| 153 | + if ft.touched: |
| 154 | + ts = ft.touches # This touch controller can measure up to 10 points! |
| 155 | + # print(ts) |
| 156 | + if ts != []: # Double check that the touchpoint list isn't empty. |
| 157 | + point = ts[0] # Just use the first touch point |
| 158 | + if point['x'] > 740 and point['y'] < 75: |
| 159 | + display.root_group = displayio.CIRCUITPYTHON_TERMINAL |
| 160 | + break |
| 161 | + # print(point) |
| 162 | + (box_group.x, box_group.y) = (point["x"], point["y"]) |
| 163 | + |
| 164 | + if ((box_group.x + box_size) > width-5) or (box_group.x < 5): |
| 165 | + x_velocity *= -1 |
| 166 | + # print ("changed direction x") |
| 167 | + if ((box_group.y + box_size) > height-5) or (box_group.y < 5): |
| 168 | + y_velocity *= -1 |
| 169 | + # print ("changed direction y") |
| 170 | + |
| 171 | + # update the bouncing box color |
| 172 | + box_palette[1] = colorwheel(color_count) |
| 173 | + color_count += 1 |
| 174 | + |
| 175 | + (box_group.x, box_group.y) = (box_group.x + x_velocity, box_group.y + y_velocity) |
| 176 | + |
| 177 | + time.sleep(0.0001) |
0 commit comments