Skip to content

Commit

Permalink
Adding RockPiS hw support
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Dec 13, 2020
1 parent f19af65 commit 4fd7fcd
Show file tree
Hide file tree
Showing 13 changed files with 2,618 additions and 244 deletions.
8 changes: 6 additions & 2 deletions RPIEasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def hardwareInit():
if rpv:
pinout = rpv["pins"]
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,str(rpv["name"])+" "+str(rpv["pins"])+" pins")
elif rpieGlobals.ossubtype == 9: # rockpi
ropv = OS.getRockPIVer()
if ropv:
pinout = ropv["pins"]
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,str(ropv["name"])+" "+str(ropv["pins"])+" pins")
elif rpieGlobals.ossubtype == 3: # opi
opv = OS.getarmbianinfo()
if opv:
Expand Down Expand Up @@ -96,7 +101,7 @@ def hardwareInit():
gpios.preinit(hwtype) # create HWPorts variable
except Exception as e:
print("init",e)
if (("40" in pinout) and (len(Settings.Pinout)<41)) or (("26" in pinout) and (len(Settings.Pinout)<27)) or (pinout=="ftdi" and len(Settings.Pinout)<1):
if (("40" in pinout) and (len(Settings.Pinout)<41)) or (("26" in pinout) and (len(Settings.Pinout)!=27) and (len(Settings.Pinout)!=53) ) or (pinout=="ftdi" and len(Settings.Pinout)<1):
print("Creating new pinout")
try:
gpios.HWPorts.createpinout(pinout)
Expand All @@ -106,7 +111,6 @@ def hardwareInit():
try:
gpios.HWPorts.readconfig()
except Exception as e:
# print(e) # debug
perror = True
if perror or len(Settings.Pinout)<1:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Your GPIO can not be identified!")
Expand Down
9 changes: 4 additions & 5 deletions _P001_Switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ def __init__(self,taskindex): # general init
self.inverselogicoption = True
self.recdataoption = False

def __del__(self):
def plugin_exit(self):
if self.enabled and self.timer100ms==False:
try:
gpios.HWPorts.remove_event_detect(int(self.taskdevicepin[0]))
except:
pass

def plugin_exit(self):
self.__del__()
return True

def plugin_init(self,enableplugin=None):
Expand All @@ -78,10 +75,11 @@ def plugin_init(self,enableplugin=None):
except:
self.taskdevicepluginconfig[3] = gpios.BOTH
try:
self.__del__()
self.plugin_exit()
if self.taskdevicepluginconfig[0]:
misc.addLog(rpieGlobals.LOG_LEVEL_INFO,"Registering 10/sec timer as asked")
self.timer100ms = True
self.initialized = True
return True
if int(self.taskdevicepluginconfig[1])>0:
gpios.HWPorts.add_event_detect(int(self.taskdevicepin[0]),int(self.taskdevicepluginconfig[3]),self.p001_handler,int(self.taskdevicepluginconfig[1]))
Expand All @@ -90,6 +88,7 @@ def plugin_init(self,enableplugin=None):
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
Expand Down
213 changes: 134 additions & 79 deletions _P002_PiAnalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Based on the Pi_Analog library:
# https://github.com/simonmonk/pi_analog
#
# Modified to support RockPIS integrated ADC_IN
#
# Copyright (C) 2019 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
import plugin
Expand All @@ -14,7 +16,19 @@
import time
import misc
import webserver
import lib.pi_analog.PiAnalog as Analog
analogpins = []
realanalog = False
try:
import gpios
analogpins = gpios.HWPorts.getanaloglist()
realanalog = True
except:
pass
try:
import lib.pi_analog.PiAnalog as Analog
rpiok = True
except:
rpiok = False

class Plugin(plugin.PluginProto):
PLUGIN_ID = 2
Expand All @@ -23,7 +37,10 @@ class Plugin(plugin.PluginProto):

