-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathHackyPi_AccessCamera.py
101 lines (84 loc) · 3.14 KB
/
HackyPi_AccessCamera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Basic Program to start camera of device and ongoing operations displayed on TFT
# This code tested for Windows based PC/Laptop but can be modified for Other OS
import time
import os
import usb_hid
import digitalio
import board
import busio
import terminalio
import displayio
from adafruit_display_text import label
from adafruit_hid.keyboard import Keyboard, Keycode
from keyboard_layout_win_uk import KeyboardLayout
from adafruit_st7789 import ST7789
# First set some parameters used for shapes and text
BORDER = 12
FONTSCALE = 3
BACKGROUND_COLOR = 0xFF0000 # red
FOREGROUND_COLOR = 0xFFFF00 # Purple
TEXT_COLOR = 0x0000ff
# Release any resources currently in use for the displays
displayio.release_displays()
tft_clk = board.GP10 # must be a SPI CLK
tft_mosi= board.GP11 # must be a SPI TX
tft_rst = board.GP12
tft_dc = board.GP8
tft_cs = board.GP9
spi = busio.SPI(clock=tft_clk, MOSI=tft_mosi)
# Make the displayio SPI bus and the GC9A01 display
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst)
display = ST7789(display_bus, rotation=270, width=240, height=135, rowstart=40, colstart=53)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = BACKGROUND_COLOR
tft_bl = board.GP13
led = digitalio.DigitalInOut(tft_bl)
led.direction = digitalio.Direction.OUTPUT
led.value=True
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# This function creates colorful rectangular box
def inner_rectangle():
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(display.width - BORDER * 2, display.height - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = FOREGROUND_COLOR
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER)
splash.append(inner_sprite)
#Function to print data on TFT
def print_onTFT(text, x_pos, y_pos):
text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR)
text_group = displayio.Group(scale=FONTSCALE,x=x_pos,y=y_pos,)
text_group.append(text_area) # Subgroup for text scaling
splash.append(text_group)
inner_rectangle()
print_onTFT("Welcome to", 30, 40)
print_onTFT("HackyPi", 60, 80)
time.sleep(3)
try:
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayout(keyboard)
time.sleep(1)
keyboard.send(Keycode.WINDOWS, Keycode.R)
time.sleep(0.3)
keyboard_layout.write('cmd.exe')
keyboard.send(Keycode.ENTER)
keyboard.send(Keycode.F11)
time.sleep(0.3)
inner_rectangle()
print_onTFT("Starting", 40, 40)
print_onTFT("Camera...", 40, 80)
keyboard_layout.write("start microsoft.windows.camera:")
keyboard.send(Keycode.ENTER)
time.sleep(1)
inner_rectangle()
print_onTFT("Camera", 60, 40)
print_onTFT("ON", 90, 80)
keyboard.release_all()
except Exception as ex:
keyboard.release_all()
raise ex