GithubHelp home page GithubHelp logo

py_dream_cheeky's Introduction

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.

py_dream_cheeky's People

Contributors

simon-tang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.