def __init__(self,taskindex): # general init
plugin.PluginProto.__init__(self,taskindex)
self.dtype = rpieGlobals.DEVICE_TYPE_DUAL
if realanalog:
self.dtype = rpieGlobals.DEVICE_TYPE_DUMMY
else:
self.dtype = rpieGlobals.DEVICE_TYPE_DUAL
self.vtype = rpieGlobals.SENSOR_TYPE_SINGLE
self.valuecount = 1
self.senddataoption = True
Expand All @@ -36,94 +53,120 @@ def __init__(self,taskindex): # general init
self.formulaoption = True

def webform_load(self): # create html page for settings
webserver.addFormNote("Pin1 is A, Pin2 is B, for wiring, see <a href='https://github.com/simonmonk/pi_analog'>https://github.com/simonmonk/pi_analog</a>")
choice0 = self.taskdevicepluginconfig[0]
options = ["Analog","Resistance","Thermistor"]
optionvalues = [0,1,2]
webserver.addFormSelector("Result Type","p002_type",len(options),options,optionvalues,None,choice0)
webserver.addFormFloatNumberBox("C1 capacitor", "p002_c1", self.taskdevicepluginconfig[1], 0, 1000000.0)
webserver.addUnit("uF")
webserver.addFormNumericBox("R1 resistor","p002_r1",self.taskdevicepluginconfig[2])
webserver.addUnit("Ohm")
webserver.addFormFloatNumberBox("Vt voltage (digital HIGH level)", "p002_vt", self.taskdevicepluginconfig[3], 0, 3.3)
webserver.addUnit("V")
webserver.addFormNote("Settings below are only valid for thermistor type!")
webserver.addFormNumericBox("Thermistor resistance","p002_tr",self.taskdevicepluginconfig[4])
webserver.addUnit("Ohm")
webserver.addFormNumericBox("Thermistor Beta","p002_tb",self.taskdevicepluginconfig[5])
global analogpins,realanalog,rpiok
if realanalog:
self.taskdevicepluginconfig[0] = 0
webserver.addHtml("<tr><td>Analog input pin:<td>")
webserver.addSelector_Head("p002_ain",False)
for d in range(len(analogpins)):
webserver.addSelector_Item(analogpins[d][1],analogpins[d][0],(self.taskdevicepluginconfig[1]==analogpins[d][0]),False)
webserver.addSelector_Foot()
elif rpiok:
webserver.addFormNote("Pin1 is A, Pin2 is B, for wiring, see <a href='https://github.com/simonmonk/pi_analog'>https://github.com/simonmonk/pi_analog</a>")
choice0 = self.taskdevicepluginconfig[0]
options = ["Analog","Resistance","Thermistor"]
optionvalues = [0,1,2]
webserver.addFormSelector("Result Type","p002_type",len(options),options,optionvalues,None,choice0)
webserver.addFormFloatNumberBox("C1 capacitor", "p002_c1", self.taskdevicepluginconfig[1], 0, 1000000.0)
webserver.addUnit("uF")
webserver.addFormNumericBox("R1 resistor","p002_r1",self.taskdevicepluginconfig[2])
webserver.addUnit("Ohm")
webserver.addFormFloatNumberBox("Vt voltage (digital HIGH level)", "p002_vt", self.taskdevicepluginconfig[3], 0, 3.3)
webserver.addUnit("V")
webserver.addFormNote("Settings below are only valid for thermistor type!")
webserver.addFormNumericBox("Thermistor resistance","p002_tr",self.taskdevicepluginconfig[4])
webserver.addUnit("Ohm")
webserver.addFormNumericBox("Thermistor Beta","p002_tb",self.taskdevicepluginconfig[5])
return True

