格力空调遥控器红外编码透析(长码)

格力空调遥控器(YB0F2)红外码组成如下,按解码顺序排列 

起始码(S)+35位数据码+连接码(C)+32位数据码 


1、各种编码的电平宽度: 

数据码由“0”“1”组成: 

0的电平宽度为:600us低电平+600us高电平,

1的电平宽度为:600us低电平+1600us高电平

起始码S电平宽度为:9000us低电平+4500us高电平

连接码C电平宽度为:600us低电平+20000us高电平


 2、数据码的形成机制 

前35位数据码形成如下图所示:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

0

模式标志

开关

风速

扫风

睡眠

温度数据

定时数据

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

0

0

0

0

0

0

0

0

0

0

0

0

1

0

1

0

定时数据

加湿

灯光

负离子

节电

换气

所有按键均显示此值

33

34

35

 

0

1

0

 

所有按键均显示此值

 


后32位数据码形成如下图所示:

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

上下扫风

 

左右扫风

 

温度显示

 

 

 

 

 

 

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

0

0

0

0

0

0

0

0

0

0

0

0

0

1

0

1

 

 

 

 

 

 

 

 

 

 

节能

 

校验码



上表中,大于两位的数据都是逆序递增的,各数据的意义如下:



校验码形成:

校验码 = (模式 – 1) + (温度– 16) + 5  + 左右扫风 + 换气 + 节能 - 开关
之后取二进制后四位,再逆序;



