idk ... stuff happend ... is working better now
This commit is contained in:
parent
bf797da205
commit
c04dc20af6
26
client/client.py
Normal file → Executable file
26
client/client.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
import socket
|
import socket
|
||||||
import getopt
|
import getopt
|
||||||
import sys
|
import sys
|
||||||
@ -13,7 +14,6 @@ def disconnect():
|
|||||||
client_socket.close() # close the connection
|
client_socket.close() # close the connection
|
||||||
|
|
||||||
def send(data):
|
def send(data):
|
||||||
#validate data. should be hex color
|
|
||||||
client_socket.send(data.encode()) # send message
|
client_socket.send(data.encode()) # send message
|
||||||
|
|
||||||
def helpmenu():
|
def helpmenu():
|
||||||
@ -23,11 +23,26 @@ def helpmenu():
|
|||||||
print("-v visualizer()")
|
print("-v visualizer()")
|
||||||
|
|
||||||
def visualizer():
|
def visualizer():
|
||||||
with subprocess.Popen(["cava", "-p", "./config"], stdout=subprocess.PIPE) as cava:
|
cava = subprocess.Popen(["cava", "-p", "./config"], stdout=subprocess.PIPE)
|
||||||
print(cava.stdout.readlines())
|
sed = subprocess.Popen(["sed", "-u", "s/;.*;$//"], stdin=cava.stdout, stdout=subprocess.PIPE)
|
||||||
|
subprocess.Popen([sys.argv[0]], stdin=sed.stdout, shell=True)
|
||||||
|
cava.stdout.close()
|
||||||
|
sed.stdout.close()
|
||||||
|
|
||||||
|
def rgb_to_hex(r,g,b):
|
||||||
|
return "%02x%02x%02x" % (r,g,b)
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
connect(server_IP)
|
||||||
|
for volume in sys.stdin:
|
||||||
|
volume = int(volume)
|
||||||
|
hex_color = rgb_to_hex(volume,0,0)
|
||||||
|
send(hex_color)
|
||||||
|
print(hex_color)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(argv, "s:vh")
|
opts, args = getopt.getopt(argv, "s:vh")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
@ -42,10 +57,13 @@ def main(argv):
|
|||||||
elif opt == "-s":
|
elif opt == "-s":
|
||||||
connect(server_IP)
|
connect(server_IP)
|
||||||
send(arg)
|
send(arg)
|
||||||
|
sys.exit()
|
||||||
elif opt == "-v":
|
elif opt == "-v":
|
||||||
connect(server_IP)
|
|
||||||
visualizer()
|
visualizer()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
helpmenu()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
||||||
@ -35,8 +35,10 @@ def main(argv):
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
elif opt == "-c":
|
elif opt == "-c":
|
||||||
color_mode.color_cycle(arg)
|
color_mode.color_cycle(arg)
|
||||||
|
sys.exit()
|
||||||
elif opt == "-d":
|
elif opt == "-d":
|
||||||
server.start()
|
server.start()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
helpmenu()
|
helpmenu()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|||||||
@ -19,14 +19,15 @@ def start():
|
|||||||
conn, address = server_socket.accept() # accept new connection
|
conn, address = server_socket.accept() # accept new connection
|
||||||
print("Connection from: " + str(address))
|
print("Connection from: " + str(address))
|
||||||
# receive data stream. it won't accept data packet greater than 1024 bytes
|
# receive data stream. it won't accept data packet greater than 1024 bytes
|
||||||
data = conn.recv(1024).decode()
|
while True:
|
||||||
if not data:
|
data = conn.recv(1024).decode()
|
||||||
print("Disconnected: " + str(address))
|
if not data:
|
||||||
break
|
print("Disconnected: " + str(address))
|
||||||
if validate_data(data):
|
break
|
||||||
r,g,b = ws2801.hex_to_rgb(data)
|
if validate_data(data):
|
||||||
ws2801.set_color(r,g,b)
|
r,g,b = ws2801.hex_to_rgb(data)
|
||||||
else:
|
ws2801.set_color(r,g,b)
|
||||||
print("incorrect format. use hex color code.")
|
else:
|
||||||
|
print("incorrect format. use hex color code.")
|
||||||
conn.close() # close the connection
|
conn.close() # close the connection
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user