def webform_save(self,params): # process settings post reply
par1 = webserver.arg("p002_type",params)
try:
self.taskdevicepluginconfig[0] = int(par1)
except:
global realanalog,rpiok
if realanalog:
self.taskdevicepluginconfig[0] = 0
par1 = webserver.arg("p002_c1",params)
try:
self.taskdevicepluginconfig[1] = float(par1)
except:
self.taskdevicepluginconfig[1] = 0.33
par1 = webserver.arg("p002_r1",params)
try:
self.taskdevicepluginconfig[2] = int(par1)
except:
self.taskdevicepluginconfig[2] = 10000
par1 = webserver.arg("p002_vt",params)
try:
self.taskdevicepluginconfig[3] = float(par1)
except:
self.taskdevicepluginconfig[3] = 1.35
par1 = webserver.arg("p002_tr",params)
try:
self.taskdevicepluginconfig[4] = int(par1)
except:
self.taskdevicepluginconfig[4] = 1000
par1 = webserver.arg("p002_tb",params)
try:
self.taskdevicepluginconfig[5] = int(par1)
except:
self.taskdevicepluginconfig[5] = 3800
self.plugin_init()
par1 = webserver.arg("p002_ain",params)
try:
self.taskdevicepluginconfig[1] = int(par1)
except:
self.taskdevicepluginconfig[1] = 0
elif rpiok:
par1 = webserver.arg("p002_type",params)
try:
self.taskdevicepluginconfig[0] = int(par1)
except:
self.taskdevicepluginconfig[0] = 0
par1 = webserver.arg("p002_c1",params)
try:
self.taskdevicepluginconfig[1] = float(par1)
except:
self.taskdevicepluginconfig[1] = 0.33
par1 = webserver.arg("p002_r1",params)
try:
self.taskdevicepluginconfig[2] = int(par1)
except:
self.taskdevicepluginconfig[2] = 10000
par1 = webserver.arg("p002_vt",params)
try:
self.taskdevicepluginconfig[3] = float(par1)
except:
self.taskdevicepluginconfig[3] = 1.35
par1 = webserver.arg("p002_tr",params)
try:
self.taskdevicepluginconfig[4] = int(par1)
except:
self.taskdevicepluginconfig[4] = 1000
par1 = webserver.arg("p002_tb",params)
try:
self.taskdevicepluginconfig[5] = int(par1)
except:
self.taskdevicepluginconfig[5] = 3800
self.plugin_init()
return True

def plugin_init(self,enableplugin=None):
global realanalog,rpiok
plugin.PluginProto.plugin_init(self,enableplugin)
self.decimals[0]=0
self.initialized=False
try:
if str(self.taskdevicepluginconfig[1])=="" or str(self.taskdevicepluginconfig[1])=="0":
self.taskdevicepluginconfig[1]=0.33
except:
self.taskdevicepluginconfig[1]=0.33
try:
if str(self.taskdevicepluginconfig[2])=="" or str(self.taskdevicepluginconfig[2])=="0":
self.taskdevicepluginconfig[2]=10000
except:
self.taskdevicepluginconfig[2]=10000
try:
if str(self.taskdevicepluginconfig[3])=="" or str(self.taskdevicepluginconfig[3])=="0":
self.taskdevicepluginconfig[3]=1.35
except:
self.taskdevicepluginconfig[3]=1.35
try:
if str(self.taskdevicepluginconfig[4])=="" or str(self.taskdevicepluginconfig[4])=="0":
self.taskdevicepluginconfig[4]=1000
except:
self.taskdevicepluginconfig[4]=1000
try:
if str(self.taskdevicepluginconfig[5])=="" or str(self.taskdevicepluginconfig[5])=="0":
self.taskdevicepluginconfig[5]=3800
except:
self.taskdevicepluginconfig[5]=3800
if self.enabled and self.taskdevicepin[0]>=0 and self.taskdevicepin[1]>=0:
self.readinprogress = False
if realanalog:
try:
self.adc = virtADC(int(self.taskdevicepluginconfig[1]))
self.initialized = True
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"Analog init error: "+str(e))
elif rpiok:
try:
self.adc = Analog.PiAnalog(gpioinit=False,a_pin=self.taskdevicepin[0],b_pin=self.taskdevicepin[1],C=self.taskdevicepluginconfig[1],R1=self.taskdevicepluginconfig[2],Vt=self.taskdevicepluginconfig[3])
self.initialized = True
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"PiAnalog init error: "+str(e))

