Created
March 21, 2013 23:10
-
-
Save eni23/5217654 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# dmx512 library | |
# sending dmx-frames, the class handles buffering of channels | |
# and only packs data frames long as needed. | |
# | |
# example usage: | |
# dmx=dmx512.dmx | |
# dmx.set_channel(1,255) | |
# dmx.set_channel(419,39) | |
# dmx.send() | |
# | |
# dmx.channel[21] //get buffer of channel 21 | |
# | |
import array | |
class dmx: | |
def __init__(self): | |
self.channel=array.array('B') | |
self.channel_new=array.array('B') | |
for i in range(512): | |
self.channel.append(0) | |
self.channel_new.append(0) | |
self.channels_change=array.array('H') | |
self.dataframe=array.array('B') | |
def reset_internal_buffers(self): | |
for i in range(512): | |
self.channel_new.append(0) | |
del self.channels_change, self.dataframe | |
self.channels_change=array.array('H') | |
self.dataframe=array.array('B') | |
def set_channel(self,channel,value): | |
self.channel_new[channel]=value | |
self.channels_change.append(channel) | |
def build_sendframe(self): | |
for i in range(0,max(self.channels_change)+1): | |
if i in self.channels_change: | |
self.dataframe.append(self.channel_new[i]) | |
else: | |
self.dataframe.append(self.channel[i]) | |
def send(self): | |
for i in range(0,max(self.channels_change)+1): | |
if i in self.channels_change: | |
self.channel[i]=self.dataframe[i] | |
print self.dataframe | |
self.reset_internal_buffers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment