格力空调红外拼码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创建一个功能完整的Windows风格计算器程序

《使用Python创建一个功能完整的Windows风格计算器程序》:本文主要介绍如何使用Python和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.

Python开发文字版随机事件游戏的项目实例

《Python开发文字版随机事件游戏的项目实例》随机事件游戏是一种通过生成不可预测的事件来增强游戏体验的类型,在这篇博文中,我们将使用Python开发一款文字版随机事件游戏,通过这个项目,读者不仅能够... 目录项目概述2.1 游戏概念2.2 游戏特色2.3 目标玩家群体技术选择与环境准备3.1 开发环境3

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

基于Python打造一个智能单词管理神器

《基于Python打造一个智能单词管理神器》这篇文章主要为大家详细介绍了如何使用Python打造一个智能单词管理神器,从查询到导出的一站式解决,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 项目概述:为什么需要这个工具2. 环境搭建与快速入门2.1 环境要求2.2 首次运行配置3. 核心功能使用指

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令