Skip to content

Commit

Permalink
Adding alternative OS support, P001 longpress, Jamibridge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Jun 23, 2020
1 parent 3d7b64f commit 96f5755
Show file tree
Hide file tree
Showing 19 changed files with 733 additions and 70 deletions.
23 changes: 14 additions & 9 deletions RPIEasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def hardwareInit():
if opv:
pinout = opv["pins"]
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,str(opv["name"])+" "+str(opv["pins"])+" pins")
if rpieGlobals.osinuse=="windows":
print("Windows OS is not supported")
import win_os as OS
import win_network as Network
Settings.NetMan = Network.NetworkManager()
Settings.SoundSystem["usable"]=False
hwtype = rpieGlobals.ossubtype
if pinout=="0":
try:
Expand Down Expand Up @@ -119,7 +125,7 @@ def PluginInit():
for fname in filenames:
tarr = [0,0,0]
tarr[0] = fname
with open(fname,"r") as fcont:
with open(fname,"r",encoding="utf8") as fcont:
for line in fcont:
if "PLUGIN_ID" in line:
tarr[1] = line[line.find("=")+1:].strip().replace('"',"")
Expand All @@ -141,7 +147,7 @@ def CPluginInit():
for fname in filenames:
tarr = [0,0,0]
tarr[0] = fname
with open(fname,"r") as fcont:
with open(fname,"r",encoding="utf8") as fcont:
for line in fcont:
if "CONTROLLER_ID" in line:
tarr[1] = line[line.find("=")+1:].strip().replace('"',"")
Expand Down Expand Up @@ -187,7 +193,7 @@ def NPluginInit():
for fname in filenames:
tarr = [0,0,0]
tarr[0] = fname
with open(fname,"r") as fcont:
with open(fname,"r",encoding="utf8") as fcont:
for line in fcont:
if "NPLUGIN_ID" in line:
tarr[1] = line[line.find("=")+1:].strip().replace('"',"")
Expand All @@ -214,7 +220,7 @@ def NPluginInit():
def RulesInit():
rules = ""
try:
with open(rpieGlobals.FILE_RULES,'r') as f:
with open(rpieGlobals.FILE_RULES,'r',encoding="utf8") as f:
rules = f.read()
except:
pass
Expand Down Expand Up @@ -356,8 +362,7 @@ def checkNetwork():
if Settings.NetMan.APMode not in [-1,100]:
if lastdisconntime!=0:
if (time.time()-lastdisconntime)>int(Settings.NetMan.APModeTime):
from linux_network import AP_start
AP_start(Settings.NetMan.WifiDevNum)
Network.AP_start(Settings.NetMan.WifiDevNum)
lastdisconntime = 0 # forgive last disconnect time
lastaptime = time.time()
else:
Expand All @@ -367,8 +372,7 @@ def checkNetwork():
if Settings.NetMan.APMode not in [-1,100]:
if lastaptime!=0:
if (time.time()-lastaptime)>int(Settings.NetMan.APStopTime):
from linux_network import AP_stop
AP_stop(Settings.NetMan.WifiDevNum)
Network.AP_stop(Settings.NetMan.WifiDevNum)
lastaptime = 0
lastdisconntime = 0 # forgive last disconnect time
except Exception as e:
Expand Down Expand Up @@ -419,7 +423,8 @@ def initprogram():
timer2s = timer100ms
timer30s = timer100ms
init_ok = True
except:
except Exception as e:
print(e)
init_ok = False
t = threading.Thread(target=mainloop) # starting sensors and background functions
t.daemon = True
Expand Down
32 changes: 16 additions & 16 deletions Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def savesettings():
global Settings, settingsfile
success = 1
try:
f = open(settingsfile,'w')
f = open(settingsfile,'w',encoding="utf8")
settingjson = jsonpickle.encode(Settings)
f.write(settingjson)
except Exception as e:
Expand Down Expand Up @@ -134,7 +134,7 @@ def savetasks():
tasktoinit.append(T)
except Exception as e:
pass
f = open(tasksfile,'w')
f = open(tasksfile,'w',encoding="utf8")
settingjson = jsonpickle.encode(Tasks_Shadow)
f.write(settingjson)
for t in tasktoinit:
Expand All @@ -150,13 +150,13 @@ def loadsettings():
global Settings, settingsfile, AdvSettings, advsettingsfile
success = 1
try:
f = open(settingsfile)
f = open(settingsfile,encoding="utf8")
settingjson = f.read()
Settings = jsonpickle.decode(settingjson)
except:
success = 0
try:
f = open(advsettingsfile)
f = open(advsettingsfile,encoding="utf8")
settingjson = f.read()
AdvSettings = jsonpickle.decode(settingjson)
except:
Expand All @@ -168,7 +168,7 @@ def loadtasks():
success = 1
tTasks = [False]
try:
f = open(tasksfile)
f = open(tasksfile,encoding="utf8")
settingjson = f.read()
tTasks = jsonpickle.decode(settingjson)
Tasks = tTasks
Expand All @@ -180,7 +180,7 @@ def savecontrollers():
global Controllers, controllersfile
success = 1
try:
f = open(controllersfile,'w')
f = open(controllersfile,'w',encoding="utf8")
settingjson = jsonpickle.encode(Controllers,max_depth=2) # Restrict Jsonpickle to encode vars at first object
f.write(settingjson)
except:
Expand All @@ -191,7 +191,7 @@ def loadcontrollers():
global Controllers, controllersfile
success = 1
try:
f = open(controllersfile)
f = open(controllersfile,encoding="utf8")
settingjson = f.read()
Controllers = jsonpickle.decode(settingjson)
except Exception as e:
Expand All @@ -203,7 +203,7 @@ def savepinout():
global Pinout, pinoutfile
success = 1
try:
f = open(pinoutfile,'w')
f = open(pinoutfile,'w',encoding="utf8")
settingjson = jsonpickle.encode(Pinout)
f.write(settingjson)
except:
Expand All @@ -214,7 +214,7 @@ def loadpinout():
global Pinout, pinoutfile
success = 1
try:
f = open(pinoutfile)
f = open(pinoutfile,encoding="utf8")
settingjson = f.read()
Pinout = jsonpickle.decode(settingjson)
except:
Expand All @@ -225,13 +225,13 @@ def loadnetsettings():
global NetworkDevices, NetMan, netdevfile, netmanfile
success = 1
try:
f = open(netdevfile)
f = open(netdevfile,encoding="utf8")
settingjson = f.read()
NetworkDevices = jsonpickle.decode(settingjson)
except:
success = 0
try:
f = open(netmanfile)
f = open(netmanfile,encoding="utf8")
settingjson = f.read()
NetMan = jsonpickle.decode(settingjson)
except:
Expand All @@ -242,13 +242,13 @@ def savenetsettings():
global NetworkDevices, NetMan, netdevfile, netmanfile
success = 1
try:
f = open(netdevfile,"w")
f = open(netdevfile,"w",encoding="utf8")
settingjson = jsonpickle.encode(NetworkDevices)
f.write(settingjson)
except:
success = 0
try:
f = open(netmanfile,"w")
f = open(netmanfile,"w",encoding="utf8")
settingjson = jsonpickle.encode(NetMan)
f.write(settingjson)
except:
Expand All @@ -259,7 +259,7 @@ def saveadvsettings():
global AdvSettings, advsettingsfile
success = 1
try:
f = open(advsettingsfile,'w')
f = open(advsettingsfile,'w',encoding="utf8")
settingjson = jsonpickle.encode(AdvSettings)
f.write(settingjson)
except:
Expand All @@ -270,7 +270,7 @@ def savenotifiers():
global Notifiers, notifiersfile
success = 1
try:
f = open(notifiersfile,'w')
f = open(notifiersfile,'w',encoding="utf8")
settingjson = jsonpickle.encode(Notifiers,max_depth=2) # Restrict Jsonpickle to encode vars at first object
f.write(settingjson)
except:
Expand All @@ -281,7 +281,7 @@ def loadnotifiers():
global Notifiers, notifiersfile
success = 1
try:
f = open(notifiersfile)
f = open(notifiersfile,encoding="utf8")
settingjson = f.read()
Notifiers = jsonpickle.decode(settingjson)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion _C009_FHEM.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import controller
import rpieGlobals
import Settings
import linux_os as OS
import os_os as OS
import misc
import urllib.request
import threading
Expand Down
4 changes: 2 additions & 2 deletions _C013_ESPEasyP2P.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import struct
import threading
try:
import linux_os as OS
import os_os as OS
except:
print("Linux OS function import error")
print("OS function import error")

