Skip to content

Commit

Permalink
Adding IR plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Oct 16, 2019
1 parent 4ba43b1 commit eb03a93
Show file tree
Hide file tree
Showing 9 changed files with 751 additions and 34 deletions.
13 changes: 7 additions & 6 deletions RPIEasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def signal_handler(signal, frame):
lastdisconntime = 0

def hardwareInit():
#print("Init hardware...")
print("Init hardware...")
rpieGlobals.osinuse = misc.getosname(0)
rpieGlobals.ossubtype = misc.getsupportlevel(1)
pinout = "0"
Expand All @@ -60,10 +60,11 @@ def hardwareInit():
if rpv:
pinout = rpv["pins"]
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,str(rpv["name"])+" "+str(rpv["pins"])+" pins")

print("Load network settings...")
Settings.loadnetsettings()
Settings.NetMan.networkinit()

print("Load GPIO settings...")
if pinout != "0":
Settings.loadpinout()
if pinout == "40" and len(Settings.Pinout)!=41:
Expand Down Expand Up @@ -112,7 +113,7 @@ def PluginInit():
tarr[0] = tarr[0].replace(".py","")
rpieGlobals.deviceselector.append(tarr) # create list for form select

#print("Load devices from file")
print("Load devices from file")
Settings.loadtasks()

return 0
Expand All @@ -134,7 +135,7 @@ def CPluginInit():
tarr[0] = tarr[0].replace(".py","")
rpieGlobals.controllerselector.append(tarr) # create list for form select

#print("Load controllers from file")
print("Load controllers from file")
Settings.loadcontrollers()

for x in range(0,len(Settings.Tasks)):
Expand Down Expand Up @@ -180,7 +181,7 @@ def NPluginInit():
tarr[0] = tarr[0].replace(".py","")
rpieGlobals.notifierselector.append(tarr) # create list for form select

#print("Load controllers from file")
print("Load notifiers from file")
Settings.loadnotifiers()

for x in range(0,len(Settings.Notifiers)):
Expand All @@ -201,7 +202,7 @@ def RulesInit():
except:
pass
if rules!="":
#print("Loading rules...")
print("Loading rules...")
commands.splitruletoevents(rules)
commands.rulesProcessing("System#Boot",rpieGlobals.RULE_SYSTEM)

Expand Down
4 changes: 2 additions & 2 deletions Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
}

Pinout = []
PinStatesMax = 9
PinStates = ["Default","Input","Input-Pulldown","Input-Pullup","Output","Output-Lo","Output-Hi","H-PWM","1WIRE","Special","Reserved"]
PinStatesMax = 13
PinStates = ["Default","Input","Input-Pulldown","Input-Pullup","Output","Output-Lo","Output-Hi","H-PWM","1WIRE","Special","IR-RX","IR-TX","IR-PWM","Reserved","Reserved"]

Tasks = [False]
Controllers = [False]
Expand Down
126 changes: 126 additions & 0 deletions _P016_IR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env python3
#############################################################################
##################### IR Receiver plugin for RPIEasy ########################
#############################################################################
#
# This plugin made for LIRC compatible IR receivers.
#
# Copyright (C) 2019 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
import plugin
import webserver
import rpieGlobals
import rpieTime
import misc
import time
import threading
from lib.lib_ir import *

class Plugin(plugin.PluginProto):
PLUGIN_ID = 16
PLUGIN_NAME = "Communication - IR Receiver (TESTING)"
PLUGIN_VALUENAME1 = "IR"

def __init__(self,taskindex): # general init
plugin.PluginProto.__init__(self,taskindex)
self.dtype = rpieGlobals.DEVICE_TYPE_DUMMY # use lirc device, not gpio directly!
self.vtype = rpieGlobals.SENSOR_TYPE_LONG
self.readinprogress = 0
self.valuecount = 1
self.senddataoption = True
self.timeroption = False
self.timeroptional = False
self.formulaoption = False
self.irdevice = None
self.bgproc = None
self.enprot = []

def __del__(self):
try:
self.initialized = False
if self.irdevice is not None:
self.irdevice.stop()
except:
pass

def plugin_exit(self):
self.__del__()

def plugin_init(self,enableplugin=None):
plugin.PluginProto.plugin_init(self,enableplugin)
self.initialized = False
if self.enabled==False:
self.__del__()
return False
if self.uservar[0]!="0":
self.uservar[0]="0"
self.decimals[0]=0
if str(self.taskdevicepluginconfig[0])!="0" and str(self.taskdevicepluginconfig[0]).strip()!="":
if self.enabled:
try:
self.irdevice = request_ir_device(self.taskdevicepluginconfig[0],True,self.receiver)
self.initialized = self.irdevice.initialized
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"LIRC device init error: ",+str(e))
if self.initialized:
try:
pname = str(self.taskdevicepluginconfig[0]).split("/")
self.ports = str(pname[-1])
except:
pass
set_ir_protocols(self.enprot) # print(enprot)
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"LIRC RX device initialized")
self.bgproc = threading.Thread(target=self.irdevice.poller)
self.bgproc.daemon = True
self.bgproc.start()

def receiver(self,proto,code):
self.set_value(1,int(code,0),True)
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"IRSEND,"+str(proto)+","+str(code))
# misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"Protocol: "+str(proto)+" Code: "+str(code))

