aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2018-07-23 22:09:32 +0200
committerMichael Buesch <m@bues.ch>2018-07-23 22:09:32 +0200
commit8eb9c7bb9850dc337e9e8e43c9785073d389554a (patch)
tree7bf7c445cc02a4be278a6ed9d0f86e216b63be55
parentb0e930358da59650d962b384bbec91f72b9eae2f (diff)
downloadxytronic-lf-8eb9c7bb9850dc337e9e8e43c9785073d389554a.tar.xz
xytronic-lf-8eb9c7bb9850dc337e9e8e43c9785073d389554a.zip
simulator: Fix writing of settings
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--firmware/simulator/simulator.cxx75
-rwxr-xr-xfirmware/simulator/xytronic_simulator.py89
2 files changed, 97 insertions, 67 deletions
diff --git a/firmware/simulator/simulator.cxx b/firmware/simulator/simulator.cxx
index 767b737..7c12575 100644
--- a/firmware/simulator/simulator.cxx
+++ b/firmware/simulator/simulator.cxx
@@ -36,6 +36,8 @@
#include "../timer.h"
#include "../measure.h"
#include "../settings.h"
+#include "../menu.h"
+#include "../measure_temp.h"
#include <thread>
#include <mutex>
@@ -450,40 +452,57 @@ bool simulator_adc_set(int adc_index, uint16_t value)
return false;
}
-#define SETTINGS_ACCESS(_field, _name, _value, _write) do { \
- if (strcmp(_name, stringify(_field)) == 0) { \
- if (_write) \
+#define SETTINGS_ACCESS(_field, _compare_name, _name, _value, _write) ({ \
+ bool retval = false; \
+ if (strcmp(_name, _compare_name) == 0) { \
+ if (_write) { \
get_settings()->_field = *(_value); \
- else \
+ store_settings(); \
+ } else \
(*_value) = get_settings()->_field; \
- return true; \
+ retval = true; \
} \
- } while (0)
+ retval; \
+ })
bool simulator_setting_access(const char *name, int *value, bool write)
{
- SETTINGS_ACCESS(temp_k[0].kp, name, value, write);
- SETTINGS_ACCESS(temp_k[0].ki, name, value, write);
- SETTINGS_ACCESS(temp_k[0].kd, name, value, write);
- SETTINGS_ACCESS(temp_k[0].d_decay_div, name, value, write);
- SETTINGS_ACCESS(temp_k[1].kp, name, value, write);
- SETTINGS_ACCESS(temp_k[1].ki, name, value, write);
- SETTINGS_ACCESS(temp_k[1].kd, name, value, write);
- SETTINGS_ACCESS(temp_k[1].d_decay_div, name, value, write);
- SETTINGS_ACCESS(temp_k[2].kp, name, value, write);
- SETTINGS_ACCESS(temp_k[2].ki, name, value, write);
- SETTINGS_ACCESS(temp_k[2].kd, name, value, write);
- SETTINGS_ACCESS(temp_k[2].d_decay_div, name, value, write);
- SETTINGS_ACCESS(temp_idle_setpoint, name, value, write);
- SETTINGS_ACCESS(temp_setpoint[0], name, value, write);
- SETTINGS_ACCESS(temp_setpoint[1], name, value, write);
- SETTINGS_ACCESS(temp_setpoint[2], name, value, write);
- SETTINGS_ACCESS(temp_setpoint[3], name, value, write);
- SETTINGS_ACCESS(temp_setpoint[4], name, value, write);
- SETTINGS_ACCESS(temp_setpoint[5], name, value, write);
- SETTINGS_ACCESS(temp_setpoint_active, name, value, write);
- SETTINGS_ACCESS(temp_adj, name, value, write);
- SETTINGS_ACCESS(serial, name, value, write);
+ struct settings *s = get_settings();
+
+ if (SETTINGS_ACCESS(temp_k[0].kp, "temp_k[0].kp", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[0].ki, "temp_k[0].ki", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[0].kd, "temp_k[0].kd", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[0].d_decay_div, "temp_k[0].d_decay_div", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[1].kp, "temp_k[1].kp", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[1].ki, "temp_k[1].ki", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[1].kd, "temp_k[1].kd", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[1].d_decay_div, "temp_k[1].d_decay_div", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[2].kp, "temp_k[2].kp", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[2].ki, "temp_k[2].ki", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[2].kd, "temp_k[2].kd", name, value, write) ||
+ SETTINGS_ACCESS(temp_k[2].d_decay_div, "temp_k[2].d_decay_div", name, value, write)) {
+ contrtemp_update_pid_config();
+ return true;
+ }
+ if (SETTINGS_ACCESS(temp_idle_setpoint, "temp_idle_setpoint", name, value, write)) {
+ contrtemp_set_idle_setpoint(get_settings()->temp_idle_setpoint);
+ return true;
+ }
+ if (SETTINGS_ACCESS(temp_setpoint[s->temp_setpoint_active], "temp_setpoint", name, value, write) ||
+ SETTINGS_ACCESS(temp_setpoint_active, "temp_setpoint_active", name, value, write)) {
+ contrtemp_update_setpoint();
+ menu_request_display_update();
+ return true;
+ }
+ if (strcmp(name, "temp_adj") == 0) {
+ if (write)
+ meastemp_adjust_set(*value);
+ else
+ *value = meastemp_adjust_get();
+ return true;
+ }
+ if (SETTINGS_ACCESS(serial, "serial", name, value, write))
+ return true;
return false;
}
diff --git a/firmware/simulator/xytronic_simulator.py b/firmware/simulator/xytronic_simulator.py
index d00bf85..b0315f6 100755
--- a/firmware/simulator/xytronic_simulator.py
+++ b/firmware/simulator/xytronic_simulator.py
@@ -26,7 +26,6 @@ import time
import sys
-
class Simulator(object):
CURR_DIV = 10.0
ADC_TEMP = 1
@@ -49,12 +48,7 @@ class Simulator(object):
"temp_k[2].kd" : "fixpt_t",
"temp_k[2].d_decay_div" : "fixpt_t",
"temp_idle_setpoint" : "fixpt_t",
- "temp_setpoint[0]" : "fixpt_t",
- "temp_setpoint[1]" : "fixpt_t",
- "temp_setpoint[2]" : "fixpt_t",
- "temp_setpoint[3]" : "fixpt_t",
- "temp_setpoint[4]" : "fixpt_t",
- "temp_setpoint[5]" : "fixpt_t",
+ "temp_setpoint" : "fixpt_t",
"temp_setpoint_active" : "uint8_t",
"temp_adj" : "fixpt_t",
"serial" : "uint8_t",
@@ -64,10 +58,16 @@ class Simulator(object):
self.xy = pyxytronic
self.__uartbuf = bytearray()
self.__reset_debuginterface()
+ self.__runHook = []
+
+ def addRunHook(self, hook):
+ self.__runHook.append(hook)
def run(self):
self.xy.simulator_mainloop_once()
self.__handle_debuginterface()
+ for hook in self.__runHook:
+ hook();
def setting_get(self, name):
value = self.xy.simulator_setting_read(name)
@@ -161,18 +161,18 @@ class Simulator(object):
return f
def __reset_debuginterface(self):
- self.__dbg_currentRealR = 0.0
- self.__dbg_currentUsedR = 0.0
- self.__dbg_currentRState = 0
- self.__dbg_currentY = 0.0
- self.__dbg_tempR = 0.0
- self.__dbg_tempY1 = 0.0
- self.__dbg_tempY2 = 0.0
- self.__dbg_measCurr = 0
- self.__dbg_filtCurr = 0
- self.__dbg_measTemp = 0
- self.__dbg_boostMode = 0
- self.__dbg_calCurrPercent = 0
+ self.dbg_currentRealR = 0.0
+ self.dbg_currentUsedR = 0.0
+ self.dbg_currentRState = 0
+ self.dbg_currentY = 0.0
+ self.dbg_tempR = 0.0
+ self.dbg_tempY1 = 0.0
+ self.dbg_tempY2 = 0.0
+ self.dbg_measCurr = 0
+ self.dbg_filtCurr = 0
+ self.dbg_measTemp = 0
+ self.dbg_boostMode = 0
+ self.dbg_calCurrPercent = 0
@classmethod
def __parseInt(cls, valStr, valIdent):
@@ -214,39 +214,33 @@ class Simulator(object):
self.error("Unknown format: %s" % line)
return
if elems[0] == "cr1":
- self.__dbg_currentRealR = self.__parseFixpt(elems[1], "cr1") / self.CURR_DIV
+ self.dbg_currentRealR = self.__parseFixpt(elems[1], "cr1") / self.CURR_DIV
elif elems[0] == "cr2":
- self.__dbg_currentUsedR = self.__parseFixpt(elems[1], "cr2") / self.CURR_DIV
+ self.dbg_currentUsedR = self.__parseFixpt(elems[1], "cr2") / self.CURR_DIV
elif elems[0] == "rs":
- self.__dbg_currentRState = self.__parseInt(elems[1], "rs")
+ self.dbg_currentRState = self.__parseInt(elems[1], "rs")
elif elems[0] == "cy":
- self.__dbg_currentY = self.__parseFixpt(elems[1], "cy") / self.CURR_DIV
+ self.dbg_currentY = self.__parseFixpt(elems[1], "cy") / self.CURR_DIV
elif elems[0] == "tr":
- self.__dbg_tempR = self.__parseFixpt(elems[1], "tr")
+ self.dbg_tempR = self.__parseFixpt(elems[1], "tr")
elif elems[0] == "ty1":
- self.__dbg_tempY1 = self.__parseFixpt(elems[1], "ty1")
+ self.dbg_tempY1 = self.__parseFixpt(elems[1], "ty1")
elif elems[0] == "ty2":
- self.__dbg_tempY2 = self.__parseFixpt(elems[1], "ty2") / self.CURR_DIV
+ self.dbg_tempY2 = self.__parseFixpt(elems[1], "ty2") / self.CURR_DIV
elif elems[0] == "tb":
- self.__dbg_boostMode = self.__parseInt(elems[1], "tb")
+ self.dbg_boostMode = self.__parseInt(elems[1], "tb")
elif elems[0] == "mc":
- self.__dbg_measCurr = self.__parseInt(elems[1], "mc")
+ self.dbg_measCurr = self.__parseInt(elems[1], "mc")
elif elems[0] == "fc":
- self.__dbg_filtCurr = self.__parseInt(elems[1], "fc")
+ self.dbg_filtCurr = self.__parseInt(elems[1], "fc")
elif elems[0] == "mt":
- self.__dbg_measTemp = self.__parseInt(elems[1], "mt")
+ self.dbg_measTemp = self.__parseInt(elems[1], "mt")
elif elems[0] == "cc":
- self.__dbg_calCurrPercent = self.__parseInt(elems[1], "cc")
+ self.dbg_calCurrPercent = self.__parseInt(elems[1], "cc")
else:
self.error("Unknown elem: %s" % elems[0])
return
- self.info("temp-r: %.02f °C current-y: %.02f A current-r: %.02f A" % (
- self.__dbg_tempR,
- self.__dbg_currentY,
- self.__dbg_currentUsedR,
- ))
-
@classmethod
def error(cls, msg):
print(msg)
@@ -255,14 +249,31 @@ class Simulator(object):
def info(cls, msg):
print(msg)
+class IronTempSimulator(object):
+ def __init__(self, sim):
+ self.sim = sim
+ self.sim.addRunHook(self.__run)
+
+ def __run(self):
+ self.sim.adc_temp_set(100)#TODO
+
+class IronCurrentSimulator(object):
+ def __init__(self, sim):
+ self.sim = sim
+ self.sim.addRunHook(self.__run)
+
+ def __run(self):
+ curY = self.sim.pwm_current_get()
+ self.sim.adc_current_set(4)#TODO
+
def main():
pyxytronic.simulator_init()
try:
sim = Simulator()
+ tempSim = IronTempSimulator(sim)
+ curSim = IronCurrentSimulator(sim)
while 1:
sim.run()
- sim.adc_temp_set(100)
- sim.adc_current_set(4)
time.sleep(0.0005)
finally:
pyxytronic.simulator_exit()
bues.ch cgit interface