#!/usr/bin/env python3

from sensors.acousticSensor import AcousticSensor
from sensors.opticalSensor import OpticalSensor
from sensors.magneticSensor import MagneticSensor
from gui.mainWindow import MainWindow

import configparser
import tkinter as tk
import traceback
import logHandler

conf = configparser.ConfigParser()
conf.read('config.ini')
print(conf.sections())

def main():
  log_handler = logHandler.get_log_handler(int(conf['gui']['log_lines']))
  ac_sensor = AcousticSensor(conf)
  opt_sensor = OpticalSensor(conf)
  mag_sensor = MagneticSensor(conf)

  try:
    ac_sensor.start()
    opt_sensor.start()
    mag_sensor.start()
    root = tk.Tk()
    root.title("Tracking System")
    root.attributes('-fullscreen', conf['gui']['fullscreen'] == "yes")
    view = MainWindow(root, conf, ac_sensor, opt_sensor, mag_sensor)
    view.pack(side="top", fill="both", expand=True)
    view.update()
    root.mainloop()

  except KeyboardInterrupt:
    print("stop")
  except Exception as e:
    print("Error: ",e)
    traceback.print_exc()
  finally:
    ac_sensor.stop()
    opt_sensor.stop()
    mag_sensor.stop()

main()