teensy-controller 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2026-present wardalll <wardal@student.unimelb.edu.au>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ __version__ = "0.0.1"
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2026-present wardalll <wardal@student.unimelb.edu.au>
2
+ #
3
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,5 @@
1
+ from teensy_controller.teensy_controller import ControllerApp
2
+
3
+ def controller():
4
+ app = ControllerApp()
5
+ app.run()
@@ -0,0 +1,151 @@
1
+ from __future__ import annotations
2
+
3
+ from pickletools import uint8
4
+ from typing import Type
5
+
6
+ from textual import on
7
+ from textual._path import CSSPathType
8
+ from textual.app import App
9
+ from textual.driver import Driver
10
+ from textual.widgets import Button, Input, Label, Static
11
+ import serial
12
+ from textual.containers import Vertical, Horizontal, Grid
13
+ import time
14
+ from textual.events import Key
15
+
16
+
17
+ class ControllerApp(App):
18
+ CSS = """
19
+
20
+ Grid {
21
+ grid-size: 3 3;
22
+ grid-rows: 3;
23
+ grid-columns: 15;
24
+ align: center middle;
25
+ grid-gutter: 1;
26
+ }
27
+
28
+ .control-button {
29
+ content-align: center middle;
30
+ height: 13;
31
+ width: 3;
32
+ }
33
+
34
+ .hidden {
35
+ visibility: hidden;
36
+ }
37
+
38
+ .small-button {
39
+ width: 5;
40
+ min-width: 5;
41
+ height: 3;
42
+ min-height: 3;
43
+ padding: 0;
44
+ content-align: center middle;
45
+ margin-left: 1;
46
+ margin-bottom: 1;
47
+ margin-top: 1;
48
+
49
+ }
50
+
51
+ .small-button:focus {
52
+ text-style: bold; /* no "reverse" */
53
+ }
54
+
55
+ .more-margin {
56
+ margin-bottom: 1;
57
+ margin-top: 1;
58
+ }
59
+
60
+ .controller {
61
+ align: center middle;
62
+ }
63
+ """
64
+
65
+ def __init__(self):
66
+ super().__init__()
67
+ self.bluetooth: serial.Serial | None = None
68
+ self.keyToButton = {
69
+ "w": "up",
70
+ "s": "down",
71
+ "a": "left",
72
+ "d": "right",
73
+ "space": "shoot",
74
+ "q": "quit",
75
+ }
76
+
77
+ def compose(self):
78
+
79
+ yield Button("X", variant="error", classes="small-button", id="quit")
80
+
81
+ # Inputs
82
+ yield Input(placeholder="Type Bluetooth address here")
83
+ yield Label("", id="port_label")
84
+
85
+ # Buttons
86
+ with Grid():
87
+ # row 1
88
+ yield Static(classes="hidden")
89
+ yield Button("Up", variant="primary", id="up", classes="control-button")
90
+ yield Static(classes="hidden")
91
+
92
+ # row 2
93
+ yield Button("Left", variant="primary", id="left", classes="control-button")
94
+ yield Button("Shoot", variant="success", id="shoot", classes="control-button")
95
+ yield Button("Right", variant="primary", id="right", classes="control-button")
96
+
97
+ # row 3
98
+ yield Static(classes="hidden")
99
+ yield Button("Down", variant="primary", id="down", classes="control-button")
100
+ yield Static(classes="hidden")
101
+
102
+ def bluetooth_response(self, key):
103
+ if key == "quit":
104
+ if self.bluetooth is not None and self.bluetooth.is_open:
105
+ self.bluetooth.write(b"0")
106
+ self.bluetooth.flush()
107
+ self.bluetooth.close()
108
+ self.exit()
109
+
110
+ commands = {
111
+ "up": "1",
112
+ "down": "2",
113
+ "left": "3",
114
+ "right": "4",
115
+ "shoot": "5",
116
+ }
117
+ write = commands.get(key)
118
+
119
+ if self.bluetooth is not None and self.bluetooth.is_open and write is not None:
120
+ self.bluetooth.write(write.encode("utf-8"))
121
+
122
+ @on(Input.Submitted)
123
+ def accept_user_input(self):
124
+ input = self.query_one(Input)
125
+ port = input.value
126
+ label = self.query_one("#port_label", Label)
127
+ label.update(port)
128
+ input.value = ""
129
+
130
+ if self.bluetooth is not None and self.bluetooth.is_open:
131
+ self.bluetooth.close()
132
+
133
+ print("Start Bluetooth connection")
134
+ self.bluetooth = serial.Serial(port, 9600, timeout=1)
135
+ print("Connected")
136
+ self.bluetooth.flushInput()
137
+
138
+ def on_key(self, event: Key):
139
+ button_id = self.keyToButton.get(event.key)
140
+ if button_id is not None:
141
+ button = self.query_one("#" + button_id, Button)
142
+ button.press()
143
+ self.bluetooth_response(button_id)
144
+
145
+ def on_button_pressed(self, event):
146
+ self.bluetooth_response(event.button.id)
147
+
148
+
149
+ if __name__ == "__main__":
150
+ app = ControllerApp()
151
+ app.run()
@@ -0,0 +1,44 @@
1
+ Metadata-Version: 2.4
2
+ Name: teensy-controller
3
+ Version: 0.0.1
4
+ Project-URL: Documentation, https://github.com/wardalll/teensy-controller#readme
5
+ Project-URL: Issues, https://github.com/wardalll/teensy-controller/issues
6
+ Project-URL: Source, https://github.com/wardalll/teensy-controller
7
+ Author-email: wardalll <wardal@student.unimelb.edu.au>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.txt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Requires-Python: >=3.8
20
+ Requires-Dist: pyserial==3.5
21
+ Requires-Dist: textual==8.2.8
22
+ Description-Content-Type: text/markdown
23
+
24
+ # teensy-controller
25
+
26
+ [![PyPI - Version](https://img.shields.io/pypi/v/teensy-controller.svg)](https://pypi.org/project/teensy-controller)
27
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/teensy-controller.svg)](https://pypi.org/project/teensy-controller)
28
+
29
+ -----
30
+
31
+ ## Table of Contents
32
+
33
+ - [Installation](#installation)
34
+ - [License](#license)
35
+
36
+ ## Installation
37
+
38
+ ```console
39
+ pip install teensy-controller
40
+ ```
41
+
42
+ ## License
43
+
44
+ `teensy-controller` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,9 @@
1
+ teensy_controller/__about__.py,sha256=2aR6kEO_VJ0SsUbnSbsBH01Cd0hefhBu3iia-03TVi0,135
2
+ teensy_controller/__init__.py,sha256=XpIWm05lizmIj-S4Q6yEBB3c_5Asw5zNGfCFYgArPRk,113
3
+ teensy_controller/entry_points.py,sha256=eJgGta6v5aEG9_Y2Q-j9LQ4X9gHH-f-RLNoPuF3fcl4,120
4
+ teensy_controller/teensy_controller.py,sha256=mYb88Hq3FmcYbeJlacQOxw2cIS5VKrxr5mmLE4dlxtU,3917
5
+ teensy_controller-0.0.1.dist-info/METADATA,sha256=jvXdn_qcZTyOi2CKazs2jrb9kYMjmvndhbMXWsH2oKo,1531
6
+ teensy_controller-0.0.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
7
+ teensy_controller-0.0.1.dist-info/entry_points.txt,sha256=-oe8yJtssYqHJgpxvm6_7Rdk9kNSfriDSwtWvWlE-P8,73
8
+ teensy_controller-0.0.1.dist-info/licenses/LICENSE.txt,sha256=oX1YBVRlpXJu78P8VavCGF4oukoKDzwYrKLFhS0YPOQ,1105
9
+ teensy_controller-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ controller = teensy_controller.entry_points:controller
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present wardalll <wardal@student.unimelb.edu.au>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.