浏览代码

Initial remote control

master
Dirk Alders 2 年前
父节点
当前提交
afc1509050

+ 2
- 0
.gitignore 查看文件

@@ -1,3 +1,5 @@
1
+config.py
2
+
1 3
 # ---> Linux
2 4
 *~
3 5
 

+ 3
- 0
.gitmodules 查看文件

@@ -0,0 +1,3 @@
1
+[submodule "report"]
2
+	path = report
3
+	url = https://git.mount-mockery.de/pylib/report.git

+ 41
- 0
__install__.py 查看文件

@@ -0,0 +1,41 @@
1
+#!/bin/python
2
+#
3
+import os
4
+import sys
5
+
6
+SERVICE_FILE = """
7
+[Unit]
8
+Description=Smarthome IR Remote Control
9
+After=network-online.target
10
+Wants=network-online.target
11
+[Service]
12
+User=%(UID)d
13
+Group=%(GID)d
14
+ExecStart=%(MY_PATH)s/remote_control.sh
15
+Type=simple
16
+[Install]
17
+WantedBy=default.target
18
+"""
19
+
20
+
21
+def help():
22
+    print("Usage: prog <UID> <GID> <TARGET_PATH>")
23
+
24
+if __name__ == "__main__":
25
+    if len(sys.argv) == 4:
26
+        try:
27
+            uid = int(sys.argv[1])
28
+            gid = int(sys.argv[2])
29
+        except ValueError:
30
+            help()
31
+        else:
32
+            if os.path.isdir(sys.argv[3]):
33
+                with open(os.path.join(sys.argv[3], 'remote_control.service'), "w") as fh:
34
+                    fh.write(SERVICE_FILE % {
35
+                        "MY_PATH": os.path.dirname(os.path.abspath(__file__)),
36
+                        "UID": uid,
37
+                        "GID": gid})
38
+            else:
39
+                help()
40
+    else:
41
+        help()

+ 31
- 0
config_example/config.py 查看文件

@@ -0,0 +1,31 @@
1
+#!/usr/bin/env python
2
+# -*- coding: UTF-8 -*-
3
+import os
4
+import report
5
+
6
+from remotes import yamaha_ras5 as amplifier
7
+from remotes import technics_eur642100 as cd_player
8
+
9
+__BASEPATH__ = os.path.abspath(os.path.dirname(__file__))
10
+
11
+MQTT_USER = "mqtt_username"
12
+MQTT_PASS = "mqtt_password"
13
+MQTT_SERVER = "mqtt_server"
14
+MQTT_TOPIC = "mqtt_topic"
15
+
16
+SUPPORTED_REMOTES = {
17
+    amplifier.NAME: amplifier.ALL,
18
+    cd_player.NAME: cd_player.ALL
19
+}
20
+
21
+#
22
+# Logging
23
+#
24
+APP_NAME = "remote_control"
25
+LOGTARGET = 'stdout'   # possible choices are: 'logfile' or 'stdout'
26
+LOGLVL = 'DEBUG'
27
+
28
+LOGHOST = 'cutelog'
29
+LOGPORT = 19996
30
+
31
+formatter = report.SHORT_FMT

+ 70
- 0
lirc/Technics-EUR642100.lircd.conf 查看文件

@@ -0,0 +1,70 @@
1
+#
2
+# This is a space encoded remote control from Technics
3
+#
4
+# lots of the codes are identical to the EUR643900 file.
5
+# Probably this remote control does work with this file too
6
+# (the power button is missing here). Major differences
7
+# in the header are: eps, aeps, gap.
8
+#
9
+# contributed by Simon Budig <Simon.Budig@unix-ag.org>
10
+#
11
+# brand:             Technics
12
+# model:             EUR642100 (probably EUR643900 too)
13
+# supported devices: SL-PG440A
14
+#
15
+
16
+begin remote
17
+
18
+  name  EUR642100
19
+  bits           16
20
+  flags SPACE_ENC
21
+  eps            30
22
+  aeps          100
23
+
24
+  header       3578  1674
25
+  one           503   368
26
+  zero          503  1238
27
+  ptrail        503
28
+  pre_data_bits   32
29
+  pre_data       0xBFFBFAAF
30
+  gap          74826
31
+  repeat_bit      0
32
+
33
+      begin codes
34
+          OPEN_CLOSE               0x0000000000007F2A
35
+          VOLDOWN                  0x0000000000007B2E
36
+          VOLUP                    0x000000000000FBAE
37
+          ONE                      0x000000000000F7A2
38
+          TWO                      0x0000000000007722
39
+          THREE                    0x000000000000B7E2
40
+          FOUR                     0x0000000000003762
41
+          FIVE                     0x000000000000D782
42
+          SIX                      0x0000000000005702
43
+          SEVEN                    0x00000000000097C2
44
+          EIGHT                    0x0000000000001742
45
+          NINE                     0x000000000000E7B2
46
+          ZERO                     0x0000000000006732
47
+          TEN                      0x0000000000005E0B
48
+          TEN_PLUS                 0x000000000000DE8B
49
+          PROGRAM                  0x000000000000AEFB
50
+          CLEAR                    0x000000000000FEAB
51
+          RECALL                   0x0000000000007E2B
52
+          TIME_MODE                0x0000000000005500
53
+          A_B_REPEAT               0x000000000000EDB8
54
+          REPEAT                   0x0000000000001D48
55
+          RANDOM                   0x0000000000004D18
56
+          AUTO_CUE                 0x0000000000002E7B
57
+          TAPE_LENGTH              0x0000000000002A7F
58
+          SIDE_A_B                 0x000000000000CA9F
59
+          TIME_FADE                0x000000000000D683
60
+          PEAK_SEARCH              0x0000000000000E5B
61
+          SEARCH_BACK              0x000000000000BFEA
62
+          SEARCH_FOR               0x0000000000003F6A
63
+          TRACK_NEXT               0x000000000000ADF8
64
+          TRACK_PREV               0x0000000000006D38
65
+          STOP                     0x000000000000FFAA
66
+          PAUSE                    0x0000000000009FCA
67
+          PLAY                     0x000000000000AFFA
68
+      end codes
69
+
70
+end remote

