Sanitising IR codes (for new plugin for KIRA)

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Sanitising IR codes (for new plugin for KIRA)

Post by krambriw » Wed May 13, 2009 3:13 pm

Just to avoid double effort, I'm currently writing on a script that is implementing the conversion from raw pronto -> KeeneIR format

BestR Walter

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Sanitising IR codes (for new plugin for KIRA)

Post by krambriw » Fri May 15, 2009 3:04 pm

After support from Mark at Keene Electronics, I have ported some java code to a simple python script. The script converts pronto code to KeeneIR format. It would not be hard to update the KeeneIR plugin using the functions to enable the plugin to support pronto codes directly

Attached is also the EG xml-file that can be used. Just open it and run the script

Kind regards, Walter
ProntoToKeene.xml
(5.19 KiB) Downloaded 196 times

Code: Select all

# To be documented when/if used...
# A script that converts raw pronto to KeeneIR
# code


def averageThis(p_data):
    X = 0
    y = 0
    tmpStr = ""
    Pair_Count = 0
    Burst_Time = []
    MyInt = []
    codeLength = len(p_data)
    last_code = 0
    timeA = 0.0
    timeB = 0.0
    zzz = 0
    error = True

    #try:
    for X in range(0,255):
        Burst_Time.append(0)

    for X in range(0,codeLength,5):
        tmpStr = p_data[X:X+4]
        Burst_Time[y] = int(tmpStr, 16)
        y += 1

    last_code = y
    Pair_Count = Burst_Time[0] % 256
    
    for zzz in range(2,last_code - 2):
        timeA = Burst_Time[zzz] * 0.75
        timeB = Burst_Time[zzz] * 1.30
        MyObjList = []
        
        for X in range(zzz,last_code):
            tstTime = Burst_Time[X]

            if (tstTime > timeA and tstTime < timeB):
                MyObjList.append(X)
                MyObjList.append(tstTime)

        L = len(MyObjList)
        total = 0
    
        if L > 0:
            for X in range(1,L,2):
                MyOb = MyObjList[X]
                total = total + MyOb

            average = total / (L / 2)
        pos = 0

        if L > 0:
            for X in range(0,L,2):
                MyOb = MyObjList[X]
                pos = MyOb
                Burst_Time[pos] = average
    
    data = ""
    
    for X in range(0,last_code):
        nb = str(hex(Burst_Time[X]))[2:]
        if len( nb ) < 4:
            nb = "0" + nb
        data = data + nb.upper() + " "

    data = "K " + data # K plus a space plus data
    error = False

    #except:
    #    print "Some error during averaging..."

    if error:
        return ""
    else:
        return data


def convertFromPronto(p_data):
    X = 0
    y = 0
    tmpStr = ""
    freq = 0.0
    Pair_Count = 0
    Lead_in = 0
    Burst_Time = []
    MyInt = []
    codeLength = len(p_data)
    error = True
    
    try:
        for X in range(0,255):
            Burst_Time.append(0)

        for X in range(0,codeLength,5):
            tmpStr = p_data[X:X+4]
            Burst_Time[y] = int(tmpStr, 16)
            y += 1

        freq = 4145 / Burst_Time[1]
        Pair_Count = Burst_Time[2]

        if Pair_Count == 0:
            Pair_Count = Burst_Time[3]

        if Pair_Count == 0:
            return ""
        
        for X in range(0,y):
            MyInt.append(0) 
        
        MyInt[0] = freq * 256 + Pair_Count
        cycle_time = 1000 / freq
        Lead_in = Burst_Time[4] * cycle_time
        MyInt[1] = Lead_in
        MyInt[2] = Burst_Time[5] * cycle_time
        Pair_Count = Pair_Count - 1
        
        for X in range(0,Pair_Count * 2):
            MyInt[X + 3] = Burst_Time[X + 6] * cycle_time

        MyInt[X + 3] = 8192
        data = ""

        for X in range(0,(Pair_Count * 2) + 3):
            nb = str(hex(MyInt[X]))[2:]
            if len( nb ) < 4:
                nb = "0" + nb
            data = data + nb.upper() + " "

        error = False

    except:
        print "Some error during conversion..."

    if error:
        return ""
    else:
        return data


# Main

# NEXA (D 16 OFF) 
#p_data = "0000 006D 0000 0019 000D 0027 0027 000D 000D 0027 0027 000D 000D 0027 000D 0027 000D 0027 000D 0027 000D 0027 0027 000D 000D 0027 0027 000D 000D 0027 0027 000D 000D 0027 0027 000D 000D 0027 000D 0027 000D 0027 0027 000D 000D 0027 0027 000D 000D 0027 000D 0027 000D 01AB"

# InterTechno (N 15 ON)
#p_data = "0000 0073 0000 0019 000e 002a 002a 000e 000e 002a 000e 002a 000e 002a 002a 000e 000e 002a 002a 000e 000e 002a 000e 002a 000e 002a 002a 000e 000e 002a 002a 000e 000e 002a 002a 000e 000e 002a 000e 002a 000e 002a 002a 000e 000e 002a 002a 000e 000e 002a 002a 000e 000e 0199"

# LG DVD Recorder RH 255 (ON)
#p_data = "0000 006d 0022 0003 00ab 00aa 0016 003f 0016 0014 0016 003e 0016 003f 0016 0014 0016 003e 0016 0014 0016 0014 0016 003e 0016 0014 0016 003e 0016 003f 0016 0014 0016 003e 0016 0014 0016 0014 0016 003e 0016 0014 0016 003f 0016 0014 0016 003e 0016 003e 0016 003f 0016 0014 0016 0014 0016 003f 0016 0014 0016 003e 0016 0014 0016 0014 0016 0014 0016 003e 0016 06c3 00ab 00aa 0016 0014 0016 0e7d"
 
# LG DVD Recorder RH 255 (OFF)
p_data = "0000 006d 0022 0003 00ab 00aa 0016 003e 0016 0014 0016 003f 0016 003e 0016 0014 0016 003e 0016 0014 0016 0014 0016 003e 0016 0014 0016 003f 0016 003e 0016 0014 0016 003f 0016 0014 0016 0014 0016 0014 0016 003e 0016 003f 0016 0014 0016 003e 0016 003f 0016 003e 0016 0014 0016 003f 0016 0014 0016 0014 0016 003e 0016 0014 0016 0014 0016 0014 0016 003e 0016 06c3 00ab 00aa 0016 0014 0016 0e7d"

t = convertFromPronto(p_data)
print "KeeneIR code after conversion"
print t

t = averageThis(t)
print "KeeneIR code after averaging"
print t



ldobson
Plugin Developer
Posts: 15
Joined: Thu Apr 16, 2009 9:55 am

Re: Sanitising IR codes (for new plugin for KIRA)

Post by ldobson » Fri May 15, 2009 6:33 pm

That's really good stuff, I'll try and get it incorporated this weekend!

Post Reply