-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosci.py
More file actions
150 lines (127 loc) · 4.63 KB
/
Copy pathosci.py
File metadata and controls
150 lines (127 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import time
import queue
import random
import math
import threading
from tkinter import *
import fft
import serial
import sys
LICENSE_MESSAGE="""
#############################################################
# #
# This program is relased in the GNU GPL v3.0 license #
# you can modify/use this program as you wish. Please #
# link the original distribution of this software. If #
# you plan to redistribute your modified/copied copy #
# you need to relased the in GNU GPL v3.0 licence too #
# according to the overmentioned licence. #
# #
# "PROUDLY" MADE BY chkrr00k (i'm not THAT proud tbh) #
# #
#############################################################
# #
# #
# YEE #
# #
# #
#############################################################
"""
class Display:
def __init__(self, canvas, max=0, step=-1):
self.canvas = canvas
self.values = list()
self.max = max
self.step = step
self.highest = 1
self.running =-1
def shift(self, v):
self.values.append(v)
if len(self.values)> self.max:
self.values = self.values[len(self.values)-self.max:]
def plot_raw(self):
self.stop()
self.running = 1
self.draw()
def plot_fft(self):
self.stop()
self.running = 2
self.drawFFT()
def stop(self):
self.running = -1
self.highest = 1
def draw(self):
self.canvas.delete("all")
if self.running == 1:
self.canvas.master.after(200, self.draw)
else:
self.stop()
step = self.step
if self.step == -1:
step = self.canvas.winfo_width()/self.max
else:
self.stop()
current = step/2
last = 0
v = 0
for d in self.values:
self.highest = max(d, self.highest)
v = int(self.canvas.winfo_height() - round(d*((self.canvas.winfo_height()-100)/self.highest)))-50
self.canvas.create_line(current, v, current-step, last, fill="yellow", width=3)
last = v
current += step
self.canvas.create_line(self.canvas.winfo_width(), last, current-step, last, fill="yellow", width=3)
self.canvas.update()
def drawFFT(self):
self.canvas.delete("all")
if self.running == 2:
self.canvas.master.after(400, self.drawFFT)
step = self.step
if self.step == -1:
step = self.canvas.winfo_width()/self.max
current = step/2
last = 0
v = 0
fourier = fft.fft(self.values)
for d in [abs(i) for i in fourier]:
self.highest = max(d, self.highest)
v = int(self.canvas.winfo_height() - round(d*((self.canvas.winfo_height()-100)/self.highest)))-50
self.canvas.create_line(current, v, current-step, last, fill="yellow", width=3)
last = v
current += step
self.canvas.create_line(self.canvas.winfo_width(), last, current-step, last, fill="yellow", width=3)
self.canvas.update_idletasks()
keep = True
def gen(d, name):
global keep
ser = serial.Serial(name)
while keep:
try:
d.shift(int(ser.readline()))
except:
pass
if len(sys.argv) != 2:
print("You must specify the serial port to read\ne.g." + sys.argv[0] + " /dev/ttyATC0")
sys.exit(1)
name = sys.argv[1]
master = Tk()
master.title("Oscilloscope")
master.maxsize(500, 500)
master.minsize(500, 500)
canvas_width = 500
canvas_height = 450
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
w.config(background="black")
d = Display(w, 64)
d.plot_raw()
bFFT = Button(master, text="FFT view", command=d.plot_fft)
bFFT.pack(side=RIGHT)
bRAW = Button(master, text="Raw input", command=d.plot_raw)
bRAW.pack(side=RIGHT)
t = threading.Thread(target=gen, args=(d, name))
t.start()
mainloop()
keep = False