From 31b646e2ba4c767f14e4be764f0c7f42f2b49a51 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sat, 22 Feb 2020 10:16:16 +0100 Subject: irmp: rework the Python language binding for the shared library Rename the Python language binding's source file and identifiers to eliminate camel case (most of it, stick with camel case in Python class names as is the convention). Adjust whitespace and arrange tables such that their indentation will last during maintenance. Re-add the license text which was missing in the original submission's copy of another decoder. Add copyright information for this submission. Don't "import *" from ctypes(3), use explicit references instead. Avoid double underscores as single leading underscore is already bad enough. Adjust the Python side to the C library's renamed API routines. Create a result data structure layout that only has a single level of nesting, which better represents the C library's interface. Only flags "get unfolded" in the Python binding, to eliminate magic numbers. Prepare to support more platforms than Linux (detected) and Windows (the default when nothing else got detected). --- decoders/ir_irmp/IrmpPythonWrap.py | 81 -------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 decoders/ir_irmp/IrmpPythonWrap.py (limited to 'decoders/ir_irmp/IrmpPythonWrap.py') diff --git a/decoders/ir_irmp/IrmpPythonWrap.py b/decoders/ir_irmp/IrmpPythonWrap.py deleted file mode 100644 index ee250c4..0000000 --- a/decoders/ir_irmp/IrmpPythonWrap.py +++ /dev/null @@ -1,81 +0,0 @@ - - - -from ctypes import * -import platform - - - -class IrmpWrap: - class IrmpData(Structure): - _fields_ = [ ("protocol" , c_uint32 ), - ("protocolName" , c_char_p ), - ("address" , c_uint32 ), - ("command" , c_uint32 ), - ("flags" , c_uint32 ), - ("startSample" , c_uint32 ), - ("endSample" , c_uint32 ), - ] - - def __init__(self): - libname = "irmp.dll" - # get the right filename - - if platform.uname()[0] == "Linux": - name = "irmp.so" - - self.__irmpDll = cdll.LoadLibrary("irmp.dll") - self.__irmpDll.IRMP_GetSampleRate.restype = c_int32 - self.__irmpDll.IRMP_GetSampleRate.argtypes = [] - - - self.__irmpDll.IRMP_GetProtocolName.restype = c_char_p - self.__irmpDll.IRMP_GetProtocolName.argtypes = [c_uint32] - - self.__irmpDll.IRMP_Reset.restype = None - self.__irmpDll.IRMP_Reset.argtypes = [] - - self.__irmpDll.IRMP_AddSample.restype = c_uint32 - self.__irmpDll.IRMP_AddSample.argtypes = [c_uint8] - - self.__irmpDll.IRMP_GetData.restype = c_uint32 - self.__irmpDll.IRMP_GetData.argtypes = [POINTER(IrmpWrap.IrmpData)] - - self.__irmpDll.IRMP_Detect.restype = IrmpWrap.IrmpData - self.__irmpDll.IRMP_Detect.argtypes = [ c_char_p, c_uint32] - - self.__data = IrmpWrap.IrmpData() - self.__startSample = c_uint32(0) - self.__endSample = c_uint32(0) - - return - - def GetProtocollName(self, pn): - return self.__irmpDll.IRMP_GetProtocollName(pn) - - def GetSampleRate(self): - return self.__irmpDll.IRMP_GetSampleRate() - - def Reset(self): - self.__irmpDll.IRMP_Reset() - - def AddSample(self, level): - - if self.__irmpDll.IRMP_AddSample(c_uint8( 1 if (level!=0) else 0)): - self.__irmpDll.IRMP_GetData( byref(self.__data)) - return True - else: - return False - - def GetData(self): - return { 'data' : { - 'protocol' : self.__data.protocol, - 'protocolName' : self.__data.protocolName.decode('UTF-8'), - 'address' : self.__data.address, - 'command' : self.__data.command, - 'repeat' : (self.__data.flags != 0) - }, - 'start' : self.__data.startSample, - 'end' : self.__data.endSample - } - -- cgit v1.2.3-70-g09d2