Skip to content

Instantly share code, notes, and snippets.

@N3MIS15
Created January 30, 2013 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save N3MIS15/4671346 to your computer and use it in GitHub Desktop.
Save N3MIS15/4671346 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#########################################################################
# Boblight config generator created by David Gray (N3MIS15) #
# Positioning is calculated starting at the middle bottom of screen #
# Only has barebone settings, any other setting should be set manually #
# Tested with adafruit 8806 LEDs and adalight #
#########################################################################
#### SETTINGS ####
# Options
clockwise = True # Looking at the front of the screen
adalight = True # Adalight prefix will be calculated
# Number of lights
# If bottom LEDs is less than top a gap will be calculated in center (for TV stand)
top = 46
bottom = 32
left = 28
right = 28
#Sceen depth
vertical = 10
horizontal = 10
# Output Filename
filename = 'boblight.conf'
# Boblight global
interface = '127.0.0.1'
port = 19333
# Boblight device
name = 'ambilight'
output = '/dev/ttyACM0'
device_type = 'momo'
interval = 20000
rate = 115200
#### END SETTINGS ####
import math
lights = []
channel_count = 0
total_leds = top + bottom + left + right
def get_prefix():
def hex2(v):
s = hex(v)[2:]
return s.upper() if len(s) % 2 == 0 else '0' + s.upper()
#Magic word
byte1 = hex2(65) #A
byte2 = hex2(100) #d
byte3 = hex2(97) #a
#LED count high byte
high = total_leds - 1 >> 8
byte4 = hex2(high)
#LED count low byte
low = total_leds - 1 & 0xff
byte5 = hex2(low)
#Checksum
byte6 = hex2(high ^ low ^ 0x55)
return '%s %s %s %s %s %s' % (byte1, byte2, byte3, byte4, byte5, byte6)
def float_range(limit1, limit2=None, increment=1.):
if limit2 is None:
limit2, limit1 = limit1, 0.
else:
limit1 = float(limit1)
count = int(math.ceil(limit2 - limit1)/increment)
return [limit1 + n*increment for n in range(count)]
def calc_bottom_left():
global channel_count, lights
if bottom:
if top and bottom < top:
led_count = bottom / 2
screen_percentage = 100 - ((float(top) - float(led_count)) / top * 100)
else:
led_count = bottom
screen_percentage = 50
step = (float(screen_percentage) / float(led_count))
percent_range = float_range(0, screen_percentage, step)
for i in range(1, led_count+1):
if clockwise:
hscan = percent_range[-i]
else:
hscan = percent_range[i-1]
light = '[light]\n'
light += 'name BottomLeft%i\n' % i
light += 'color red ambilight %i\n' % (channel_count + 1)
light += 'color green ambilight %i\n' % (channel_count + 2)
light += 'color blue ambilight %i\n' % (channel_count + 3)
light += 'hscan %.1f %.1f\n'% (hscan, float(hscan + step))
light += 'vscan %i %i\n' % (100 - vertical, 100)
channel_count += 3
lights.append(light)
def calc_bottom_right():
global channel_count, lights
if bottom:
if top and bottom < top:
led_count = bottom / 2
screen_percentage = 100 - ((float(top) - float(led_count)) / top * 100)
else:
led_count = bottom
screen_percentage = 50
step = (float(screen_percentage) / float(led_count))
if clockwise:
percent_range = float_range(screen_percentage, 100, step)
else:
percent_range = float_range(100 - screen_percentage, 100, step)
for i in range(1, led_count+1):
if clockwise:
hscan = percent_range[-i]
else:
hscan = percent_range[i-1]
light = '[light]\n'
light += 'name BottomRight%i\n' % i
light += 'color red ambilight %i\n' % (channel_count + 1)
light += 'color green ambilight %i\n' % (channel_count + 2)
light += 'color blue ambilight %i\n' % (channel_count + 3)
light += 'hscan %.1f %.1f\n'% (hscan, float(hscan + step))
light += 'vscan %i %i\n' % (100 - vertical, 100)
channel_count += 3
lights.append(light)
def calc_left():
global channel_count, lights
led_count = left
step = (float(100) / float(led_count))
percent_range = float_range(0, 100, step)
for i in range(1, led_count+1):
if clockwise:
vscan = percent_range[-i]
else:
vscan = percent_range[i-1]
light = '[light]\n'
light += 'name LeftSide%i\n' % i
light += 'color red ambilight %i\n' % (channel_count + 1)
light += 'color green ambilight %i\n' % (channel_count + 2)
light += 'color blue ambilight %i\n' % (channel_count + 3)
light += 'hscan %i %i\n' % (0, horizontal)
light += 'vscan %.1f %.1f\n'% (vscan, float(vscan + step))
channel_count += 3
lights.append(light)
def calc_right():
global channel_count, lights
led_count = right
step = (float(100) / float(led_count))
percent_range = float_range(0, 100, step)
for i in range(1, led_count+1):
if clockwise:
vscan = percent_range[i-1]
else:
vscan = percent_range[-i]
light = '[light]\n'
light += 'name RightSide%i\n' % i
light += 'color red ambilight %i\n' % (channel_count + 1)
light += 'color green ambilight %i\n' % (channel_count + 2)
light += 'color blue ambilight %i\n' % (channel_count + 3)
light += 'hscan %i %i\n' % (0, horizontal)
light += 'vscan %.1f %.1f\n'% (vscan, float(vscan + step))
channel_count += 3
lights.append(light)
def calc_top():
global channel_count, lights
led_count = top
step = (float(100) / float(led_count))
percent_range = float_range(0, 100, step)
for i in range(1, led_count+1):
if clockwise:
hscan = percent_range[i-1]
else:
hscan = percent_range[-i]
light = '[light]\n'
light += 'name Top%i\n' % i
light += 'color red ambilight %i\n' % (channel_count + 1)
light += 'color green ambilight %i\n' % (channel_count + 2)
light += 'color blue ambilight %i\n' % (channel_count + 3)
light += 'hscan %.1f %.1f\n'% (hscan, float(hscan + step))
light += 'vscan %i %i\n' % (100 - vertical, 100)
channel_count += 3
lights.append(light)
def main():
settings = '[global]\n'
settings += 'interface %s\n' % interface
settings += 'port %i\n\n' % port
settings += '[device]\n'
settings += 'name %s\n' % name
settings += 'output %s\n' % output
settings += 'channels %s\n' % channel_count
settings += 'type %s\n' % device_type
settings += 'interval %i\n' % interval
if adalight == True:
settings += 'prefix %s\n' % get_prefix()
settings += 'rate %i\n\n' % rate
settings += '[color]\n'
settings += 'name red\n'
settings += 'rgb FF0000\n'
settings += 'gamma 1.0\n'
settings += 'adjust 1.0\n'
settings += 'blacklevel 0.0\n\n'
settings += '[color]\n'
settings += 'name green\n'
settings += 'rgb 00FF00\n'
settings += 'gamma 1.0\n'
settings += 'adjust 1.0\n'
settings += 'blacklevel 0.0\n\n'
settings += '[color]\n'
settings += 'name blue\n'
settings += 'rgb 0000FF\n'
settings += 'gamma 1.0\n'
settings += 'adjust 1.0\n'
settings += 'blacklevel 0.0\n\n'
if clockwise:
calc_bottom_left()
calc_left()
calc_top()
calc_right()
calc_bottom_right()
else:
calc_bottom_right()
calc_right()
calc_top()
calc_left()
calc_bottom_left()
f = open(filename,'w')
f.write(settings)
for light in lights:
f.write(light)
f.write('\n')
f.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment