57 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import sys
 | |
| import os
 | |
| import tkinter as tk
 | |
| from tkinter import ttk
 | |
| import RPi.GPIO as GPIO
 | |
| from matplotlib.figure import Figure
 | |
| from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
 | |
| import time
 | |
| # 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_pins import *  # Import pin assignments
 | |
| 
 | |
| def create_digital_plot_tab(notebook):
 | |
|     frame = ttk.Frame(notebook)
 | |
|     notebook.add(frame, text="Digital Inputs")
 | |
| 
 | |
|     figure = Figure(figsize=(8, 5), dpi=100)
 | |
|     ax = figure.add_subplot(1, 1, 1)
 | |
|     ax.set_title("Digital Input States Over Time")
 | |
|     ax.set_xlabel("Time (s)")
 | |
|     ax.set_ylabel("State (0=LOW, 1=HIGH)")
 | |
|     ax.set_ylim(-0.2, 1.2)
 | |
| 
 | |
|     canvas = FigureCanvasTkAgg(figure, master=frame)
 | |
|     canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True)
 | |
| 
 | |
|     input_channels = list(range(8))
 | |
|     data = {ch: [] for ch in input_channels}
 | |
|     time_data = []
 | |
| 
 | |
|     def update_plot():
 | |
|         current_time = time.time()
 | |
|         if len(time_data) > 50:
 | |
|             for ch in input_channels:
 | |
|                 data[ch].pop(0)
 | |
|             time_data.pop(0)
 | |
| 
 | |
|         time_data.append(current_time)
 | |
|         for ch in input_channels:
 | |
|             state = GPIO.input(GPIO_DIGITAL_INPUTS[ch])
 | |
|             data[ch].append(state)
 | |
| 
 | |
|         ax.clear()
 | |
|         ax.set_title("Digital Input States Over Time")
 | |
|         ax.set_xlabel("Time (s)")
 | |
|         ax.set_ylabel("State (0=LOW, 1=HIGH)")
 | |
|         ax.set_ylim(-0.2, 1.2)
 | |
| 
 | |
|         for ch in input_channels:
 | |
|             ax.step(time_data, data[ch], label=f"IN {ch+1}", where="post")
 | |
| 
 | |
|         ax.legend(loc="upper right")
 | |
|         canvas.draw()
 | |
|         frame.after(500, update_plot)
 | |
| 
 | |
|     update_plot()
 |