Skip to content

Commit 96f5755

Browse files
committed
Adding alternative OS support, P001 longpress, Jamibridge fixes
1 parent 3d7b64f commit 96f5755

19 files changed

+733
-70
lines changed

RPIEasy.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ def hardwareInit():
6969
if opv:
7070
pinout = opv["pins"]
7171
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,str(opv["name"])+" "+str(opv["pins"])+" pins")
72+
if rpieGlobals.osinuse=="windows":
73+
print("Windows OS is not supported")
74+
import win_os as OS
75+
import win_network as Network
76+
Settings.NetMan = Network.NetworkManager()
77+
Settings.SoundSystem["usable"]=False
7278
hwtype = rpieGlobals.ossubtype
7379
if pinout=="0":
7480
try:
@@ -119,7 +125,7 @@ def PluginInit():
119125
for fname in filenames:
120126
tarr = [0,0,0]
121127
tarr[0] = fname
122-
with open(fname,"r") as fcont:
128+
with open(fname,"r",encoding="utf8") as fcont:
123129
for line in fcont:
124130
if "PLUGIN_ID" in line:
125131
tarr[1] = line[line.find("=")+1:].strip().replace('"',"")
@@ -141,7 +147,7 @@ def CPluginInit():
141147
for fname in filenames:
142148
tarr = [0,0,0]
143149
tarr[0] = fname
144-
with open(fname,"r") as fcont:
150+
with open(fname,"r",encoding="utf8") as fcont:
145151
for line in fcont:
146152
if "CONTROLLER_ID" in line:
147153
tarr[1] = line[line.find("=")+1:].strip().replace('"',"")
@@ -187,7 +193,7 @@ def NPluginInit():
187193
for fname in filenames:
188194
tarr = [0,0,0]
189195
tarr[0] = fname
190-
with open(fname,"r") as fcont:
196+
with open(fname,"r",encoding="utf8") as fcont:
191197
for line in fcont:
192198
if "NPLUGIN_ID" in line:
193199
tarr[1] = line[line.find("=")+1:].strip().replace('"',"")
@@ -214,7 +220,7 @@ def NPluginInit():
214220
def RulesInit():
215221
rules = ""
216222
try:
217-
with open(rpieGlobals.FILE_RULES,'r') as f:
223+
with open(rpieGlobals.FILE_RULES,'r',encoding="utf8") as f:
218224
rules = f.read()
219225
except:
220226
pass
@@ -356,8 +362,7 @@ def checkNetwork():
356362
if Settings.NetMan.APMode not in [-1,100]:
357363
if lastdisconntime!=0:
358364
if (time.time()-lastdisconntime)>int(Settings.NetMan.APModeTime):
359-
from linux_network import AP_start
360-
AP_start(Settings.NetMan.WifiDevNum)
365+
Network.AP_start(Settings.NetMan.WifiDevNum)
361366
lastdisconntime = 0 # forgive last disconnect time
362367
lastaptime = time.time()
363368
else:
@@ -367,8 +372,7 @@ def checkNetwork():
367372
if Settings.NetMan.APMode not in [-1,100]:
368373
if lastaptime!=0:
369374
if (time.time()-lastaptime)>int(Settings.NetMan.APStopTime):
370-
from linux_network import AP_stop
371-
AP_stop(Settings.NetMan.WifiDevNum)
375+
Network.AP_stop(Settings.NetMan.WifiDevNum)
372376
lastaptime = 0
373377
lastdisconntime = 0 # forgive last disconnect time
374378
except Exception as e:
@@ -419,7 +423,8 @@ def initprogram():
419423
timer2s = timer100ms
420424
timer30s = timer100ms
421425
init_ok = True
422-
except:
426+
except Exception as e:
427+
print(e)
423428
init_ok = False
424429
t = threading.Thread(target=mainloop) # starting sensors and background functions
425430
t.daemon = True