下面是Python语言拼码程序,Python版本为2.7.11

  1. #coding=utf-8  
  2. #说明:格力空调红外拼码Python脚本程序  
  3. #对应的码库为格力9,inst值:100032  
  4.   
  5. startLevel = (9000,4500)    #起始码  
  6. linkLevel = (550,20000)     #连接码  
  7. lowLevel = (550,550)        #低电平  
  8. highLevel = (550,1660)      #高电平  
  9.   
  10. #模式标志  
  11. modeFlag = 4  
  12. def modeCodeFunc(m):  
  13.     global modeFlag  
  14.     modeCode = (lowLevel+lowLevel+lowLevel, #自动  
  15.         highLevel+lowLevel+lowLevel, #制冷  
  16.         lowLevel+highLevel+lowLevel, #加湿  
  17.         highLevel+highLevel+lowLevel,#送风  
  18.         lowLevel+lowLevel+highLevel) #制热  
  19.     if m > modeCode.__len__()-1:  
  20.         print "模式参数必须小于" +str(modeCode.__len__())  
  21.         return modeCode[0]  
  22.     modeFlag = m  
  23.     return modeCode[m]  
  24.   
  25. #开关  
  26. keyFlag = 0  
  27. def keyCodeFunc(k):  
  28.     global keyFlag  
  29.     keyCode = (lowLevel,    #关  
  30.            highLevel)   #开  
  31.     keyFlag = k  
  32.     return keyCode[k]  
  33.   
  34. #风速  
  35. fanSpeedFlag =0  
  36. def fanSpeedCodeFunc(f):  
  37.     global fanSpeedFlag  
  38.     fanSpeedCode = (lowLevel+lowLevel,  #自动  
  39.             highLevel+lowLevel, #一档  
  40.             lowLevel+highLevel, #二档  
  41.             highLevel+highLevel)    #三档  
  42.     if f>fanSpeedCode.__len__()-1:  
  43.         print "风速参数必须小于"+str(fanSpeedCode.__len__())  
  44.         return fanSpeedCode[0]  
  45.     fanSpeedFlag = f  
  46.     return fanSpeedCode[f]  
  47.   
  48. #扫风  
  49. #fanScanFlag = 0  
  50. def fanScanCodeFunc(f):  
  51.   
  52.     fanScanCode = (lowLevel,highLevel)  
  53.     fanScanFlag = f  
  54.     if f>fanScanCode.__len__()-1:  
  55.         print "扫风参数必须小于"+str(fanScanCode.__len__())  
  56.         return fanScanCode[0]  
  57.     return fanScanCode[f]  
  58.   
  59. def getSleepCode(s):  
  60.     sleepCode = (lowLevel,highLevel)  
  61.     if s>sleepCode.__len__()-1:  
  62.         print "睡眠参数必须小于"+str(sleepCode.__len__())  
  63.         return sleepCode[0]  
  64.     return sleepCode[s]  
  65.   
  66. tempFlag = 16  
  67. def tempertureCodeFunc(t):  
  68.     global tempFlag  
  69.     tempFlag = t  
  70.     tempCode = ()# lowLevel+lowLevel+lowLevel+lowLevel  
  71.   
  72.     dat  = t - 16  
  73.     #print dat  
  74.     print bin(dat)  
  75.     for i in range(041):  
  76.         x = dat & 1  
  77.         #print x,  
  78.         if x == 1:  
  79.             tempCode += highLevel  
  80.         elif x == 0:  
  81.             tempCode += lowLevel  
  82.         dat = dat >> 1  
  83.   
  84.     return tempCode  
  85.   
  86. #定时数据  
  87. def getTimerCode():  
  88.     timerCode = lowLevel+lowLevel+lowLevel+lowLevel+\  
  89.                 lowLevel+lowLevel+lowLevel+lowLevel  
  90.     return timerCode  
  91.   
  92. #超强、灯光、健康、干燥、换气  
  93. def getOtherCode(strong, light, health, dry, breath):  
  94.     otherFuncCode = ()  
  95.     if True==strong:  
  96.         otherFuncCode = highLevel  
  97.     else:  
  98.         otherFuncCode = lowLevel  
  99.   
  100.     if True==light:  
  101.         otherFuncCode += highLevel  
  102.     else:  
  103.         otherFuncCode += lowLevel  
  104.   
  105.     if True==health:  
  106.         otherFuncCode += highLevel  
  107.     else:  
  108.         otherFuncCode += lowLevel  
  109.   
  110.     if True==dry:  
  111.         otherFuncCode += highLevel  
  112.     else:  
  113.         otherFuncCode += lowLevel  
  114.   
  115.     if True==breath:  
  116.         otherFuncCode += highLevel  
  117.     else:  
  118.         otherFuncCode += lowLevel  
  119.   
  120.     return otherFuncCode  
  121.   
  122.   
  123. #前35位结束码后七位结束码  
  124. #所有按键都是  
  125. #000 1010  
  126. def getFirstCodeEnd():  
  127.     firstCodeEnd = lowLevel+lowLevel+lowLevel+highLevel+lowLevel+highLevel+lowLevel  
  128.     return firstCodeEnd  
  129.   
  130. #连接码  
  131. def getLinkCode():  
  132.     linkCode = lowLevel+highLevel+lowLevel+linkLevel  
  133.     return linkCode  
  134.   
  135.   
  136. #上下扫风  
  137. fanUpAndDownFlag = 1;  
  138. fanLeftAndRightFlag = 1;  
  139. def fanUpAndDownCodeFunc(f):  
  140.     global fanUpAndDownFlag  
  141.     fanUpAndDownCode = (lowLevel+lowLevel+lowLevel+lowLevel,  
  142.                     highLevel+lowLevel+lowLevel+lowLevel)  
  143.     fanUpAndDownFlag = f  
  144.     fanScanCodeFunc(fanUpAndDownFlag or fanLeftAndRightFlag)  
  145.     return fanUpAndDownCode[f]  
  146.   
  147. #左右扫风  
  148.   
  149. def fanLeftAndRightCodeFunc(f):  
  150.     global fanLeftAndRightFlag  
  151.     fanLeftAndRightCode =(lowLevel+lowLevel+lowLevel+lowLevel,  
  152.                       highLevel+lowLevel+lowLevel+lowLevel)  
  153.     fanLeftAndRightFlag = f  
  154.     fanScanCodeFunc(fanUpAndDownFlag or fanLeftAndRightFlag)  
  155.     return fanLeftAndRightCode[f]  
  156.   
  157. #0000  
  158. #0100  
  159. #0000  
  160. #0000  
  161. #0000  
  162. def getOtherFunc2():  
  163.     otherFunc2 = lowLevel+lowLevel+lowLevel+lowLevel  
  164.     otherFunc2 += lowLevel+highLevel+lowLevel+lowLevel  
  165.     otherFunc2+= lowLevel+lowLevel+lowLevel+lowLevel+\  
  166.                 lowLevel+lowLevel+lowLevel+lowLevel+\  
  167.                 lowLevel+lowLevel+lowLevel+lowLevel  
  168.     return otherFunc2  
  169.   
  170. def getCheckoutCode():  
  171.     #校验码 = (模式 – 1) + (温度 – 16) + 5 + 左右扫风 + 换气 + 节能 - 开关  
  172.     # 取二进制后四位,再逆序  
  173.     dat = (modeFlag - 1) + (tempFlag - 16) + 5 + fanLeftAndRightFlag + 0 + 0 - keyFlag  
  174.     print(dat)  
  175.     code = ()  
  176.     for i in range(041):  
  177.         x = dat & 1  
  178.         if 1 == x:  
  179.             code += highLevel  
  180.         elif 0 == x:  
  181.             code += lowLevel  
  182.         dat = dat >> 1  
  183.   
  184.     #print code  
  185.     return code  
  186.   
  187. def getSecondCodeEnd():  
  188.     secondCodeEnd = (550,40000)  
  189.     return secondCodeEnd  
  190.   
  191. if __name__ == "__main__":  
  192.     print("格力空调遥控器红外编码-长码")  
  193.     print("100032-格力9")  
  194.     code = startLevel               #起始码  
  195.     code += modeCodeFunc(1)         #模式:0自动,1制冷,2加湿,3送风,4加热  
  196.     code += keyCodeFunc(1)          #开关:0关,1开  
  197.     code += fanSpeedCodeFunc(0)     #风速:0自动,1一档,2二档,3三档  
  198.     code += fanScanCodeFunc(0)      #扫风:0关,1开-设置上下扫风和左右扫风的时候会自动设置为1  
  199.     code += getSleepCode(0)         #睡眠  
  200.     code += tempertureCodeFunc(16)   #温度  
  201.     code += getTimerCode()          #定时  
  202.     code += getOtherCode(False,True,False,False,False)  #其他-超强、灯光、健康、干燥、换气  
  203.     code += getFirstCodeEnd()       #剩余的编码  
  204.     code += getLinkCode()           #连接码  
  205.     code += fanUpAndDownCodeFunc(0)     #上下扫风  
  206.     code += fanLeftAndRightCodeFunc(1)  #左右扫风  
  207.     code += getOtherFunc2()             #固定码  
  208.     code += getCheckoutCode()           #校验码  
  209.     code += getSecondCodeEnd()          #结束码  
  210.     print "电平码:"  
  211.     print code 
  • 12
    点赞
  • 75
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dxmcu

谢谢鼓励!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值