-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxBoxAndOledTest.py
More file actions
executable file
·80 lines (62 loc) · 1.71 KB
/
xBoxAndOledTest.py
File metadata and controls
executable file
·80 lines (62 loc) · 1.71 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-17 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK
"""
Simple println capabilities.
"""
import os
import time
from demo_opts import get_device
from luma.core.virtual import terminal
from luma.core.render import canvas
from PIL import ImageFont
import xbox
def make_font(name, size):
font_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), 'fonts', name))
return ImageFont.truetype(font_path, size)
def draw_text(x, y, text):
with canvas(device) as draw:
if text:
draw.text((x,y), str(text), font=usedfont, fill=255)
else: draw.point((x,y), fill=255)
def mapXCoordinate(x):
oledXMax = device.width-1
oledXMin=1
xBoxXMax=1
xBoxXMin=-1
return (((x - xBoxXMin) * (oledXMax - oledXMin)) / (xBoxXMax - xBoxXMin)) + oledXMin
def mapYCoordinate(y):
oledYMax=1
oledYMin = device.height-1
xBoxYMax=1
xBoxYMin=-1
return (((y - xBoxYMin) * (oledYMax - oledYMin)) / (xBoxYMax - xBoxYMin)) + oledYMin
def main():
term = terminal(device, usedfont)
term.animate=False
term.println("Connecting to XBOX Controller...")
joy = xbox.Joystick()
term.println("SUCCESS")
while not joy.Back():
text = ""
if joy.A():
text+="A"
if joy.B():
text+="B"
if joy.Y():
text+="Y"
if joy.X():
text+="X"
x, y = joy.leftStick()
draw_text(mapXCoordinate(x), mapYCoordinate(y), text)
joy.close()
if __name__ == "__main__":
try:
usedfont= make_font("tiny.ttf", 6)
device = get_device()
main()
except KeyboardInterrupt:
pass