def webform_load(self):
try:
choice1 = self.taskdevicepluginconfig[0]
options = find_lirc_devices()
if len(options)>0:
webserver.addHtml("<tr><td>LIRC device<td>")
webserver.addSelector_Head("p016_dev",False)
for o in range(len(options)):
webserver.addSelector_Item(options[o],options[o],(str(options[o])==str(choice1)),False)
webserver.addSelector_Foot()
else:
webserver.addFormNote("/dev/lirc* not found")
return False
webserver.addFormNote("Select a receiver LIRC device (lirc-rx)! Do not forget to set the Data pin to IR-RX <a href='pinout'>at pinout settings</a>!")
except Exception as e:
print(e)
try:
supprot = get_ir_supported_protocols()
enprot = get_ir_enabled_protocols()
webserver.addRowLabel("Enabled protocols")
for s in range(len(supprot)):
webserver.addHtml("<label class='container' style='height:30px'>"+supprot[s]+" <input type='checkbox' id='")
webserver.addHtml("_"+supprot[s]+"' name='_"+supprot[s]+"'")
if (supprot[s] in enprot):
webserver.addHtml(" checked")
webserver.addHtml("><span class='checkmark'></span></label>")
except Exception as e:
print(e)
return True

def webform_save(self,params):
par = webserver.arg("p016_dev",params)
self.taskdevicepluginconfig[0] = str(par)
self.enprot = []
try:
for k,v in params.items():
if k[0]=="_":
if v=="on":
self.enprot.append(k[1:])
except Exception as e:
print(e)
# set_ir_protocols(self.enprot) # print(enprot)
self.plugin_init()
return True

134 changes: 134 additions & 0 deletions _P035_IRTX.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env python3
#############################################################################
##################### IR Transmitter plugin for RPIEasy #####################
#############################################################################
#
# This plugin made for LIRC compatible IR transceivers.
# GPIO-IR-TX provides unstable output, PWM-IR-TX has to be better, but not works to me at all.
#
# Available commands:
#
# IRSEND: That commands format is: IRSEND,<protocol>,<data>,<bits>,<repeat>
# bits and repeat default to 0 if not used and they are optional
#
# Copyright (C) 2019 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
import plugin
import webserver
import rpieGlobals
import rpieTime
import misc
import time
import threading
from lib.lib_ir import *

class Plugin(plugin.PluginProto):
PLUGIN_ID = 35
PLUGIN_NAME = "Communication - IR Transmit (EXPERIMENTAL)"
PLUGIN_VALUENAME1 = "IR"

def __init__(self,taskindex): # general init
plugin.PluginProto.__init__(self,taskindex)
self.dtype = rpieGlobals.DEVICE_TYPE_DUMMY # use lirc device, not gpio directly!
self.vtype = rpieGlobals.SENSOR_TYPE_NONE
self.readinprogress = 0
self.valuecount = 0
self.senddataoption = False
self.timeroption = False
self.timeroptional = False
self.formulaoption = False
self.irdevice = None

def __del__(self):
try:
self.initialized = False
if self.irdevice is not None:
self.irdevice.stop()
except:
pass

def plugin_exit(self):
self.__del__()

def plugin_init(self,enableplugin=None):
plugin.PluginProto.plugin_init(self,enableplugin)
self.initialized = False
if self.uservar[0]!="0":
self.uservar[0]="0"
self.decimals[0]=0
if str(self.taskdevicepluginconfig[0])!="0" and str(self.taskdevicepluginconfig[0]).strip()!="":
if self.enabled:
try:
self.irdevice = request_ir_device(self.taskdevicepluginconfig[0],False)
self.initialized = self.irdevice.initialized
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"LIRC device init error: ",+str(e))
if self.initialized:
try:
pname = str(self.taskdevicepluginconfig[0]).split("/")
self.ports = str(pname[-1])
except:
pass
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"LIRC TX device initialized")

def webform_load(self):
try:
choice1 = self.taskdevicepluginconfig[0]
options = find_lirc_devices()
if len(options)>0:
webserver.addHtml("<tr><td>LIRC device<td>")
webserver.addSelector_Head("p035_dev",False)
for o in range(len(options)):
webserver.addSelector_Item(options[o],options[o],(str(options[o])==str(choice1)),False)
webserver.addSelector_Foot()
else:
webserver.addFormNote("/dev/lirc* not found")
return False
webserver.addFormNote("Select a transceiver LIRC device (lirc-tx)! Do not forget to set the Data pin to IR-PWM or IR-TX <a href='pinout'>at pinout settings</a>!")
webserver.addFormNote("According to documentation, only GPIO18 or GPIO12 is supported as IR-PWM!")
except Exception as e:
print(e)
return True

def webform_save(self,params):
par = webserver.arg("p035_dev",params)
self.taskdevicepluginconfig[0] = str(par)
self.plugin_init()
return True

def plugin_write(self,cmd):
res = False
if self.initialized == False or self.enabled==False:
return False
cmdarr = cmd.split(",")
cmdarr[0] = cmdarr[0].strip().lower()
if cmdarr[0] == "irsend":
prot = ""
data = -1
bits = 8
repeat = 1
try:
prot = str(cmdarr[1].strip()).upper()
data = int(cmdarr[2].strip(),0)
except:
pass
try:
bits = int(cmdarr[3].strip())
except:
bits = data.bit_length()
try:
repeat = int(cmdarr[4].strip())
except:
repeat = 1
if prot!="" and data>-1:
protonum = get_protonum(prot,bits)
# print(prot,bits,protonum)
if protonum != -1:
while repeat>0:
res = self.irdevice.irsend(data,protonum)
time.sleep(1)
repeat=repeat-1
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"IRTX code sent "+str(hex(data))+" (protocoll:"+get_protoname(protonum)+")")
else:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Unknown protocol "+str(prot))
return res
Loading

0 comments on commit eb03a93

Please sign in to comment.