Skip to content

Simon-Tang/py_dream_cheeky

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyDreamCheeky

A simple solution for all your button-mashing projects.

Version 1.0 supports the Big Red Button.

Installation

Requirements

  1. The Big Red Button from Dream Cheeky
  2. The prerequisites for installing pyusb (check the link for pyusb setup instructions)

In the virtual environment for your project:

pip3 install pydreamcheeky

The Python Software Foundation has an excellent guide on installing Python packages inside of virtual environments.

Usage

Each DreamCheekyThread can be used synchronously by reading from an event queue, or asynchronously by providing an event handler function.

Each DreamCheekyEvent has the following read-only attributes:

Attribute Notes
thread The DreamCheekyThread instance that generated the event.
device The usb.core.Device that generated the event.
type The EventType that represents the type of event.

Big Red Button

Event Types

The following event types are generated by DreamCheekyButtonThread:

DreamCheekyEvent Notes
ButtonEventType.BUTTON_PRESS
ButtonEventType.BUTTON_RELEASE
ButtonEventType.BUTTON_CLICK Generated only if total time held is within the thread's hold_duration value, in milliseconds
ButtonEventType.BUTTON_HOLD Generated as soon as the button is held for the thread's hold_duration value, in milliseconds
ButtonEventType.BUTTON_DOUBLE_CLICK
ButtonEventType.LID_OPEN This event will also trigger once at initialization, if the lid is open.
ButtonEventType.LID_CLOSE

Examples

Event Queue

from py_dream_cheeky.button import DreamCheekyButtonThread, ButtonEventType

button_thread = DreamCheekyButtonThread(enqueue_events=True)
button_thread.start()

try:
    event_queue = button_thread.get_event_queue()
    while True:
        event = event_queue.get()
        if event.type == ButtonEventType.LID_OPEN:
            print("Good morning!")
        elif event.type == ButtonEventType.LID_CLOSE:
            print("Good night!")
            break
finally:
    button_thread.stop()

Event Handler

from py_dream_cheeky.button import DreamCheekyButtonThread, ButtonEventType

def handle_button_event(button_event):
    if button_event.type == ButtonEventType.LID_OPEN:
        print("Hello!")
    elif button_event.type in (ButtonEventType.BUTTON_CLICK, ButtonEventType.BUTTON_HOLD):
        print("Click!")
    elif button_event.type == ButtonEventType.LID_CLOSE:
        print("Goodbye!")
        thread.stop()

thread = DreamCheekyButtonThread(event_handler=handle_button_event)

try:
    thread.start()
    thread.join()
except KeyboardInterrupt:
    pass
finally:
    thread.stop()

Troubleshooting

Big Red Button

[Errno 13] Access denied (insufficient permissions)

This error is likely to occur without root permissions:

usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

To give access permissions for the button, create a udev rule. Run the following commands in a terminal (tested on Debian):

sudo sh -c "echo 'SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1d34\", ATTRS{idProduct}==\"000d\", MODE=\"0666\", GROUP=\"plugdev\"' >> /etc/udev/rules.d/99-dream_cheeky.rules"
sudo udevadm control --reload-rules

Then remove and plug in your Big Red Button again.

About

Python drivers for Dream Cheeky peripherals.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages