From 7a408a093672020994beac038898ad90986d96c6 Mon Sep 17 00:00:00 2001 From: Ths2-9Y-LqJt6 Date: Tue, 14 Jan 2020 10:28:36 -0800 Subject: [PATCH] Rewrite readme, add both and for systemd and udev rules respectively. --- 60-powermate.rules | 1 + README.md | 73 +++++++++++++++++++++++++++++----------------- cattmate.service | 14 +++++++++ 3 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 60-powermate.rules create mode 100644 cattmate.service diff --git a/60-powermate.rules b/60-powermate.rules new file mode 100644 index 0000000..b1fcd34 --- /dev/null +++ b/60-powermate.rules @@ -0,0 +1 @@ +ACTION=="add", ENV{ID_USB_DRIVER}=="powermate", SYMLINK+="input/powermate", TAG+="uaccess" \ No newline at end of file diff --git a/README.md b/README.md index 218a8bf..4693477 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A WiFi enabled physical volume knob for Chromecasts via a mash up of Griffin's n [PowerMate](https://support.griffintechnology.com/product/powermate/) and the awesome python Chromecast controlling library [catt](https://github.com/skorokithakis/catt/) using the equally awesome [powermate](https://github.com/bethebunny/powermate) - python library. + python library. You can optionally show the volume on a screen. Here's the current demo in an animated gif. Behind the PowerMate is a Chromebook running the Google Home app. When the Cattmate sets the volume you @@ -14,57 +14,76 @@ can kinda make out Google Home reflect the volume change as well: ## Status -This project is very much a work in progress. Don't -use unless you're looking to learn and experiment like am right now ;) - -Currently it seems pretty stable. You have to manually start it though, and I haven't -tested daemonizing it. +This is my first real Python project! That means while the code is super stable +(my desktop version has an uptime of weeks now), I'm guessing not everything follows the +[Pythonic way](https://docs.python-guide.org/writing/style/) just so. ## Hardware * Raspbery Pi - I used a [Raspberry Pi Model 3B Rev 1.2](https://amzn.to/2REZXwb) -* [PowerMate](https://support.griffintechnology.com/product/powermate/) - Hopefully you can [find one used on eBay](https://www.ebay.com/sch/i.html?_nkw=griffin+powermate+usb+-bluetooth) if you don't already have one +* [PowerMate](https://support.griffintechnology.com/product/powermate/) - Hopefully you +can [find one used on eBay](https://www.ebay.com/sch/i.html?_nkw=griffin+powermate+usb+-bluetooth) if +you don't already have one * 0.96" SSD1336 OLED Screen (_optional_) - I use [these from MakerFocus](https://amzn.to/2PKMQqL) * [Chromecast](https://en.wikipedia.org/wiki/Chromecast) - any sort will do, original, audio or ultra +## Use + +Cattmate supports: + +* Increase volume - rotate clockwise +* Decrease volume - rotate counter-clockwise +* Mute - push down - the light will strobe to denote muted status +* Unmute - push down again +* Pause - push down and hold 1+ second +* Play - push down and hold 1+ second again +* Fast Forward - push down and rotate clockwise +* Rewind - push down and rotate counter-clockwise ## Install These steps assume you have your Pi set up with Raspbian, that it's booted up, connected -to the same WiFi as your Chromecast and that the PowerMate is plugged into one of the Pi's -USB ports. If your Chromecast is on a different network, but you can get to it by IP, the -config supports IPs instead of Chromecast names. - -1. Make sure the following requirements are installed: - * [pip3](https://pip.pypa.io/en/stable/installing/) - * [virtualenv](https://virtualenv.pypa.io/en/stable/) (_optional_) -1. Clone this repo `git clone https://github.com/Ths2-9Y-LqJt6/cattmate.git` -1. Change directories to cattmate `cd cattmate` +to the same WiFi as your Chromecast. If your Chromecast is on a different network, but +you can get to it by IP, the +config supports IPs instead of Chromecast names. It also assumes you're using the `pi` +default user with a home directory of `/home/pi` and that you have both +[pip3](https://pip.pypa.io/en/stable/installing/) and optionally +[virtualenv](https://virtualenv.pypa.io/en/stable/) installed: + +1. Clone this repo and cd into it: + `git clone https://github.com/Ths2-9Y-LqJt6/cattmate.git /home/pi/cattmate; cd /home/pi/cattmate` 1. Create your own virtualenv and activate it `python3 -m venv venv;. venv/bin/activate` (_optional_) 1. Install all the python prerequisites with `pip3 install -r requirements.txt` 1. Create your own config file `cp config.dist.py config.dist` and edit `config.dist` with the names or IPs of the chromecasts you want to use (ony first one supported right now ;) and whether you want to use an external I2C screen or not -1. Start the cattmate controller `python3 cattmate.py` +1. Copy the systemd file into place, reload systemd, start and enable it: + ```bash + sudo cp cattmate.service /etc/systemd/system/ + sudo systemctl daemon-reload + sudo systemctl enable cattmate + sudo systemctl start cattmate + ``` +1. Add the ``udev`` rule with ``sudo cp 60-powermate.rules /etc/udev/rules.d/`` and plug your +powermate into an open USB port. +You should be good to go! The system is very resilient in that you can not have screen plugged +in when you start and the plug it in and systemd will notice and start things up. Same +for the powermatte - you can unplug and plug and unplug all day and it satisfyingly just works! -## Use +# Troubleshooting -After getting your hardware and software set up per above, cattmate supports: -* Increase volume - rotate clockwise -* Decrease volume - rotate counter-clockwise -* Mute - push down -* Unmute - push down again -* Pause - push down and hold 1+ second -* Play - push down and hold 1+ second again -* Fast Forward - push down and rotate clockwise -* Rewind - push down and rotate counter-clockwise +You can debug the system in syslog with `sudo tail -f /var/log/syslog`. I try to do a lot +of testing and explicit have `except` errors that expictly tell you what went wrong +and how to fix it. If all else fails, open an issue and I'l try and help ya! ## Releases +* 14 Jan 2020 v0.5 - Rewrite readme, add both `cattmate.service` and `60-powermate.rules` for +systemd and udev rules respectively. * 16 Dec 2019 v0.13 - Complete refactor to use native python driver per [#8](https://github.com/Ths2-9Y-LqJt6/cattmate/issues/8) and add pause, ff & rrwnd per [#10](https://github.com/Ths2-9Y-LqJt6/cattmate/issues/10) diff --git a/cattmate.service b/cattmate.service new file mode 100644 index 0000000..c44a147 --- /dev/null +++ b/cattmate.service @@ -0,0 +1,14 @@ +[Unit] +Description=powermate +After=network.target + +[Service] +Type=simple +User=pi +WorkingDirectory=/home/pi/cattmate +ExecStart=/usr/bin/python3 -u /home/pi/cattmate/cattmate.py +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target \ No newline at end of file