forked from M-Labs/thermostat
Compare commits
43 Commits
9c22950e59
...
a85f512b47
Author | SHA1 | Date | |
---|---|---|---|
a85f512b47 | |||
911b6b2eb4 | |||
712f7e1648 | |||
0129c3d93f | |||
05ca3b59fe | |||
9d1074e605 | |||
62d0f510a3 | |||
27b326eaa9 | |||
2ed1bfab5e | |||
d75f207808 | |||
3369ed2c77 | |||
9aaadfa6e6 | |||
3fc32c81f5 | |||
a7a847e2dd | |||
89dd28b844 | |||
f17f8de0b0 | |||
279bd446c5 | |||
0cb50d5aac | |||
2f8814a93c | |||
3ba58ab4ae | |||
978d44f886 | |||
288b94352b | |||
5574559ac6 | |||
e160a6f514 | |||
ae9bd1a859 | |||
0f768f30e8 | |||
07095d77c8 | |||
4a7d7abf3a | |||
b9cf60f2df | |||
3ffa939970 | |||
87ba107ce5 | |||
319fb9cf9e | |||
f7c266539b | |||
df9715b3ef | |||
82279f15da | |||
fff42bfa4c | |||
d3b93b1263 | |||
4309f9044c | |||
81418d0a55 | |||
7fb933faa2 | |||
437c9cec34 | |||
7829ce6adf | |||
0f14212622 |
@ -71,9 +71,8 @@ openocd -f interface/stlink.cfg -f target/stm32f4x.cfg -c "program target/thumbv
|
|||||||
|
|
||||||
A GUI has been developed for easy configuration and plotting of key parameters.
|
A GUI has been developed for easy configuration and plotting of key parameters.
|
||||||
|
|
||||||
The Python GUI program is located at pytec/tec_qt.py.
|
The Python GUI program is located at pytec/tec_qt.py, and is developed based on the Python library pyqtgraph. The GUI can be configured and
|
||||||
|
launched automatically by running:
|
||||||
The GUI is developed based on the Python library pyqtgraph. The GUI can be configured and launched automatically by running:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
nix run .#thermostat_gui
|
nix run .#thermostat_gui
|
||||||
|
70
flake.nix
70
flake.nix
@ -1,10 +1,15 @@
|
|||||||
{
|
{
|
||||||
description = "Firmware for the Sinara 8451 Thermostat";
|
description = "Firmware for the Sinara 8451 Thermostat";
|
||||||
|
|
||||||
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05;
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
|
||||||
inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; };
|
inputs.mozilla-overlay = {url = github:mozilla/nixpkgs-mozilla; flake = false; };
|
||||||
|
|
||||||
outputs = { self, nixpkgs, mozilla-overlay }:
|
outputs =
|
||||||
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
mozilla-overlay,
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; };
|
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; };
|
||||||
rustManifest = pkgs.fetchurl {
|
rustManifest = pkgs.fetchurl {
|
||||||
@ -76,7 +81,26 @@
|
|||||||
inherit pname version;
|
inherit pname version;
|
||||||
hash = "sha256-WBCNhBHHBU4IQdi3ke6F4QH8KWubNZwOAd3jipj/Ks4=";
|
hash = "sha256-WBCNhBHHBU4IQdi3ke6F4QH8KWubNZwOAd3jipj/Ks4=";
|
||||||
};
|
};
|
||||||
propagatedBuildInputs = with pkgs.python3Packages; [ numpy pyqt6 ];
|
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||||
|
numpy
|
||||||
|
pyqt6
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
qtextras = pkgs.python3Packages.buildPythonPackage rec {
|
||||||
|
pname = "qtextras";
|
||||||
|
version = "0.6.8";
|
||||||
|
format = "pyproject";
|
||||||
|
src = pkgs.fetchPypi {
|
||||||
|
inherit pname version;
|
||||||
|
hash = "sha256-d1ZotSlOI4surUy0H0N4xHoq94IRQvMHunwRH1uubFg=";
|
||||||
|
};
|
||||||
|
buildInputs = [ pkgs.python3Packages.hatchling ];
|
||||||
|
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||||
|
numpy
|
||||||
|
pyqtgraph
|
||||||
|
ruamel-yaml
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
pglive = pkgs.python3Packages.buildPythonPackage rec {
|
pglive = pkgs.python3Packages.buildPythonPackage rec {
|
||||||
@ -88,7 +112,10 @@
|
|||||||
hash = "sha256-jqj8X6H1N5mJQ4OrY5ANqRB0YJByqg/bNneEALWmH1A=";
|
hash = "sha256-jqj8X6H1N5mJQ4OrY5ANqRB0YJByqg/bNneEALWmH1A=";
|
||||||
};
|
};
|
||||||
buildInputs = [ pkgs.python3Packages.poetry-core ];
|
buildInputs = [ pkgs.python3Packages.poetry-core ];
|
||||||
propagatedBuildInputs = [ pyqtgraph pkgs.python3Packages.numpy ];
|
propagatedBuildInputs = [
|
||||||
|
pyqtgraph
|
||||||
|
pkgs.python3Packages.numpy
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
thermostat_gui = pkgs.python3Packages.buildPythonPackage {
|
thermostat_gui = pkgs.python3Packages.buildPythonPackage {
|
||||||
@ -98,14 +125,23 @@
|
|||||||
src = "${self}/pytec";
|
src = "${self}/pytec";
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ];
|
nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ];
|
||||||
propagatedBuildInputs = [ pkgs.qt6.qtbase ] ++ (with pkgs.python3Packages; [ pyqtgraph pyqt6 qasync pglive ]);
|
propagatedBuildInputs =
|
||||||
|
[ pkgs.qt6.qtbase ]
|
||||||
|
++ (with pkgs.python3Packages; [
|
||||||
|
pyqtgraph
|
||||||
|
pyqt6
|
||||||
|
qasync
|
||||||
|
pglive
|
||||||
|
qtextras
|
||||||
|
]);
|
||||||
|
|
||||||
dontWrapQtApps = true;
|
dontWrapQtApps = true;
|
||||||
postFixup = ''
|
postFixup = ''
|
||||||
wrapQtApp "$out/bin/tec_qt"
|
wrapQtApp "$out/bin/tec_qt"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
packages.x86_64-linux = {
|
packages.x86_64-linux = {
|
||||||
inherit thermostat thermostat_gui;
|
inherit thermostat thermostat_gui;
|
||||||
};
|
};
|
||||||
@ -121,10 +157,22 @@
|
|||||||
|
|
||||||
devShell.x86_64-linux = pkgs.mkShell {
|
devShell.x86_64-linux = pkgs.mkShell {
|
||||||
name = "thermostat-dev-shell";
|
name = "thermostat-dev-shell";
|
||||||
buildInputs = with pkgs; [
|
buildInputs =
|
||||||
rust openocd dfu-util
|
with pkgs;
|
||||||
] ++ (with python3Packages; [
|
[
|
||||||
numpy matplotlib pyqtgraph setuptools pyqt6 qasync pglive
|
rust
|
||||||
|
openocd
|
||||||
|
dfu-util
|
||||||
|
]
|
||||||
|
++ (with python3Packages; [
|
||||||
|
numpy
|
||||||
|
matplotlib
|
||||||
|
pyqtgraph
|
||||||
|
setuptools
|
||||||
|
pyqt6
|
||||||
|
qasync
|
||||||
|
pglive
|
||||||
|
qtextras
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
defaultPackage.x86_64-linux = thermostat;
|
defaultPackage.x86_64-linux = thermostat;
|
||||||
|
3
pytec/.flake8
Normal file
3
pytec/.flake8
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[flake8]
|
||||||
|
max-line-length = 88
|
||||||
|
extend-ignore = E203,E701
|
@ -12,32 +12,33 @@ from pytec.client import Client
|
|||||||
|
|
||||||
|
|
||||||
class PIDAutotuneState(Enum):
|
class PIDAutotuneState(Enum):
|
||||||
STATE_OFF = 'off'
|
STATE_OFF = "off"
|
||||||
STATE_RELAY_STEP_UP = 'relay step up'
|
STATE_RELAY_STEP_UP = "relay step up"
|
||||||
STATE_RELAY_STEP_DOWN = 'relay step down'
|
STATE_RELAY_STEP_DOWN = "relay step down"
|
||||||
STATE_SUCCEEDED = 'succeeded'
|
STATE_SUCCEEDED = "succeeded"
|
||||||
STATE_FAILED = 'failed'
|
STATE_FAILED = "failed"
|
||||||
STATE_READY = 'ready'
|
STATE_READY = "ready"
|
||||||
|
|
||||||
|
|
||||||
class PIDAutotune:
|
class PIDAutotune:
|
||||||
PIDParams = namedtuple('PIDParams', ['Kp', 'Ki', 'Kd'])
|
PIDParams = namedtuple("PIDParams", ["Kp", "Ki", "Kd"])
|
||||||
|
|
||||||
PEAK_AMPLITUDE_TOLERANCE = 0.05
|
PEAK_AMPLITUDE_TOLERANCE = 0.05
|
||||||
|
|
||||||
_tuning_rules = {
|
_tuning_rules = {
|
||||||
"ziegler-nichols": [0.6, 1.2, 0.075],
|
"ziegler-nichols": [0.6, 1.2, 0.075],
|
||||||
"tyreus-luyben": [0.4545, 0.2066, 0.07214],
|
"tyreus-luyben": [0.4545, 0.2066, 0.07214],
|
||||||
"ciancone-marlin": [0.303, 0.1364, 0.0481],
|
"ciancone-marlin": [0.303, 0.1364, 0.0481],
|
||||||
"pessen-integral": [0.7, 1.75, 0.105],
|
"pessen-integral": [0.7, 1.75, 0.105],
|
||||||
"some-overshoot": [0.333, 0.667, 0.111],
|
"some-overshoot": [0.333, 0.667, 0.111],
|
||||||
"no-overshoot": [0.2, 0.4, 0.0667]
|
"no-overshoot": [0.2, 0.4, 0.0667],
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, setpoint, out_step=10, lookback=60,
|
def __init__(
|
||||||
noiseband=0.5, sampletime=1.2):
|
self, setpoint, out_step=10, lookback=60, noiseband=0.5, sampletime=1.2
|
||||||
|
):
|
||||||
if setpoint is None:
|
if setpoint is None:
|
||||||
raise ValueError('setpoint must be specified')
|
raise ValueError("setpoint must be specified")
|
||||||
|
|
||||||
self._inputs = deque(maxlen=round(lookback / sampletime))
|
self._inputs = deque(maxlen=round(lookback / sampletime))
|
||||||
self._setpoint = setpoint
|
self._setpoint = setpoint
|
||||||
@ -84,7 +85,7 @@ class PIDAutotune:
|
|||||||
"""Get a list of all available tuning rules."""
|
"""Get a list of all available tuning rules."""
|
||||||
return self._tuning_rules.keys()
|
return self._tuning_rules.keys()
|
||||||
|
|
||||||
def get_pid_parameters(self, tuning_rule='ziegler-nichols'):
|
def get_pid_parameters(self, tuning_rule="ziegler-nichols"):
|
||||||
"""Get PID parameters.
|
"""Get PID parameters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -97,7 +98,7 @@ class PIDAutotune:
|
|||||||
kd = divisors[2] * self._Ku * self._Pu
|
kd = divisors[2] * self._Ku * self._Pu
|
||||||
return PIDAutotune.PIDParams(kp, ki, kd)
|
return PIDAutotune.PIDParams(kp, ki, kd)
|
||||||
|
|
||||||
def get_tec_pid (self):
|
def get_tec_pid(self):
|
||||||
divisors = self._tuning_rules["tyreus-luyben"]
|
divisors = self._tuning_rules["tyreus-luyben"]
|
||||||
kp = self._Ku * divisors[0]
|
kp = self._Ku * divisors[0]
|
||||||
ki = divisors[1] * self._Ku / self._Pu
|
ki = divisors[1] * self._Ku / self._Pu
|
||||||
@ -116,28 +117,34 @@ class PIDAutotune:
|
|||||||
"""
|
"""
|
||||||
now = time_input * 1000
|
now = time_input * 1000
|
||||||
|
|
||||||
if (self._state == PIDAutotuneState.STATE_OFF
|
if (
|
||||||
or self._state == PIDAutotuneState.STATE_SUCCEEDED
|
self._state == PIDAutotuneState.STATE_OFF
|
||||||
or self._state == PIDAutotuneState.STATE_FAILED
|
or self._state == PIDAutotuneState.STATE_SUCCEEDED
|
||||||
or self._state == PIDAutotuneState.STATE_READY):
|
or self._state == PIDAutotuneState.STATE_FAILED
|
||||||
|
or self._state == PIDAutotuneState.STATE_READY
|
||||||
|
):
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
|
||||||
self._last_run_timestamp = now
|
self._last_run_timestamp = now
|
||||||
|
|
||||||
# check input and change relay state if necessary
|
# check input and change relay state if necessary
|
||||||
if (self._state == PIDAutotuneState.STATE_RELAY_STEP_UP
|
if (
|
||||||
and input_val > self._setpoint + self._noiseband):
|
self._state == PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
and input_val > self._setpoint + self._noiseband
|
||||||
|
):
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
logging.debug('switched state: {0}'.format(self._state))
|
logging.debug("switched state: {0}".format(self._state))
|
||||||
logging.debug('input: {0}'.format(input_val))
|
logging.debug("input: {0}".format(input_val))
|
||||||
elif (self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
elif (
|
||||||
and input_val < self._setpoint - self._noiseband):
|
self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
|
and input_val < self._setpoint - self._noiseband
|
||||||
|
):
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
logging.debug('switched state: {0}'.format(self._state))
|
logging.debug("switched state: {0}".format(self._state))
|
||||||
logging.debug('input: {0}'.format(input_val))
|
logging.debug("input: {0}".format(input_val))
|
||||||
|
|
||||||
# set output
|
# set output
|
||||||
if (self._state == PIDAutotuneState.STATE_RELAY_STEP_UP):
|
if self._state == PIDAutotuneState.STATE_RELAY_STEP_UP:
|
||||||
self._output = self._initial_output - self._outputstep
|
self._output = self._initial_output - self._outputstep
|
||||||
elif self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
elif self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
||||||
self._output = self._initial_output + self._outputstep
|
self._output = self._initial_output + self._outputstep
|
||||||
@ -180,8 +187,8 @@ class PIDAutotune:
|
|||||||
self._peak_count += 1
|
self._peak_count += 1
|
||||||
self._peaks.append(input_val)
|
self._peaks.append(input_val)
|
||||||
self._peak_timestamps.append(now)
|
self._peak_timestamps.append(now)
|
||||||
logging.debug('found peak: {0}'.format(input_val))
|
logging.debug("found peak: {0}".format(input_val))
|
||||||
logging.debug('peak count: {0}'.format(self._peak_count))
|
logging.debug("peak count: {0}".format(self._peak_count))
|
||||||
|
|
||||||
# check for convergence of induced oscillation
|
# check for convergence of induced oscillation
|
||||||
# convergence of amplitude assessed on last 4 peaks (1.5 cycles)
|
# convergence of amplitude assessed on last 4 peaks (1.5 cycles)
|
||||||
@ -191,20 +198,19 @@ class PIDAutotune:
|
|||||||
abs_max = self._peaks[-2]
|
abs_max = self._peaks[-2]
|
||||||
abs_min = self._peaks[-2]
|
abs_min = self._peaks[-2]
|
||||||
for i in range(0, len(self._peaks) - 2):
|
for i in range(0, len(self._peaks) - 2):
|
||||||
self._induced_amplitude += abs(self._peaks[i]
|
self._induced_amplitude += abs(self._peaks[i] - self._peaks[i + 1])
|
||||||
- self._peaks[i+1])
|
|
||||||
abs_max = max(self._peaks[i], abs_max)
|
abs_max = max(self._peaks[i], abs_max)
|
||||||
abs_min = min(self._peaks[i], abs_min)
|
abs_min = min(self._peaks[i], abs_min)
|
||||||
|
|
||||||
self._induced_amplitude /= 6.0
|
self._induced_amplitude /= 6.0
|
||||||
|
|
||||||
# check convergence criterion for amplitude of induced oscillation
|
# check convergence criterion for amplitude of induced oscillation
|
||||||
amplitude_dev = ((0.5 * (abs_max - abs_min)
|
amplitude_dev = (
|
||||||
- self._induced_amplitude)
|
0.5 * (abs_max - abs_min) - self._induced_amplitude
|
||||||
/ self._induced_amplitude)
|
) / self._induced_amplitude
|
||||||
|
|
||||||
logging.debug('amplitude: {0}'.format(self._induced_amplitude))
|
logging.debug("amplitude: {0}".format(self._induced_amplitude))
|
||||||
logging.debug('amplitude deviation: {0}'.format(amplitude_dev))
|
logging.debug("amplitude deviation: {0}".format(amplitude_dev))
|
||||||
|
|
||||||
if amplitude_dev < PIDAutotune.PEAK_AMPLITUDE_TOLERANCE:
|
if amplitude_dev < PIDAutotune.PEAK_AMPLITUDE_TOLERANCE:
|
||||||
self._state = PIDAutotuneState.STATE_SUCCEEDED
|
self._state = PIDAutotuneState.STATE_SUCCEEDED
|
||||||
@ -218,25 +224,24 @@ class PIDAutotune:
|
|||||||
|
|
||||||
if self._state == PIDAutotuneState.STATE_SUCCEEDED:
|
if self._state == PIDAutotuneState.STATE_SUCCEEDED:
|
||||||
self._output = 0
|
self._output = 0
|
||||||
logging.debug('peak finding successful')
|
logging.debug("peak finding successful")
|
||||||
|
|
||||||
# calculate ultimate gain
|
# calculate ultimate gain
|
||||||
self._Ku = 4.0 * self._outputstep / \
|
self._Ku = 4.0 * self._outputstep / (self._induced_amplitude * math.pi)
|
||||||
(self._induced_amplitude * math.pi)
|
logging.debug("Ku: {0}".format(self._Ku))
|
||||||
logging.debug('Ku: {0}'.format(self._Ku))
|
|
||||||
|
|
||||||
# calculate ultimate period in seconds
|
# calculate ultimate period in seconds
|
||||||
period1 = self._peak_timestamps[3] - self._peak_timestamps[1]
|
period1 = self._peak_timestamps[3] - self._peak_timestamps[1]
|
||||||
period2 = self._peak_timestamps[4] - self._peak_timestamps[2]
|
period2 = self._peak_timestamps[4] - self._peak_timestamps[2]
|
||||||
self._Pu = 0.5 * (period1 + period2) / 1000.0
|
self._Pu = 0.5 * (period1 + period2) / 1000.0
|
||||||
logging.debug('Pu: {0}'.format(self._Pu))
|
logging.debug("Pu: {0}".format(self._Pu))
|
||||||
|
|
||||||
for rule in self._tuning_rules:
|
for rule in self._tuning_rules:
|
||||||
params = self.get_pid_parameters(rule)
|
params = self.get_pid_parameters(rule)
|
||||||
logging.debug('rule: {0}'.format(rule))
|
logging.debug("rule: {0}".format(rule))
|
||||||
logging.debug('Kp: {0}'.format(params.Kp))
|
logging.debug("Kp: {0}".format(params.Kp))
|
||||||
logging.debug('Ki: {0}'.format(params.Ki))
|
logging.debug("Ki: {0}".format(params.Ki))
|
||||||
logging.debug('Kd: {0}'.format(params.Kd))
|
logging.debug("Kd: {0}".format(params.Kd))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -263,16 +268,17 @@ def main():
|
|||||||
data = next(tec.report_mode())
|
data = next(tec.report_mode())
|
||||||
ch = data[channel]
|
ch = data[channel]
|
||||||
|
|
||||||
tuner = PIDAutotune(target_temperature, output_step,
|
tuner = PIDAutotune(
|
||||||
lookback, noiseband, ch['interval'])
|
target_temperature, output_step, lookback, noiseband, ch["interval"]
|
||||||
|
)
|
||||||
|
|
||||||
for data in tec.report_mode():
|
for data in tec.report_mode():
|
||||||
|
|
||||||
ch = data[channel]
|
ch = data[channel]
|
||||||
|
|
||||||
temperature = ch['temperature']
|
temperature = ch["temperature"]
|
||||||
|
|
||||||
if (tuner.run(temperature, ch['time'])):
|
if tuner.run(temperature, ch["time"]):
|
||||||
break
|
break
|
||||||
|
|
||||||
tuner_out = tuner.output()
|
tuner_out = tuner.output()
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from pytec.aioclient import Client
|
from pytec.aioclient import AsyncioClient
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
tec = Client()
|
tec = AsyncioClient()
|
||||||
await tec.start_session() #(host="192.168.1.26", port=23)
|
await tec.start_session() # (host="192.168.1.26", port=23)
|
||||||
await tec.set_param("s-h", 1, "t0", 20)
|
await tec.set_param("s-h", 1, "t0", 20)
|
||||||
print(await tec.get_pwm())
|
print(await tec.get_pwm())
|
||||||
print(await tec.get_pid())
|
print(await tec.get_pid())
|
||||||
@ -13,4 +14,5 @@ async def main():
|
|||||||
async for data in tec.report_mode():
|
async for data in tec.report_mode():
|
||||||
print(data)
|
print(data)
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from pytec.client import Client
|
from pytec.client import Client
|
||||||
|
|
||||||
tec = Client() #(host="localhost", port=6667)
|
tec = Client() # (host="localhost", port=6667)
|
||||||
tec.set_param("s-h", 1, "t0", 20)
|
tec.set_param("s-h", 1, "t0", 20)
|
||||||
print(tec.get_pwm())
|
print(tec.get_pwm())
|
||||||
print(tec.get_pid())
|
print(tec.get_pid())
|
||||||
|
@ -7,9 +7,10 @@ from pytec.client import Client
|
|||||||
TIME_WINDOW = 300.0
|
TIME_WINDOW = 300.0
|
||||||
|
|
||||||
tec = Client()
|
tec = Client()
|
||||||
target_temperature = tec.get_pid()[0]['target']
|
target_temperature = tec.get_pid()[0]["target"]
|
||||||
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
|
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
|
||||||
|
|
||||||
|
|
||||||
class Series:
|
class Series:
|
||||||
def __init__(self, conv=lambda x: x):
|
def __init__(self, conv=lambda x: x):
|
||||||
self.conv = conv
|
self.conv = conv
|
||||||
@ -27,24 +28,26 @@ class Series:
|
|||||||
self.x_data = self.x_data[drop:]
|
self.x_data = self.x_data[drop:]
|
||||||
self.y_data = self.y_data[drop:]
|
self.y_data = self.y_data[drop:]
|
||||||
|
|
||||||
|
|
||||||
series = {
|
series = {
|
||||||
# 'adc': Series(),
|
# 'adc': Series(),
|
||||||
# 'sens': Series(lambda x: x * 0.0001),
|
# 'sens': Series(lambda x: x * 0.0001),
|
||||||
'temperature': Series(),
|
"temperature": Series(),
|
||||||
# 'i_set': Series(),
|
# 'i_set': Series(),
|
||||||
'pid_output': Series(),
|
"pid_output": Series(),
|
||||||
# 'vref': Series(),
|
# 'vref': Series(),
|
||||||
# 'dac_value': Series(),
|
# 'dac_value': Series(),
|
||||||
# 'dac_feedback': Series(),
|
# 'dac_feedback': Series(),
|
||||||
# 'i_tec': Series(),
|
# 'i_tec': Series(),
|
||||||
'tec_i': Series(),
|
"tec_i": Series(),
|
||||||
'tec_u_meas': Series(),
|
"tec_u_meas": Series(),
|
||||||
# 'interval': Series(),
|
# 'interval': Series(),
|
||||||
}
|
}
|
||||||
series_lock = Lock()
|
series_lock = Lock()
|
||||||
|
|
||||||
quit = False
|
quit = False
|
||||||
|
|
||||||
|
|
||||||
def recv_data(tec):
|
def recv_data(tec):
|
||||||
global last_packet_time
|
global last_packet_time
|
||||||
for data in tec.report_mode():
|
for data in tec.report_mode():
|
||||||
@ -55,22 +58,24 @@ def recv_data(tec):
|
|||||||
if k in ch0:
|
if k in ch0:
|
||||||
v = ch0[k]
|
v = ch0[k]
|
||||||
if type(v) is float:
|
if type(v) is float:
|
||||||
s.append(ch0['time'], v)
|
s.append(ch0["time"], v)
|
||||||
finally:
|
finally:
|
||||||
series_lock.release()
|
series_lock.release()
|
||||||
|
|
||||||
if quit:
|
if quit:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
thread = Thread(target=recv_data, args=(tec,))
|
thread = Thread(target=recv_data, args=(tec,))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
|
|
||||||
for k, s in series.items():
|
for k, s in series.items():
|
||||||
s.plot, = ax.plot([], [], label=k)
|
(s.plot,) = ax.plot([], [], label=k)
|
||||||
legend = ax.legend()
|
legend = ax.legend()
|
||||||
|
|
||||||
|
|
||||||
def animate(i):
|
def animate(i):
|
||||||
min_x, max_x, min_y, max_y = None, None, None, None
|
min_x, max_x, min_y, max_y = None, None, None, None
|
||||||
|
|
||||||
@ -120,8 +125,8 @@ def animate(i):
|
|||||||
legend.remove()
|
legend.remove()
|
||||||
legend = ax.legend()
|
legend = ax.legend()
|
||||||
|
|
||||||
ani = animation.FuncAnimation(
|
|
||||||
fig, animate, interval=1, blit=False, save_count=50)
|
ani = animation.FuncAnimation(fig, animate, interval=1, blit=False, save_count=50)
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
quit = True
|
quit = True
|
||||||
|
@ -16,3 +16,6 @@ tec_qt = "tec_qt:main"
|
|||||||
[tool.setuptools]
|
[tool.setuptools]
|
||||||
packages.find = {}
|
packages.find = {}
|
||||||
py-modules = ["autotune", "plot", "tec_qt"]
|
py-modules = ["autotune", "plot", "tec_qt"]
|
||||||
|
|
||||||
|
[tool.pylint.format]
|
||||||
|
max-line-length = "88"
|
@ -2,58 +2,34 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class CommandError(Exception):
|
class CommandError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class StoppedConnecting(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Client:
|
class AsyncioClient:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._reader = None
|
self._reader = None
|
||||||
self._writer = None
|
self._writer = None
|
||||||
self._connecting_task = None
|
|
||||||
self._command_lock = asyncio.Lock()
|
self._command_lock = asyncio.Lock()
|
||||||
self._report_mode_on = False
|
self._report_mode_on = False
|
||||||
self.timeout = None
|
|
||||||
|
|
||||||
async def start_session(self, host='192.168.1.26', port=23, timeout=None):
|
async def start_session(self, host="192.168.1.26", port=23):
|
||||||
"""Start session to Thermostat at specified host and port.
|
"""Start session to Thermostat at specified host and port.
|
||||||
Throws StoppedConnecting if disconnect was called while connecting.
|
|
||||||
Throws asyncio.TimeoutError if timeout was exceeded.
|
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
client = Client()
|
client = AsyncioClient()
|
||||||
try:
|
await client.start_session()
|
||||||
await client.start_session()
|
|
||||||
except StoppedConnecting:
|
|
||||||
print("Stopped connecting")
|
|
||||||
"""
|
"""
|
||||||
self._connecting_task = asyncio.create_task(
|
self._reader, self._writer = await asyncio.open_connection(host, port)
|
||||||
asyncio.wait_for(asyncio.open_connection(host, port), timeout)
|
|
||||||
)
|
|
||||||
self.timeout = timeout
|
|
||||||
try:
|
|
||||||
self._reader, self._writer = await self._connecting_task
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
raise StoppedConnecting
|
|
||||||
finally:
|
|
||||||
self._connecting_task = None
|
|
||||||
|
|
||||||
await self._check_zero_limits()
|
await self._check_zero_limits()
|
||||||
|
|
||||||
def connecting(self):
|
|
||||||
"""Returns True if client is connecting"""
|
|
||||||
return self._connecting_task is not None
|
|
||||||
|
|
||||||
def connected(self):
|
def connected(self):
|
||||||
"""Returns True if client is connected"""
|
"""Returns True if client is connected"""
|
||||||
return self._writer is not None
|
return self._writer is not None
|
||||||
|
|
||||||
async def end_session(self):
|
async def end_session(self):
|
||||||
"""End session to Thermostat if connected, cancel connection if connecting"""
|
"""End session to Thermostat"""
|
||||||
if self._connecting_task is not None:
|
|
||||||
self._connecting_task.cancel()
|
|
||||||
|
|
||||||
if self._writer is None:
|
if self._writer is None:
|
||||||
return
|
return
|
||||||
@ -69,23 +45,26 @@ class Client:
|
|||||||
for pwm_channel in pwm_report:
|
for pwm_channel in pwm_report:
|
||||||
for limit in ["max_i_neg", "max_i_pos", "max_v"]:
|
for limit in ["max_i_neg", "max_i_pos", "max_v"]:
|
||||||
if pwm_channel[limit]["value"] == 0.0:
|
if pwm_channel[limit]["value"] == 0.0:
|
||||||
logging.warning("`{}` limit is set to zero on channel {}".format(limit, pwm_channel["channel"]))
|
logging.warning(
|
||||||
|
"`{}` limit is set to zero on channel {}".format(
|
||||||
|
limit, pwm_channel["channel"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
async def _read_line(self):
|
async def _read_line(self):
|
||||||
# read 1 line
|
# read 1 line
|
||||||
chunk = await asyncio.wait_for(self._reader.readline(), self.timeout) # Only wait for response until timeout
|
chunk = await self._reader.readline()
|
||||||
return chunk.decode('utf-8', errors='ignore')
|
return chunk.decode("utf-8", errors="ignore")
|
||||||
|
|
||||||
async def _read_write(self, command):
|
async def _read_write(self, command):
|
||||||
self._writer.write(((" ".join(command)).strip() + "\n").encode('utf-8'))
|
self._writer.write(((" ".join(command)).strip() + "\n").encode("utf-8"))
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
return await self._read_line()
|
return await self._read_line()
|
||||||
|
|
||||||
async def _command(self, *command):
|
async def _command(self, *command):
|
||||||
async with self._command_lock:
|
async with self._command_lock:
|
||||||
# protect the read-write process from being cancelled midway
|
line = await self._read_write(command)
|
||||||
line = await asyncio.shield(self._read_write(command))
|
|
||||||
|
|
||||||
response = json.loads(line)
|
response = json.loads(line)
|
||||||
logging.debug(f"{command}: {response}")
|
logging.debug(f"{command}: {response}")
|
||||||
@ -244,7 +223,7 @@ class Client:
|
|||||||
"""Load current configuration from EEPROM"""
|
"""Load current configuration from EEPROM"""
|
||||||
await self._command("load", str(channel))
|
await self._command("load", str(channel))
|
||||||
if channel == "":
|
if channel == "":
|
||||||
await self._read_line() # Read the extra {}
|
await self._read_line() # Read the extra {}
|
||||||
|
|
||||||
async def hw_rev(self):
|
async def hw_rev(self):
|
||||||
"""Get Thermostat hardware revision"""
|
"""Get Thermostat hardware revision"""
|
||||||
@ -256,7 +235,7 @@ class Client:
|
|||||||
The client is disconnected as the TCP session is terminated.
|
The client is disconnected as the TCP session is terminated.
|
||||||
"""
|
"""
|
||||||
async with self._command_lock:
|
async with self._command_lock:
|
||||||
self._writer.write("reset\n".encode('utf-8'))
|
self._writer.write("reset\n".encode("utf-8"))
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
await self.end_session()
|
await self.end_session()
|
||||||
@ -269,11 +248,11 @@ class Client:
|
|||||||
power-cycling.
|
power-cycling.
|
||||||
"""
|
"""
|
||||||
async with self._command_lock:
|
async with self._command_lock:
|
||||||
self._writer.write("dfu\n".encode('utf-8'))
|
self._writer.write("dfu\n".encode("utf-8"))
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
await self.end_session()
|
await self.end_session()
|
||||||
|
|
||||||
async def ipv4(self):
|
async def ipv4(self):
|
||||||
"""Get the IPv4 settings of the Thermostat"""
|
"""Get the IPv4 settings of the Thermostat"""
|
||||||
return await self._command('ipv4')
|
return await self._command("ipv4")
|
||||||
|
@ -2,9 +2,11 @@ import socket
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class CommandError(Exception):
|
class CommandError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, host="192.168.1.26", port=23, timeout=None):
|
def __init__(self, host="192.168.1.26", port=23, timeout=None):
|
||||||
self._socket = socket.create_connection((host, port), timeout)
|
self._socket = socket.create_connection((host, port), timeout)
|
||||||
@ -20,7 +22,11 @@ class Client:
|
|||||||
for pwm_channel in pwm_report:
|
for pwm_channel in pwm_report:
|
||||||
for limit in ["max_i_neg", "max_i_pos", "max_v"]:
|
for limit in ["max_i_neg", "max_i_pos", "max_v"]:
|
||||||
if pwm_channel[limit]["value"] == 0.0:
|
if pwm_channel[limit]["value"] == 0.0:
|
||||||
logging.warning("`{}` limit is set to zero on channel {}".format(limit, pwm_channel["channel"]))
|
logging.warning(
|
||||||
|
"`{}` limit is set to zero on channel {}".format(
|
||||||
|
limit, pwm_channel["channel"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _read_line(self):
|
def _read_line(self):
|
||||||
# read more lines
|
# read more lines
|
||||||
@ -28,7 +34,7 @@ class Client:
|
|||||||
chunk = self._socket.recv(4096)
|
chunk = self._socket.recv(4096)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
return None
|
return None
|
||||||
buf = self._lines[-1] + chunk.decode('utf-8', errors='ignore')
|
buf = self._lines[-1] + chunk.decode("utf-8", errors="ignore")
|
||||||
self._lines = buf.split("\n")
|
self._lines = buf.split("\n")
|
||||||
|
|
||||||
line = self._lines[0]
|
line = self._lines[0]
|
||||||
@ -36,7 +42,7 @@ class Client:
|
|||||||
return line
|
return line
|
||||||
|
|
||||||
def _command(self, *command):
|
def _command(self, *command):
|
||||||
self._socket.sendall((" ".join(command) + "\n").encode('utf-8'))
|
self._socket.sendall((" ".join(command) + "\n").encode("utf-8"))
|
||||||
|
|
||||||
line = self._read_line()
|
line = self._read_line()
|
||||||
response = json.loads(line)
|
response = json.loads(line)
|
||||||
|
@ -4,10 +4,10 @@ from autotune import PIDAutotuneState, PIDAutotune
|
|||||||
|
|
||||||
|
|
||||||
class PIDAutoTuner(QObject):
|
class PIDAutoTuner(QObject):
|
||||||
def __init__(self, parent, client, num_of_channel):
|
def __init__(self, parent, thermostat, num_of_channel):
|
||||||
super().__init__()
|
super().__init__(parent)
|
||||||
|
|
||||||
self._client = client
|
self._thermostat = thermostat
|
||||||
self.autotuners = [PIDAutotune(25) for _ in range(num_of_channel)]
|
self.autotuners = [PIDAutotune(25) for _ in range(num_of_channel)]
|
||||||
self.target_temp = [20.0 for _ in range(num_of_channel)]
|
self.target_temp = [20.0 for _ in range(num_of_channel)]
|
||||||
self.test_current = [1.0 for _ in range(num_of_channel)]
|
self.test_current = [1.0 for _ in range(num_of_channel)]
|
||||||
@ -28,7 +28,7 @@ class PIDAutoTuner(QObject):
|
|||||||
def load_params_and_set_ready(self, ch):
|
def load_params_and_set_ready(self, ch):
|
||||||
self.autotuners[ch].setParam(
|
self.autotuners[ch].setParam(
|
||||||
self.target_temp[ch],
|
self.target_temp[ch],
|
||||||
self.test_current[ch] / 1000,
|
self.test_current[ch],
|
||||||
self.temp_swing[ch],
|
self.temp_swing[ch],
|
||||||
1 / self.sampling_interval[ch],
|
1 / self.sampling_interval[ch],
|
||||||
self.lookback[ch],
|
self.lookback[ch],
|
||||||
@ -37,7 +37,7 @@ class PIDAutoTuner(QObject):
|
|||||||
|
|
||||||
async def stop_pid_from_running(self, ch):
|
async def stop_pid_from_running(self, ch):
|
||||||
self.autotuners[ch].setOff()
|
self.autotuners[ch].setOff()
|
||||||
await self._client.set_param("pwm", ch, "i_set", 0)
|
await self._thermostat.set_param("pwm", ch, "i_set", 0)
|
||||||
|
|
||||||
@asyncSlot(list)
|
@asyncSlot(list)
|
||||||
async def tick(self, report):
|
async def tick(self, report):
|
||||||
@ -48,25 +48,29 @@ class PIDAutoTuner(QObject):
|
|||||||
|
|
||||||
ch = channel_report["channel"]
|
ch = channel_report["channel"]
|
||||||
match self.autotuners[ch].state():
|
match self.autotuners[ch].state():
|
||||||
case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
case (
|
||||||
|
PIDAutotuneState.STATE_READY
|
||||||
|
| PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
| PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
|
):
|
||||||
self.autotuners[ch].run(
|
self.autotuners[ch].run(
|
||||||
channel_report["temperature"], channel_report["time"]
|
channel_report["temperature"], channel_report["time"]
|
||||||
)
|
)
|
||||||
await self._client.set_param(
|
await self._thermostat.set_param(
|
||||||
"pwm", ch, "i_set", self.autotuners[ch].output()
|
"pwm", ch, "i_set", self.autotuners[ch].output()
|
||||||
)
|
)
|
||||||
case PIDAutotuneState.STATE_SUCCEEDED:
|
case PIDAutotuneState.STATE_SUCCEEDED:
|
||||||
kp, ki, kd = self.autotuners[ch].get_tec_pid()
|
kp, ki, kd = self.autotuners[ch].get_tec_pid()
|
||||||
self.autotuners[ch].setOff()
|
self.autotuners[ch].setOff()
|
||||||
|
|
||||||
await self._client.set_param("pid", ch, "kp", kp)
|
await self._thermostat.set_param("pid", ch, "kp", kp)
|
||||||
await self._client.set_param("pid", ch, "ki", ki)
|
await self._thermostat.set_param("pid", ch, "ki", ki)
|
||||||
await self._client.set_param("pid", ch, "kd", kd)
|
await self._thermostat.set_param("pid", ch, "kd", kd)
|
||||||
await self._client.set_param("pwm", ch, "pid")
|
await self._thermostat.set_param("pwm", ch, "pid")
|
||||||
|
|
||||||
await self._client.set_param(
|
await self._thermostat.set_param(
|
||||||
"pid", ch, "target", self.target_temp[ch]
|
"pid", ch, "target", self.target_temp[ch]
|
||||||
)
|
)
|
||||||
case PIDAutotuneState.STATE_FAILED:
|
case PIDAutotuneState.STATE_FAILED:
|
||||||
self.autotuners[ch].setOff()
|
self.autotuners[ch].setOff()
|
||||||
await self._client.set_param("pwm", ch, "i_set", 0)
|
await self._thermostat.set_param("pwm", ch, "i_set", 0)
|
||||||
|
@ -1,20 +1,9 @@
|
|||||||
from pytec.aioclient import Client
|
|
||||||
from PyQt6.QtCore import pyqtSignal, QObject, pyqtSlot
|
from PyQt6.QtCore import pyqtSignal, QObject, pyqtSlot
|
||||||
from qasync import asyncSlot
|
from qasync import asyncSlot
|
||||||
from pytec.gui.model.property import Property, PropertyMeta
|
from pytec.gui.model.property import Property, PropertyMeta
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from pytec.aioclient import AsyncioClient
|
||||||
|
|
||||||
class WrappedClient(QObject, Client):
|
|
||||||
connection_error = pyqtSignal()
|
|
||||||
|
|
||||||
async def _read_line(self):
|
|
||||||
try:
|
|
||||||
return await super()._read_line()
|
|
||||||
except (Exception, TimeoutError, asyncio.exceptions.TimeoutError):
|
|
||||||
logging.error("Client connection error, disconnecting", exc_info=True)
|
|
||||||
self.connection_error.emit()
|
|
||||||
|
|
||||||
|
|
||||||
class Thermostat(QObject, metaclass=PropertyMeta):
|
class Thermostat(QObject, metaclass=PropertyMeta):
|
||||||
@ -27,35 +16,40 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
interval = Property(list)
|
interval = Property(list)
|
||||||
report = Property(list)
|
report = Property(list)
|
||||||
info_box_trigger = pyqtSignal(str, str)
|
info_box_trigger = pyqtSignal(str, str)
|
||||||
|
connection_error = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent, client, update_s):
|
def __init__(self, parent, update_s):
|
||||||
self._update_s = update_s
|
self._update_s = update_s
|
||||||
self._client = client
|
self._client = AsyncioClient()
|
||||||
self._watch_task = None
|
self._watch_task = None
|
||||||
self._report_mode_task = None
|
self._report_mode_task = None
|
||||||
self._poll_for_report = True
|
self._poll_for_report = True
|
||||||
|
self.connection_errored = False
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
async def start_session(self, host, port):
|
||||||
|
await self._client.start_session(host, port)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
self.task = asyncio.create_task(self.update_params())
|
self.task = asyncio.create_task(self.update_params())
|
||||||
while True:
|
while True:
|
||||||
if self.task.done():
|
if self.task.done():
|
||||||
if self.task.exception() is not None:
|
try:
|
||||||
try:
|
_ = self.task.result()
|
||||||
raise self.task.exception()
|
except asyncio.TimeoutError:
|
||||||
except (
|
logging.error(
|
||||||
Exception,
|
"Encountered an error while updating parameter tree.",
|
||||||
TimeoutError,
|
exc_info=True,
|
||||||
asyncio.exceptions.TimeoutError,
|
)
|
||||||
):
|
self.connection_error.emit()
|
||||||
logging.error(
|
return
|
||||||
"Encountered an error while updating parameter tree.",
|
|
||||||
exc_info=True,
|
|
||||||
)
|
|
||||||
_ = self.task.result()
|
|
||||||
self.task = asyncio.create_task(self.update_params())
|
self.task = asyncio.create_task(self.update_params())
|
||||||
await asyncio.sleep(self._update_s)
|
await asyncio.sleep(self._update_s)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def timed_out(self):
|
||||||
|
self.connection_errored = True
|
||||||
|
|
||||||
async def get_hw_rev(self):
|
async def get_hw_rev(self):
|
||||||
self.hw_rev = await self._client.hw_rev()
|
self.hw_rev = await self._client.hw_rev()
|
||||||
return self.hw_rev
|
return self.hw_rev
|
||||||
@ -73,10 +67,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
self.postfilter = await self._client.get_postfilter()
|
self.postfilter = await self._client.get_postfilter()
|
||||||
|
|
||||||
def connected(self):
|
def connected(self):
|
||||||
return self._client.connected
|
return self._client.connected()
|
||||||
|
|
||||||
def connecting(self):
|
|
||||||
return self._client.connecting
|
|
||||||
|
|
||||||
def start_watching(self):
|
def start_watching(self):
|
||||||
self._watch_task = asyncio.create_task(self.run())
|
self._watch_task = asyncio.create_task(self.run())
|
||||||
@ -106,6 +97,7 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
|
|
||||||
async def end_session(self):
|
async def end_session(self):
|
||||||
await self._client.end_session()
|
await self._client.end_session()
|
||||||
|
self.connection_errored = False
|
||||||
|
|
||||||
async def set_ipv4(self, ipv4):
|
async def set_ipv4(self, ipv4):
|
||||||
await self._client.set_param("ipv4", ipv4)
|
await self._client.set_param("ipv4", ipv4)
|
||||||
@ -117,14 +109,14 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
async def save_cfg(self, ch):
|
async def save_cfg(self, ch):
|
||||||
await self._client.save_config(ch)
|
await self._client.save_config(ch)
|
||||||
self.info_box_trigger.emit(
|
self.info_box_trigger.emit(
|
||||||
"Config saved", f"Channel {ch} Config has been saved from flash."
|
"Settings saved", f"Channel {ch} Settings has been saved to flash."
|
||||||
)
|
)
|
||||||
|
|
||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def load_cfg(self, ch):
|
async def load_cfg(self, ch):
|
||||||
await self._client.load_config(ch)
|
await self._client.load_config(ch)
|
||||||
self.info_box_trigger.emit(
|
self.info_box_trigger.emit(
|
||||||
"Config loaded", f"Channel {ch} Config has been loaded from flash."
|
"Settings loaded", f"Channel {ch} Settings has been loaded from flash."
|
||||||
)
|
)
|
||||||
|
|
||||||
async def dfu(self):
|
async def dfu(self):
|
||||||
@ -136,3 +128,12 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
|||||||
@pyqtSlot(float)
|
@pyqtSlot(float)
|
||||||
def set_update_s(self, update_s):
|
def set_update_s(self, update_s):
|
||||||
self._update_s = update_s
|
self._update_s = update_s
|
||||||
|
|
||||||
|
async def set_fan(self, power="auto"):
|
||||||
|
await self._client.set_fan(power)
|
||||||
|
|
||||||
|
async def get_fan(self):
|
||||||
|
return await self._client.get_fan()
|
||||||
|
|
||||||
|
async def set_param(self, topic, channel, field="", value=""):
|
||||||
|
await self._client.set_param(topic, channel, field, value)
|
||||||
|
@ -4,42 +4,14 @@ from pyqtgraph.parametertree import (
|
|||||||
Parameter,
|
Parameter,
|
||||||
registerParameterType,
|
registerParameterType,
|
||||||
)
|
)
|
||||||
|
import pytec.gui.view.lockable_unit
|
||||||
|
|
||||||
|
|
||||||
class MutexParameter(pTypes.ListParameter):
|
def set_tree_label_tips(tree):
|
||||||
"""
|
for item in tree.listAllItems():
|
||||||
Mutually exclusive parameter where only one of its children is visible at a time, list selectable.
|
p = item.param
|
||||||
|
if "tip" in p.opts:
|
||||||
The ordering of the list items determines which children will be visible.
|
item.setToolTip(0, p.opts["tip"])
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, **opts):
|
|
||||||
super().__init__(**opts)
|
|
||||||
|
|
||||||
self.sigValueChanged.connect(self.show_chosen_child)
|
|
||||||
self.sigValueChanged.emit(self, self.opts["value"])
|
|
||||||
|
|
||||||
def _get_param_from_value(self, value):
|
|
||||||
if isinstance(self.opts["limits"], dict):
|
|
||||||
values_list = list(self.opts["limits"].values())
|
|
||||||
else:
|
|
||||||
values_list = self.opts["limits"]
|
|
||||||
|
|
||||||
return self.children()[values_list.index(value)]
|
|
||||||
|
|
||||||
@pyqtSlot(object, object)
|
|
||||||
def show_chosen_child(self, value):
|
|
||||||
for param in self.children():
|
|
||||||
param.hide()
|
|
||||||
|
|
||||||
child_to_show = self._get_param_from_value(value.value())
|
|
||||||
child_to_show.show()
|
|
||||||
|
|
||||||
if child_to_show.opts.get("triggerOnShow", None):
|
|
||||||
child_to_show.sigValueChanged.emit(child_to_show, child_to_show.value())
|
|
||||||
|
|
||||||
|
|
||||||
registerParameterType("mutex", MutexParameter)
|
|
||||||
|
|
||||||
|
|
||||||
class CtrlPanel(QObject):
|
class CtrlPanel(QObject):
|
||||||
@ -58,55 +30,63 @@ class CtrlPanel(QObject):
|
|||||||
self.trees_ui = trees_ui
|
self.trees_ui = trees_ui
|
||||||
self.NUM_CHANNELS = len(trees_ui)
|
self.NUM_CHANNELS = len(trees_ui)
|
||||||
|
|
||||||
self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)]
|
def _set_value_with_lock(self, value):
|
||||||
|
if not self.opts.get("lock"):
|
||||||
|
self.setValue(value)
|
||||||
|
Parameter.set_value_with_lock = _set_value_with_lock
|
||||||
|
|
||||||
self.params = [
|
self.params = [
|
||||||
Parameter.create(
|
Parameter.create(
|
||||||
name=f"Thermostat Channel {ch} Parameters",
|
name=f"Thermostat Channel {ch} Parameters",
|
||||||
type="group",
|
type="group",
|
||||||
value=ch,
|
value=ch,
|
||||||
children=self.THERMOSTAT_PARAMETERS[ch],
|
children=param_tree,
|
||||||
)
|
)
|
||||||
for ch in range(self.NUM_CHANNELS)
|
for ch in range(self.NUM_CHANNELS)
|
||||||
]
|
]
|
||||||
|
|
||||||
for i, param in enumerate(self.params):
|
for ch, tree in enumerate(self.trees_ui):
|
||||||
param.channel = i
|
|
||||||
|
|
||||||
for i, tree in enumerate(self.trees_ui):
|
|
||||||
tree.setHeaderHidden(True)
|
tree.setHeaderHidden(True)
|
||||||
tree.setParameters(self.params[i], showTop=False)
|
tree.setParameters(self.params[ch], showTop=False)
|
||||||
self.params[i].setValue = self._setValue
|
|
||||||
self.params[i].sigTreeStateChanged.connect(sigTreeStateChanged_handle)
|
|
||||||
|
|
||||||
for handle in sigActivated_handles[i]:
|
set_tree_label_tips(tree)
|
||||||
self.params[i].child(*handle[0]).sigActivated.connect(handle[1])
|
|
||||||
|
|
||||||
def _setValue(self, value, blockSignal=None):
|
for ch, param in enumerate(self.params):
|
||||||
"""
|
param.sigTreeStateChanged.connect(sigTreeStateChanged_handle)
|
||||||
Implement 'lock' mechanism for Parameter Type
|
|
||||||
|
|
||||||
Modified from the source
|
for handle in sigActivated_handles[ch]:
|
||||||
"""
|
param.child(*handle[0]).sigActivated.connect(handle[1])
|
||||||
try:
|
|
||||||
if blockSignal is not None:
|
|
||||||
self.sigValueChanged.disconnect(blockSignal)
|
|
||||||
value = self._interpretValue(value)
|
|
||||||
if fn.eq(self.opts["value"], value):
|
|
||||||
return value
|
|
||||||
|
|
||||||
if "lock" in self.opts.keys():
|
self.params[ch].child("output", "control_method").sigValueChanged.connect(
|
||||||
if self.opts["lock"]:
|
lambda param, value: param.parent()
|
||||||
return value
|
.parent()
|
||||||
self.opts["value"] = value
|
.child("pid")
|
||||||
self.sigValueChanged.emit(
|
.setOpts(expanded=(value == "temperature_pid"))
|
||||||
self, value
|
)
|
||||||
) # value might change after signal is received by tree item
|
|
||||||
finally:
|
|
||||||
if blockSignal is not None:
|
|
||||||
self.sigValueChanged.connect(blockSignal)
|
|
||||||
|
|
||||||
return self.opts["value"]
|
def _indicate_usage(param, control_method="constant_current"):
|
||||||
|
for item in param.child("i_set").items:
|
||||||
|
is_constant_current = control_method == "constant_current"
|
||||||
|
font = item.font(0)
|
||||||
|
font.setUnderline(is_constant_current)
|
||||||
|
font.setBold(is_constant_current)
|
||||||
|
item.setFont(0, font)
|
||||||
|
for item in param.child("target").items:
|
||||||
|
is_temperature_pid = control_method == "temperature_pid"
|
||||||
|
font = item.font(0)
|
||||||
|
font.setUnderline(is_temperature_pid)
|
||||||
|
font.setBold(is_temperature_pid)
|
||||||
|
item.setFont(0, font)
|
||||||
|
|
||||||
|
param.child("output", "control_method").sigValueChanged.connect(
|
||||||
|
_indicate_usage
|
||||||
|
)
|
||||||
|
_indicate_usage(param.child("output", "control_method"))
|
||||||
|
|
||||||
|
for item in param.child("output", "control_method").items:
|
||||||
|
font = item.font(0)
|
||||||
|
font.setBold(True)
|
||||||
|
item.setFont(0, font)
|
||||||
|
|
||||||
def change_params_title(self, channel, path, title):
|
def change_params_title(self, channel, path, title):
|
||||||
self.params[channel].child(*path).setOpts(title=title)
|
self.params[channel].child(*path).setOpts(title=title)
|
||||||
@ -116,57 +96,59 @@ class CtrlPanel(QObject):
|
|||||||
for settings in pid_settings:
|
for settings in pid_settings:
|
||||||
channel = settings["channel"]
|
channel = settings["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child("PID Config", "Kp").setValue(
|
self.params[channel].child("pid", "kp").set_value_with_lock(
|
||||||
settings["parameters"]["kp"]
|
settings["parameters"]["kp"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("PID Config", "Ki").setValue(
|
self.params[channel].child("pid", "ki").set_value_with_lock(
|
||||||
settings["parameters"]["ki"]
|
settings["parameters"]["ki"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("PID Config", "Kd").setValue(
|
self.params[channel].child("pid", "kd").set_value_with_lock(
|
||||||
settings["parameters"]["kd"]
|
settings["parameters"]["kd"]
|
||||||
)
|
)
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"PID Config", "PID Output Clamping", "Minimum"
|
"pid", "pid_output_clamping", "output_min"
|
||||||
).setValue(settings["parameters"]["output_min"] * 1000)
|
).set_value_with_lock(settings["parameters"]["output_min"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"PID Config", "PID Output Clamping", "Maximum"
|
"pid", "pid_output_clamping", "output_max"
|
||||||
).setValue(settings["parameters"]["output_max"] * 1000)
|
).set_value_with_lock(settings["parameters"]["output_max"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"Output Config", "Control Method", "Set Temperature"
|
"output", "control_method", "target"
|
||||||
).setValue(settings["target"])
|
).set_value_with_lock(settings["target"])
|
||||||
|
|
||||||
@pyqtSlot("QVariantList")
|
@pyqtSlot("QVariantList")
|
||||||
def update_report(self, report_data):
|
def update_report(self, report_data):
|
||||||
for settings in report_data:
|
for settings in report_data:
|
||||||
channel = settings["channel"]
|
channel = settings["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child("Output Config", "Control Method").setValue(
|
self.params[channel].child(
|
||||||
"Temperature PID" if settings["pid_engaged"] else "Constant Current"
|
"output", "control_method"
|
||||||
|
).set_value_with_lock(
|
||||||
|
"temperature_pid" if settings["pid_engaged"] else "constant_current"
|
||||||
)
|
)
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"Output Config", "Control Method", "Set Current"
|
"output", "control_method", "i_set"
|
||||||
).setValue(settings["i_set"] * 1000)
|
).set_value_with_lock(settings["i_set"])
|
||||||
if settings["temperature"] is not None:
|
if settings["temperature"] is not None:
|
||||||
self.params[channel].child("Temperature").setValue(
|
self.params[channel].child(
|
||||||
settings["temperature"]
|
"readings", "temperature"
|
||||||
)
|
).set_value_with_lock(settings["temperature"])
|
||||||
if settings["tec_i"] is not None:
|
if settings["tec_i"] is not None:
|
||||||
self.params[channel].child("Current through TEC").setValue(
|
self.params[channel].child(
|
||||||
settings["tec_i"] * 1000
|
"readings", "tec_i"
|
||||||
)
|
).set_value_with_lock(settings["tec_i"])
|
||||||
|
|
||||||
@pyqtSlot("QVariantList")
|
@pyqtSlot("QVariantList")
|
||||||
def update_thermistor(self, sh_data):
|
def update_thermistor(self, sh_data):
|
||||||
for sh_param in sh_data:
|
for sh_param in sh_data:
|
||||||
channel = sh_param["channel"]
|
channel = sh_param["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child("Thermistor Config", "T₀").setValue(
|
self.params[channel].child("thermistor", "t0").set_value_with_lock(
|
||||||
sh_param["params"]["t0"] - 273.15
|
sh_param["params"]["t0"] - 273.15
|
||||||
)
|
)
|
||||||
self.params[channel].child("Thermistor Config", "R₀").setValue(
|
self.params[channel].child("thermistor", "r0").set_value_with_lock(
|
||||||
sh_param["params"]["r0"]
|
sh_param["params"]["r0"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("Thermistor Config", "B").setValue(
|
self.params[channel].child("thermistor", "b").set_value_with_lock(
|
||||||
sh_param["params"]["b"]
|
sh_param["params"]["b"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -178,14 +160,14 @@ class CtrlPanel(QObject):
|
|||||||
channel = pwm_params["channel"]
|
channel = pwm_params["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"Output Config", "Limits", "Max Voltage Difference"
|
"output", "limits", "max_v"
|
||||||
).setValue(pwm_params["max_v"]["value"])
|
).set_value_with_lock(pwm_params["max_v"]["value"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"Output Config", "Limits", "Max Cooling Current"
|
"output", "limits", "max_i_pos"
|
||||||
).setValue(pwm_params["max_i_pos"]["value"] * 1000)
|
).set_value_with_lock(pwm_params["max_i_pos"]["value"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"Output Config", "Limits", "Max Heating Current"
|
"output", "limits", "max_i_neg"
|
||||||
).setValue(pwm_params["max_i_neg"]["value"] * 1000)
|
).set_value_with_lock(pwm_params["max_i_neg"]["value"])
|
||||||
|
|
||||||
for limit in "max_i_pos", "max_i_neg", "max_v":
|
for limit in "max_i_pos", "max_i_neg", "max_v":
|
||||||
if pwm_params[limit]["value"] == 0.0:
|
if pwm_params[limit]["value"] == 0.0:
|
||||||
@ -197,6 +179,6 @@ class CtrlPanel(QObject):
|
|||||||
for postfilter_params in postfilter_data:
|
for postfilter_params in postfilter_data:
|
||||||
channel = postfilter_params["channel"]
|
channel = postfilter_params["channel"]
|
||||||
with QSignalBlocker(self.params[channel]):
|
with QSignalBlocker(self.params[channel]):
|
||||||
self.params[channel].child(
|
self.params[channel].child("postfilter", "rate").set_value_with_lock(
|
||||||
"Thermistor Config", "Postfilter Rate"
|
postfilter_params["rate"]
|
||||||
).setValue(postfilter_params["rate"])
|
)
|
||||||
|
@ -67,9 +67,7 @@ class _TecGraphs:
|
|||||||
self._t_line = self._t_widget.getPlotItem().addLine(label="{value} °C")
|
self._t_line = self._t_widget.getPlotItem().addLine(label="{value} °C")
|
||||||
self._t_line.setVisible(False)
|
self._t_line.setVisible(False)
|
||||||
# Hack for keeping setpoint line in plot range
|
# Hack for keeping setpoint line in plot range
|
||||||
self._t_setpoint_plot = (
|
self._t_setpoint_plot = LiveLinePlot()
|
||||||
LiveLinePlot()
|
|
||||||
)
|
|
||||||
|
|
||||||
for graph in t_widget, i_widget:
|
for graph in t_widget, i_widget:
|
||||||
time_axis = LiveAxis(
|
time_axis = LiveAxis(
|
||||||
|
185
pytec/pytec/gui/view/lockable_unit.py
Normal file
185
pytec/pytec/gui/view/lockable_unit.py
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
from PyQt6.QtCore import QSignalBlocker
|
||||||
|
from PyQt6.QtGui import QValidator
|
||||||
|
|
||||||
|
from pyqtgraph import SpinBox
|
||||||
|
import pyqtgraph.functions as fn
|
||||||
|
from pyqtgraph.parametertree import registerParameterItemType
|
||||||
|
from pyqtgraph.parametertree.parameterTypes import SimpleParameter, NumericParameterItem
|
||||||
|
|
||||||
|
|
||||||
|
# See https://github.com/pyqtgraph/pyqtgraph/issues/3115
|
||||||
|
fn.FLOAT_REGEX = re.compile(
|
||||||
|
r"(?P<number>[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)|((?i:nan)|(inf))))\s*"
|
||||||
|
+ r"((?P<siPrefix>[u" + fn.SI_PREFIXES + r"]?)(?P<suffix>.*))?$"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class LockableUnitSpinBox(SpinBox):
|
||||||
|
"""
|
||||||
|
Extension of PyQtGraph's SpinBox widget.
|
||||||
|
Adds:
|
||||||
|
|
||||||
|
* The "pinSiPrefix" option, where the siPrefix could be fixed to a
|
||||||
|
particular scale instead of as determined by its value.
|
||||||
|
* The "noUnitEditing" option, where the suffix and pinned siPrefix
|
||||||
|
of the SpinBox text is fixed and uneditable.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, parent=None, value=0.0, **kwargs):
|
||||||
|
super().__init__(parent, value, **kwargs)
|
||||||
|
|
||||||
|
self.lineEdit().cursorPositionChanged.connect(
|
||||||
|
self._editor_cursor_position_changed
|
||||||
|
)
|
||||||
|
|
||||||
|
def validate(self, strn, pos):
|
||||||
|
ret, strn, pos = super().validate(strn, pos)
|
||||||
|
|
||||||
|
if self.opts.get("noUnitEditing") is True:
|
||||||
|
suffix = self.opts["suffix"]
|
||||||
|
pinned_si_prefix = self.opts.get("pinSiPrefix")
|
||||||
|
|
||||||
|
suffix_edited = not strn.endswith(suffix)
|
||||||
|
pinned_si_prefix_edited = (
|
||||||
|
pinned_si_prefix is not None
|
||||||
|
and not strn.removesuffix(suffix).endswith(pinned_si_prefix)
|
||||||
|
)
|
||||||
|
|
||||||
|
if suffix_edited or pinned_si_prefix_edited:
|
||||||
|
ret = QValidator.State.Invalid
|
||||||
|
|
||||||
|
return ret, strn, pos
|
||||||
|
|
||||||
|
def _editor_cursor_position_changed(self, oldpos, newpos):
|
||||||
|
# Called on cursor position change
|
||||||
|
# Skips over the suffix and pinned SI prefix on cursor navigation if option
|
||||||
|
# noUnitEditing is enabled.
|
||||||
|
|
||||||
|
# Modified from the original Qt C++ source,
|
||||||
|
# QAbstractSpinBox::editorCursorPositionChanged.
|
||||||
|
# Their suffix is different than our suffix; there's no obvious way to set
|
||||||
|
# theirs here in the derived class since it is private.
|
||||||
|
|
||||||
|
if self.opts.get("noUnitEditing") is True:
|
||||||
|
edit = self.lineEdit()
|
||||||
|
if edit.hasSelectedText():
|
||||||
|
return # Allow for selecting units, for copy-and-paste
|
||||||
|
|
||||||
|
pinned_si_prefix = self.opts.get("pinSiPrefix") or ""
|
||||||
|
unit_len = len(pinned_si_prefix) + len(self.opts["suffix"])
|
||||||
|
text_len = len(edit.text())
|
||||||
|
|
||||||
|
pos = -1
|
||||||
|
# Cursor in unit
|
||||||
|
if text_len - unit_len < newpos < text_len:
|
||||||
|
if oldpos == text_len:
|
||||||
|
pos = text_len - unit_len
|
||||||
|
else:
|
||||||
|
pos = text_len
|
||||||
|
|
||||||
|
if pos != -1:
|
||||||
|
with QSignalBlocker(edit):
|
||||||
|
edit.setCursorPosition(pos)
|
||||||
|
|
||||||
|
def setOpts(self, **opts):
|
||||||
|
if "pinSiPrefix" in opts:
|
||||||
|
self.opts["pinSiPrefix"] = opts.pop("pinSiPrefix")
|
||||||
|
if "noUnitEditing" in opts:
|
||||||
|
self.opts["noUnitEditing"] = opts.pop("noUnitEditing")
|
||||||
|
|
||||||
|
super().setOpts(**opts)
|
||||||
|
|
||||||
|
def editingFinishedEvent(self):
|
||||||
|
# Modified from pyqtgraph.SpinBox.editingFinishedEvent source
|
||||||
|
|
||||||
|
new_text = self.lineEdit().text()
|
||||||
|
if new_text == self.lastText:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
val = self.interpret()
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
|
if val is False:
|
||||||
|
return
|
||||||
|
if val == self.val:
|
||||||
|
self.updateText() # still update text so that values are reformatted pretty-like
|
||||||
|
return
|
||||||
|
self.setValue(val, delaySignal=False) ## allow text update so that values are reformatted pretty-like
|
||||||
|
|
||||||
|
def formatText(self, prev=None):
|
||||||
|
"""
|
||||||
|
In addition to pyqtgraph.SpinBox's formatting, incorporate the
|
||||||
|
'pinSiPrefix' mechanism, where SI prefixes could be fixed.
|
||||||
|
"""
|
||||||
|
# Code modified from the PyQtGraph source
|
||||||
|
|
||||||
|
# get the number of decimal places to print
|
||||||
|
decimals = self.opts['decimals']
|
||||||
|
suffix = self.opts['suffix']
|
||||||
|
prefix = self.opts['prefix']
|
||||||
|
pin_si_prefix = self.opts.get("pinSiPrefix")
|
||||||
|
|
||||||
|
# format the string
|
||||||
|
val = self.value()
|
||||||
|
if self.opts['siPrefix'] is True:
|
||||||
|
# SI prefix was requested, so scale the value accordingly
|
||||||
|
if pin_si_prefix is not None and pin_si_prefix in fn.SI_PREFIX_EXPONENTS:
|
||||||
|
# fixed scale
|
||||||
|
s = 10**-fn.SI_PREFIX_EXPONENTS[pin_si_prefix]
|
||||||
|
p = pin_si_prefix
|
||||||
|
elif self.val == 0 and prev is not None:
|
||||||
|
# special case: if it's zero use the previous prefix
|
||||||
|
(s, p) = fn.siScale(prev)
|
||||||
|
else:
|
||||||
|
(s, p) = fn.siScale(val)
|
||||||
|
parts = {'value': val, 'suffix': suffix, 'decimals': decimals, 'siPrefix': p, 'scaledValue': s*val, 'prefix':prefix}
|
||||||
|
|
||||||
|
else:
|
||||||
|
# no SI prefix /suffix requested; scale is 1
|
||||||
|
parts = {'value': val, 'suffix': suffix, 'decimals': decimals, 'siPrefix': '', 'scaledValue': val, 'prefix':prefix}
|
||||||
|
|
||||||
|
parts['prefixGap'] = '' if parts['prefix'] == '' else ' '
|
||||||
|
parts['suffixGap'] = '' if (parts['suffix'] == '' and parts['siPrefix'] == '') else ' '
|
||||||
|
|
||||||
|
return self.opts['format'].format(**parts)
|
||||||
|
|
||||||
|
|
||||||
|
class UnitfulNumericParameterItem(NumericParameterItem):
|
||||||
|
"""
|
||||||
|
Subclasses PyQtGraph's `NumericParameterItem` and uses
|
||||||
|
UnitfulSpinBox for editing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def makeWidget(self):
|
||||||
|
opts = self.param.opts
|
||||||
|
t = opts['type']
|
||||||
|
defs = {
|
||||||
|
'value': 0, 'min': None, 'max': None,
|
||||||
|
'step': 1.0, 'dec': False,
|
||||||
|
'siPrefix': False, 'suffix': '', 'decimals': 3,
|
||||||
|
'pinSiPrefix': None, 'noUnitEditing': False,
|
||||||
|
}
|
||||||
|
if t == 'int':
|
||||||
|
defs['int'] = True
|
||||||
|
defs['minStep'] = 1.0
|
||||||
|
for k in defs:
|
||||||
|
if k in opts:
|
||||||
|
defs[k] = opts[k]
|
||||||
|
if 'limits' in opts:
|
||||||
|
defs['min'], defs['max'] = opts['limits']
|
||||||
|
w = LockableUnitSpinBox()
|
||||||
|
w.setOpts(**defs)
|
||||||
|
w.sigChanged = w.sigValueChanged
|
||||||
|
w.sigChanging = w.sigValueChanging
|
||||||
|
return w
|
||||||
|
|
||||||
|
|
||||||
|
registerParameterItemType(
|
||||||
|
"float", UnitfulNumericParameterItem, SimpleParameter, override=True
|
||||||
|
)
|
||||||
|
registerParameterItemType(
|
||||||
|
"int", UnitfulNumericParameterItem, SimpleParameter, override=True
|
||||||
|
)
|
@ -1,365 +1,489 @@
|
|||||||
{
|
{
|
||||||
"ctrl_panel":[
|
"ctrl_panel": [
|
||||||
{
|
{
|
||||||
"name":"Temperature",
|
"name": "readings",
|
||||||
"type":"float",
|
"title": "Readings",
|
||||||
"format":"{value:.4f} °C",
|
"type": "group",
|
||||||
"readonly":true
|
"tip": "Thermostat readings",
|
||||||
},
|
"children": [
|
||||||
{
|
{
|
||||||
"name":"Current through TEC",
|
"name": "temperature",
|
||||||
"type":"float",
|
"title": "Temperature",
|
||||||
"suffix":"mA",
|
"type": "float",
|
||||||
"decimals":6,
|
"format": "{value:.4f} {suffix}",
|
||||||
"readonly":true
|
"suffix": "°C",
|
||||||
},
|
"readonly": true,
|
||||||
{
|
"tip": "The measured temperature at the thermistor"
|
||||||
"name":"Output Config",
|
},
|
||||||
"expanded":true,
|
{
|
||||||
"type":"group",
|
"name": "tec_i",
|
||||||
"children":[
|
"title": "Current through TEC",
|
||||||
{
|
"type": "float",
|
||||||
"name":"Control Method",
|
"siPrefix": true,
|
||||||
"type":"mutex",
|
"suffix": "A",
|
||||||
"limits":[
|
"decimals": 6,
|
||||||
"Constant Current",
|
"readonly": true,
|
||||||
"Temperature PID"
|
"tip": "The measured current through the TEC"
|
||||||
],
|
}
|
||||||
"activaters":[
|
]
|
||||||
null,
|
},
|
||||||
[
|
{
|
||||||
"pwm",
|
"name": "output",
|
||||||
"ch",
|
"title": "Output Settings",
|
||||||
"pid"
|
"expanded": true,
|
||||||
]
|
"type": "group",
|
||||||
],
|
"tip": "Settings of the output to the TEC",
|
||||||
"children":[
|
"children": [
|
||||||
{
|
{
|
||||||
"name":"Set Current",
|
"name": "control_method",
|
||||||
"type":"float",
|
"title": "Control Method",
|
||||||
"value":0,
|
"type": "list",
|
||||||
"step":100,
|
"limits": {
|
||||||
"limits":[
|
"Constant Current": "constant_current",
|
||||||
-2000,
|
"Temperature PID": "temperature_pid"
|
||||||
2000
|
},
|
||||||
],
|
"activaters": [
|
||||||
"triggerOnShow":true,
|
null,
|
||||||
"decimals":6,
|
[
|
||||||
"suffix":"mA",
|
"pwm",
|
||||||
"param":[
|
"ch",
|
||||||
"pwm",
|
"pid"
|
||||||
"ch",
|
]
|
||||||
"i_set"
|
],
|
||||||
],
|
"tip": "Select control method of output",
|
||||||
"lock":false
|
"children": [
|
||||||
},
|
{
|
||||||
{
|
"name": "i_set",
|
||||||
"name":"Set Temperature",
|
"title": "Set Current",
|
||||||
"type":"float",
|
"type": "float",
|
||||||
"value":25,
|
"value": 0,
|
||||||
"step":0.1,
|
"step": 0.1,
|
||||||
"limits":[
|
"limits": [
|
||||||
-273,
|
-2,
|
||||||
300
|
2
|
||||||
],
|
],
|
||||||
"format":"{value:.4f} °C",
|
"decimals": 6,
|
||||||
"param":[
|
"pinSiPrefix": "m",
|
||||||
"pid",
|
"suffix": "A",
|
||||||
"ch",
|
"siPrefix": true,
|
||||||
"target"
|
"noUnitEditing": true,
|
||||||
],
|
"compactHeight": false,
|
||||||
"lock":false
|
"param": [
|
||||||
}
|
"pwm",
|
||||||
]
|
"ch",
|
||||||
},
|
"i_set"
|
||||||
{
|
],
|
||||||
"name":"Limits",
|
"tip": "The set current through TEC",
|
||||||
"expanded":true,
|
"lock": false
|
||||||
"type":"group",
|
},
|
||||||
"children":[
|
{
|
||||||
{
|
"name": "target",
|
||||||
"name":"Max Cooling Current",
|
"title": "Setpoint",
|
||||||
"type":"float",
|
"type": "float",
|
||||||
"value":0,
|
"value": 25,
|
||||||
"step":100,
|
"step": 0.1,
|
||||||
"decimals":6,
|
"limits": [
|
||||||
"limits":[
|
-273,
|
||||||
0,
|
300
|
||||||
2000
|
],
|
||||||
],
|
"format": "{value:.4f} {suffix}",
|
||||||
"suffix":"mA",
|
"suffix": "°C",
|
||||||
"param":[
|
"noUnitEditing": true,
|
||||||
"pwm",
|
"compactHeight": false,
|
||||||
"ch",
|
"param": [
|
||||||
"max_i_pos"
|
"pid",
|
||||||
],
|
"ch",
|
||||||
"lock":false
|
"target"
|
||||||
},
|
],
|
||||||
{
|
"tip": "The temperature setpoint of the TEC",
|
||||||
"name":"Max Heating Current",
|
"lock": false
|
||||||
"type":"float",
|
}
|
||||||
"value":0,
|
]
|
||||||
"step":100,
|
},
|
||||||
"decimals":6,
|
{
|
||||||
"limits":[
|
"name": "limits",
|
||||||
0,
|
"title": "Limits",
|
||||||
2000
|
"expanded": true,
|
||||||
],
|
"type": "group",
|
||||||
"suffix":"mA",
|
"tip": "The limits of output, with the polarity at the front panel as reference",
|
||||||
"param":[
|
"children": [
|
||||||
"pwm",
|
{
|
||||||
"ch",
|
"name": "max_i_pos",
|
||||||
"max_i_neg"
|
"title": "Max Cooling Current",
|
||||||
],
|
"type": "float",
|
||||||
"lock":false
|
"value": 0,
|
||||||
},
|
"step": 0.1,
|
||||||
{
|
"decimals": 6,
|
||||||
"name":"Max Voltage Difference",
|
"limits": [
|
||||||
"type":"float",
|
0,
|
||||||
"value":0,
|
2
|
||||||
"step":0.1,
|
],
|
||||||
"limits":[
|
"siPrefix": true,
|
||||||
0,
|
"pinSiPrefix": "m",
|
||||||
5
|
"suffix": "A",
|
||||||
],
|
"noUnitEditing": true,
|
||||||
"siPrefix":true,
|
"compactHeight": false,
|
||||||
"suffix":"V",
|
"param": [
|
||||||
"param":[
|
"pwm",
|
||||||
"pwm",
|
"ch",
|
||||||
"ch",
|
"max_i_pos"
|
||||||
"max_v"
|
],
|
||||||
],
|
"tip": "The maximum cooling (+ve) current through the output pins",
|
||||||
"lock":false
|
"lock": false
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
}
|
"name": "max_i_neg",
|
||||||
]
|
"title": "Max Heating Current",
|
||||||
},
|
"type": "float",
|
||||||
{
|
"value": 0,
|
||||||
"name":"Thermistor Config",
|
"step": 0.1,
|
||||||
"expanded":true,
|
"decimals": 6,
|
||||||
"type":"group",
|
"siPrefix": true,
|
||||||
"children":[
|
"pinSiPrefix": "m",
|
||||||
{
|
"suffix": "A",
|
||||||
"name":"T₀",
|
"noUnitEditing": true,
|
||||||
"type":"float",
|
"limits": [
|
||||||
"value":25,
|
0,
|
||||||
"step":0.1,
|
2
|
||||||
"limits":[
|
],
|
||||||
-100,
|
"compactHeight": false,
|
||||||
100
|
"param": [
|
||||||
],
|
"pwm",
|
||||||
"format":"{value:.4f} °C",
|
"ch",
|
||||||
"param":[
|
"max_i_neg"
|
||||||
"s-h",
|
],
|
||||||
"ch",
|
"tip": "The maximum heating (-ve) current through the output pins",
|
||||||
"t0"
|
"lock": false
|
||||||
],
|
},
|
||||||
"lock":false
|
{
|
||||||
},
|
"name": "max_v",
|
||||||
{
|
"title": "Max Absolute Voltage",
|
||||||
"name":"R₀",
|
"type": "float",
|
||||||
"type":"float",
|
"value": 0,
|
||||||
"value":10000,
|
"step": 0.1,
|
||||||
"step":1,
|
"decimals": 3,
|
||||||
"siPrefix":true,
|
"limits": [
|
||||||
"suffix":"Ω",
|
0,
|
||||||
"param":[
|
4
|
||||||
"s-h",
|
],
|
||||||
"ch",
|
"suffix": "V",
|
||||||
"r0"
|
"noUnitEditing": true,
|
||||||
],
|
"compactHeight": false,
|
||||||
"lock":false
|
"param": [
|
||||||
},
|
"pwm",
|
||||||
{
|
"ch",
|
||||||
"name":"B",
|
"max_v"
|
||||||
"type":"float",
|
],
|
||||||
"value":3950,
|
"tip": "The maximum voltage (in both directions) across the output pins",
|
||||||
"step":1,
|
"lock": false
|
||||||
"suffix":"K",
|
}
|
||||||
"decimals":4,
|
]
|
||||||
"param":[
|
}
|
||||||
"s-h",
|
]
|
||||||
"ch",
|
},
|
||||||
"b"
|
{
|
||||||
],
|
"name": "thermistor",
|
||||||
"lock":false
|
"title": "Thermistor Settings",
|
||||||
},
|
"expanded": true,
|
||||||
{
|
"type": "group",
|
||||||
"name":"Postfilter Rate",
|
"tip": "Parameters for the resistance to temperature conversion with the B-Parameter equation",
|
||||||
"type":"list",
|
"children": [
|
||||||
"value":16.67,
|
{
|
||||||
"param":[
|
"name": "t0",
|
||||||
"postfilter",
|
"title": "T₀",
|
||||||
"ch",
|
"type": "float",
|
||||||
"rate"
|
"value": 25,
|
||||||
],
|
"step": 0.1,
|
||||||
"limits":{
|
"limits": [
|
||||||
"Off":null,
|
-100,
|
||||||
"16.67 Hz":16.67,
|
100
|
||||||
"20 Hz":20.0,
|
],
|
||||||
"21.25 Hz":21.25,
|
"format": "{value:.4f} {suffix}",
|
||||||
"27 Hz":27.0
|
"suffix": "°C",
|
||||||
},
|
"noUnitEditing": true,
|
||||||
"lock":false
|
"compactHeight": false,
|
||||||
}
|
"param": [
|
||||||
]
|
"s-h",
|
||||||
},
|
"ch",
|
||||||
{
|
"t0"
|
||||||
"name":"PID Config",
|
],
|
||||||
"expanded":true,
|
"tip": "The base temperature",
|
||||||
"type":"group",
|
"lock": false
|
||||||
"children":[
|
},
|
||||||
{
|
{
|
||||||
"name":"Kp",
|
"name": "r0",
|
||||||
"type":"float",
|
"title": "R₀",
|
||||||
"step":0.1,
|
"type": "float",
|
||||||
"suffix":"",
|
"value": 10000,
|
||||||
"param":[
|
"step": 100,
|
||||||
"pid",
|
"min": 0,
|
||||||
"ch",
|
"siPrefix": true,
|
||||||
"kp"
|
"pinSiPrefix": "k",
|
||||||
],
|
"suffix": "Ω",
|
||||||
"lock":false
|
"noUnitEditing": true,
|
||||||
},
|
"compactHeight": false,
|
||||||
{
|
"param": [
|
||||||
"name":"Ki",
|
"s-h",
|
||||||
"type":"float",
|
"ch",
|
||||||
"step":0.1,
|
"r0"
|
||||||
"suffix":"Hz",
|
],
|
||||||
"param":[
|
"tip": "The resistance of the thermistor at base temperature T₀",
|
||||||
"pid",
|
"lock": false
|
||||||
"ch",
|
},
|
||||||
"ki"
|
{
|
||||||
],
|
"name": "b",
|
||||||
"lock":false
|
"title": "B",
|
||||||
},
|
"type": "float",
|
||||||
{
|
"value": 3950,
|
||||||
"name":"Kd",
|
"step": 10,
|
||||||
"type":"float",
|
"suffix": "K",
|
||||||
"step":0.1,
|
"noUnitEditing": true,
|
||||||
"suffix":"s",
|
"decimals": 4,
|
||||||
"param":[
|
"compactHeight": false,
|
||||||
"pid",
|
"param": [
|
||||||
"ch",
|
"s-h",
|
||||||
"kd"
|
"ch",
|
||||||
],
|
"b"
|
||||||
"lock":false
|
],
|
||||||
},
|
"tip": "The Beta Parameter",
|
||||||
{
|
"lock": false
|
||||||
"name":"PID Output Clamping",
|
}
|
||||||
"expanded":true,
|
]
|
||||||
"type":"group",
|
},
|
||||||
"children":[
|
{
|
||||||
{
|
"name": "postfilter",
|
||||||
"name":"Minimum",
|
"title": "ADC Settings",
|
||||||
"type":"float",
|
"type": "group",
|
||||||
"step":100,
|
"tip": "Settings of the ADC on the SENS input",
|
||||||
"limits":[
|
"children": [
|
||||||
-2000,
|
{
|
||||||
2000
|
"name": "rate",
|
||||||
],
|
"title": "50/60 Hz Rejection Filter",
|
||||||
"decimals":6,
|
"type": "list",
|
||||||
"suffix":"mA",
|
"value": 16.67,
|
||||||
"param":[
|
"param": [
|
||||||
"pid",
|
"postfilter",
|
||||||
"ch",
|
"ch",
|
||||||
"output_min"
|
"rate"
|
||||||
],
|
],
|
||||||
"lock":false
|
"limits": {
|
||||||
},
|
"16.67 SPS": 16.67,
|
||||||
{
|
"20 SPS": 20.0,
|
||||||
"name":"Maximum",
|
"21.25 SPS": 21.25,
|
||||||
"type":"float",
|
"27 SPS": 27.0,
|
||||||
"step":100,
|
"Off": null
|
||||||
"limits":[
|
},
|
||||||
-2000,
|
"tip": "Adjust the output data rate of the enhanced 50 Hz & 60 Hz rejection filter\n(Helps avoid mains interference)",
|
||||||
2000
|
"lock": false
|
||||||
],
|
}
|
||||||
"decimals":6,
|
]
|
||||||
"suffix":"mA",
|
},
|
||||||
"param":[
|
{
|
||||||
"pid",
|
"name": "pid",
|
||||||
"ch",
|
"title": "PID Settings",
|
||||||
"output_max"
|
"expanded": false,
|
||||||
],
|
"type": "group",
|
||||||
"lock":false
|
"tip": "Settings of PID parameters and clamping",
|
||||||
}
|
"children": [
|
||||||
]
|
{
|
||||||
},
|
"name": "kp",
|
||||||
{
|
"title": "Kp",
|
||||||
"name":"PID Auto Tune",
|
"type": "float",
|
||||||
"expanded":false,
|
"step": 0.1,
|
||||||
"type":"group",
|
"compactHeight": false,
|
||||||
"children":[
|
"param": [
|
||||||
{
|
"pid",
|
||||||
"name":"Target Temperature",
|
"ch",
|
||||||
"type":"float",
|
"kp"
|
||||||
"value":20,
|
],
|
||||||
"step":0.1,
|
"tip": "Proportional gain",
|
||||||
"format":"{value:.4f} °C",
|
"lock": false
|
||||||
"pid_autotune":[
|
},
|
||||||
"target_temp",
|
{
|
||||||
"ch"
|
"name": "ki",
|
||||||
]
|
"title": "Ki",
|
||||||
},
|
"type": "float",
|
||||||
{
|
"step": 0.1,
|
||||||
"name":"Test Current",
|
"suffix": "Hz",
|
||||||
"type":"float",
|
"noUnitEditing": true,
|
||||||
"value":0,
|
"compactHeight": false,
|
||||||
"decimals":6,
|
"param": [
|
||||||
"step":100,
|
"pid",
|
||||||
"limits":[
|
"ch",
|
||||||
-2000,
|
"ki"
|
||||||
2000
|
],
|
||||||
],
|
"tip": "Integral gain",
|
||||||
"suffix":"mA",
|
"lock": false
|
||||||
"pid_autotune":[
|
},
|
||||||
"test_current",
|
{
|
||||||
"ch"
|
"name": "kd",
|
||||||
]
|
"title": "Kd",
|
||||||
},
|
"type": "float",
|
||||||
{
|
"step": 0.1,
|
||||||
"name":"Temperature Swing",
|
"suffix": "s",
|
||||||
"type":"float",
|
"noUnitEditing": true,
|
||||||
"value":1.5,
|
"compactHeight": false,
|
||||||
"step":0.1,
|
"param": [
|
||||||
"prefix":"±",
|
"pid",
|
||||||
"format":"{value:.4f} °C",
|
"ch",
|
||||||
"pid_autotune":[
|
"kd"
|
||||||
"temp_swing",
|
],
|
||||||
"ch"
|
"tip": "Differential gain",
|
||||||
]
|
"lock": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name":"Lookback",
|
"name": "pid_output_clamping",
|
||||||
"type":"float",
|
"title": "PID Output Clamping",
|
||||||
"value":3.0,
|
"expanded": true,
|
||||||
"step":0.1,
|
"type": "group",
|
||||||
"format":"{value:.4f} s",
|
"tip": "Clamps PID outputs to specified range\nCould be different than output limits",
|
||||||
"pid_autotune":[
|
"children": [
|
||||||
|
{
|
||||||
|
"name": "output_min",
|
||||||
|
"title": "Minimum",
|
||||||
|
"type": "float",
|
||||||
|
"step": 0.1,
|
||||||
|
"limits": [
|
||||||
|
-2,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"decimals": 6,
|
||||||
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
|
"noUnitEditing": true,
|
||||||
|
"compactHeight": false,
|
||||||
|
"param": [
|
||||||
|
"pid",
|
||||||
|
"ch",
|
||||||
|
"output_min"
|
||||||
|
],
|
||||||
|
"tip": "Minimum PID output",
|
||||||
|
"lock": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "output_max",
|
||||||
|
"title": "Maximum",
|
||||||
|
"type": "float",
|
||||||
|
"step": 0.1,
|
||||||
|
"limits": [
|
||||||
|
-2,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"decimals": 6,
|
||||||
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
|
"noUnitEditing": true,
|
||||||
|
"compactHeight": false,
|
||||||
|
"param": [
|
||||||
|
"pid",
|
||||||
|
"ch",
|
||||||
|
"output_max"
|
||||||
|
],
|
||||||
|
"tip": "Maximum PID output",
|
||||||
|
"lock": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pid_autotune",
|
||||||
|
"title": "PID Autotune",
|
||||||
|
"expanded": false,
|
||||||
|
"type": "group",
|
||||||
|
"tip": "Automatically tune PID parameters",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"name": "target_temp",
|
||||||
|
"title": "Target Temperature",
|
||||||
|
"type": "float",
|
||||||
|
"value": 20,
|
||||||
|
"step": 0.1,
|
||||||
|
"format": "{value:.4f} {suffix}",
|
||||||
|
"suffix": "°C",
|
||||||
|
"noUnitEditing": true,
|
||||||
|
"compactHeight": false,
|
||||||
|
"pid_autotune": [
|
||||||
|
"target_temp",
|
||||||
|
"ch"
|
||||||
|
],
|
||||||
|
"tip": "The target temperature to autotune for"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test_current",
|
||||||
|
"title": "Test Current",
|
||||||
|
"type": "float",
|
||||||
|
"value": 0,
|
||||||
|
"decimals": 6,
|
||||||
|
"step": 0.1,
|
||||||
|
"limits": [
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
|
"noUnitEditing": true,
|
||||||
|
"compactHeight": false,
|
||||||
|
"pid_autotune": [
|
||||||
|
"test_current",
|
||||||
|
"ch"
|
||||||
|
],
|
||||||
|
"tip": "The testing current when autotuning"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "temp_swing",
|
||||||
|
"title": "Temperature Swing",
|
||||||
|
"type": "float",
|
||||||
|
"value": 1.5,
|
||||||
|
"step": 0.1,
|
||||||
|
"format": "{value:.4f} {suffix}",
|
||||||
|
"suffix": "K",
|
||||||
|
"noUnitEditing": true,
|
||||||
|
"compactHeight": false,
|
||||||
|
"pid_autotune": [
|
||||||
|
"temp_swing",
|
||||||
|
"ch"
|
||||||
|
],
|
||||||
|
"tip": "The temperature swing around the target"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "lookback",
|
||||||
|
"title": "Lookback",
|
||||||
|
"type": "float",
|
||||||
|
"value": 3.0,
|
||||||
|
"step": 0.1,
|
||||||
|
"format": "{value:.4f} {suffix}",
|
||||||
|
"noUnitEditing": true,
|
||||||
|
"suffix": "s",
|
||||||
|
"compactHeight": false,
|
||||||
|
"pid_autotune": [
|
||||||
"lookback",
|
"lookback",
|
||||||
"ch"
|
"ch"
|
||||||
]
|
],
|
||||||
|
"tip": "Amount of time referenced for tuning"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name":"Run",
|
"name": "run_pid",
|
||||||
"type":"action",
|
"title": "Run",
|
||||||
"tip":"Run"
|
"type": "action",
|
||||||
}
|
"tip": "Run PID Autotune with above settings"
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
{
|
},
|
||||||
"name":"Save to flash",
|
{
|
||||||
"type":"action",
|
"name": "save",
|
||||||
"tip":"Save config to thermostat, applies on reset"
|
"title": "Save to flash",
|
||||||
},
|
"type": "action",
|
||||||
{
|
"tip": "Save settings to thermostat, applies on reset"
|
||||||
"name":"Load from flash",
|
},
|
||||||
"type":"action",
|
{
|
||||||
"tip":"Load config from flash"
|
"name": "load",
|
||||||
}
|
"title": "Load from flash",
|
||||||
]
|
"type": "action",
|
||||||
}
|
"tip": "Load settings from thermostat"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -67,16 +67,30 @@ class QtWaitingSpinner(QWidget):
|
|||||||
painter.setPen(Qt.PenStyle.NoPen)
|
painter.setPen(Qt.PenStyle.NoPen)
|
||||||
for i in range(0, self._numberOfLines):
|
for i in range(0, self._numberOfLines):
|
||||||
painter.save()
|
painter.save()
|
||||||
painter.translate(self._innerRadius + self._lineLength, self._innerRadius + self._lineLength)
|
painter.translate(
|
||||||
|
self._innerRadius + self._lineLength,
|
||||||
|
self._innerRadius + self._lineLength,
|
||||||
|
)
|
||||||
rotateAngle = float(360 * i) / float(self._numberOfLines)
|
rotateAngle = float(360 * i) / float(self._numberOfLines)
|
||||||
painter.rotate(rotateAngle)
|
painter.rotate(rotateAngle)
|
||||||
painter.translate(self._innerRadius, 0)
|
painter.translate(self._innerRadius, 0)
|
||||||
distance = self.lineCountDistanceFromPrimary(i, self._currentCounter, self._numberOfLines)
|
distance = self.lineCountDistanceFromPrimary(
|
||||||
color = self.currentLineColor(distance, self._numberOfLines, self._trailFadePercentage,
|
i, self._currentCounter, self._numberOfLines
|
||||||
self._minimumTrailOpacity, self._color)
|
)
|
||||||
|
color = self.currentLineColor(
|
||||||
|
distance,
|
||||||
|
self._numberOfLines,
|
||||||
|
self._trailFadePercentage,
|
||||||
|
self._minimumTrailOpacity,
|
||||||
|
self._color,
|
||||||
|
)
|
||||||
painter.setBrush(color)
|
painter.setBrush(color)
|
||||||
painter.drawRoundedRect(QRect(0, int(-self._lineWidth / 2), self._lineLength, self._lineWidth), self._roundness,
|
painter.drawRoundedRect(
|
||||||
self._roundness, Qt.SizeMode.RelativeSize)
|
QRect(0, int(-self._lineWidth / 2), self._lineLength, self._lineWidth),
|
||||||
|
self._roundness,
|
||||||
|
self._roundness,
|
||||||
|
Qt.SizeMode.RelativeSize,
|
||||||
|
)
|
||||||
painter.restore()
|
painter.restore()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
@ -160,7 +174,9 @@ class QtWaitingSpinner(QWidget):
|
|||||||
self.setFixedSize(self.size, self.size)
|
self.setFixedSize(self.size, self.size)
|
||||||
|
|
||||||
def updateTimer(self):
|
def updateTimer(self):
|
||||||
self._timer.setInterval(int(1000 / (self._numberOfLines * self._revolutionsPerSecond)))
|
self._timer.setInterval(
|
||||||
|
int(1000 / (self._numberOfLines * self._revolutionsPerSecond))
|
||||||
|
)
|
||||||
|
|
||||||
def lineCountDistanceFromPrimary(self, current, primary, totalNrOfLines):
|
def lineCountDistanceFromPrimary(self, current, primary, totalNrOfLines):
|
||||||
distance = primary - current
|
distance = primary - current
|
||||||
@ -168,7 +184,9 @@ class QtWaitingSpinner(QWidget):
|
|||||||
distance += totalNrOfLines
|
distance += totalNrOfLines
|
||||||
return distance
|
return distance
|
||||||
|
|
||||||
def currentLineColor(self, countDistance, totalNrOfLines, trailFadePerc, minOpacity, colorinput):
|
def currentLineColor(
|
||||||
|
self, countDistance, totalNrOfLines, trailFadePerc, minOpacity, colorinput
|
||||||
|
):
|
||||||
color = QColor(colorinput)
|
color = QColor(colorinput)
|
||||||
if countDistance == 0:
|
if countDistance == 0:
|
||||||
return color
|
return color
|
||||||
@ -186,7 +204,7 @@ class QtWaitingSpinner(QWidget):
|
|||||||
return color
|
return color
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
waiting_spinner = QtWaitingSpinner()
|
waiting_spinner = QtWaitingSpinner()
|
||||||
waiting_spinner.show()
|
waiting_spinner.show()
|
||||||
|
141
pytec/tec_qt.py
141
pytec/tec_qt.py
@ -7,12 +7,11 @@ from pytec.gui.view.live_plot_view import LiveDataPlotter
|
|||||||
from pytec.gui.view.ctrl_panel import CtrlPanel
|
from pytec.gui.view.ctrl_panel import CtrlPanel
|
||||||
from pytec.gui.view.info_box import InfoBox
|
from pytec.gui.view.info_box import InfoBox
|
||||||
from pytec.gui.model.pid_autotuner import PIDAutoTuner
|
from pytec.gui.model.pid_autotuner import PIDAutoTuner
|
||||||
from pytec.gui.model.thermostat import WrappedClient, Thermostat
|
from pytec.gui.model.thermostat import Thermostat
|
||||||
import json
|
import json
|
||||||
from autotune import PIDAutotuneState
|
from autotune import PIDAutotuneState
|
||||||
from qasync import asyncSlot, asyncClose
|
from qasync import asyncSlot, asyncClose
|
||||||
import qasync
|
import qasync
|
||||||
from pytec.aioclient import StoppedConnecting
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
@ -63,14 +62,23 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.hw_rev_data = None
|
self.hw_rev_data = None
|
||||||
self.info_box = InfoBox()
|
self.info_box = InfoBox()
|
||||||
|
|
||||||
self.client = WrappedClient(self)
|
|
||||||
self.client.connection_error.connect(self.bail)
|
|
||||||
|
|
||||||
self.thermostat = Thermostat(
|
self.thermostat = Thermostat(
|
||||||
self, self.client, self.report_refresh_spin.value()
|
self, self.report_refresh_spin.value()
|
||||||
)
|
)
|
||||||
|
|
||||||
self.autotuners = PIDAutoTuner(self, self.client, 2)
|
def handle_connection_error():
|
||||||
|
self.info_box.display_info_box(
|
||||||
|
"Connection Error", "Thermostat connection lost. Is it unplugged?"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.bail()
|
||||||
|
|
||||||
|
self.thermostat.connection_error.connect(handle_connection_error)
|
||||||
|
|
||||||
|
self.client.connection_error.connect(self.thermostat.timed_out)
|
||||||
|
self.client.connection_error.connect(self.bail)
|
||||||
|
|
||||||
|
self.autotuners = PIDAutoTuner(self, self.thermostat, 2)
|
||||||
|
|
||||||
def get_ctrl_panel_config(args):
|
def get_ctrl_panel_config(args):
|
||||||
with open(args.param_tree, "r") as f:
|
with open(args.param_tree, "r") as f:
|
||||||
@ -78,26 +86,27 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
param_tree_sigActivated_handles = [
|
param_tree_sigActivated_handles = [
|
||||||
[
|
[
|
||||||
[["Save to flash"], partial(self.thermostat.save_cfg, ch)],
|
[["save"], partial(self.thermostat.save_cfg, ch)],
|
||||||
[["Load from flash"], partial(self.thermostat.load_cfg, ch)],
|
[["load"], partial(self.thermostat.load_cfg, ch)],
|
||||||
[
|
[
|
||||||
["PID Config", "PID Auto Tune", "Run"],
|
["pid", "pid_autotune", "run_pid"],
|
||||||
partial(self.pid_auto_tune_request, ch),
|
partial(self.pid_autotune_request, ch),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
for ch in range(self.NUM_CHANNELS)
|
for ch in range(self.NUM_CHANNELS)
|
||||||
]
|
]
|
||||||
self.thermostat.info_box_trigger.connect(self.info_box.display_info_box)
|
self.thermostat.info_box_trigger.connect(self.info_box.display_info_box)
|
||||||
|
|
||||||
self.zero_limits_warning = ZeroLimitsWarningView(
|
|
||||||
self.style(), self.limits_warning
|
|
||||||
)
|
|
||||||
self.ctrl_panel_view = CtrlPanel(
|
self.ctrl_panel_view = CtrlPanel(
|
||||||
[self.ch0_tree, self.ch1_tree],
|
[self.ch0_tree, self.ch1_tree],
|
||||||
get_ctrl_panel_config(args),
|
get_ctrl_panel_config(args),
|
||||||
self.send_command,
|
self.send_command,
|
||||||
param_tree_sigActivated_handles,
|
param_tree_sigActivated_handles,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.zero_limits_warning = ZeroLimitsWarningView(
|
||||||
|
self.style(), self.limits_warning
|
||||||
|
)
|
||||||
self.ctrl_panel_view.set_zero_limits_warning_sig.connect(
|
self.ctrl_panel_view.set_zero_limits_warning_sig.connect(
|
||||||
self.zero_limits_warning.set_limits_warning
|
self.zero_limits_warning.set_limits_warning
|
||||||
)
|
)
|
||||||
@ -188,9 +197,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.thermostat_ctrl_menu.fan_pwm_warning.setToolTip("")
|
self.thermostat_ctrl_menu.fan_pwm_warning.setToolTip("")
|
||||||
self.clear_graphs()
|
self.clear_graphs()
|
||||||
self.report_box.setChecked(False)
|
self.report_box.setChecked(False)
|
||||||
if not Thermostat.connecting or Thermostat.connected:
|
for ch in range(self.NUM_CHANNELS):
|
||||||
for ch in range(self.NUM_CHANNELS):
|
if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
|
||||||
if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
|
if self.thermostat.connection_errored:
|
||||||
|
# Don't send any commands, just reset local state
|
||||||
|
self.autotuners.autotuners[ch].setOff()
|
||||||
|
else:
|
||||||
await self.autotuners.stop_pid_from_running(ch)
|
await self.autotuners.stop_pid_from_running(ch)
|
||||||
await self.thermostat.set_report_mode(False)
|
await self.thermostat.set_report_mode(False)
|
||||||
self.thermostat.stop_watching()
|
self.thermostat.stop_watching()
|
||||||
@ -232,23 +244,30 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.conn_menu.host_set_line.text(),
|
self.conn_menu.host_set_line.text(),
|
||||||
self.conn_menu.port_set_spin.value(),
|
self.conn_menu.port_set_spin.value(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._connecting_task = None
|
||||||
try:
|
try:
|
||||||
if not (self.client.connecting() or self.client.connected()):
|
if (self._connecting_task is None) or (not self.thermostat.connected()):
|
||||||
self.status_lbl.setText("Connecting...")
|
self.status_lbl.setText("Connecting...")
|
||||||
self.connect_btn.setText("Stop")
|
self.connect_btn.setText("Stop")
|
||||||
self.conn_menu.host_set_line.setEnabled(False)
|
self.conn_menu.host_set_line.setEnabled(False)
|
||||||
self.conn_menu.port_set_spin.setEnabled(False)
|
self.conn_menu.port_set_spin.setEnabled(False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.client.start_session(host=host, port=port, timeout=5)
|
self._connecting_task = asyncio.wait_for(
|
||||||
except StoppedConnecting:
|
self.thermostat.start_session(host=host, port=port), timeout=5
|
||||||
|
)
|
||||||
|
await self._connecting_task
|
||||||
|
except asyncio.TimeoutError:
|
||||||
return
|
return
|
||||||
await self._on_connection_changed(True)
|
await self._on_connection_changed(True)
|
||||||
else:
|
else:
|
||||||
|
if self._connecting_task is not None:
|
||||||
|
self._connecting_task.cancel()
|
||||||
await self.bail()
|
await self.bail()
|
||||||
|
|
||||||
# TODO: Remove asyncio.TimeoutError in Python 3.11
|
# TODO: Remove asyncio.TimeoutError in Python 3.11
|
||||||
except (OSError, TimeoutError, asyncio.TimeoutError):
|
except (OSError, asyncio.TimeoutError):
|
||||||
try:
|
try:
|
||||||
await self.bail()
|
await self.bail()
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
@ -257,53 +276,58 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def bail(self):
|
async def bail(self):
|
||||||
await self._on_connection_changed(False)
|
await self._on_connection_changed(False)
|
||||||
await self.client.end_session()
|
await self.thermostat.disconnect()
|
||||||
|
|
||||||
@asyncSlot(object, object)
|
@asyncSlot(object, object)
|
||||||
async def send_command(self, param, changes):
|
async def send_command(self, param, changes):
|
||||||
"""Translates parameter tree changes into thermostat set_param calls"""
|
"""Translates parameter tree changes into thermostat set_param calls"""
|
||||||
ch = param.channel
|
ch = param.value()
|
||||||
|
|
||||||
for inner_param, change, data in changes:
|
for inner_param, change, data in changes:
|
||||||
if change == "value":
|
if change == "value":
|
||||||
if inner_param.opts.get("param", None) is not None:
|
if inner_param.opts.get("param", None) is not None:
|
||||||
if inner_param.opts.get("suffix", None) == "mA":
|
|
||||||
data /= 1000 # Given in mA
|
|
||||||
|
|
||||||
thermostat_param = inner_param.opts["param"]
|
thermostat_param = inner_param.opts["param"]
|
||||||
if thermostat_param[1] == "ch":
|
if thermostat_param[1] == "ch":
|
||||||
thermostat_param[1] = ch
|
thermostat_param[1] = ch
|
||||||
|
|
||||||
if inner_param.name() == "Postfilter Rate" and data is None:
|
if inner_param.name() == "rate" and data is None:
|
||||||
set_param_args = (*thermostat_param[:2], "off")
|
set_param_args = (*thermostat_param[:2], "off")
|
||||||
else:
|
else:
|
||||||
set_param_args = (*thermostat_param, data)
|
set_param_args = (*thermostat_param, data)
|
||||||
param.child(*param.childPath(inner_param)).setOpts(lock=True)
|
param.child(*param.childPath(inner_param)).setOpts(lock=True)
|
||||||
await self.client.set_param(*set_param_args)
|
await self.thermostat.set_param(*set_param_args)
|
||||||
param.child(*param.childPath(inner_param)).setOpts(lock=False)
|
param.child(*param.childPath(inner_param)).setOpts(lock=False)
|
||||||
|
|
||||||
if inner_param.opts.get("pid_autotune", None) is not None:
|
if inner_param.opts.get("pid_autotune", None) is not None:
|
||||||
auto_tuner_param = inner_param.opts["pid_autotune"][0]
|
autotuner_param = inner_param.opts["pid_autotune"][0]
|
||||||
if inner_param.opts["pid_autotune"][1] != "ch":
|
if inner_param.opts["pid_autotune"][1] != "ch":
|
||||||
ch = inner_param.opts["pid_autotune"][1]
|
ch = inner_param.opts["pid_autotune"][1]
|
||||||
self.autotuners.set_params(auto_tuner_param, ch, data)
|
self.autotuners.set_params(autotuner_param, ch, data)
|
||||||
|
|
||||||
if inner_param.opts.get("activaters", None) is not None:
|
if inner_param.opts.get("activaters", None) is not None:
|
||||||
activater = inner_param.opts["activaters"][
|
activater = inner_param.opts["activaters"][
|
||||||
inner_param.opts["limits"].index(data)
|
inner_param.reverse[0].index(data) # ListParameter.reverse = list of codename values
|
||||||
]
|
]
|
||||||
if activater is not None:
|
if activater is not None:
|
||||||
if activater[1] == "ch":
|
if activater[1] == "ch":
|
||||||
activater[1] = ch
|
activater[1] = ch
|
||||||
await self.client.set_param(*activater)
|
await self.thermostat.set_param(*activater)
|
||||||
|
else:
|
||||||
|
await self.thermostat.set_param(
|
||||||
|
"pwm", ch, "i_set", inner_param.child("i_set").value()
|
||||||
|
)
|
||||||
|
|
||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def pid_auto_tune_request(self, ch=0):
|
async def pid_autotune_request(self, ch=0):
|
||||||
match self.autotuners.get_state(ch):
|
match self.autotuners.get_state(ch):
|
||||||
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
|
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
|
||||||
self.autotuners.load_params_and_set_ready(ch)
|
self.autotuners.load_params_and_set_ready(ch)
|
||||||
|
|
||||||
case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
case (
|
||||||
|
PIDAutotuneState.STATE_READY
|
||||||
|
| PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
| PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
|
):
|
||||||
await self.autotuners.stop_pid_from_running(ch)
|
await self.autotuners.stop_pid_from_running(ch)
|
||||||
# To Update the UI elements
|
# To Update the UI elements
|
||||||
self.pid_autotune_handler([])
|
self.pid_autotune_handler([])
|
||||||
@ -315,24 +339,29 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
match self.autotuners.get_state(ch):
|
match self.autotuners.get_state(ch):
|
||||||
case PIDAutotuneState.STATE_OFF:
|
case PIDAutotuneState.STATE_OFF:
|
||||||
self.ctrl_panel_view.change_params_title(
|
self.ctrl_panel_view.change_params_title(
|
||||||
ch, ("PID Config", "PID Auto Tune", "Run"), "Run"
|
ch, ("pid", "pid_autotune", "run_pid"), "Run"
|
||||||
)
|
)
|
||||||
case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
case (
|
||||||
|
PIDAutotuneState.STATE_READY
|
||||||
|
| PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
| PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
|
):
|
||||||
self.ctrl_panel_view.change_params_title(
|
self.ctrl_panel_view.change_params_title(
|
||||||
ch, ("PID Config", "PID Auto Tune", "Run"), "Stop"
|
ch, ("pid", "pid_autotune", "run_pid"), "Stop"
|
||||||
)
|
)
|
||||||
ch_tuning.append(ch)
|
ch_tuning.append(ch)
|
||||||
|
|
||||||
case PIDAutotuneState.STATE_SUCCEEDED:
|
case PIDAutotuneState.STATE_SUCCEEDED:
|
||||||
self.info_box.display_info_box(
|
self.info_box.display_info_box(
|
||||||
"PID Autotune Success",
|
"PID Autotune Success",
|
||||||
f"Channel {ch} PID Config has been loaded to Thermostat. Regulating temperature.",
|
f"Channel {ch} PID Settings has been loaded to Thermostat. Regulating temperature.",
|
||||||
)
|
)
|
||||||
self.info_box.show()
|
self.info_box.show()
|
||||||
|
|
||||||
case PIDAutotuneState.STATE_FAILED:
|
case PIDAutotuneState.STATE_FAILED:
|
||||||
self.info_box.display_info_box(
|
self.info_box.display_info_box(
|
||||||
"PID Autotune Failed", f"Channel {ch} PID Autotune has failed."
|
"PID Autotune Failed",
|
||||||
|
f"Channel {ch} PID Autotune has failed.",
|
||||||
)
|
)
|
||||||
self.info_box.show()
|
self.info_box.show()
|
||||||
|
|
||||||
@ -349,42 +378,50 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def fan_set_request(self, value):
|
async def fan_set_request(self, value):
|
||||||
if not self.client.connected():
|
assert self.thermostat.connected()
|
||||||
return
|
|
||||||
if self.thermostat_ctrl_menu.fan_auto_box.isChecked():
|
if self.thermostat_ctrl_menu.fan_auto_box.isChecked():
|
||||||
with QSignalBlocker(self.thermostat_ctrl_menu.fan_auto_box):
|
with QSignalBlocker(self.thermostat_ctrl_menu.fan_auto_box):
|
||||||
self.thermostat_ctrl_menu.fan_auto_box.setChecked(False)
|
self.thermostat_ctrl_menu.fan_auto_box.setChecked(False)
|
||||||
await self.client.set_fan(value)
|
await self.thermostat.set_fan(value)
|
||||||
if not self.hw_rev_data["settings"]["fan_pwm_recommended"]:
|
if not self.hw_rev_data["settings"]["fan_pwm_recommended"]:
|
||||||
self.thermostat_ctrl_menu.set_fan_pwm_warning()
|
self.thermostat_ctrl_menu.set_fan_pwm_warning()
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def fan_auto_set_request(self, enabled):
|
async def fan_auto_set_request(self, enabled):
|
||||||
if not self.client.connected():
|
assert self.thermostat.connected()
|
||||||
return
|
|
||||||
if enabled:
|
if enabled:
|
||||||
await self.client.set_fan("auto")
|
await self.thermostat.set_fan("auto")
|
||||||
self.fan_update(await self.client.get_fan())
|
self.fan_update(await self.thermostat.get_fan())
|
||||||
else:
|
else:
|
||||||
await self.client.set_fan(
|
await self.thermostat.set_fan(
|
||||||
self.thermostat_ctrl_menu.fan_power_slider.value()
|
self.thermostat_ctrl_menu.fan_power_slider.value()
|
||||||
)
|
)
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def save_cfg_request(self, ch):
|
async def save_cfg_request(self, ch):
|
||||||
|
assert self.thermostat.connected()
|
||||||
|
|
||||||
await self.thermostat.save_cfg(str(ch))
|
await self.thermostat.save_cfg(str(ch))
|
||||||
|
|
||||||
@asyncSlot(int)
|
@asyncSlot(int)
|
||||||
async def load_cfg_request(self, ch):
|
async def load_cfg_request(self, ch):
|
||||||
|
assert self.thermostat.connected()
|
||||||
|
|
||||||
await self.thermostat.load_cfg(str(ch))
|
await self.thermostat.load_cfg(str(ch))
|
||||||
|
|
||||||
@asyncSlot(bool)
|
@asyncSlot(bool)
|
||||||
async def dfu_request(self, _):
|
async def dfu_request(self, _):
|
||||||
|
assert self.thermostat.connected()
|
||||||
|
|
||||||
await self._on_connection_changed(False)
|
await self._on_connection_changed(False)
|
||||||
await self.thermostat.dfu()
|
await self.thermostat.dfu()
|
||||||
|
|
||||||
@asyncSlot(bool)
|
@asyncSlot(bool)
|
||||||
async def reset_request(self, _):
|
async def reset_request(self, _):
|
||||||
|
assert self.thermostat.connected()
|
||||||
|
|
||||||
await self._on_connection_changed(False)
|
await self._on_connection_changed(False)
|
||||||
await self.thermostat.reset()
|
await self.thermostat.reset()
|
||||||
await asyncio.sleep(0.1) # Wait for the reset to start
|
await asyncio.sleep(0.1) # Wait for the reset to start
|
||||||
@ -393,14 +430,18 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
@asyncSlot(bool)
|
@asyncSlot(bool)
|
||||||
async def net_settings_request(self, _):
|
async def net_settings_request(self, _):
|
||||||
|
assert self.thermostat.connected()
|
||||||
|
|
||||||
ipv4 = await self.thermostat.get_ipv4()
|
ipv4 = await self.thermostat.get_ipv4()
|
||||||
self.net_settings_input_diag = NetSettingsInputDiag(ipv4["addr"])
|
self.net_settings_input_diag = NetSettingsInputDiag(ipv4["addr"])
|
||||||
self.net_settings_input_diag.set_ipv4_act.connect(self.set_net_settings_request)
|
self.net_settings_input_diag.set_ipv4_act.connect(self.set_net_settings_request)
|
||||||
|
|
||||||
@asyncSlot(str)
|
@asyncSlot(str)
|
||||||
async def set_net_settings_request(self, ipv4_settings):
|
async def set_net_settings_request(self, ipv4_settings):
|
||||||
|
assert self.thermostat.connected()
|
||||||
|
|
||||||
await self.thermostat.set_ipv4(ipv4_settings)
|
await self.thermostat.set_ipv4(ipv4_settings)
|
||||||
await self.thermostat._client.end_session()
|
await self.thermostat.end_session()
|
||||||
await self._on_connection_changed(False)
|
await self._on_connection_changed(False)
|
||||||
|
|
||||||
|
|
||||||
@ -414,7 +455,9 @@ async def coro_main():
|
|||||||
app = QtWidgets.QApplication.instance()
|
app = QtWidgets.QApplication.instance()
|
||||||
app.aboutToQuit.connect(app_quit_event.set)
|
app.aboutToQuit.connect(app_quit_event.set)
|
||||||
app.setWindowIcon(
|
app.setWindowIcon(
|
||||||
QtGui.QIcon(str(importlib.resources.files("pytec.gui.resources").joinpath("artiq.ico")))
|
QtGui.QIcon(
|
||||||
|
str(importlib.resources.files("pytec.gui.resources").joinpath("artiq.ico"))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
main_window = MainWindow(args)
|
main_window = MainWindow(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user