-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathpd.py
More file actions
executable file
·93 lines (83 loc) · 2.85 KB
/
pd.py
File metadata and controls
executable file
·93 lines (83 loc) · 2.85 KB
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
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2023 Marshal Horn <kamocat@gmail.com>
##
## 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 2 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/>.
##
import sigrokdecode as srd
from .sc import key_decode
class Ps2Packet:
def __init__(self, val, host=False, pok=False, ack=False):
self.val = val #byte value
self.host = host #Host transmissions
self.pok = pok #Parity ok
self.ack = ack #Acknowlege ok for host transmission.
class Ann:
PRESS,RELEASE,ACK = range(3)
class Decoder(srd.Decoder):
api_version = 3
id = 'ps2_keyboard'
name = 'PS/2 Keyboard'
longname = 'PS/2 Keyboard'
desc = 'PS/2 keyboard interface.'
license = 'gplv2+'
inputs = ['ps2']
outputs = []
tags = ['PC']
binary = (
('Keys', 'Key presses'),
)
annotations = (
('Press', 'Key pressed'),
('Release', 'Key released'),
('Ack', 'Acknowledge'),
)
annotation_rows = (
('keys', 'key presses and releases',(0,1,2)),
)
def __init__(self):
self.reset()
def reset(self):
self.sw = 0 #for switch statement
self.ann = Ann.PRESS #defualt to keypress
self.extended = False
def start(self):
self.out_binary = self.register(srd.OUTPUT_BINARY)
self.out_ann = self.register(srd.OUTPUT_ANN)
def decode(self,startsample,endsample,data):
if data.host:
# Ignore host commands or interrupted keycodes
self.reset()
return
if self.sw < 1:
self.ss = startsample
self.sw = 1
if self.sw < 2:
if data.val == 0xF0: #Break code
self.ann = Ann.RELEASE
return
elif data.val == 0xE0: #Extended character
self.extended = True
return
elif data.val == 0xFA: #Acknowledge code
c = ['Acknowledge','ACK']
self.ann = Ann.ACK
self.sw = 4
if self.sw < 3:
c = key_decode(data.val, self.extended)
self.put(self.ss,endsample,self.out_ann,[self.ann,c])
if self.ann == Ann.PRESS:
self.put(self.ss,endsample,self.out_binary,[0,c[-1].encode('UTF-8')])
self.reset()