[dataio] adding stop button

This commit is contained in:
wendtalexander 2024-10-09 17:14:56 +02:00
parent e3ed301252
commit 32c79ff47b

View File

@ -18,8 +18,7 @@ class SinProducer:
buffer: CircBuffer, buffer: CircBuffer,
) -> None: ) -> None:
self.buffer = buffer self.buffer = buffer
self.stop = False
# self.stopbutton = stopbutton
def produce_sin( def produce_sin(
self, self,
@ -32,20 +31,27 @@ class SinProducer:
log.debug("producing Sin") log.debug("producing Sin")
start_time = time.time() start_time = time.time()
t = 0 t = 0
while time.time() - start_time < 20: while not self.stop:
s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t) s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t)
self.buffer.append(s) self.buffer.append(s)
t += 1 / self.buffer.samplerate t += 1 / self.buffer.samplerate
time.sleep(1 / self.buffer.samplerate) time.sleep(1 / self.buffer.samplerate)
end_time = time.time()
data = self.buffer.get_all() data = self.buffer.get_all()
log.debug(data.shape[0]) log.debug(f"duration sinus {end_time-start_time}")
log.debug(data.shape[0] / self.buffer.samplerate) log.debug(f"Stimulation time {t}")
# log.debug(data.shape[0])
# log.debug(data.shape[0] / self.buffer.samplerate)
# plt.plot(np.arange(data.size) / self.buffer.samplerate, data) # plt.plot(np.arange(data.size) / self.buffer.samplerate, data)
# plt.show() # plt.show()
def stop_request(self):
self.stop = True
if __name__ == "__main__": if __name__ == "__main__":
buf = CircBuffer(1_000_000, 1, samplerate=10000) buf = CircBuffer(1_000_000, 1, samplerate=10_000)
pro_sin = SinProducer(buf) pro_sin = SinProducer(buf)
pro_sin.produce_sin() pro_sin.produce_sin()