From 686851bcbbfcd4339a5f05ca49e666ab70e3bd0d Mon Sep 17 00:00:00 2001 From: hydrosys4 Date: Thu, 9 Dec 2021 19:53:42 +0100 Subject: [PATCH] Fix readinputpin --- HWcontrol.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++- changelog/change | 5 +++++ hardwaremod.py | 20 ++++++++++++++++++ interruptmod.py | 4 ++-- start.py | 34 +++++++++++++++--------------- 5 files changed, 97 insertions(+), 20 deletions(-) diff --git a/HWcontrol.py b/HWcontrol.py index 911bc4c..6f03c8d 100755 --- a/HWcontrol.py +++ b/HWcontrol.py @@ -16,6 +16,9 @@ #import os import glob import logging +import subprocess + +from GPIOEXPI2Ccontrol import tonumber logger = logging.getLogger("hydrosys4."+__name__) @@ -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"] @@ -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 @@ -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 diff --git a/changelog/change b/changelog/change index b4c05c4..fbf55c8 100755 --- a/changelog/change +++ b/changelog/change @@ -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 + diff --git a/hardwaremod.py b/hardwaremod.py index ade12e2..1952ab5 100755 --- a/hardwaremod.py +++ b/hardwaremod.py @@ -1028,11 +1028,13 @@ def checkallsensors(): def initallGPIOpins(): removeallinterruptevents() checkGPIOconsistency() + initallGPIOinput() initallGPIOoutput() initallGPIOoutputEXP() return True + def initGPIOEXP(): GPIOEXPI2Ccontrol.initMCP23017() @@ -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: diff --git a/interruptmod.py b/interruptmod.py index 38ff69a..4385e1f 100755 --- a/interruptmod.py +++ b/interruptmod.py @@ -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) diff --git a/start.py b/start.py index 7a9b58d..45845b8 100755 --- a/start.py +++ b/start.py @@ -3,7 +3,7 @@ from builtins import str from builtins import range -Release="3.35g" +Release="3.36a" #--------------------- from loggerconfig import LOG_SETTINGS @@ -3451,10 +3451,10 @@ def Autotesting1(): if (reading>rangemin)and(readingrangemin)and(readingrangemin)and(readingrangemin)and(reading