Settings.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def savesettings():
105105
global Settings, settingsfile
106106
success = 1
107107
try:
108-
f = open(settingsfile,'w')
108+
f = open(settingsfile,'w',encoding="utf8")
109109
settingjson = jsonpickle.encode(Settings)
110110
f.write(settingjson)
111111
except Exception as e:
@@ -134,7 +134,7 @@ def savetasks():
134134
tasktoinit.append(T)
135135
except Exception as e:
136136
pass
137-
f = open(tasksfile,'w')
137+
f = open(tasksfile,'w',encoding="utf8")
138138
settingjson = jsonpickle.encode(Tasks_Shadow)
139139
f.write(settingjson)
140140
for t in tasktoinit:
@@ -150,13 +150,13 @@ def loadsettings():
150150
global Settings, settingsfile, AdvSettings, advsettingsfile
151151
success = 1
152152
try:
153-
f = open(settingsfile)
153+
f = open(settingsfile,encoding="utf8")
154154
settingjson = f.read()
155155
Settings = jsonpickle.decode(settingjson)
156156
except:
157157
success = 0
158158
try:
159-
f = open(advsettingsfile)
159+
f = open(advsettingsfile,encoding="utf8")
160160
settingjson = f.read()
161161
AdvSettings = jsonpickle.decode(settingjson)
162162
except:
@@ -168,7 +168,7 @@ def loadtasks():
168168
success = 1
169169
tTasks = [False]
170170
try:
171-
f = open(tasksfile)
171+
f = open(tasksfile,encoding="utf8")
172172
settingjson = f.read()
173173
tTasks = jsonpickle.decode(settingjson)
174174
Tasks = tTasks
@@ -180,7 +180,7 @@ def savecontrollers():
180180
global Controllers, controllersfile
181181
success = 1
182182
try:
183-
f = open(controllersfile,'w')
183+
f = open(controllersfile,'w',encoding="utf8")
184184
settingjson = jsonpickle.encode(Controllers,max_depth=2) # Restrict Jsonpickle to encode vars at first object
185185
f.write(settingjson)
186186
except:
@@ -191,7 +191,7 @@ def loadcontrollers():
191191
global Controllers, controllersfile
192192
success = 1
193193
try:
194-
f = open(controllersfile)
194+
f = open(controllersfile,encoding="utf8")
195195
settingjson = f.read()
196196
Controllers = jsonpickle.decode(settingjson)
197197
except Exception as e:
@@ -203,7 +203,7 @@ def savepinout():
203203
global Pinout, pinoutfile
204204
success = 1
205205
try:
206-
f = open(pinoutfile,'w')
206+
f = open(pinoutfile,'w',encoding="utf8")
207207
settingjson = jsonpickle.encode(Pinout)
208208
f.write(settingjson)
209209
except:
@@ -214,7 +214,7 @@ def loadpinout():
214214
global Pinout, pinoutfile
215215
success = 1
216216
try:
217-
f = open(pinoutfile)
217+
f = open(pinoutfile,encoding="utf8")
218218
settingjson = f.read()
219219
Pinout = jsonpickle.decode(settingjson)
220220
except:
@@ -225,13 +225,13 @@ def loadnetsettings():
225225
global NetworkDevices, NetMan, netdevfile, netmanfile
226226
success = 1
227227
try:
228-
f = open(netdevfile)
228+
f = open(netdevfile,encoding="utf8")
229229
settingjson = f.read()
230230
NetworkDevices = jsonpickle.decode(settingjson)
231231
except:
232232
success = 0
233233
try:
234-
f = open(netmanfile)
234+
f = open(netmanfile,encoding="utf8")
235235
settingjson = f.read()
236236
NetMan = jsonpickle.decode(settingjson)
237237
except:
@@ -242,13 +242,13 @@ def savenetsettings():
242242
global NetworkDevices, NetMan, netdevfile, netmanfile
243243
success = 1
244244
try:
245-
f = open(netdevfile,"w")
245+
f = open(netdevfile,"w",encoding="utf8")
246246
settingjson = jsonpickle.encode(NetworkDevices)
247247
f.write(settingjson)
248248
except:
249249
success = 0
250250
try:
251-
f = open(netmanfile,"w")
251+
f = open(netmanfile,"w",encoding="utf8")
252252
settingjson = jsonpickle.encode(NetMan)
253253
f.write(settingjson)
254254
except:
@@ -259,7 +259,7 @@ def saveadvsettings():
259259
global AdvSettings, advsettingsfile
260260
success = 1
261261
try:
262-
f = open(advsettingsfile,'w')
262+
f = open(advsettingsfile,'w',encoding="utf8")
263263
settingjson = jsonpickle.encode(AdvSettings)
264264
f.write(settingjson)
265265
except:
@@ -270,7 +270,7 @@ def savenotifiers():
270270
global Notifiers, notifiersfile
271271
success = 1
272272
try:
273-
f = open(notifiersfile,'w')
273+
f = open(notifiersfile,'w',encoding="utf8")
274274
settingjson = jsonpickle.encode(Notifiers,max_depth=2) # Restrict Jsonpickle to encode vars at first object
275275
f.write(settingjson)
276276
except:
@@ -281,7 +281,7 @@ def loadnotifiers():
281281
global Notifiers, notifiersfile
282282
success = 1
283283
try:
284-
f = open(notifiersfile)
284+
f = open(notifiersfile,encoding="utf8")
285285
settingjson = f.read()
286286
Notifiers = jsonpickle.decode(settingjson)
287287
except Exception as e:

