90 lines
2.8 KiB
Python
90 lines
2.8 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
from tkinter import messagebox
|
|
import RPi.GPIO as GPIO
|
|
|
|
# Add the parent directory to the module search path
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
from interface_board_libs.adc_mcp3208 import MCP3208
|
|
from interface_board_libs.shift_register import ShiftRegister
|
|
from interface_board_pins import * # Import pin assignments
|
|
from tab_control import create_control_tab
|
|
from tab_control import set_updating_enabled as tab_control__set_updating_enabled
|
|
from tab_adc_plot import create_adc_plot_tab
|
|
from tab_adc_plot import set_updating_enabled as tab_analog_plot__set_updating_enabled
|
|
from tab_digital_plot import create_digital_plot_tab
|
|
from tab_digital_plot import set_updating_enabled as tab_digital_plot__set_updating_enabled
|
|
from tab_exit import create_exit_tab
|
|
|
|
|
|
# Initialize ADC & Shift Register
|
|
adc = MCP3208()
|
|
shift_reg = ShiftRegister(GPIO_SHIFT_REG_DATA, GPIO_SHIFT_REG_LATCH, GPIO_SHIFT_REG_CLOCK)
|
|
|
|
|
|
# GPIO Setup
|
|
GPIO.setmode(GPIO.BCM)
|
|
for pin in GPIO_DIGITAL_INPUTS.values():
|
|
GPIO.setup(pin, GPIO.IN)
|
|
GPIO.setup(GPIO_PWM1, GPIO.OUT)
|
|
GPIO.setup(GPIO_PWM2, GPIO.OUT)
|
|
pwm1 = GPIO.PWM(GPIO_PWM1, 1000)
|
|
pwm2 = GPIO.PWM(GPIO_PWM2, 1000)
|
|
pwm1.start(0)
|
|
pwm2.start(0)
|
|
|
|
|
|
# Tkinter GUI
|
|
root = tk.Tk()
|
|
root.title("Raspberry Pi Interface Board")
|
|
root.attributes('-fullscreen', True)
|
|
root.configure(bg="black")
|
|
|
|
|
|
# Tabbed Interface
|
|
notebook = ttk.Notebook(root)
|
|
notebook.pack(expand=True, fill="both")
|
|
|
|
|
|
# Track active tab
|
|
def on_tab_change(event):
|
|
active_tab = event.widget.tab(event.widget.index("current"), "text")
|
|
print (f"INFO: switched to tab {active_tab}")
|
|
match active_tab:
|
|
case "ADC Plot":
|
|
tab_control__set_updating_enabled(False)
|
|
tab_analog_plot__set_updating_enabled(True)
|
|
tab_digital_plot__set_updating_enabled(False)
|
|
case "Digital Inputs":
|
|
tab_control__set_updating_enabled(False)
|
|
tab_analog_plot__set_updating_enabled(False)
|
|
tab_digital_plot__set_updating_enabled(True)
|
|
case "Controls":
|
|
tab_control__set_updating_enabled(True)
|
|
tab_analog_plot__set_updating_enabled(False)
|
|
tab_digital_plot__set_updating_enabled(False)
|
|
case "EXIT":
|
|
pass
|
|
case _:
|
|
print(f"unhandled change to tab {active_tab}")
|
|
|
|
notebook.bind("<<NotebookTabChanged>>", on_tab_change)
|
|
|
|
|
|
# Add tabs
|
|
create_control_tab(notebook, adc, shift_reg, pwm1, pwm2)
|
|
create_adc_plot_tab(notebook, adc)
|
|
create_digital_plot_tab(notebook)
|
|
create_exit_tab(notebook, root, pwm1, pwm2)
|
|
|
|
|
|
# Run GUI
|
|
try:
|
|
root.mainloop()
|
|
|
|
except KeyboardInterrupt:
|
|
print('Keyboard interrupt -> exiting')
|
|
exit() |