-
Notifications
You must be signed in to change notification settings - Fork 0
/
walkAndMesure2.py
120 lines (93 loc) · 3.62 KB
/
walkAndMesure2.py
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
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import random
import numpy as np
import sys
import Tkinter as tk
import time
import API.winWlanApi as wlanAPI
import API.PhysicalAccessPoint as PhyAP
import AP_Relative_Plot_Lib as APRelPlotLib
class gridPlotUpdate:
def __init__(self, ax, starterPosition=(0,-11)):
self.position = starterPosition
self.ax = ax
def step(self,key,ax):
if key == 'Up':
self.position = (self.position[0],self.position[1]+1)
elif key == 'Down':
self.position = (self.position[0],self.position[1]-1)
elif key == 'Right':
self.position = (self.position[0]+1,self.position[1])
elif key == 'Left':
self.position = (self.position[0]-1,self.position[1])
else :
return "Tecla "+key+" nao faz nada"
self.measureBSSI()
return "Mexeu 1 casa: "+key
def plotPosition(self ):
print "Position update to "+str(self.position)
self.ax.plot(self.position[0],self.position[1], marker='D',color='r')
def measureBSSI(self):
tmpWriteBSSI = {}
tmpWriteBSSI[self.position[0],self.position[1]] = wlanAPI.get_BSSI_times_and_total_seconds(1,30)
self.plotPosition()
with open("walkAndMesure2-LOG.csv","ab") as f:
for position in tmpWriteBSSI:
for bssi in tmpWriteBSSI[position]:
f.write(str(position[0])+","+str(position[1])+","+str(bssi)+","
+str(tmpWriteBSSI[position][bssi].getCSVValues()+"\n"))
return
def gridInitialPlot():
fig = plt.figure()
ax = fig.gca()
ax = fig.add_subplot(111)
ax.set_xticks(np.arange(-10,11,1))
ax.set_yticks(np.arange(-10,11,1))
x = range(-10,11)
y = range(-10,11)
plt.plot(x, [0 for i in range(-10,11)], marker='o', linestyle='--', color='b', label='Square')
plt.plot([0 for i in range(-10,11)],y, marker='o', linestyle='--', color='b', label='Square')
plt.axis([-12, 12, -12, 12])
return fig,ax
class App():
def key(self,event):
print('press', event.keysym)
self.textInput = "Scanning..."
self.labelInput.config(text=self.textInput)
import time
time.sleep(0.5)
self.textInput = self.plotUpdate.step(event.keysym,self.ax)
self.labelInput.config(text=self.textInput)
def __init__(self):
self.root = tk.Tk()
self.root.wm_title("Embedding in TK")
self.frame = tk.Frame(self.root, width=100, height=100)
self.fig,self.ax = gridInitialPlot()
self.canvas = FigureCanvasTkAgg(self.fig, master=self.root)
self.toolbar = NavigationToolbar2TkAgg( self.canvas, self.root )
self.toolbar.update()
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self.label = tk.Label(text="")
self.textInput = "-----"
self.labelInput = tk.Label(text = self.textInput)
self.plotUpdate = gridPlotUpdate(self.ax)
self.frame.bind("<Key>", self.key)
self.frame.bind("<1>", lambda event: self.frame.focus_set())
self.frame.pack()
self.labelInput.pack()
self.label.pack()
self.update_clock()
self.root.mainloop()
def update_clock(self):
#self.fig = realTimePlot(self.fig,self.ax)
self.canvas.show()
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
now = time.strftime("%H:%M:%S")
self.label.configure(text=now)
self.root.after(200, self.update_clock)
app=App()