Updating for adding offset

This commit is contained in:
Patrick McDonagh
2018-08-10 15:08:29 -05:00
parent e87e405580
commit 630f5960dc
15 changed files with 52 additions and 10 deletions

1
.gitignore vendored
View File

@@ -100,3 +100,4 @@ ENV/
# mypy
.mypy_cache/
/python_driver/cal_data.db
/.pytest_cache

6
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"python.unitTest.promptToConfigure": false,
"python.unitTest.pyTestEnabled": false,
"python.unitTest.unittestEnabled": false,
"python.unitTest.nosetestsEnabled": false
}

View File

@@ -105,6 +105,31 @@
</div>
</div>
<div class="col-md-6 box-me entry-top-level" id="setleveloffset">
<div class="pad15">
<h2>Level Offset (Ft.)</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['pondlevel.setleveloffset'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend=25.0
data-channelId="<%= channels["pondlevel.setleveloffset"].channelId %>"
data-techname="<%=channels["pondlevel.setleveloffset"].techName %>"
data-name="<%= channels["pondlevel.setleveloffset"].name%>"
data-nodechannelcurrentId="<%= channels["pondlevel.setleveloffset"].nodechannelcurrentId %>"
id="<%= channels["pondlevel.setleveloffset"].channelId %>"
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
</form>
</div>
</div>
</div>
<div class="row row-flex">

BIN
python-driver/cal_data.db Normal file

Binary file not shown.

View File

@@ -2,7 +2,7 @@
"driverFileName": "pondlevel.py",
"deviceName": "pondlevel",
"driverId": "0130",
"releaseVersion": "4",
"releaseVersion": "5",
"files": {
"file1": "pondlevel.py",
"file2": "calibration_db.py",

View File

@@ -8,6 +8,6 @@
"utilities.py",
"file_logger.py"
],
"version": 4,
"version": 5,
"s3BucketName": "pondlevel"
}

View File

@@ -30,12 +30,12 @@ scaling_persist = persistence.load(filename="scaling_persist.json")
strapping_persist = persistence.load(filename="strapping_persist.json")
def scale_to_eu(inp_measurement, raw_max, raw_min, eu_max, eu_min):
def scale_to_eu(inp_measurement, raw_max, raw_min, eu_max, eu_min, offset=0.0):
"""Scale the inp_measurement to engineering units."""
m = (eu_max - eu_min) / (raw_max - raw_min)
b = eu_max - raw_max * m
scaled = inp_measurement * m + b
return scaled
return scaled + offset
class start(threading.Thread, deviceBase):
@@ -47,7 +47,7 @@ class start(threading.Thread, deviceBase):
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "4"
self.version = "5"
self.finished = threading.Event()
self.forceSend = False
threading.Thread.start(self)
@@ -59,6 +59,7 @@ class start(threading.Thread, deviceBase):
self.PL_RAWMIN = 4.0
self.PL_EUMAX = 23.068
self.PL_EUMIN = 0.0
self.PL_OFFSET = 0.0
self.PSI_RAWMAX = 10.0
self.PSI_RAWMIN = 0.0
@@ -67,10 +68,10 @@ class start(threading.Thread, deviceBase):
# Strapping table format
# {
# height: volume,
# height: volume,
# height: volume,
# etc...
# height: volume,
# height: volume,
# height: volume,
# etc...
# }
self.strapping_table = {}
@@ -89,6 +90,7 @@ class start(threading.Thread, deviceBase):
self.PL_RAWMIN = scaling_persist['raw_min']
self.PL_EUMAX = scaling_persist['eu_max']
self.PL_EUMIN = scaling_persist['eu_min']
self.PL_OFFSET = scaling_persist['eu_offset']
except KeyError:
log.warning("No persistence data for pond level scaling parameters.")
except TypeError:
@@ -127,6 +129,7 @@ class start(threading.Thread, deviceBase):
self.sendtodb("setrawmin", self.PL_RAWMIN, 0)
self.sendtodb("seteumax", self.PL_EUMAX, 0)
self.sendtodb("seteumin", self.PL_EUMIN, 0)
self.sendtodb("setleveloffset", self.PL_OFFSET, 0)
self.sendtodb("setpsirawmax", self.PSI_RAWMAX, 0)
self.sendtodb("setpsirawmin", self.PSI_RAWMIN, 0)
@@ -148,7 +151,7 @@ class start(threading.Thread, deviceBase):
mcu_status = self.mcu.getDict() # Gets a dictionary of the IO states
cloop_val = float(mcu_status['cloop'])
analog1_val = float(mcu_status['analog1'])
temp_pl = scale_to_eu(cloop_val, self.PL_RAWMAX, self.PL_RAWMIN, self.PL_EUMAX, self.PL_EUMIN)
temp_pl = scale_to_eu(cloop_val, self.PL_RAWMAX, self.PL_RAWMIN, self.PL_EUMAX, self.PL_EUMIN, offset=self.PL_OFFSET)
temp_psi = scale_to_eu(analog1_val, self.PSI_RAWMAX, self.PSI_RAWMIN, self.PSI_EUMAX, self.PSI_EUMIN)
except AttributeError as err:
log.error("Could not connect to MCU object, this device might not have an MCU: {}".format(err))
@@ -333,6 +336,13 @@ class start(threading.Thread, deviceBase):
self.store_scaling_data()
return(True)
def pondlevel_setleveloffset(self, name, value):
"""Set the Pond level offset scaling value."""
self.PL_OFFSET = float(value)
self.sendtodb("setleveloffset", self.PL_OFFSET, 0)
self.store_scaling_data()
return(True)
def pondlevel_setpsirawmin(self, name, value):
"""Set the raw min pressure scaling value."""
self.PSI_RAWMIN = float(value)