-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
#!/usr/bin/env python | ||
|
||
import pigpio | ||
import subprocess | ||
verifyMode = False | ||
|
||
class hasher: | ||
|
||
""" | ||
This class forms a hash over the IR pulses generated by an | ||
IR remote. | ||
The remote key press is not converted into a code in the manner of | ||
the lirc module. No attempt is made to decode the type of protocol | ||
used by the remote. The hash is likely to be unique for different | ||
keys and different remotes but this is not guaranteed. | ||
This hashing process works for some remotes/protocols but not for | ||
others. The only way to find out if it works for one or more of | ||
your remotes is to try it and see. | ||
EXAMPLE CODE | ||
#!/usr/bin/env python | ||
import time | ||
import pigpio | ||
import ir_hasher | ||
def callback(hash): | ||
print("hash={}".format(hash)); | ||
pi = pigpio.pi() | ||
ir = ir_hasher.hasher(pi, 7, callback, 5) | ||
print("ctrl c to exit"); | ||
time.sleep(300) | ||
pi.stop() | ||
""" | ||
|
||
def __init__(self, pi, gpio, callback, timeout=5): | ||
|
||
""" | ||
Initialises an IR remote hasher on a pi's gpio. A gap of timeout | ||
milliseconds indicates the end of the remote key press. | ||
""" | ||
|
||
self.pi = pi | ||
self.gpio = gpio | ||
self.code_timeout = timeout | ||
self.callback = callback | ||
|
||
self.in_code = False | ||
|
||
pi.set_mode(gpio, pigpio.INPUT) | ||
|
||
self.cb = pi.callback(gpio, pigpio.EITHER_EDGE, self._cb) | ||
|
||
def _hash(self, old_val, new_val): | ||
|
||
if new_val < (old_val * 0.60): | ||
val = 13 | ||
elif old_val < (new_val * 0.60): | ||
val = 23 | ||
else: | ||
val = 2 | ||
|
||
self.hash_val = self.hash_val ^ val | ||
self.hash_val *= 16777619 # FNV_PRIME_32 | ||
self.hash_val = self.hash_val & ((1<<32)-1) | ||
|
||
def _cb(self, gpio, level, tick): | ||
|
||
if level != pigpio.TIMEOUT: | ||
|
||
if self.in_code == False: | ||
|
||
self.in_code = True | ||
|
||
self.pi.set_watchdog(self.gpio, self.code_timeout) | ||
|
||
self.hash_val = 2166136261 # FNV_BASIS_32 | ||
|
||
self.edges = 1 | ||
|
||
self.t1 = None | ||
self.t2 = None | ||
self.t3 = None | ||
self.t4 = tick | ||
|
||
else: | ||
|
||
self.edges += 1 | ||
|
||
self.t1 = self.t2 | ||
self.t2 = self.t3 | ||
self.t3 = self.t4 | ||
self.t4 = tick | ||
|
||
if self.t1 is not None: | ||
|
||
d1 = pigpio.tickDiff(self.t1,self.t2) | ||
d2 = pigpio.tickDiff(self.t3,self.t4) | ||
|
||
self._hash(d1, d2) | ||
|
||
else: | ||
|
||
if self.in_code: | ||
|
||
self.in_code = False | ||
|
||
self.pi.set_watchdog(self.gpio, 0) | ||
|
||
if self.edges > 12: | ||
|
||
self.callback(self.hash_val) | ||
|
||
if __name__ == "__main__": | ||
|
||
import time | ||
import pigpio | ||
import ir_hasher | ||
|
||
hashes = { | ||
2808021165: '1', | ||
111974127: '2', | ||
927325: '3', | ||
405145461: '4', | ||
676276135: '5', | ||
579589237:'6', | ||
3120151957:'7', | ||
2433712471:'8', | ||
1239742133:'9', | ||
2064946831: '10' | ||
|
||
} | ||
|
||
def callback(hash): | ||
if hash in hashes: | ||
print("{}".format(hashes[hash])); | ||
if int(hashes[hash])<3: | ||
subprocess.call("chromium-browser http://192.168.137.1:3000/ad/%s" % hashes[hash], shell=True) | ||
else: | ||
if verifyMode ==False: | ||
subprocess.call("chromium-browser http://192.168.137.1:3000/product/%s" % (int(hashes[hash])-3), shell=True) | ||
else: | ||
print("fafsa") | ||
else: | ||
print(hash); | ||
|
||
pi = pigpio.pi() | ||
|
||
ir = ir_hasher.hasher(pi, 24, callback, 5) | ||
|
||
print("ctrl c to exit"); | ||
|
||
time.sleep(1000) | ||
|
||
pi.stop() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.