+ 54
- 0
lirc/Yamaha-RAS5.lircd.conf 查看文件

@@ -0,0 +1,54 @@
1
+
2
+# Please take the time to finish this file as described in
3
+# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
4
+# and make it available to others by sending it to
5
+# <lirc@bartelmus.de>
6
+#
7
+# This config file was automatically generated
8
+# using lirc-0.10.1(default) on Sat Sep  3 23:03:52 2022
9
+# Command line used: --disable-namespace yamaha_ras5.conf
10
+# Kernel version (uname -r): 5.15.61-v7+
11
+#
12
+# Remote name (as of config file): Yamaha-RAS5
13
+# Brand of remote device, the thing you hold in your hand:
14
+# Remote device model nr:
15
+# Remote device info url:
16
+# Does remote device has a bundled capture device e. g., a
17
+#     usb dongle? :
18
+# For bundled USB devices: usb vendor id, product id
19
+#     and device string (use dmesg or lsusb):
20
+# Type of device controlled
21
+#     (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :
22
+# Device(s) controlled by this remote:
23
+
24
+begin remote
25
+
26
+  name  RAS5
27
+  bits           32
28
+  flags SPACE_ENC|CONST_LENGTH
29
+  eps            30
30
+  aeps          100
31
+
32
+  header       8921  4481
33
+  one           536  1698
34
+  zero          536   578
35
+  ptrail        539
36
+  repeat       8923  2258
37
+  gap          107243
38
+  toggle_bit_mask 0x0
39
+  frequency    38000
40
+
41
+      begin codes
42
+          POWER                    0x7E81542B 0x00000000
43
+          PHONO                    0x5EA12857 0x00000000
44
+          DOCK                     0xFE80522D 0x00000000
45
+          CD                       0x5EA1A8D7 0x00000000
46
+          LINE1                    0x5EA183FC 0x00000000
47
+          LINE2                    0x5EA11867 0x00000000
48
+          LINE3                    0x5EA198E7 0x00000000
49
+          MUTE                     0x5EA13847 0x00000000
50
+          VOLUP                    0x5EA15827 0x00000000
51
+          VOLDOWN                  0x5EA1D8A7 0x00000000
52
+      end codes
53
+
54
+end remote

+ 60
- 0
remote_control.py 查看文件

