Skip to content

Commit

Permalink
Fix readinputpin
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrosys4 committed Dec 9, 2021
1 parent 760d027 commit 686851b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 20 deletions.
54 changes: 53 additions & 1 deletion HWcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#import os
import glob
import logging
import subprocess

from GPIOEXPI2Ccontrol import tonumber


logger = logging.getLogger("hydrosys4."+__name__)
Expand Down Expand Up @@ -57,7 +60,7 @@
ISRPI=True


HWCONTROLLIST=["tempsensor","humidsensor","pressuresensor","analogdigital","lightsensor","pulse","pinstate","servo","stepper","stepperstatus","photo","mail+info+link","mail+info","returnzero","stoppulse","readinputpin","hbridge","empty","DS18B20","Hygro24_I2C","HX711","SlowWire","InterrFreqCounter","WeatherAPI","BME280_temperature","BME280_humidity","BME280_pressure","BMP180_temperature"]
HWCONTROLLIST=["tempsensor","humidsensor","pressuresensor","analogdigital","lightsensor","pulse","pinstate","servo","stepper","stepperstatus","photo","mail+info+link","mail+info","returnzero","stoppulse","readinputpin","hbridge","empty","DS18B20","Hygro24_I2C","HX711","SlowWire","InterrFreqCounter","WeatherAPI","BME280_temperature","BME280_humidity","BME280_pressure","BMP180_temperature","RPI_Core_temperature"]
RPIMODBGPIOPINLIST=["1","2", "3", "4","5","6", "7", "8", "9", "10", "11", "12","13","14", "15", "16","17", "18", "19", "20","21","22", "23", "24", "25","26", "27"]
NALIST=["N/A"]
GPIOPLUSLIST=["I2C", "SPI", "SPI2"]
Expand Down Expand Up @@ -235,6 +238,9 @@ def execute_task(cmd, message, recdata):
elif cmd==HWCONTROLLIST[27]:
return get_BMP180_data(cmd, message, recdata, "temperature")

elif cmd==HWCONTROLLIST[28]:
return get_RPI_Core_temperature(cmd, message, recdata)

else:
returnmsg(recdata,cmd,"Command not found",0)
return False
Expand Down Expand Up @@ -572,7 +578,53 @@ def get_BH1750_light(cmd, message, recdata):
returnmsg(recdata,cmd,light,successflag)
return True

def get_RPI_Core_temperature(cmd, message, recdata):
# uses the OS commands to get the SoC core temperature

successflag=0
msgarray=message.split(":")

# needed to provide the temperature in celsius or Farehneit
TemperatureUnit="C"
if len(msgarray)>4:
TemperatureUnit=msgarray[4]

temperature=0

oscmd = ["vcgencmd", "measure_temp"]
wordtofind="temp="

try:
result=subprocess.run(oscmd, capture_output="True", text="True")
scanoutput=result.stdout

except:
msg=" Error reading the RPI internal temperature "
returnmsg(recdata,cmd,msg,0)
return True

for line in scanoutput.split('\n'):
#print " line ",line
strstart=line.find(wordtofind)
if strstart>-1:
substr=line[(strstart+len(wordtofind)):]
lastdigit =[i for i in range(len(substr)) if substr[i].isdigit()].pop()
substr=substr[:lastdigit+1]
print (substr)
try:
temperature=float(substr)
if (TemperatureUnit=="F") and (temperature is not None):
temperature=temperature*1.8+32
temperature=('{:3.2f}'.format(temperature))
successflag=1

except:
msg=" Error reading the RPI internal temperature "
returnmsg(recdata,cmd,msg,0)
return True

returnmsg(recdata,cmd,temperature,successflag)
return True

def get_DS18B20_temperature(cmd, message, recdata):
successflag=0
Expand Down
5 changes: 5 additions & 0 deletions changelog/change
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,11 @@ Verified clock setting behavior, when the Internet connection is present the set
- Fix the hydrosys4_installation bash file updating the library libjpeg9-dev (former libjpeg9-dev8)


2021-12-09 -> release 336a

- Fix the "readinputpin", "not" pos and "neg" activate the pull_down, pull_up even if the interrupt is not used
- Added the reading for Raspberry PI internal chip temperature




Expand Down
20 changes: 20 additions & 0 deletions hardwaremod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,11 +1028,13 @@ def checkallsensors():
def initallGPIOpins():
removeallinterruptevents()
checkGPIOconsistency()
initallGPIOinput()
initallGPIOoutput()
initallGPIOoutputEXP()
return True



def initGPIOEXP():
GPIOEXPI2Ccontrol.initMCP23017()

Expand Down Expand Up @@ -1179,6 +1181,24 @@ def setPinOutput(PIN,level):
HWcontrol.GPIO_setup(PIN, "out")
HWcontrol.GPIO_output(PIN, level)

def initallGPIOinput():
for ln in IOdata:
iotype=ln[HW_INFO_IOTYPE]

# input: set gpio status
if (iotype=="input") :
if (ln[HW_CTRL_CMD]=="readinputpin"):
PINstr=ln[HW_CTRL_PIN]
print("set event for the PIN ", PINstr)
if not PINstr=="":
logic=ln[HW_CTRL_LOGIC]
# set Sw pull up / down mode
if logic=="pos":
GPIO_setup(PINstr, "in", "pull_down")
else:
GPIO_setup(PINstr, "in" , "pull_up")



def initallGPIOoutput():
for ln in IOdata:
Expand Down
4 changes: 2 additions & 2 deletions interruptmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def interruptexecute(refsensor,element):
interrupt_validinterval=hardwaremod.tonumber(interruptdbmod.searchdata("element",element,"interrupt_validinterval"),0)
#"Counter Only"
if workmode=="Counter Only":
CounterOnlyNew(element,sensor,interrupt_validinterval)
return
CounterOnlyNew(element,sensor,interrupt_validinterval)
return

interrupt_triggernumber=hardwaremod.tonumber(interruptdbmod.searchdata("element",element,"interrupt_triggernumber"),1)
actuatoroutput=hardwaremod.tonumber(interruptdbmod.searchdata("element",element,"actuator_output"),0)
Expand Down
34 changes: 17 additions & 17 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from builtins import str
from builtins import range

Release="3.35g"
Release="3.36a"

#---------------------
from loggerconfig import LOG_SETTINGS
Expand Down Expand Up @@ -3451,10 +3451,10 @@ def Autotesting1():
if (reading>rangemin)and(reading<rangemax):
print(" sensorname " , sensorname , " data in RANGE !!!!!!!!!!!! ")
else:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
except:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " Not able to read the sensor :( "
Expand Down Expand Up @@ -3511,10 +3511,10 @@ def Autotesting1_v10():
if (reading>rangemin)and(reading<rangemax):
print(" sensorname " , sensorname , " data in RANGE !!!!!!!!!!!! ")
else:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
except:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " Not able to read the sensor :( "
Expand Down Expand Up @@ -3575,10 +3575,10 @@ def Autotesting2():
if (reading>rangemin)and(reading<rangemax):
print(" sensorname " , sensorname , " data in RANGE !!!!!!!!!!!! ")
else:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
except:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " Not able to read the sensor :( "
Expand Down Expand Up @@ -3646,10 +3646,10 @@ def Autotesting3():
if (reading>rangemin)and(reading<rangemax):
print(" sensorname " , sensorname , " data in RANGE !!!!!!!!!!!! ")
else:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " data out of range :( "
print(errorstring)
break
except:
Errorcounter=Errorcounter+1
errorstring=" sensorname " + sensorname + " Not able to read the sensor :( "
Expand Down

0 comments on commit 686851b

Please sign in to comment.