_C009_FHEM.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import controller
1111
import rpieGlobals
1212
import Settings
13-
import linux_os as OS
13+
import os_os as OS
1414
import misc
1515
import urllib.request
1616
import threading

_C013_ESPEasyP2P.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import struct
2121
import threading
2222
try:
23-
import linux_os as OS
23+
import os_os as OS
2424
except:
25-
print("Linux OS function import error")
25+
print("OS function import error")
2626

2727
class Controller(controller.ControllerProto):
2828
CONTROLLER_ID = 13

_C016_DBStore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import webserver
1414
import datetime
1515
import Settings
16-
import linux_os as OS
16+
import os_os as OS
1717
import time
1818

1919
_lastRSSIval = 0

_P001_Switch.py

+59-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def plugin_exit(self):
6060
def plugin_init(self,enableplugin=None):
6161
plugin.PluginProto.plugin_init(self,enableplugin)
6262
self.decimals[0]=0
63+
self.decimals[1]=0
64+
self.decimals[2]=0
6365
self.initialized = False
6466
try:
6567
gpioinit = gpios.HWPorts is not None
@@ -87,6 +89,18 @@ def plugin_init(self,enableplugin=None):
8789
gpios.HWPorts.add_event_detect(int(self.taskdevicepin[0]),int(self.taskdevicepluginconfig[3]),self.p001_handler)
8890
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"Event registered to pin "+str(self.taskdevicepin[0]))
8991
self.timer100ms = False
92+
self._lastdataservetime = 0
93+
if self.taskdevicepluginconfig[4]>0:
94+
self.valuecount = 3
95+
self.uservar[1]=-1
96+
if len(self.valuenames)<3:
97+
self.valuenames.append("")
98+
self.valuenames.append("")
99+
if self.valuenames[1]=="":
100+
self.valuenames[1]="Longpress"
101+
self.valuenames[2]="PressedTime"
102+
else:
103+
self.valuecount = 1
90104
except Exception as e:
91105
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Event can not be added, register backup timer "+str(e))
92106
self.timer100ms = True
@@ -108,6 +122,10 @@ def webform_load(self):
108122
webserver.addFormNote("Only valid if event detection activated")
109123
except:
110124
pass
125+
options = ["None","1-->0","0-->1","Both"]
126+
optionvalues = [0,1,2,3]
127+
webserver.addFormSelector("Longpress detection","p001_long",len(optionvalues),options,optionvalues,None,self.taskdevicepluginconfig[4])
128+
webserver.addFormNumericBox("Longpress min time (ms)","p001_longtime",self.taskdevicepluginconfig[5],0,10000)
111129
return True
112130

