From 1f673d29ab42cb5142bcc469e8e1318ec01c5b5c Mon Sep 17 00:00:00 2001 From: TSGames Date: Sun, 15 Aug 2021 17:28:01 +0200 Subject: [PATCH] Update IRModule.py use time_ns() to improve accuracy (python 3.7+) --- IRModule.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/IRModule.py b/IRModule.py index e22f6e8..c568d68 100644 --- a/IRModule.py +++ b/IRModule.py @@ -31,7 +31,7 @@ def __init__(self, callback = None): self.decoding = False self.pList = [] - self.timer = time.time() + self.timer = time.time_ns() if callback == 'DECODE': self.callback = self.print_ir_code else: @@ -47,8 +47,8 @@ def pWidth(self, pin): of the IR remote signal and start the function to look for the end of the IR remote signal""" - self.pList.append(time.time()-self.timer) - self.timer = time.time() + self.pList.append((time.time_ns()-self.timer)/1000000000.) + self.timer = time.time_ns() if self.decoding == False: self.decoding = True @@ -68,10 +68,10 @@ def pulse_checker(self): 2 - if the length of time receiving the pulse is great than self.checkTime - used for repeat codes""" - timer = time.time() + timer = time.time_ns() while True: - check = (time.time()-timer)*1000 + check = (time.time_ns()-timer)/1000000 if check > self.checkTime: print(check, len(self.pList)) break @@ -117,7 +117,7 @@ def decode_pulse(self,pList): for p in range(0,len(pList)): try: - pList[p]=float(pList[p])*1000 + pList[p]=pList[p]*1000. if self.verbose == True: print(pList[p]) if pList[p]<11: