|
@@ -0,0 +1,232 @@
|
|
1
|
+import FSM
|
|
2
|
+import utils as u
|
|
3
|
+import menus as m
|
|
4
|
+import pygame
|
|
5
|
+from itertools import cycle
|
|
6
|
+import os
|
|
7
|
+
|
|
8
|
+#====================================
|
|
9
|
+
|
|
10
|
+State = type("State", (object,), {})
|
|
11
|
+#====================================
|
|
12
|
+class State(object):
|
|
13
|
+ def __init__(self, FSM):
|
|
14
|
+ self.FSM = FSM
|
|
15
|
+ def Enter(self):
|
|
16
|
+ pass
|
|
17
|
+ def Execute(self):
|
|
18
|
+ pass
|
|
19
|
+ def Exit(self):
|
|
20
|
+ pass
|
|
21
|
+
|
|
22
|
+class WifiSSID(State):
|
|
23
|
+ def __init__(self,FSM):
|
|
24
|
+ super(WifiSSID, self).__init__(FSM)
|
|
25
|
+
|
|
26
|
+ def Enter(self):
|
|
27
|
+ o = self.FSM.owner
|
|
28
|
+ m.menu1_actions(self, o)
|
|
29
|
+ if o.keyState[16] == 1:
|
|
30
|
+ m.draw_menu1(o)
|
|
31
|
+ o.update_display(0)
|
|
32
|
+ elif o.keyState[16] == 4:
|
|
33
|
+ self.draw(o)
|
|
34
|
+ o.update_display(0)
|
|
35
|
+ self.input_string = ""
|
|
36
|
+ o.header_text = "EnterText"
|
|
37
|
+ o.pub.register("beat", self)
|
|
38
|
+ self.last_action = pygame.time.get_ticks()
|
|
39
|
+ self.caps = False
|
|
40
|
+ self.cur_but = 18
|
|
41
|
+ self.cur_letter = ""
|
|
42
|
+ if o.keyState[16] > 0 or o.keyState[17] > 0:
|
|
43
|
+ pass
|
|
44
|
+ else:
|
|
45
|
+ pass
|
|
46
|
+
|
|
47
|
+ self.skips = [7, 3, 11, 12, 13, 14, 15]
|
|
48
|
+
|
|
49
|
+ self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"],
|
|
50
|
+ ["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"],
|
|
51
|
+ ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "[", "]", ";", ",", ".", "/", " "], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"],
|
|
52
|
+ [], [], [], []]
|
|
53
|
+
|
|
54
|
+ self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"],
|
|
55
|
+ ["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"],
|
|
56
|
+ ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+", "=", "{", "}", "|", ":", "<", ">", "?"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"],
|
|
57
|
+ [], [], [], []]
|
|
58
|
+
|
|
59
|
+ self.labels = self.lc_labels
|
|
60
|
+ self.cycles = []
|
|
61
|
+ for l in self.labels:
|
|
62
|
+ self.cycles.append(cycle(l))
|
|
63
|
+
|
|
64
|
+ self.draw(o)
|
|
65
|
+ o.center_block('SSID: ' + self.input_string, o.h2, [0, 0, o.width, o.height / 4], o.light_grey)
|
|
66
|
+ o.update_display(0)
|
|
67
|
+ super(WifiSSID, self).Enter()
|
|
68
|
+
|
|
69
|
+ def Execute(self):
|
|
70
|
+ o = self.FSM.owner
|
|
71
|
+
|
|
72
|
+ if o.wifi_ssid == '':
|
|
73
|
+ in_type = 'SSID: '
|
|
74
|
+ else:
|
|
75
|
+ in_type = 'PASS: '
|
|
76
|
+
|
|
77
|
+ y_size = o.height / 4
|
|
78
|
+ if o.keyState[11] == 1:
|
|
79
|
+ if self.input_string != 'blank':
|
|
80
|
+ if self.input_string != '':
|
|
81
|
+ if o.wifi_ssid == '':
|
|
82
|
+ o.wifi_ssid = self.input_string
|
|
83
|
+ self.input_string = ''
|
|
84
|
+ in_type = 'PASS: '
|
|
85
|
+ u.draw_header(o)
|
|
86
|
+ self.draw(o)
|
|
87
|
+ o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
88
|
+ o.update_display(0)
|
|
89
|
+
|
|
90
|
+ else:
|
|
91
|
+ if len(self.input_string) > 7:
|
|
92
|
+ o.wifi_pass = self.input_string
|
|
93
|
+ self.setup_new(o)
|
|
94
|
+ self.FSM.ToTransition('toWifi')
|
|
95
|
+
|
|
96
|
+ m.menu1_actions(self, o)
|
|
97
|
+ m.menu2_actions_saveas(self, o)
|
|
98
|
+ if o.keyState[16] == 1:
|
|
99
|
+ m.draw_menu1(o)
|
|
100
|
+ o.update_display(0)
|
|
101
|
+ elif o.keyState[16] == 4:
|
|
102
|
+ u.draw_header(o)
|
|
103
|
+ self.draw(o)
|
|
104
|
+ o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
105
|
+ o.update_display(0)
|
|
106
|
+
|
|
107
|
+ if o.keyState[17] == 1:
|
|
108
|
+ m.draw_menu_saveas(o)
|
|
109
|
+ o.update_display(0)
|
|
110
|
+ elif o.keyState[17] == 4:
|
|
111
|
+ u.draw_header(o)
|
|
112
|
+ self.draw(o)
|
|
113
|
+ o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
114
|
+ o.update_display(0)
|
|
115
|
+
|
|
116
|
+ # if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
|
|
117
|
+ # u.draw_header(o)
|
|
118
|
+ # self.draw(o)
|
|
119
|
+ # o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
120
|
+ # o.update_display(0)
|
|
121
|
+
|
|
122
|
+ if o.keyState[16] > 0 or o.keyState[17] > 0:
|
|
123
|
+ pass
|
|
124
|
+
|
|
125
|
+ else:
|
|
126
|
+ _iter = 0
|
|
127
|
+ for k in o.keyState:
|
|
128
|
+ if k == 1:
|
|
129
|
+ cur_time = pygame.time.get_ticks()
|
|
130
|
+ if _iter not in self.skips:
|
|
131
|
+ self.last_action = cur_time
|
|
132
|
+ if _iter < len(self.cycles):
|
|
133
|
+ self.cur_letter = next(self.cycles[_iter])
|
|
134
|
+ self.cur_but = _iter
|
|
135
|
+ self.draw(o)
|
|
136
|
+ o.center_block(in_type + self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
137
|
+
|
|
138
|
+ if _iter == 7:
|
|
139
|
+ self.input_string = self.input_string[:-1]
|
|
140
|
+ self.last_action = 100000000
|
|
141
|
+ self.draw(o)
|
|
142
|
+ o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
143
|
+
|
|
144
|
+ elif _iter == 3:
|
|
145
|
+ if self.caps:
|
|
146
|
+ self.caps = False
|
|
147
|
+ self.labels = self.lc_labels
|
|
148
|
+
|
|
149
|
+ else:
|
|
150
|
+ self.caps = True
|
|
151
|
+ self.labels = self.uc_labels
|
|
152
|
+ self.draw(o)
|
|
153
|
+ o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
154
|
+ self.cycles = []
|
|
155
|
+ for l in self.labels:
|
|
156
|
+ self.cycles.append(cycle(l))
|
|
157
|
+
|
|
158
|
+ o.update_display(0)
|
|
159
|
+ _iter += 1
|
|
160
|
+
|
|
161
|
+ cur_time = pygame.time.get_ticks()
|
|
162
|
+ delay = cur_time - self.last_action
|
|
163
|
+ if delay > 1000 and delay < 100000:
|
|
164
|
+ self.input_string += self.cur_letter
|
|
165
|
+ self.last_action = 100000000
|
|
166
|
+ self.reset_cycles()
|
|
167
|
+ self.draw(o)
|
|
168
|
+ o.center_block(in_type + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
|
|
169
|
+ o.update_display(0)
|
|
170
|
+
|
|
171
|
+ def ReceiveMessage(self, message):
|
|
172
|
+ o = self.FSM.owner
|
|
173
|
+ u.play_seq(o, message)
|
|
174
|
+
|
|
175
|
+ def draw(self, o):
|
|
176
|
+ x_size = o.width / 4
|
|
177
|
+ y_size = o.height / 4
|
|
178
|
+ og_x = 0
|
|
179
|
+ o_x = og_x
|
|
180
|
+ o_y = o.height
|
|
181
|
+ text_padding = 6
|
|
182
|
+
|
|
183
|
+ _id = 0
|
|
184
|
+ while _id < 16:
|
|
185
|
+ lab = ""
|
|
186
|
+ for i in self.labels[_id]:
|
|
187
|
+ lab += i
|
|
188
|
+
|
|
189
|
+ if _id == 8:
|
|
190
|
+ if self.caps:
|
|
191
|
+ lab = "!@#"
|
|
192
|
+ else:
|
|
193
|
+ lab = "_12"
|
|
194
|
+
|
|
195
|
+ o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
|
|
196
|
+ o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
|
|
197
|
+
|
|
198
|
+ o_x = o_x + x_size
|
|
199
|
+ _id += 1
|
|
200
|
+ if _id % 4 == 0:
|
|
201
|
+ o_y -= y_size
|
|
202
|
+ o_x = og_x
|
|
203
|
+ o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
|
|
204
|
+
|
|
205
|
+ def setup_new(self, o):
|
|
206
|
+ o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
|
|
207
|
+ o.center_block("puters be putin..", o.h2, [0, 0, o.width, o.height], o.light_grey)
|
|
208
|
+ o.update_display(0)
|
|
209
|
+
|
|
210
|
+ with open('wifi.txt', 'w') as f:
|
|
211
|
+ f.write(o.wifi_ssid + "\n" + o.wifi_pass + "\n")
|
|
212
|
+
|
|
213
|
+ command = 'sleep 3'
|
|
214
|
+ os.system(command)
|
|
215
|
+
|
|
216
|
+ command = 'sudo ./set_wifi.sh'
|
|
217
|
+ os.system(command)
|
|
218
|
+
|
|
219
|
+ command = 'sleep 2'
|
|
220
|
+
|
|
221
|
+ command = 'sudo wpa_cli -i wlan0 reconfigure'
|
|
222
|
+ os.system(command)
|
|
223
|
+
|
|
224
|
+ command = 'sleep 8'
|
|
225
|
+
|
|
226
|
+ def reset_cycles(self):
|
|
227
|
+ self.cycles = []
|
|
228
|
+ for l in self.labels:
|
|
229
|
+ self.cycles.append(cycle(l))
|
|
230
|
+
|
|
231
|
+ def Exit(self):
|
|
232
|
+ self.FSM.owner.pub.unregister("beat", self)
|