class Controller(controller.ControllerProto):
CONTROLLER_ID = 13
Expand Down
2 changes: 1 addition & 1 deletion _C016_DBStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import webserver
import datetime
import Settings
import linux_os as OS
import os_os as OS
import time

_lastRSSIval = 0
Expand Down
61 changes: 59 additions & 2 deletions _P001_Switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def plugin_exit(self):
def plugin_init(self,enableplugin=None):
plugin.PluginProto.plugin_init(self,enableplugin)
self.decimals[0]=0
self.decimals[1]=0
self.decimals[2]=0
self.initialized = False
try:
gpioinit = gpios.HWPorts is not None
Expand Down Expand Up @@ -87,6 +89,18 @@ def plugin_init(self,enableplugin=None):
gpios.HWPorts.add_event_detect(int(self.taskdevicepin[0]),int(self.taskdevicepluginconfig[3]),self.p001_handler)
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"Event registered to pin "+str(self.taskdevicepin[0]))
self.timer100ms = False
self._lastdataservetime = 0
if self.taskdevicepluginconfig[4]>0:
self.valuecount = 3
self.uservar[1]=-1
if len(self.valuenames)<3:
self.valuenames.append("")
self.valuenames.append("")
if self.valuenames[1]=="":
self.valuenames[1]="Longpress"
self.valuenames[2]="PressedTime"
else:
self.valuecount = 1
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Event can not be added, register backup timer "+str(e))
self.timer100ms = True
Expand All @@ -108,6 +122,10 @@ def webform_load(self):
webserver.addFormNote("Only valid if event detection activated")
except:
pass
options = ["None","1-->0","0-->1","Both"]
optionvalues = [0,1,2,3]
webserver.addFormSelector("Longpress detection","p001_long",len(optionvalues),options,optionvalues,None,self.taskdevicepluginconfig[4])
webserver.addFormNumericBox("Longpress min time (ms)","p001_longtime",self.taskdevicepluginconfig[5],0,10000)
return True

def webform_save(self,params):
Expand Down Expand Up @@ -135,18 +153,33 @@ def webform_save(self,params):
self.taskdevicepluginconfig[2] = int(par)
except:
self.taskdevicepluginconfig[2] = 0
par = webserver.arg("p001_det",params)
if prevval != self.taskdevicepluginconfig[2]:
changed = True

prevval = self.taskdevicepluginconfig[3]
par = webserver.arg("p001_det",params)
try:
self.taskdevicepluginconfig[3] = int(par)
except:
self.taskdevicepluginconfig[3] = gpios.BOTH
if prevval != self.taskdevicepluginconfig[3]:
changed = True

prevval = self.taskdevicepluginconfig[4]
par = webserver.arg("p001_long",params)
try:
self.taskdevicepluginconfig[4] = int(par)
except:
self.taskdevicepluginconfig[4] = 0
if prevval != self.taskdevicepluginconfig[4]:
changed = True

par = webserver.arg("p001_longtime",params)
try:
self.taskdevicepluginconfig[5] = int(par)
except:
self.taskdevicepluginconfig[5] = 1000

if changed:
self.plugin_init()
return True
Expand Down Expand Up @@ -181,7 +214,31 @@ def pinstate_check(self,postcheck=False):
if inval==1: # if high
outval = 1-int(prevval) # negate
if prevval != outval:
self.set_value(1,int(outval),True)
if self.taskdevicepluginconfig[4]>0 and self._lastdataservetime>0: # check for longpress
docheck = False
if self.taskdevicepluginconfig[4]==3:
docheck = True
elif self.taskdevicepluginconfig[4]==1 and int(prevval)==1 and int(outval)==0:
docheck = True
elif self.taskdevicepluginconfig[4]==2 and int(prevval)==0 and int(outval)==1:
docheck = True
self.set_value(1,int(outval),False)
diff = (rpieTime.millis()-self._lastdataservetime)
dolong = False
if docheck:
if diff > self.taskdevicepluginconfig[5]:
dolong = True
if dolong:
self.set_value(2,1,False)
else:
self.set_value(2,0,False)
if docheck:
self.set_value(3,diff,False)
else:
self.set_value(3,0,False)
self.plugin_senddata()
else:
self.set_value(1,int(outval),True)
self._lastdataservetime = rpieTime.millis()
if self.taskdevicepluginconfig[2]>0 and self.timer100ms:
time.sleep(self.taskdevicepluginconfig[1]/1000) # force debounce if not event driven detection
Expand Down
2 changes: 1 addition & 1 deletion _P026_Sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import webserver
import rpieGlobals
import rpieTime
import linux_os as OS
import os_os as OS
import misc

class Plugin(plugin.PluginProto):
Expand Down
7 changes: 6 additions & 1 deletion _P523_DRingCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ def plugin_write(self,cmd):
self.jami.endCall()
except Exception as e:
print(e)

elif subcmd=="contactlist":
try:
clist = self.jami.getContactList()
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"Jami contacts: "+str(clist))
except Exception as e:
print(e)
res = True
else:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Jami is not initialized")
Expand Down
4 changes: 2 additions & 2 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
import misc
import Settings
import linux_os as OS
import os_os as OS
import time
import os
import signal
Expand All @@ -16,7 +16,7 @@
from datetime import datetime
import rpieTime
import time
import linux_network as Network
import os_network as Network
import socket
import urllib.request
import threading
Expand Down
Loading

0 comments on commit 96f5755

Please sign in to comment.