113131
def webform_save(self,params):
@@ -135,18 +153,33 @@ def webform_save(self,params):
135153
self.taskdevicepluginconfig[2] = int(par)
136154
except:
137155
self.taskdevicepluginconfig[2] = 0
138-
par = webserver.arg("p001_det",params)
139156
if prevval != self.taskdevicepluginconfig[2]:
140157
changed = True
141158

142159
prevval = self.taskdevicepluginconfig[3]
160+
par = webserver.arg("p001_det",params)
143161
try:
144162
self.taskdevicepluginconfig[3] = int(par)
145163
except:
146164
self.taskdevicepluginconfig[3] = gpios.BOTH
147165
if prevval != self.taskdevicepluginconfig[3]:
148166
changed = True
149167

168+
prevval = self.taskdevicepluginconfig[4]
169+
par = webserver.arg("p001_long",params)
170+
try:
171+
self.taskdevicepluginconfig[4] = int(par)
172+
except:
173+
self.taskdevicepluginconfig[4] = 0
174+
if prevval != self.taskdevicepluginconfig[4]:
175+
changed = True
176+
177+
par = webserver.arg("p001_longtime",params)
178+
try:
179+
self.taskdevicepluginconfig[5] = int(par)
180+
except:
181+
self.taskdevicepluginconfig[5] = 1000
182+
150183
if changed:
151184
self.plugin_init()
152185
return True
@@ -181,7 +214,31 @@ def pinstate_check(self,postcheck=False):
181214
if inval==1: # if high
182215
outval = 1-int(prevval) # negate
183216
if prevval != outval:
184-
self.set_value(1,int(outval),True)
217+
if self.taskdevicepluginconfig[4]>0 and self._lastdataservetime>0: # check for longpress
218+
docheck = False
219+
if self.taskdevicepluginconfig[4]==3:
220+
docheck = True
221+
elif self.taskdevicepluginconfig[4]==1 and int(prevval)==1 and int(outval)==0:
222+
docheck = True
223+
elif self.taskdevicepluginconfig[4]==2 and int(prevval)==0 and int(outval)==1:
224+
docheck = True
225+
self.set_value(1,int(outval),False)
226+
diff = (rpieTime.millis()-self._lastdataservetime)
227+
dolong = False
228+
if docheck:
229+
if diff > self.taskdevicepluginconfig[5]:
230+
dolong = True
231+
if dolong:
232+
self.set_value(2,1,False)
233+
else:
234+
self.set_value(2,0,False)
235+
if docheck:
236+
self.set_value(3,diff,False)
237+
else:
238+
self.set_value(3,0,False)
239+
self.plugin_senddata()
240+
else:
241+
self.set_value(1,int(outval),True)
185242
self._lastdataservetime = rpieTime.millis()
186243
if self.taskdevicepluginconfig[2]>0 and self.timer100ms:
187244
time.sleep(self.taskdevicepluginconfig[1]/1000) # force debounce if not event driven detection

_P026_Sysinfo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import webserver
1010
import rpieGlobals
1111
import rpieTime
12-
import linux_os as OS
12+
import os_os as OS
1313
import misc
1414

1515
class Plugin(plugin.PluginProto):

_P523_DRingCtrl.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ def plugin_write(self,cmd):
248248
self.jami.endCall()
249249
except Exception as e:
250250
print(e)
251-
251+
elif subcmd=="contactlist":
252+
try:
253+
clist = self.jami.getContactList()
254+
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"Jami contacts: "+str(clist))
255+
except Exception as e:
256+
print(e)
252257
res = True
253258
else:
254259
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Jami is not initialized")

commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
import misc
99
import Settings
10-
import linux_os as OS
10+
import os_os as OS
1111
import time
1212
import os
1313
import signal
@@ -16,7 +16,7 @@
1616
from datetime import datetime
1717
import rpieTime
1818
import time
19-
import linux_network as Network
19+
import os_network as Network
2020
import socket
2121
import urllib.request
2222
import threading

0 commit comments

Comments
 (0)