Configure refresh rate in ExampleDeviceScalar
This commit is contained in:
parent
3b9b0fc06c
commit
0549cfe0d6
@ -13,8 +13,9 @@ LOGGER = logging.getLogger("my_logger")
|
||||
class ExampleDeviceWorker(Thread):
|
||||
"""Communicates with the measuring hardware. Here we only produce random data."""
|
||||
|
||||
def __init__(self, message_queue):
|
||||
def __init__(self, message_queue, refresh_rate):
|
||||
super().__init__(name="Measure")
|
||||
self.refresh_rate = refresh_rate
|
||||
self.message_queue = message_queue
|
||||
self.produceData = Event()
|
||||
self.exit_request = Event()
|
||||
@ -30,7 +31,7 @@ class ExampleDeviceWorker(Thread):
|
||||
self.message_queue.put((ts, temp))
|
||||
else:
|
||||
pass
|
||||
sleep(0.2)
|
||||
sleep(self.refresh_rate)
|
||||
|
||||
|
||||
class ExampleDeviceScalar(Device):
|
||||
@ -38,11 +39,11 @@ class ExampleDeviceScalar(Device):
|
||||
|
||||
def __init__(self):
|
||||
super(Device, self).__init__()
|
||||
self.refresh_rate = 0.2
|
||||
self.measureQueue = Queue()
|
||||
self.measureThread = ExampleDeviceWorker(self.measureQueue)
|
||||
self.measureThread = ExampleDeviceWorker(self.measureQueue, self.refresh_rate)
|
||||
self.measureThread.start()
|
||||
self.measureThread.produceData.set()
|
||||
self.speed = 10
|
||||
self.running = False
|
||||
|
||||
def exit(self):
|
||||
@ -50,10 +51,11 @@ class ExampleDeviceScalar(Device):
|
||||
self.measureThread.exit_request.set()
|
||||
|
||||
def set_config(self, config: dict):
|
||||
self.speed = config["speed"]
|
||||
self.refresh_rate = config["refresh_rate"]
|
||||
self.measureThread.refresh_rate = self.refresh_rate
|
||||
|
||||
def get_config(self):
|
||||
return {"speed": self.speed}
|
||||
return {"refresh_rate": self.refresh_rate}
|
||||
|
||||
def get_status(self):
|
||||
return {"running": self.running}
|
||||
|
@ -1,7 +1,6 @@
|
||||
from time import sleep
|
||||
from shutil import rmtree
|
||||
from CoreLibrary.Param_Model import Param_Model
|
||||
from CoreLibrary.Measurement import Measurement
|
||||
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
@ -15,17 +14,17 @@ def clean():
|
||||
def main(param_model: Param_Model):
|
||||
sensor = param_model.devices["mess1"]
|
||||
driver = param_model.devices["treib1"]
|
||||
driver.set_config({"speed": 2})
|
||||
driver.set_config({"refresh_rate": 0.2})
|
||||
status = driver.get_status()
|
||||
|
||||
plot_data = param_model.get_plot_data()
|
||||
|
||||
for speed in [1.0, 2.0, 3.0]:
|
||||
for speed in [0.2, 0.5, 1.0]:
|
||||
print(speed)
|
||||
driver.set_config({"speed": speed})
|
||||
driver.set_config({"refresh_rate": speed})
|
||||
|
||||
measurement = param_model.new_measurement(name=f"penis_{speed}", writer="CSV")
|
||||
measurement.attach_device(device=sensor, name="mess1")
|
||||
measurement.attach_device(device=driver, name="treib1")
|
||||
measurement.write_log("ich mag ramen")
|
||||
param_model.start_measuring()
|
||||
sleep(2)
|
||||
|
Loading…
Reference in New Issue
Block a user