info@shuvit.org 7 months ago
parent
commit
3907959127
12 changed files with 300 additions and 31 deletions
  1. 2
    2
      config.txt
  2. 2
    1
      lib/FSM.py
  3. 1
    0
      lib/StatesProg.py
  4. 8
    5
      lib/sCalculator.py
  5. 4
    4
      lib/sEnterText.py
  6. 9
    9
      lib/sNewDir.py
  7. 28
    3
      lib/sWifi.py
  8. 232
    0
      lib/sWifiSSID.py
  9. 3
    0
      main.py
  10. 1
    0
      readme.txt
  11. 4
    2
      set_wifi.sh
  12. 6
    5
      user/songs/default.sng

+ 2
- 2
config.txt View File

@@ -1,6 +1,6 @@
1
-default_song = default
1
+default_song = Roland_TR-808
2 2
 theme = default
3 3
 title = default
4 4
 bpm = 90
5 5
 volume = 10
6
-song_dir = /home/pi/zpc_ct/user/songs/
6
+song_dir = /home/pi/zpc_ct/user/songs/drum_machines/

+ 2
- 1
lib/FSM.py View File

@@ -95,7 +95,8 @@ class ProgFSM(Char):
95 95
         'Calculator',
96 96
         'About',
97 97
         'SelectFolder',
98
-        'NewDir'
98
+        'NewDir', 
99
+        'WifiSSID'
99 100
         ]
100 101
         
101 102
         for s in state_list:

+ 1
- 0
lib/StatesProg.py View File

@@ -43,6 +43,7 @@ from sAbout import About
43 43
 from sUpdate import Update
44 44
 from sSelectFolder import SelectFolder
45 45
 from sNewDir import NewDir
46
+from sWifiSSID import WifiSSID
46 47
 #====================================     
47 48
 
48 49
 State = type("State", (object,), {})

+ 8
- 5
lib/sCalculator.py View File

@@ -181,17 +181,20 @@ class Calculator(State):
181 181
 			if _id % 4 == 0:
182 182
 				o_y -= y_size
183 183
 				o_x = og_x
184
-		o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
184
+		#o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
185
+		o.draw.rectangle((0, 0, x_size * 3, y_size), outline=0, fill=o.blue)
186
+		o.draw.rectangle((x_size * 3, 0, o.width, y_size), outline=0, fill=o.blue)
187
+		o.center_block("Clear", o.h2, [x_size * 3, 0, o.width, y_size], o.light_grey)
185 188
 		#o.center_block('where is my fucking text', o.h2, [0, 0, o.width, y_size], o.light_grey)
186 189
 		if self.num1 != '':
187 190
 			if self.result != '':
188
-				o.center_block(str(self.result), o.h2, [0, 0, o.width, y_size], o.light_grey)
191
+				o.center_block(str(self.result), o.h2, [0, 0, x_size * 3, y_size], o.light_grey)
189 192
 			elif self.num2 != '':
190
-				o.center_block(str(self.num2), o.h2, [0, 0, o.width, y_size], o.light_grey)
193
+				o.center_block(str(self.num2), o.h2, [0, 0, x_size * 3, y_size], o.light_grey)
191 194
 			elif self.op != '':
192
-				o.center_block(str(self.op), o.h2, [0, 0, o.width, y_size], o.light_grey)
195
+				o.center_block(str(self.op), o.h2, [0, 0, x_size * 3, y_size], o.light_grey)
193 196
 			else:
194
-				o.center_block(str(self.num1), o.h2, [0, 0, o.width, y_size], o.light_grey)
197
+				o.center_block(str(self.num1), o.h2, [0, 0, x_size * 3, y_size], o.light_grey)
195 198
 			print('fucking do something')
196 199
 		else:
197 200
 			print('num1 is empty')

+ 4
- 4
lib/sEnterText.py View File

@@ -100,10 +100,10 @@ class EnterText(State):
100 100
 			self.draw(o)
101 101
 			o.update_display(0)
102 102
 
103
-		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:
104
-			u.draw_header(o)
105
-			self.draw(o)
106
-			o.update_display(0)	
103
+		# 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:
104
+		# 	u.draw_header(o)
105
+		# 	self.draw(o)
106
+		# 	o.update_display(0)	
107 107
 			
108 108
 		if o.keyState[16] > 0 or o.keyState[17] > 0:
109 109
 			pass

+ 9
- 9
lib/sNewDir.py View File

@@ -97,11 +97,11 @@ class NewDir(State):
97 97
 			self.draw(o)
98 98
 			o.update_display(0)
99 99
 
100
-		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:
101
-			u.draw_header(o)
102
-			self.draw(o)
103
-			#self.draw_main(o)
104
-			o.update_display(0)	
100
+		# 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:
101
+		# 	u.draw_header(o)
102
+		# 	self.draw(o)
103
+		# 	#self.draw_main(o)
104
+		# 	o.update_display(0)	
105 105
 			
106 106
 
107 107
 		if o.keyState[16] > 0 or o.keyState[17] > 0:
@@ -118,13 +118,13 @@ class NewDir(State):
118 118
 							self.cur_letter = next(self.cycles[_iter])
119 119
 							self.cur_but = _iter
120 120
 							self.draw(o)
