-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlkxrrccli.py
96 lines (84 loc) · 2.43 KB
/
lkxrrccli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
#-*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
### This is the commandline interface to start and use the lkxrrc
### Make sure to configure settings.cfg before you run
import time
import threading
from lkxrrc import LKXRRC
import sshkeyboard
lkx = LKXRRC()
lkx.Connect()
runloop = True
def press(key):
# Handle keypresses
global runloop
global lkx
print(f"'{key}' pressed")
if key == 'q':
lkx.Disconnect()
runloop = False
if key == 'a':
msg = '\x06AI1;\r\n'
lkx.sockethandler.SendCommsg(msg)
print("Sendtit", msg)
if key == 's':
msg = '\x06AI0;\r\n'
lkx.sockethandler.SendCommsg(msg)
print("Sendtit", msg)
if key == 'z' or key == 'space':
lkx.PttOn()
print("Ptt on")
if key == 'x':
lkx.PttOff()
print("Ptt off")
if key == 'b':
print("CW")
lkx.cwserialhandler.CWEvent(True)
if key == 'p':
msg = '\x06PS1;\r\n'
print("Trying to power on")
lkx.sockethandler.SendCommsg(msg)
if key == 'l':
msg = '\x06PS0;\r\n'
print("Trying to power off")
lkx.sockethandler.SendCommsg(msg)
def release(key):
if key == 'b':
print("CW")
lkx.cwserialhandler.CWEvent(False)
if key == 'space':
lkx.PttOff()
print("Ptt off")
print(f"'{key}' released")
def keyboardwork():
sshkeyboard.listen_keyboard(
on_press=press,
on_release=release,
delay_second_char=0.3,
delay_other_chars=0.3,
)
keboardthread = threading.Thread(target=keyboardwork)
keboardthread.start()
lasttime = time.time()
while runloop:
lkx.HandleData()
if time.time() - lasttime > 5:
lasttime = time.time()
lkx.PrintQueueSizes()
time.sleep(1e-3) # so much sleep...
time.sleep(1)
print("fin")