格力空调红外拼码Python脚本程序

2024-02-04 12:50

本文主要是介绍格力空调红外拼码Python脚本程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

#coding=utf-8  

#说明:格力空调红外拼码Python脚本程序  

#对应的码库为格力9,inst值:100032  

startLevel = (9000,4500)    #起始码  

linkLevel = (550,20000)     #连接码  

lowLevel = (550,550)        #低电平  

highLevel = (550,1660)      #高电平  

#模式标志  

modeFlag = 4  

def modeCodeFunc(m):  

global modeFlag  

    modeCode = (lowLevel+lowLevel+lowLevel, #自动  

        highLevel+lowLevel+lowLevel, #制冷  

        lowLevel+highLevel+lowLevel, #加湿  

        highLevel+highLevel+lowLevel,#送风  

        lowLevel+lowLevel+highLevel) #制热  

if m > modeCode.__len__()-1:  

print "模式参数必须小于" +str(modeCode.__len__())  

return modeCode[0]  

    modeFlag = m  

return modeCode[m]  

#开关  

keyFlag = 0  

def keyCodeFunc(k):  

global keyFlag  

    keyCode = (lowLevel,    #关  

           highLevel)   #开  

    keyFlag = k  

return keyCode[k]  

#风速  

fanSpeedFlag =0  

def fanSpeedCodeFunc(f):  

global fanSpeedFlag  

    fanSpeedCode = (lowLevel+lowLevel,  #自动  

            highLevel+lowLevel, #一档  

            lowLevel+highLevel, #二档  

            highLevel+highLevel)    #三档  

if f>fanSpeedCode.__len__()-1:  

print "风速参数必须小于"+str(fanSpeedCode.__len__())  

return fanSpeedCode[0]  

    fanSpeedFlag = f  

return fanSpeedCode[f]  

#扫风  

#fanScanFlag = 0  

def fanScanCodeFunc(f):  

    fanScanCode = (lowLevel,highLevel)  

    fanScanFlag = f  

if f>fanScanCode.__len__()-1:  

print "扫风参数必须小于"+str(fanScanCode.__len__())  

return fanScanCode[0]  

return fanScanCode[f]  

def getSleepCode(s):  

    sleepCode = (lowLevel,highLevel)  

if s>sleepCode.__len__()-1:  

print "睡眠参数必须小于"+str(sleepCode.__len__())  

return sleepCode[0]  

return sleepCode[s]  

tempFlag = 16  

def tempertureCodeFunc(t):  

global tempFlag  

    tempFlag = t  

    tempCode = ()# lowLevel+lowLevel+lowLevel+lowLevel  

    dat  = t - 16  

#print dat  

print bin(dat)  

for i in range(0, 4, 1):  

        x = dat & 1  

#print x,  

if x == 1:  

            tempCode += highLevel  

elif x == 0:  

            tempCode += lowLevel  

        dat = dat >> 1  

return tempCode  

#定时数据  

def getTimerCode():  

    timerCode = lowLevel+lowLevel+lowLevel+lowLevel+\  

                lowLevel+lowLevel+lowLevel+lowLevel  

return timerCode  

#超强、灯光、健康、干燥、换气  

def getOtherCode(strong, light, health, dry, breath):  

    otherFuncCode = ()  

if True==strong:  

        otherFuncCode = highLevel  

else:  

        otherFuncCode = lowLevel  

if True==light:  

        otherFuncCode += highLevel  

else:  

        otherFuncCode += lowLevel  

if True==health:  

        otherFuncCode += highLevel  

else:  

        otherFuncCode += lowLevel  

if True==dry:  

        otherFuncCode += highLevel  

else:  

        otherFuncCode += lowLevel  

if True==breath:  

        otherFuncCode += highLevel  

else:  

        otherFuncCode += lowLevel  

return otherFuncCode  

#前35位结束码后七位结束码  

#所有按键都是  

#000 1010  

def getFirstCodeEnd():  

    firstCodeEnd = lowLevel+lowLevel+lowLevel+highLevel+lowLevel+highLevel+lowLevel  

return firstCodeEnd  

#连接码  

def getLinkCode():  

    linkCode = lowLevel+highLevel+lowLevel+linkLevel  

return linkCode  

#上下扫风  

fanUpAndDownFlag = 1;  

fanLeftAndRightFlag = 1;  

def fanUpAndDownCodeFunc(f):  

global fanUpAndDownFlag  

    fanUpAndDownCode = (lowLevel+lowLevel+lowLevel+lowLevel,  

                    highLevel+lowLevel+lowLevel+lowLevel)  

    fanUpAndDownFlag = f  

    fanScanCodeFunc(fanUpAndDownFlag or fanLeftAndRightFlag)  

return fanUpAndDownCode[f]  

#左右扫风  

def fanLeftAndRightCodeFunc(f):  

global fanLeftAndRightFlag  

    fanLeftAndRightCode =(lowLevel+lowLevel+lowLevel+lowLevel,  

                      highLevel+lowLevel+lowLevel+lowLevel)  

    fanLeftAndRightFlag = f  

    fanScanCodeFunc(fanUpAndDownFlag or fanLeftAndRightFlag)  

return fanLeftAndRightCode[f]  

#0000  

#0100  