121
-							o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
121
+							o.center_block("Folder: " + self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
122 122
 
123 123
 					if _iter == 7:						
124 124
 						self.input_string = self.input_string[:-1]
125 125
 						self.last_action = 100000000
126 126
 						self.draw(o)
127
-						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
127
+						o.center_block("Folder: " + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
128 128
 
129 129
 					elif _iter == 3:
130 130
 						if self.caps:
@@ -135,7 +135,7 @@ class NewDir(State):
135 135
 							self.caps = True
136 136
 							self.labels = self.uc_labels
137 137
 						self.draw(o)
138
-						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
138
+						o.center_block("Folder: " + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
139 139
 						self.cycles = []
140 140
 						for l in self.labels:
141 141
 							self.cycles.append(cycle(l))
@@ -151,7 +151,7 @@ class NewDir(State):
151 151
 			self.reset_cycles()
152 152
 			self.draw(o)
153 153
 
154
-			o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
154
+			o.center_block("Folder: " + self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
155 155
 			o.update_display(0)
156 156
 	
157 157
 	def ReceiveMessage(self, message):

+ 28
- 3
lib/sWifi.py View File

@@ -3,6 +3,7 @@ import utils as u
3 3
 import menus as m
4 4
 import os
5 5
 import socket 
6
+
6 7
 #====================================     
7 8
 
8 9
 State = type("State", (object,), {})
@@ -30,7 +31,9 @@ class Wifi(State):
30 31
 		o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
31 32
 		u.draw_header(o)
32 33
 		self.draw_main(o)
34
+		self.draw_footer(o)
33 35
 		o.update_display(0)
36
+		
34 37
 		super(Wifi, self).Enter()        
35 38
 		
36 39
 	def Execute(self):
@@ -42,16 +45,21 @@ class Wifi(State):
42 45
 		elif o.keyState[16] == 4:
43 46
 			u.draw_header(o)
44 47
 			self.draw_main(o)
48
+			self.draw_footer(o)
45 49
 			o.update_display(0)
46 50
 
47 51
 		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:
48 52
 			u.draw_header(o)
49 53
 			self.draw_main(o)
54
+			self.draw_footer(o)
50 55
 			o.update_display(0)	
56
+
57
+		if o.keyState[0] == 1 or o.keyState[1] == 1  or o.keyState[2] == 1  or o.keyState[3] == 1:
58
+			self.FSM.ToTransition('toWifiSSID')
51 59
 			
52 60
 	def draw_main(self, o):
53
-		o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
54
-		o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
61
+		o.center_block("SSID: " + self.ssid, o.h2, [0, 0, o.width, o.height-30], o.light_grey)
62
+		o.center_block("IP: " + self.ipad, o.h2, [0, 20, o.width, o.height-30], o.light_grey)
55 63
 
56 64
 	def extract_ip(self):
57 65
 		st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -59,11 +67,28 @@ class Wifi(State):
59 67
 			st.connect(("8.8.8.8", 80))
60 68
 			IP = st.getsockname()[0]
61 69
 		except Exception:
62
-			IP = '127.0.0.1'
70
+			IP = 'Network Failed'
63 71
 		finally:
64 72
 			st.close()
65 73
 		return IP
66 74
 
75
+	def draw_footer(self, o):
76
+		_iter = 0
77
+		width = o.width
78
+		xpos = 0
79
+		yposa = 135 - 25
80
+		yposb = 135
81
+		opts = ["Add New"]
82
+		while _iter < 1:
83
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)			
84
+			if o.keyState[_iter] == 1:
85
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
86
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
87
+			else:
88
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
89
+			xpos += width
90
+			_iter += 1
91
+
67 92
 	def ReceiveMessage(self, message):
68 93
 		o = self.FSM.owner 
69 94
 		u.play_seq(o, message)

+ 232
- 0
lib/sWifiSSID.py View File

@@ -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)        

+ 3
- 0
main.py View File

@@ -169,6 +169,9 @@ class Prog:
169 169
 		self.defender_sounds = []
170 170
 		self.load_defender()
171 171
 
172
+		self.wifi_ssid = ''
173
+		self.wifi_pass = ''
174
+
172 175
 	class SoundSlot:
173 176
 		def __init__(self, file, obj_id, o):
174 177
 			self.file = file

+ 1
- 0
readme.txt View File

@@ -0,0 +1 @@
1
+Create a new text file!

+ 4
- 2
set_wifi.sh View File

@@ -1,3 +1,5 @@
1
+#!/usr/bin/env bash
2
+
1 3
 FILE=wifi.txt
2 4
 declare -i _iter=0
3 5
 declare -i _first=0
@@ -8,9 +10,9 @@ if [ -f "$FILE" ]; then
8 10
 
9 11
 
10 12
 	while read line; do
11
-		if [[$_iter==0]];
13
+		if (($_iter==0));
12 14
 		then
13
-			#echo "this"
15
+			echo "this"
14 16
 	    		echo "    ssid=\"$line\"" >> /etc/wpa_supplicant/wpa_supplicant.conf
15 17
 		else
16 18
 			echo "that"

+ 6
- 5
user/songs/default.sng
File diff suppressed because it is too large
View File


Loading…
Cancel
Save