Dr. Arne Jachens

Set up the Raspberry Pi

no warranty for any of the provided information

Keine Erläuterungen gefunden.

import  os
from HvcTables import  *

class HvcRaw2phys:
    """
    Convert electronic raw values to physical units.
    """
    def  __init__(self):
        pass

    def  ADCverbose(self,raw,weight,HvcTables):
        """
        The verbose mode is good to understand, what is going on,
        used at initializations.
        """
        phys = {}
        message = "HvcRaw2phys.ADC \n"
        
        #initialize LowPass not set yet
        for  val in raw:
            value = float(raw[val])
            try:
                foo = HvcRaw2phys.LowPass[val]
            except:
                HvcRaw2phys.LowPass[val] = value
        
        #check validity of signals
        for  val in raw:
            value = raw[val]
            if value<=1 or value>=4095:
                message = message + "WARNING: check electrical connection of port: "+val+"\n"
            elif value<0.9*HvcRaw2phys.LowPass[val] or value>1.1*HvcRaw2phys.LowPass[val]:
                message = message + "WARNING: check connection of floating port: "+val+"\n"
        
        #reduce noise by low pass filter
        for  val in raw:
            value = float(raw[val])
#            last = HvcRaw2phys.LowPass[val] #arne
            HvcRaw2phys.LowPass[val] = (1.0-weight)*HvcRaw2phys.LowPass[val] + weight * value
 #           if val=="haus":
  #              print("LowPass",last,value,HvcRaw2phys.LowPass[val],weight) #arne

        #convert raw to physical value
        for  val in raw:
            if val=="TLow":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="THot":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="ret":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="flow":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" )
            elif val=="coll":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Pt1000", "no-saturate" )
            elif val=="fire":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "NTCoven", "saturate" )
            elif val=="haus":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "NTCoven", "saturate" )
            elif val=="erde":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            elif val=="zulu":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            elif val=="ablu":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            elif val=="folu":
                phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" )
            #    phys["folu"] = phys["ablu"]  - (phys["zulu"]-phys["erde"])
            else:
                message = message + "WARNING: for  "+val+" there is no conversion! \n"
                phys[val] = HvcRaw2phys.LowPass[val]
                

        message = message+"\t\t"
        for  val in raw:
            message = message+('\t{}'.format(val))
        message = message + "\n"
        message = message + "lowPass \t"
        for  val in raw:
            message = message+('\t{:.2f}'.format(HvcRaw2phys.LowPass[val]))
        message = message + "\n"
        message = message + "physical \t"
        for  val in raw:
            message = message+('\t{:.2f}'.format(phys[val]))
        message = message + "\n"
        
        return phys, message

    
    def  ADC(self,raw,weight,HvcTables):
        """
        For regular calls, drop the messages.
        """
        phys, message = HvcRaw2phys.ADCverbose(self,raw,weight,HvcTables)
        return phys

        
    #persistant values:
    LowPass={}



if __name__ == "__main__":
    #first init tables
    HvcTables = HvcTables()
    r2p = HvcRaw2phys()
    
    myRaw = {'coll': 1936, 'TLow': 2128, 'THot': 2016, 'flow': 2160, 'ret': 2164, 'fire': 682, 'haus': 707, 'erde': 1735, 'zulu': 2412, 'ablu': 1768, 'posBp': 401}
    
    weight=0.5
    phys, message = r2p.ADCverbose(myRaw,weight,HvcTables)
    print(message)

    print("============================")
    print("second call, all LowPass +1 ?")
    for  val in myRaw:
        myRaw[val] = myRaw[val]+2
        
    weight=0.5
    phys, message = r2p.ADCverbose(myRaw,weight,HvcTables)
    print(message)
    print("============================")
    print("execute short function")
    phys = r2p.ADC(myRaw,weight,HvcTables)
    print(phys)

python

1HvcControl.py
2HvcHCSR04ultrasonic.py
3HvcMain.py
4HvcMotorDriver.py
5HvcOneWire.py
6HvcOperationMode.py
7HvcRaw2phys.py
8HvcReadSPI.py
9HvcSendI2C.py
10HvcSetGPIO.py
11HvcTables.py
12HvcWeather.py
13makeDoc.py

php

1HV_Admin_Login.php
2HV_colorMap.php
3HV_composeH2Oplot.php
4HV_config.php
5HV_H2Olevel.php
6HV_readOperationState.php
7HV_restart.php
8HV_serviceLog.php
9HV_setParameters.php
10HV_showHouse.php
11HV_showLog.php
12HV_showWeatherForecast.php
13HV_TempCal.php
14index.php
15readFilenames.php
16readNamedData.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.