格力空调红外拼码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结合PyWebView库打造跨平台桌面应用

《Python结合PyWebView库打造跨平台桌面应用》随着Web技术的发展,将HTML/CSS/JavaScript与Python结合构建桌面应用成为可能,本文将系统讲解如何使用PyWebView... 目录一、技术原理与优势分析1.1 架构原理1.2 核心优势二、开发环境搭建2.1 安装依赖2.2 验

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

Python运行中频繁出现Restart提示的解决办法

《Python运行中频繁出现Restart提示的解决办法》在编程的世界里,遇到各种奇怪的问题是家常便饭,但是,当你的Python程序在运行过程中频繁出现“Restart”提示时,这可能不仅仅是令人头疼... 目录问题描述代码示例无限循环递归调用内存泄漏解决方案1. 检查代码逻辑无限循环递归调用内存泄漏2.

Python中判断对象是否为空的方法

《Python中判断对象是否为空的方法》在Python开发中,判断对象是否为“空”是高频操作,但看似简单的需求却暗藏玄机,从None到空容器,从零值到自定义对象的“假值”状态,不同场景下的“空”需要精... 目录一、python中的“空”值体系二、精准判定方法对比三、常见误区解析四、进阶处理技巧五、性能优化

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo

Python如何自动生成环境依赖包requirements

《Python如何自动生成环境依赖包requirements》:本文主要介绍Python如何自动生成环境依赖包requirements问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录生成当前 python 环境 安装的所有依赖包1、命令2、常见问题只生成当前 项目 的所有依赖包1、

如何将Python彻底卸载的三种方法

《如何将Python彻底卸载的三种方法》通常我们在一些软件的使用上有碰壁,第一反应就是卸载重装,所以有小伙伴就问我Python怎么卸载才能彻底卸载干净,今天这篇文章,小编就来教大家如何彻底卸载Pyth... 目录软件卸载①方法:②方法:③方法:清理相关文件夹软件卸载①方法:首先,在安装python时,下