if str(self.taskdevicepluginconfig[1])=="" or str(self.taskdevicepluginconfig[1])=="0":
self.taskdevicepluginconfig[1]=0.33
except:
self.taskdevicepluginconfig[1]=0.33
try:
if str(self.taskdevicepluginconfig[2])=="" or str(self.taskdevicepluginconfig[2])=="0":
self.taskdevicepluginconfig[2]=10000
except:
self.taskdevicepluginconfig[2]=10000
try:
if str(self.taskdevicepluginconfig[3])=="" or str(self.taskdevicepluginconfig[3])=="0":
self.taskdevicepluginconfig[3]=1.35
except:
self.taskdevicepluginconfig[3]=1.35
try:
if str(self.taskdevicepluginconfig[4])=="" or str(self.taskdevicepluginconfig[4])=="0":
self.taskdevicepluginconfig[4]=1000
except:
self.taskdevicepluginconfig[4]=1000
try:
if str(self.taskdevicepluginconfig[5])=="" or str(self.taskdevicepluginconfig[5])=="0":
self.taskdevicepluginconfig[5]=3800
except:
self.taskdevicepluginconfig[5]=3800
if self.enabled and self.taskdevicepin[0]>=0 and self.taskdevicepin[1]>=0:
self.readinprogress = False
try:
self.adc = Analog.PiAnalog(gpioinit=False,a_pin=self.taskdevicepin[0],b_pin=self.taskdevicepin[1],C=self.taskdevicepluginconfig[1],R1=self.taskdevicepluginconfig[2],Vt=self.taskdevicepluginconfig[3])
self.initialized = True
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"PiAnalog init error: "+str(e))

def plugin_read(self):
result = False
if self.initialized and self.enabled and self.readinprogress==False and (self.adc is not None):
Expand All @@ -142,3 +185,15 @@ def plugin_read(self):
self.readinprogress = False
result = True
return result

class virtADC:
def __init__(self,channel):
self.channel = channel

def analog_read(self):
res = None
try:
res = gpios.HWPorts.analog_read(self.channel)
except Exception as e:
pass
return res
13 changes: 13 additions & 0 deletions gpios.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ def preinit(gpiotype):
PUD_UP=GPIOHW.PUD_UP
PUD_DOWN=GPIOHW.PUD_DOWN
HWPorts = hwports()
elif gpiotype==9: # RockPI
import lib.lib_rockgpios as GPIOHW
from lib.lib_rockgpios import hwports
BOTH=GPIOHW.BOTH
RISING=GPIOHW.RISING
FALLING=GPIOHW.FALLING
IN=GPIOHW.IN
OUT=GPIOHW.OUT
PUD_UP=GPIOHW.PUD_UP
PUD_DOWN=GPIOHW.PUD_DOWN
OUT_HIGH=GPIOHW.OUT_HIGH
OUT_LOW=GPIOHW.OUT_LOW
HWPorts = hwports()
elif gpiotype==19: # FTDI
import lib.lib_ftdigpios as GPIOHW
from lib.lib_ftdigpios import hwports
Expand Down
7 changes: 5 additions & 2 deletions lib/lib_gpiohelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ def setservoangle(servopin,angle):

def play_tone(pin,freq,delay):
gpios.HWPorts.output_pwm(pin,50,freq) # generate 'freq' sound
s = float(delay/1000)
try:
s = float(delay/1000)
except:
s = 0.5
time.sleep(s)

def play_rtttl(pin,notestr):
Expand All @@ -291,4 +294,4 @@ def play_rtttl(pin,notestr):
play_tone(pin,int(note['frequency']),float(note['duration']))
except:
pass
gpios.HWPorts.output_pwm(pin,0,0) # stop sound
gpios.HWPorts.output_pwm(pin,0,0) # stop sound
Loading

0 comments on commit 4fd7fcd

Please sign in to comment.