Forráskód Böngészése

minor QoL changes

subDesTagesMitExtraKaese 3 éve
szülő
commit
60cf6bd580

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 26 - 1
README.md


+ 5 - 1
raspberry-pi/config.ini

@@ -38,4 +38,8 @@
 
 [mag_sensor]
 
-[opt_sensor]
+[opt_sensor]
+
+[gui]
+  fullscreen = yes
+  log_lines  = 100

+ 3 - 3
raspberry-pi/gui/logScreen.py

@@ -30,7 +30,7 @@ class LogScreen(tk.Frame):
     self.quit_button = tk.Button(self, text="Close", command=self.close, height=2, width = 10)
     self.quit_button.pack(side="right", fill="both")
 
-    self.disable_refresh_button = tk.Button(self,text="disable refreshing", command=self.toggle_refreshing, height=2, width=20, relief="raised", bg="green", fg="white")
+    self.disable_refresh_button = tk.Button(self,text="disable refreshing", command=self.toggle_refreshing, height=2, width=20, relief="raised", bg="green", activebackground="#00dd00", fg="white")
     self.disable_refresh_button.pack(side="right", fill="both")
 
     for element in self.log_handler.get_log_list():
@@ -56,6 +56,6 @@ class LogScreen(tk.Frame):
   def toggle_refreshing(self):
     self.disable_refresh = not self.disable_refresh
     if self.disable_refresh:
-      self.disable_refresh_button.config(text="Enable refresh", relief="sunken", bg="red")
+      self.disable_refresh_button.config(text="Enable refresh", relief="sunken", background="#ee0000", activebackground="#ff0000")
     else:
-      self.disable_refresh_button.config(text="Disable refresh", relief="raised", bg="green")
+      self.disable_refresh_button.config(text="Disable refresh", relief="raised", background="green", activebackground="#00dd00")

+ 3 - 4
raspberry-pi/gui/mainWindow.py

@@ -11,13 +11,12 @@ import logHandler
 
 
 class MainWindow(tk.Frame):
-  def __init__(self, root, ac_sensor, ac_queue, ac_cal_state, conf):
+  def __init__(self, root, ac_sensor, ac_cal_state, conf):
     self.root = root
     self.popup = None
     self.log_window = None
     self.ac_cal_state = ac_cal_state
     self.ac_sensor = ac_sensor
-    self.ac_queue = ac_queue
     self.log_handler = logHandler.get_log_handler()
     self.conf = conf
 
@@ -61,8 +60,8 @@ class MainWindow(tk.Frame):
 
     ac_positions = []
     # aggregate measurements
-    while self.ac_queue.qsize() > 0:
-      name, data = self.ac_queue.get()
+    while self.ac_sensor.queue.qsize() > 0:
+      name, data = self.ac_sensor.queue.get()
       if name == "data":
         ac_positions.append(data[0:2])
         self.ac_dro_val_sums += data

+ 5 - 4
raspberry-pi/logHandler.py

@@ -1,15 +1,16 @@
 import datetime
 
 class LogList():
-  def __init__(self):
+  def __init__(self, line_count):
     self.log_list = list()
     self.read_index = 0
     self.write_index = 0
+    self.line_count = line_count
 
   def add_item(self, item):
     self.log_list.append(item)
     self.write_index += 1
-    if len(self.log_list) > 100:
+    if len(self.log_list) > self.line_count:
       self.log_list.pop(0)
 
   def log_and_print(self, *args):
@@ -30,8 +31,8 @@ class LogList():
 
 _log_handler = None
 
-def get_log_handler():
+def get_log_handler(line_count = 100):
   global _log_handler
   if not _log_handler:
-    _log_handler = LogList()
+    _log_handler = LogList(line_count)
   return _log_handler

+ 7 - 7
raspberry-pi/main.py

@@ -1,8 +1,9 @@
+#!/usr/bin/env python3
+
 from sensors.acousticSensor import AcousticSensor
 from sensors.calibration import CalibrationStateMashine
 from gui.mainWindow import MainWindow
 
-import queue
 import configparser
 import tkinter as tk
 import traceback
@@ -12,17 +13,16 @@ conf = configparser.ConfigParser()
 conf.read('config.ini')
 
 def main():
-  log_handler = logHandler.get_log_handler()
-  ac_queue = queue.Queue()
-  ac_calibration_state = CalibrationStateMashine(log_handler)
-  ac_sensor = AcousticSensor(conf, ac_queue, ac_calibration_state)
+  log_handler = logHandler.get_log_handler(int(conf['gui']['log_lines']))
+  ac_calibration_state = CalibrationStateMashine()
+  ac_sensor = AcousticSensor(conf, ac_calibration_state)
 
   try:
     ac_sensor.start()
     root = tk.Tk()
     root.title("Tracking System")
-    root.attributes('-fullscreen', True)
-    view = MainWindow(root, ac_sensor, ac_queue, ac_calibration_state, conf)
+    root.attributes('-fullscreen', conf['gui']['fullscreen'] == "yes")
+    view = MainWindow(root, ac_sensor, ac_calibration_state, conf)
     view.pack(side="top", fill="both", expand=True)
     view.update()
     root.mainloop()

+ 5 - 0
raspberry-pi/requirements.txt

@@ -0,0 +1,5 @@
+numpy==1.17.4
+pyglet==1.5.15
+opencv_python==4.4.0.44
+Pillow==8.3.1
+pyserial==3.5

+ 4 - 3
raspberry-pi/sensors/acousticSensor.py

@@ -4,6 +4,7 @@ import math
 import threading
 import random
 import traceback
+import queue
 
 from sensors.connection import globalArduinoSlave
 import logHandler
@@ -12,9 +13,9 @@ conn = globalArduinoSlave()
 
 
 class AcousticSensor:
-  def __init__(self, conf, ac_queue, calibration_state):
+  def __init__(self, conf, calibration_state):
     self.conf = conf
-    self.ac_queue               = ac_queue
+    self.queue                  = queue.Queue()
     self.calibration_state      = calibration_state
     self.field_height           = float(conf["field"]["y"])
     self.field_width            = float(conf["field"]["x"])
@@ -183,4 +184,4 @@ class AcousticSensor:
     return (distance_left / sonic_speed + overhead_left, distance_right / sonic_speed + overhead_right)
 
   def pass_to_gui(self, data):
-    self.ac_queue.put(("data", data))
+    self.queue.put(("data", data))

+ 3 - 2
raspberry-pi/sensors/calibration.py

@@ -1,7 +1,8 @@
+import logHandler
 
 class CalibrationStateMashine():
 
-  def __init__(self,log_handler):
+  def __init__(self):
     self.state = 0
     self.progress = 0
 
@@ -12,7 +13,7 @@ class CalibrationStateMashine():
     self.ACCUMULATING_2 = 4
     self.CALIBRATION_DONE = 5
 
-    self.log_handler = log_handler
+    self.log_handler = logHandler.get_log_handler()
     
   def state_clearname(self):
     if self.state == self.NOT_CALIBRATED: