parent
0042a51fce
commit
1b6e93c051
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import wifi
|
import wifi
|
||||||
from sacn import sACNlistener
|
|
||||||
from neopixel import *
|
from neopixel import *
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
@ -60,41 +59,21 @@ def is_connected_to_wifi():
|
||||||
except wifi.exceptions.InterfaceError:
|
except wifi.exceptions.InterfaceError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def update_led_strip(dmx_values, dmx_address, strip, LED_PER_PIXEL):
|
def update_led_strip(r, g, b, dmx_address, strip, LED_PER_PIXEL):
|
||||||
for i in range(LED_COUNT):
|
for i in range(LED_COUNT):
|
||||||
pixel_index = i // LEDS_PER_PIXEL
|
pixel_index = i // LEDS_PER_PIXEL
|
||||||
dmx_index = dmx_address + (pixel_index * 3)
|
dmx_index = dmx_address + (pixel_index * 3)
|
||||||
|
|
||||||
r = dmx_values[dmx_index]
|
|
||||||
g = dmx_values[dmx_index + 1]
|
|
||||||
b = dmx_values[dmx_index + 2]
|
|
||||||
|
|
||||||
strip.setPixelColor(i, Color(r, g, b))
|
strip.setPixelColor(i, Color(r, g, b))
|
||||||
|
|
||||||
# Update the LED strip
|
# Update the LED strip
|
||||||
strip.show()
|
strip.show()
|
||||||
|
|
||||||
def listen_to_sacn(universe, dmx_address, strip, LEDS_PER_PIXEL):
|
def mqtt_listner(universe, dmx_address, strip, LEDS_PER_PIXEL):
|
||||||
try:
|
try:
|
||||||
# Create a new sACN listener
|
|
||||||
listener = sACNlistener()
|
|
||||||
|
|
||||||
# Configure the listener to listen to the specified universe
|
|
||||||
listener.register_listener(universe)
|
|
||||||
|
|
||||||
# Start the listener
|
|
||||||
listener.start()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# Get the latest data from the specified universe
|
|
||||||
packet = listener[universe].listen()
|
update_led_strip(values, dmx_address, strip, LEDS_PER_PIXEL)
|
||||||
|
|
||||||
if packet is not None:
|
|
||||||
# Extract DMX values from the sACN packet
|
|
||||||
dmx_values = packet.dmx_frame
|
|
||||||
|
|
||||||
# Update the LED strip based on the received DMX values
|
|
||||||
update_led_strip(dmx_values, dmx_address, strip, LEDS_PER_PIXEL)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
|
|
||||||
|
@ -108,14 +87,6 @@ def loopCheckSettingUpdates():
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
def loopUpdatePixels():
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
listen_to_artnet(universe, dmx_address, strip, LEDS_PER_PIXEL)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Connect to Wi-Fi
|
# Connect to Wi-Fi
|
||||||
if is_connected_to_wifi():
|
if is_connected_to_wifi():
|
||||||
|
@ -125,10 +96,9 @@ if __name__ == "__main__":
|
||||||
global universe
|
global universe
|
||||||
global dmx_address
|
global dmx_address
|
||||||
universe, dmx_address = get_assigned_params()
|
universe, dmx_address = get_assigned_params()
|
||||||
listen_to_artnet(universe, dmx_address, strip, LEDS_PER_PIXEL)
|
|
||||||
|
|
||||||
settingsUpdateThread = Thread(target=loopCheckSettingUpdates, args=())
|
settingsUpdateThread = Thread(target=loopCheckSettingUpdates, args=())
|
||||||
pixelUpdateThread = Thread(target=loopUpdatePixels, args=())
|
pixelUpdateThread = Thread(target=mqtt_listner, args=(universe, dmx_address, strip, LEDS_PER_PIXEL))
|
||||||
|
|
||||||
settingsUpdateThread.start()
|
settingsUpdateThread.start()
|
||||||
pixelUpdateThread.start()
|
pixelUpdateThread.start()
|
|
@ -21,18 +21,19 @@ artnetBindIp = get_eth0_ip()
|
||||||
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = False, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
|
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = False, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
|
||||||
tuple_ip = (str(get_eth0_ip()), 6454)
|
tuple_ip = (str(get_eth0_ip()), 6454)
|
||||||
artNet.art_pol_reply(tuple_ip)
|
artNet.art_pol_reply(tuple_ip)
|
||||||
while True:
|
print(type(artNet.readPacket()))
|
||||||
try:
|
# while True:
|
||||||
# Gets whatever the last Art-Net packet we received is
|
# try:
|
||||||
artNetPacket = artNet.readPacket()
|
# # Gets whatever the last Art-Net packet we received is
|
||||||
# Make sure we actually *have* a packet
|
# artNetPacket = artNet.readPacket()
|
||||||
if artNetPacket is not None and artNetPacket.data is not None:
|
# # Make sure we actually *have* a packet
|
||||||
print("Universe: "+str(artNetPacket.universe))
|
# if artNetPacket is not None and artNetPacket.data is not None:
|
||||||
# Stores the packet data array
|
# print("Universe: "+str(artNetPacket.universe))
|
||||||
dmxPacket = artNetPacket.data
|
# # Stores the packet data array
|
||||||
|
# dmxPacket = artNetPacket.data
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
# except KeyboardInterrupt:
|
||||||
break
|
# break
|
||||||
|
|
||||||
# Close the various connections cleanly so nothing explodes :)
|
# Close the various connections cleanly so nothing explodes :)
|
||||||
artNet.close()
|
artNet.close()
|
||||||
|
|
Loading…
Reference in New Issue