Skip to content

Commit 31eb856

Browse files
Merge pull request #2540 from SyedImtiyaz-1/tv
Added Remote Controller
2 parents 54bed26 + 35854e6 commit 31eb856

File tree

17 files changed

+962
-0
lines changed

17 files changed

+962
-0
lines changed

TV-Remote/.github/workflows/main.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Tests
2+
on:
3+
push:
4+
pull_request:
5+
schedule:
6+
- cron: '12 8 * * 1'
7+
8+
jobs:
9+
build:
10+
name: build
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest]
15+
python:
16+
- "3.7"
17+
- "3.8"
18+
- "3.9"
19+
- "3.10"
20+
defaults:
21+
run:
22+
shell: bash
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-python@v2
27+
with:
28+
python-version: ${{ matrix.python }}
29+
30+
- run: python -m pip install -U pip
31+
- run: python -m pip install setuptools wheel twine flake8
32+
33+
- run: python setup.py sdist bdist_wheel
34+
35+
- run: twine check dist/*
36+
- run: flake8
37+
38+
- name: Publish PyPI package
39+
if: startsWith(github.ref, 'refs/tags/v') &&
40+
matrix.os == 'ubuntu-latest' &&
41+
matrix.python == '3.9'
42+
env:
43+
TWINE_USERNAME: __token__
44+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
45+
run: twine upload dist/*

TV-Remote/.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Python binaries
2+
*.py[cod]
3+
4+
# C extensions
5+
*.so
6+
7+
# Packages
8+
.eggs
9+
*.egg
10+
*.egg-info
11+
dist
12+
build
13+
eggs
14+
parts
15+
bin
16+
var
17+
sdist
18+
develop-eggs
19+
.installed.cfg
20+
lib
21+
lib64
22+
__pycache__
23+
MANIFEST
24+
25+
# Installer logs
26+
pip-log.txt
27+
28+
# Unit test / coverage reports
29+
.coverage
30+
.tox
31+
nosetests.xml
32+
htmlcov

TV-Remote/CHANGES.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Changes
2+
-------
3+
4+
v1.0.0
5+
~~~~~~
6+
Date: 28.11.2021
7+
8+
- rename to cecmap
9+
- switch default keybindings for F1 (blue) and F4 (yellow)
10+
- add keycodes for all user control codes defined by CEC
11+
12+
13+
v0.0.5
14+
~~~~~~
15+
Date: 27.11.2021
16+
17+
- fix KeyError if a motion-bound key was already pressed before starting
18+
picec but released afterwards
19+
- set/decrease notification timeout to 3s
20+
- move code to picec.cli submodule
21+
- remove ability to load .py config files
22+
- add ability to load .cfg config files
23+
- add ability to reload config on the fly using SIGUSR1
24+
- add ability to merge config from multiple .cfg files
25+
- document config format
26+
27+
28+
v0.0.4
29+
~~~~~~
30+
Date: 26.11.2021
31+
32+
- fix: TypeError: __init__() missing 1 required positional argument: 'app_name'
33+
- fix: AttributeError: 'dict' object has no attribute 'setup'
34+
- fix: AttributeError: module 'os' has no attribute 'setpgrgp'
35+
36+
37+
v0.0.3
38+
~~~~~~
39+
Date: 25.11.2021
40+
41+
- spawn subprocesses in new process group
42+
(to avoid tearing them down with us when we are stopped)
43+
- execute via ``bash -l`` in .service file to ensure PATH customizations are
44+
available. This may fix an error when autostarting the service, and will
45+
be useful for launching locally installed applications.
46+
- move code to package structure
47+
- use entrypoint for creating the executable
48+
- rename executable from ``picec.py`` to ``picec``
49+
- add command line option to change config
50+
(undocumented so far, and the API will change!)
51+
- load config from ``~/.config/picec/config.py`` if exists
52+
- simplify config
53+
- bind ``matchbox-keyboard`` to red button in mouse mode
54+
- add notification about mode changes using notify2
55+
56+
57+
v0.0.2
58+
~~~~~~
59+
Date: 22.11.2021
60+
61+
- replace xdotool by ``pynput``
62+
- make .service restart on failure
63+
64+
65+
v0.0.1
66+
~~~~~~
67+
Date: 22.11.2021
68+
69+
Initial prototype:
70+
71+
- hard coded keybindings
72+
- for LG TV with magic remote
73+
- "mouse" and "keyboard" mode for controlling the mouse or cursor keys
74+
- based on xdotool
75+
- includes an example .service file

TV-Remote/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include cecmap/config/*.cfg

TV-Remote/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
TV-Controller
2+
======
3+
4+
Install
5+
-------
6+
7+
You can install *TV-Controller* as user or root:
8+
9+
**as user:**
10+
11+
::
12+
13+
pip3 install --user cecmap
14+
15+
Also, make sure to add ``~/.local/bin`` to your PATH.
16+
17+
18+
**as root:**
19+
20+
::
21+
22+
sudo pip3 install cecmap
23+
24+
In order to see notifications when switching modes, it's also necessary to
25+
have a notification daemon installed. I recommend ``xfce4-notifyd``::
26+
27+
sudo apt install xfce4-notifyd
28+
29+
I also recommend installing an onscreen keyboard, e.g.::
30+
31+
sudo apt install matchbox-keyboard
32+
33+
34+
Usage
35+
-----
36+
37+
Launch::
38+
39+
cecmap
40+
41+
# or:
42+
43+
python -m tv
44+
45+
46+
Running as service
47+
------------------
48+
49+
Enable running at startup::
50+
51+
systemctl --user enable tv
52+
53+
Start as service::
54+
55+
systemctl --user start tv
56+
57+
58+
Default keybindings
59+
-------------------
60+
The default keybindings are as follows:
61+
62+
.. list-table::
63+
:header-rows: 1
64+
65+
* - Key
66+
- *Mouse* mode
67+
- *Keyboard* mode
68+
69+
* - 🔵 F1 blue
70+
- switch mode
71+
- switch mode
72+
* - 🔴 F2 red
73+
- launch ``matchbox-keyboard``
74+
- ``<Win>``
75+
* - 🟢 F3 green
76+
- mouse wheel up
77+
- launch kodi
78+
* - 🟡 F4 yellow
79+
- mouse wheel down
80+
- launch ``chromium-browser``
81+
82+
* - ⬆ up
83+
- move cursor up
84+
- ``<up>``
85+
* - ⬇ down
86+
- move cursor down
87+
- ``<down>``
88+
* - ⬅ left
89+
- move cursor left
90+
- ``<left>``
91+
* - ➡ right
92+
- move cursor right
93+
- ``<right>``
94+
95+
* - 🆗 select
96+
- left click
97+
- ``<enter>``
98+
* - ▶ play
99+
- middle click
100+
- ``<media_play_pause>``
101+
102+
* - ⏸ pause
103+
- right click
104+
- ``<media_play_pause>``
105+
* - ↩ exit
106+
- ``<esc>``
107+
- ``<esc>``
108+
109+
110+
Configuration
111+
-------------
112+
113+
*cecmap* uses a simple config format to set keycodes and keybindings. The
114+
config to be used can be specified on the command line using the ``-c
115+
FILE.cfg`` option. The format is as follows:
116+
117+
.. code-block:: cfg
118+
119+
[keycode]
120+
KEY = <NUMBER>
121+
...
122+
123+
[mode.NAME]
124+
KEY = <command> [<args>...]
125+
...
126+
127+
e.g.:
128+
129+
.. code-block:: cfg
130+
131+
[keycode]
132+
left = 123
133+
yellow = 321
134+
...
135+
136+
[mode.Keyboard]
137+
left = key left
138+
yellow = launch kodi
139+
...

TV-Remote/cecmap.service

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=CEC input mappings
3+
4+
[Service]
5+
Type=simple
6+
ExecStart=/bin/bash -lc cecmap
7+
ExecReload=/bin/kill -USR1 $MAINPID
8+
9+
[Install]
10+
WantedBy=default.target

TV-Remote/cecmap/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
3+
# Needed for pynput (!):
4+
os.environ.setdefault('DISPLAY', ':0')
5+
6+
__version__ = '1.0.0'

TV-Remote/cecmap/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from cecmap.cli import main
2+
main()

0 commit comments

Comments
 (0)