info@shuvit.org 2 years 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
-default_song = default
1
+default_song = Roland_TR-808
2
 theme = default
2
 theme = default
3
 title = default
3
 title = default
4
 bpm = 90
4
 bpm = 90
5
 volume = 10
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
         'Calculator',
95
         'Calculator',
96
         'About',
96
         'About',
97
         'SelectFolder',
97
         'SelectFolder',
98
-        'NewDir'
98
+        'NewDir', 
99
+        'WifiSSID'
99
         ]
100
         ]
100
         
101
         
101
         for s in state_list:
102
         for s in state_list:

+ 1
- 0
lib/StatesProg.py View File

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

+ 8
- 5
lib/sCalculator.py View File

181
 			if _id % 4 == 0:
181
 			if _id % 4 == 0:
182
 				o_y -= y_size
182
 				o_y -= y_size
183
 				o_x = og_x
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
 		#o.center_block('where is my fucking text', o.h2, [0, 0, o.width, y_size], o.light_grey)
188
 		#o.center_block('where is my fucking text', o.h2, [0, 0, o.width, y_size], o.light_grey)
186
 		if self.num1 != '':
189
 		if self.num1 != '':
187
 			if self.result != '':
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
 			elif self.num2 != '':
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
 			elif self.op != '':
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
 			else:
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
 			print('fucking do something')
198
 			print('fucking do something')
196
 		else:
199
 		else:
197
 			print('num1 is empty')
200
 			print('num1 is empty')

+ 4
- 4
lib/sEnterText.py View File

100
 			self.draw(o)
100
 			self.draw(o)
101
 			o.update_display(0)
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
 		if o.keyState[16] > 0 or o.keyState[17] > 0:
108
 		if o.keyState[16] > 0 or o.keyState[17] > 0:
109
 			pass
109
 			pass

+ 9
- 9
lib/sNewDir.py View File

97
 			self.draw(o)
97
 			self.draw(o)
98
 			o.update_display(0)
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
 		if o.keyState[16] > 0 or o.keyState[17] > 0:
107
 		if o.keyState[16] > 0 or o.keyState[17] > 0:
118
 							self.cur_letter = next(self.cycles[_iter])
118
 							self.cur_letter = next(self.cycles[_iter])
119
 							self.cur_but = _iter
119
 							self.cur_but = _iter
120
 							self.draw(o)
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
 					if _iter == 7:						
123
 					if _iter == 7:						
124
 						self.input_string = self.input_string[:-1]
124
 						self.input_string = self.input_string[:-1]
125
 						self.last_action = 100000000
125
 						self.last_action = 100000000
126
 						self.draw(o)
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
 					elif _iter == 3:
129
 					elif _iter == 3:
130
 						if self.caps:
130
 						if self.caps:
135
 							self.caps = True
135
 							self.caps = True
136
 							self.labels = self.uc_labels
136
 							self.labels = self.uc_labels
137
 						self.draw(o)
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
 						self.cycles = []
139
 						self.cycles = []
140
 						for l in self.labels:
140
 						for l in self.labels:
141
 							self.cycles.append(cycle(l))
141
 							self.cycles.append(cycle(l))
151
 			self.reset_cycles()
151
 			self.reset_cycles()
152
 			self.draw(o)
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
 			o.update_display(0)
155
 			o.update_display(0)
156
 	
156
 	
157
 	def ReceiveMessage(self, message):
157
 	def ReceiveMessage(self, message):

+ 28
- 3
lib/sWifi.py View File

3
 import menus as m
3
 import menus as m
4
 import os
4
 import os
5
 import socket 
5
 import socket 
6
+
6
 #====================================     
7
 #====================================     
7
 
8
 
8
 State = type("State", (object,), {})
9
 State = type("State", (object,), {})
30
 		o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
31
 		o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
31
 		u.draw_header(o)
32
 		u.draw_header(o)
32
 		self.draw_main(o)
33
 		self.draw_main(o)
34
+		self.draw_footer(o)
33
 		o.update_display(0)
35
 		o.update_display(0)
36
+		
34
 		super(Wifi, self).Enter()        
37
 		super(Wifi, self).Enter()        
35
 		
38
 		
36
 	def Execute(self):
39
 	def Execute(self):
42
 		elif o.keyState[16] == 4:
45
 		elif o.keyState[16] == 4:
43
 			u.draw_header(o)
46
 			u.draw_header(o)
44
 			self.draw_main(o)
47
 			self.draw_main(o)
48
+			self.draw_footer(o)
45
 			o.update_display(0)
49
 			o.update_display(0)
46
 
50
 
47
 		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:
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
 			u.draw_header(o)
52
 			u.draw_header(o)
49
 			self.draw_main(o)
53
 			self.draw_main(o)
54
+			self.draw_footer(o)
50
 			o.update_display(0)	
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
 	def draw_main(self, o):
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
 	def extract_ip(self):
64
 	def extract_ip(self):
57
 		st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
65
 		st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
59
 			st.connect(("8.8.8.8", 80))
67
 			st.connect(("8.8.8.8", 80))
60
 			IP = st.getsockname()[0]
68
 			IP = st.getsockname()[0]
61
 		except Exception:
69
 		except Exception:
62
-			IP = '127.0.0.1'
70
+			IP = 'Network Failed'
63
 		finally:
71
 		finally:
64
 			st.close()
72
 			st.close()
65
 		return IP
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
 	def ReceiveMessage(self, message):
92
 	def ReceiveMessage(self, message):
68
 		o = self.FSM.owner 
93
 		o = self.FSM.owner 
69
 		u.play_seq(o, message)
94
 		u.play_seq(o, message)

+ 232
- 0
lib/sWifiSSID.py View File

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
 		self.defender_sounds = []
169
 		self.defender_sounds = []
170
 		self.load_defender()
170
 		self.load_defender()
171
 
171
 
172
+		self.wifi_ssid = ''
173
+		self.wifi_pass = ''
174
+
172
 	class SoundSlot:
175
 	class SoundSlot:
173
 		def __init__(self, file, obj_id, o):
176
 		def __init__(self, file, obj_id, o):
174
 			self.file = file
177
 			self.file = file

+ 1
- 0
readme.txt View File

1
+Create a new text file!

+ 4
- 2
set_wifi.sh View File

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

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


Loading…
Cancel
Save