格力空调红外拼码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删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

Python包管理工具pip的升级指南

《Python包管理工具pip的升级指南》本文全面探讨Python包管理工具pip的升级策略,从基础升级方法到高级技巧,涵盖不同操作系统环境下的最佳实践,我们将深入分析pip的工作原理,介绍多种升级方... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

基于Python实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

Python中反转字符串的常见方法小结

《Python中反转字符串的常见方法小结》在Python中,字符串对象没有内置的反转方法,然而,在实际开发中,我们经常会遇到需要反转字符串的场景,比如处理回文字符串、文本加密等,因此,掌握如何在Pyt... 目录python中反转字符串的方法技术背景实现步骤1. 使用切片2. 使用 reversed() 函

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核