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 getopt
|
||||
import sys
|
||||
@ -13,7 +14,6 @@ def disconnect():
|
||||
client_socket.close() # close the connection
|
||||
|
||||
def send(data):
|
||||
#validate data. should be hex color
|
||||
client_socket.send(data.encode()) # send message
|
||||
|
||||
def helpmenu():
|
||||
@ -23,11 +23,26 @@ def helpmenu():
|
||||
print("-v visualizer()")
|
||||
|
||||
def visualizer():
|
||||
with subprocess.Popen(["cava", "-p", "./config"], stdout=subprocess.PIPE) as cava:
|
||||
print(cava.stdout.readlines())
|
||||
cava = subprocess.Popen(["cava", "-p", "./config"], stdout=subprocess.PIPE)
|
||||
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):
|
||||
|
||||
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:
|
||||
opts, args = getopt.getopt(argv, "s:vh")
|
||||
except getopt.GetoptError:
|
||||
@ -42,10 +57,13 @@ def main(argv):
|
||||
elif opt == "-s":
|
||||
connect(server_IP)
|
||||
send(arg)
|
||||
sys.exit()
|
||||
elif opt == "-v":
|
||||
connect(server_IP)
|
||||
visualizer()
|
||||
sys.exit()
|
||||
|
||||
helpmenu()
|
||||
sys.exit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
@ -35,8 +35,10 @@ def main(argv):
|
||||
sys.exit()
|
||||
elif opt == "-c":
|
||||
color_mode.color_cycle(arg)
|
||||
sys.exit()
|
||||
elif opt == "-d":
|
||||
server.start()
|
||||
sys.exit()
|
||||
|
||||
helpmenu()
|
||||
sys.exit()
|
||||
|
||||
@ -19,14 +19,15 @@ def start():
|
||||
conn, address = server_socket.accept() # accept new connection
|
||||
print("Connection from: " + str(address))
|
||||
# receive data stream. it won't accept data packet greater than 1024 bytes
|
||||
data = conn.recv(1024).decode()
|
||||
if not data:
|
||||
print("Disconnected: " + str(address))
|
||||
break
|
||||
if validate_data(data):
|
||||
r,g,b = ws2801.hex_to_rgb(data)
|
||||
ws2801.set_color(r,g,b)
|
||||
else:
|
||||
print("incorrect format. use hex color code.")
|
||||
while True:
|
||||
data = conn.recv(1024).decode()
|
||||
if not data:
|
||||
print("Disconnected: " + str(address))
|
||||
break
|
||||
if validate_data(data):
|
||||
r,g,b = ws2801.hex_to_rgb(data)
|
||||
ws2801.set_color(r,g,b)
|
||||
else:
|
||||
print("incorrect format. use hex color code.")
|
||||
conn.close() # close the connection
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user