@@ -0,0 +1,60 @@
1
+import config
2
+import json
3
+import lirc
4
+import logging
5
+import paho.mqtt.client as mqtt
6
+import report
7
+import socket
8
+import time
9
+
10
+try:
11
+    from config import APP_NAME as ROOT_LOGGER_NAME
12
+except ImportError:
13
+    ROOT_LOGGER_NAME = 'root'
14
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
15
+
16
+
17
+class remote_control(object):
18
+    def __init__(self):
19
+        self.__lirc_client__ = lirc.Client()
20
+
21
+        self.__client__ = mqtt.Client(config.APP_NAME)                          # create client object
22
+        self.__client__.on_message = self.__receive__                           # attach function to callback
23
+        self.__client__.username_pw_set(config.MQTT_USER, config.MQTT_PASS)     # login with credentials
24
+        try:
25
+            self.__client__.connect(config.MQTT_SERVER, 1883)                       # establish connection
26
+            self.__client__.loop_start()                                            # start the loop
27
+            for remote in config.SUPPORTED_REMOTES:
28
+                for command in config.SUPPORTED_REMOTES[remote]:
29
+                    topic = config.MQTT_TOPIC + "/" + remote + "/" + command
30
+                    logger.debug("Subscribing \"%s\"", topic)
31
+                    self.__client__.subscribe(topic)                                # subscibe a topic
32
+        except (socket.timeout, OSError) as e:
33
+            logger.warning("Erro while setting up mqtt instance and listener")
34
+
35
+    def __receive__(self, client, userdata, message):
36
+        try:
37
+            payload = json.loads(message.payload)
38
+        except json.decoder.JSONDecodeError:
39
+            payload = None
40
+        if payload is None:
41
+            remote = message.topic.split("/")[-2]
42
+            command = message.topic.split("/")[-1]
43
+            try:
44
+                self.__lirc_client__.send_once(remote, command)
45
+            except TimeoutError:
46
+                logger.exception("Timeout-Error while sending IR-Command.")
47
+            logger.info("Sending once: %s to %s.", command, remote)
48
+        elif payload is True:
49
+            logger.warning("Start of remote command NYI!")
50
+        elif payload is False:
51
+            logger.warning("Stop of remote command NYI!")
52
+
53
+
54
+if __name__ == '__main__': 
55
+    report.appLoggingConfigure(config.__BASEPATH__, config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
56
+    #
57
+    rc = remote_control()
58
+    #
59
+    while (True):
60
+        time.sleep(30)

+ 4
- 0
remote_control.sh 查看文件

@@ -0,0 +1,4 @@
1
+#!/bin/sh
2
+#
3
+BASEPATH=`dirname $0`
4
+$BASEPATH/venv/bin/python $BASEPATH/remote_control.py

+ 0
- 0
remotes/__init__.py 查看文件


+ 73
- 0
remotes/technics_eur642100.py 查看文件

@@ -0,0 +1,73 @@
1
+NAME = "EUR642100"
2
+#
3
+OPEN_CLOSE = "OPEN_CLOSE"
4
+VOLDOWN = "VOLDOWN"
5
+VOLUP = "VOLUP"
6
+ONE = "ONE"
7
+TWO = "TWO"
8
+THREE = "THREE"
9
+FOUR = "FOUR"
10
+FIVE = "FIVE"
11
+SIX = "SIX"
12
+SEVEN = "SEVEN"
13
+EIGHT = "EIGHT"
14
+NINE = "NINE"
15
+ZERO = "ZERO"
16
+TEN = "TEN"
17
+TEN_PLUS = "TEN_PLUS"
18
+PROGRAM = "PROGRAM"
19
+CLEAR = "CLEAR"
20
+RECALL = "RECALL"
21
+TIME_MODE = "TIME_MODE"
22
+A_B_REPEAT = "A_B_REPEAT"
23
+REPEAT = "REPEAT"
24
+RANDOM = "RANDOM"
25
+AUTO_CUE = "AUTO_CUE"
26
+TAPE_LENGTH = "TAPE_LENGTH"
27
+SIDE_A_B = "SIDE_A_B"
28
+TIME_FADE = "TIME_FADE"
29
+PEAK_SEARCH = "PEAK_SEARCH"
30
+SEARCH_BACK = "SEARCH_BACK"
31
+SEARCH_FOR = "SEARCH_FOR"
32
+TRACK_NEXT = "TRACK_NEXT"
33
+TRACK_PREV = "TRACK_PREV"
34
+STOP = "STOP"
35
+PAUSE = "PAUSE"
36
+PLAY = "PLAY"
37
+#
38
+ALL = [
39
+    OPEN_CLOSE,
40
+    VOLDOWN,
41
+    VOLUP,
42
+    ONE,
43
+    TWO,
44
+    THREE,
45
+    FOUR,
46
+    FIVE,
47
+    SIX,
48
+    SEVEN,
49
+    EIGHT,
50
+    NINE,
51
+    ZERO,
52
+    TEN,
53
+    TEN_PLUS,
54
+    PROGRAM,
55
+    CLEAR,
56
+    RECALL,
57
+    TIME_MODE,
58
+    A_B_REPEAT,
59
+    REPEAT,
60
+    RANDOM,
61
+    AUTO_CUE,
62
+    TAPE_LENGTH,
63
+    SIDE_A_B,
64
+    TIME_FADE,
65
+    PEAK_SEARCH,
66
+    SEARCH_BACK,
67
+    SEARCH_FOR,
68
+    TRACK_NEXT,
69
+    TRACK_PREV,
70
+    STOP,
71
+    PAUSE,
72
+    PLAY
73
+]

+ 25
- 0
remotes/yamaha_ras5.py 查看文件

@@ -0,0 +1,25 @@
1
+NAME = "RAS5"
2
+#
3
+POWER = "POWER"
4
+PHONO = "PHONO"
5
+DOCK = "DOCK"
6
+CD = "CD"
7
+LINE1 = "LINE1"
8
+LINE2 = "LINE2"
9
+LINE3 = "LINE3"
10
+MUTE = "MUTE"
11
+VOLUP = "VOLUP"
12
+VOLDOWN = "VOLDOWN"
13
+#
14
+ALL = [
15
+    POWER,
16
+    PHONO,
17
+    DOCK,
18
+    CD,
19
+    LINE1,
20
+    LINE2,
21
+    LINE3,
22
+    MUTE,
23
+    VOLUP,
24
+    VOLDOWN
25
+]

+ 1
- 0
report

@@ -0,0 +1 @@
1
+Subproject commit 21bac82e0c459ebf6d34783c9249526a657a6bbd

+ 2
- 0
requirements.txt 查看文件

@@ -0,0 +1,2 @@
1
+paho-mqtt
2
+lirc

正在加载...
取消
保存