#0000  

#0000  

#0000  

def getOtherFunc2():  

    otherFunc2 = lowLevel+lowLevel+lowLevel+lowLevel  

    otherFunc2 += lowLevel+highLevel+lowLevel+lowLevel  

    otherFunc2+= lowLevel+lowLevel+lowLevel+lowLevel+\  

                lowLevel+lowLevel+lowLevel+lowLevel+\  

                lowLevel+lowLevel+lowLevel+lowLevel  

return otherFunc2  

def getCheckoutCode():  

#校验码 = (模式 – 1) + (温度 – 16) + 5 + 左右扫风 + 换气 + 节能 - 开关  

# 取二进制后四位,再逆序  

    dat = (modeFlag - 1) + (tempFlag - 16) + 5 + fanLeftAndRightFlag + 0 + 0 - keyFlag  

print(dat)  

    code = ()  

for i in range(0, 4, 1):  

        x = dat & 1  

if 1 == x:  

            code += highLevel  

elif 0 == x:  

            code += lowLevel  

        dat = dat >> 1  

#print code  

return code  

def getSecondCodeEnd():  

    secondCodeEnd = (550,40000)  

return secondCodeEnd  

if __name__ == "__main__":  

print("格力空调遥控器红外编码-长码")  

print("100032-格力9")  

    code = startLevel               #起始码  

    code += modeCodeFunc(1)         #模式:0自动,1制冷,2加湿,3送风,4加热  

    code += keyCodeFunc(1)          #开关:0关,1开  

    code += fanSpeedCodeFunc(0)     #风速:0自动,1一档,2二档,3三档  

    code += fanScanCodeFunc(0)      #扫风:0关,1开-设置上下扫风和左右扫风的时候会自动设置为1  

    code += getSleepCode(0)         #睡眠  

    code += tempertureCodeFunc(16)   #温度  

    code += getTimerCode()          #定时  

    code += getOtherCode(False,True,False,False,False)  #其他-超强、灯光、健康、干燥、换气  

    code += getFirstCodeEnd()       #剩余的编码  

    code += getLinkCode()           #连接码  

    code += fanUpAndDownCodeFunc(0)     #上下扫风  

    code += fanLeftAndRightCodeFunc(1)  #左右扫风  

    code += getOtherFunc2()             #固定码  

    code += getCheckoutCode()           #校验码  

    code += getSecondCodeEnd()          #结束码  

print "电平码:"  

print code  

转载于:https://www.cnblogs.com/blhw/p/6702874.html

这篇关于格力空调红外拼码Python脚本程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/677569

相关文章

Python中你不知道的gzip高级用法分享

《Python中你不知道的gzip高级用法分享》在当今大数据时代,数据存储和传输成本已成为每个开发者必须考虑的问题,Python内置的gzip模块提供了一种简单高效的解决方案,下面小编就来和大家详细讲... 目录前言:为什么数据压缩如此重要1. gzip 模块基础介绍2. 基本压缩与解压缩操作2.1 压缩文

Python设置Cookie永不超时的详细指南

《Python设置Cookie永不超时的详细指南》Cookie是一种存储在用户浏览器中的小型数据片段,用于记录用户的登录状态、偏好设置等信息,下面小编就来和大家详细讲讲Python如何设置Cookie... 目录一、Cookie的作用与重要性二、Cookie过期的原因三、实现Cookie永不超时的方法(一)

Python内置函数之classmethod函数使用详解

《Python内置函数之classmethod函数使用详解》:本文主要介绍Python内置函数之classmethod函数使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 类方法定义与基本语法2. 类方法 vs 实例方法 vs 静态方法3. 核心特性与用法(1编程客

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos

Python实现对阿里云OSS对象存储的操作详解

《Python实现对阿里云OSS对象存储的操作详解》这篇文章主要为大家详细介绍了Python实现对阿里云OSS对象存储的操作相关知识,包括连接,上传,下载,列举等功能,感兴趣的小伙伴可以了解下... 目录一、直接使用代码二、详细使用1. 环境准备2. 初始化配置3. bucket配置创建4. 文件上传到os

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四

Python中win32包的安装及常见用途介绍

《Python中win32包的安装及常见用途介绍》在Windows环境下,PythonWin32模块通常随Python安装包一起安装,:本文主要介绍Python中win32包的安装及常见用途的相关... 目录前言主要组件安装方法常见用途1. 操作Windows注册表2. 操作Windows服务3. 窗口操作

Python中re模块结合正则表达式的实际应用案例

《Python中re模块结合正则表达式的实际应用案例》Python中的re模块是用于处理正则表达式的强大工具,正则表达式是一种用来匹配字符串的模式,它可以在文本中搜索和匹配特定的字符串模式,这篇文章主... 目录前言re模块常用函数一、查看文本中是否包含 A 或 B 字符串二、替换多个关键词为统一格式三、提

python常用的正则表达式及作用

《python常用的正则表达式及作用》正则表达式是处理字符串的强大工具,Python通过re模块提供正则表达式支持,本文给大家介绍python常用的正则表达式及作用详解,感兴趣的朋友跟随小编一起看看吧... 目录python常用正则表达式及作用基本匹配模式常用正则表达式示例常用量词边界匹配分组和捕获常用re