-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update DisplayPad to v1.0.3, add async support, and image handling
Upgraded project version to 1.0.3. Refactored examples and event loop to use asyncio instead of time for improved async handling. Added the Python Imaging Library (PIL) dependency to facilitate setting key images.
- Loading branch information
1 parent
0e6135c
commit 4e93889
Showing
8 changed files
with
81 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
import time | ||
import asyncio | ||
|
||
from displaypad import DisplayPad | ||
|
||
|
||
def main(): | ||
async def main(): | ||
# Create a new DisplayPad instance | ||
pad = DisplayPad.DisplayPad() | ||
|
||
# Define event handlers | ||
@pad.on('down') | ||
def on_key_down(key_index): | ||
print(f"Key {key_index} has been pressed.") | ||
|
||
# Define event handlers | ||
@pad.on('up') | ||
def on_key_down(key_index): | ||
print(f"Key {key_index} has been released.") | ||
|
||
# Define event handlers | ||
@pad.on('error') | ||
def on_error(error): | ||
print(f"Error: {error}") | ||
|
||
# Clear all keys | ||
pad.clear_all_keys() | ||
|
||
# Set the first three keys to red, green and blue | ||
pad.set_key_color(0, 255, 0, 0) | ||
pad.set_key_color(1, 0, 255, 0) | ||
pad.set_key_color(2, 0, 0, 255) | ||
|
||
image = bytearray(pad.ICON_SIZE * pad.ICON_SIZE * 3) | ||
for i in range(pad.ICON_SIZE * pad.ICON_SIZE): | ||
image[i * 3] = 0xff | ||
image[i * 3 + 1] = 0x00 | ||
image[i * 3 + 2] = 0x00 | ||
# Keep the script running | ||
while True: | ||
time.sleep(1) | ||
|
||
await asyncio.sleep(1) | ||
|
||
if __name__ == "__main__": | ||
main() | ||
# Run the main function | ||
asyncio.run(main()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import asyncio | ||
|
||
from displaypad import DisplayPad | ||
|
||
|
||
async def main(): | ||
# Create a new DisplayPad instance | ||
pad = DisplayPad.DisplayPad() | ||
|
||
# Define event handlers | ||
@pad.on('down') | ||
def on_key_down(key_index): | ||
print(f"Key {key_index} has been pressed.") | ||
|
||
# Define event handlers | ||
@pad.on('up') | ||
def on_key_down(key_index): | ||
print(f"Key {key_index} has been released.") | ||
|
||
# Define event handlers | ||
@pad.on('error') | ||
def on_error(error): | ||
print(f"Error: {error}") | ||
|
||
# Clear all keys | ||
pad.clear_all_keys() | ||
|
||
# Set the fourth key to an image | ||
pad.set_key_image(0, pad.get_image_buffer('icons/sl.png')) | ||
|
||
# Keep the script running | ||
while True: | ||
await asyncio.sleep(1) | ||
|
||
if __name__ == "__main__": | ||
# Run the main function | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "DisplayPad" | ||
version = "1.0.2" | ||
version = "1.0.3" | ||
authors = [ | ||
{ name="Sytxlabs", email="[email protected]" }, | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
setup( | ||
name='DisplayPad', | ||
version='1.0.2', | ||
version='1.0.3', | ||
author='Sytxlabs', | ||
author_email='[email protected]', | ||
url='https://sytxlabs.eu', | ||
|
Empty file.