-
-
Save anonymous/5f46885e18bbd84e9303 to your computer and use it in GitHub Desktop.
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 | |
#-------------------------------------# | |
#------- SERIAL LED CONTROL GUI ------# | |
#--------------- v0.1 ----------------# | |
#------------ teldredge --------------# | |
#-------- www.funkboxing.com ---------# | |
#------ teldredge1979@gmail.com ------# | |
#-------------------------------------# | |
### FOR USE WITH FASTSPI2 FX EXAMPLES v0.4 | |
### LICENSE:::USE FOR WHATEVER YOU WANT, WHENEVER YOU WANT, HOWEVER YOU WANT, WHYEVER YOU WANT | |
### BUT YOU MUST YODEL ONCE FOR FREEDOM AND MAYBE DONATE TO SOMETHING WORTHWHILE | |
import pygtk | |
pygtk.require('2.0') | |
import gtk | |
import serial | |
import glob | |
class myRGBController: | |
def button_callback(self, widget, button): | |
name = widget.get_name() | |
if name == "Connect": | |
self.ser = serial.Serial() | |
self.ser.setPort(self.combobox_port.get_active_text()) | |
#self.ser.baudrate = 9600 | |
self.ser.baudrate = 57600 | |
self.ser.open() | |
if (self.ser.isOpen()): | |
print "Success" | |
else: | |
print "Failed" | |
elif name == "Mode": | |
print "Mode Set to - " + str(self.combobox_mode.get_active()) + " - " + self.combobox_mode.get_active_text() | |
self.ser.write("m" + str(self.combobox_mode.get_active()) + ";") | |
def enter_callback(self, widget, entry): | |
self.entry_text = entry.get_text() | |
self.ser.write(self.entry_text + ";") | |
self.entry.set_text("") | |
def scale_callback(self, widget): | |
val = widget.get_value() | |
name = widget.get_name() | |
if name == "bright": | |
self.ser.write("b" + str(int(val)) + ";") | |
elif name == "delay": | |
self.ser.write("d" + str(int(val)) + ";") | |
elif name == "step": | |
self.ser.write("s" + str(int(val)) + ";") | |
elif name == "hue": | |
self.ser.write("h" + str(int(val)) + ";") | |
elif name == "sat": | |
self.ser.write("t" + str(int(val)) + ";") | |
elif name == "index": | |
col = self.colorsel.get_current_color() | |
thisstr = "l" + str(int(val)) + "," + \ | |
str(col.red/257) + "," + \ | |
str(col.green/257) + "," + \ | |
str(col.blue/257) | |
print thisstr | |
self.ser.write(thisstr) | |
def __init__(self): | |
#------------WINDOW------------ | |
window = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
window.set_size_request(400, 600) | |
window.set_title("LED Controller") | |
window.connect("delete_event", lambda w,e: gtk.main_quit()) | |
#------------BUTTON WIDGETS------------ | |
#-CONNECT BUTTON | |
button_connect = gtk.Button("Serial Connect") | |
button_connect.set_name("Connect") | |
button_connect.connect("clicked", self.button_callback, None) | |
#-MODE BUTTON | |
button_mode = gtk.Button("Set Mode") | |
button_mode.set_name("Mode") | |
button_mode.connect("clicked", self.button_callback, None) | |
#------------COMBO BOX WIDGETS------------ | |
#-PORT COMBO | |
self.combobox_port = gtk.combo_box_new_text() | |
for i in glob.glob('/dev/ttyUSB*'): | |
print i | |
self.combobox_port.append_text(i) | |
self.combobox_port.set_active(0) | |
#-MODE COMBO | |
self.combobox_mode = gtk.combo_box_new_text() | |
self.combobox_mode.append_text("All OFF") | |
self.combobox_mode.append_text("All ON") | |
self.combobox_mode.append_text("Color Fade") | |
self.combobox_mode.append_text("Color Loop") | |
self.combobox_mode.append_text("Random Burst") | |
self.combobox_mode.append_text("Cylon v1") | |
self.combobox_mode.append_text("Cylon v2") | |
self.combobox_mode.append_text("Emergency v1") | |
self.combobox_mode.append_text("Emergecny v2") | |
self.combobox_mode.append_text("Flicker") | |
self.combobox_mode.append_text("Pulse Color") | |
self.combobox_mode.append_text("Pulse Color Reverse") | |
self.combobox_mode.append_text("Vertical Fade") | |
self.combobox_mode.append_text("Rule 30 - 1D Cell Automata") | |
self.combobox_mode.append_text("Random March") | |
self.combobox_mode.append_text("Red White Blue March") | |
self.combobox_mode.append_text("Radiation") | |
self.combobox_mode.append_text("Acceleration Loop") | |
self.combobox_mode.append_text("White Temperatures") | |
self.combobox_mode.append_text("Sine Brightness Wave") | |
self.combobox_mode.append_text("Pop Horizontal") | |
self.combobox_mode.append_text("Quadratic Brightness") | |
self.combobox_mode.append_text("Flame") | |
self.combobox_mode.append_text("Vertical Rainbow") | |
self.combobox_mode.append_text("PacMan") | |
self.combobox_mode.append_text("Random Pop") | |
self.combobox_mode.append_text("Emergency Strobe") | |
self.combobox_mode.append_text("RGB Propeller") | |
self.combobox_mode.append_text("Knight Industries 2000") | |
self.combobox_mode.append_text("Matrix Rain") | |
self.combobox_mode.set_active(0) | |
#------------ENTRY WIDGETS------------ | |
#-MANUAL SERIAL COMMAND ENTRY | |
self.entry = gtk.Entry() | |
self.entry.set_width_chars(36) | |
self.entry.set_max_length(100) | |
self.entry.connect("activate", self.enter_callback, self.entry) | |
self.entry.set_text("serial command text") | |
#------------COLOR PICKER WIDGET------------ | |
self.colorsel = gtk.ColorSelection() | |
#------------SCALE WIDGETS------------ | |
#-BRIGHTNESS SCALE | |
scale_b = gtk.HScale() | |
scale_b.set_update_policy(gtk.UPDATE_CONTINUOUS) | |
scale_b.set_name("bright") | |
scale_b.set_range(0, 255) | |
scale_b.set_value(64) | |
scale_b.set_size_request(300, 40) | |
scale_b.set_digits(0) | |
scale_b.connect("value-changed", self.scale_callback) | |
scale_b_label = gtk.Label("brightness") | |
#-DELAY SCALE | |
scale_d = gtk.HScale() | |
scale_d.set_update_policy(gtk.UPDATE_CONTINUOUS) | |
scale_d.set_name("delay") | |
scale_d.set_range(1, 50) | |
scale_d.set_value(15) | |
scale_d.set_size_request(300, 40) | |
scale_d.set_digits(0) | |
scale_d.connect("value-changed", self.scale_callback) | |
scale_d_label = gtk.Label("delay") | |
#-STEP SCALE | |
scale_s = gtk.HScale() | |
scale_s.set_update_policy(gtk.UPDATE_CONTINUOUS) | |
scale_s.set_name("step") | |
scale_s.set_range(1, 50) | |
scale_s.set_value(20) | |
scale_s.set_size_request(300, 40) | |
scale_s.set_digits(0) | |
scale_s.connect("value-changed", self.scale_callback) | |
scale_s_label = gtk.Label("step") | |
#-HUE SCALE | |
scale_h = gtk.HScale() | |
scale_h.set_update_policy(gtk.UPDATE_CONTINUOUS) | |
scale_h.set_name("hue") | |
scale_h.set_range(0, 255) | |
scale_h.set_value(0) | |
scale_h.set_size_request(300, 40) | |
scale_h.set_digits(0) | |
scale_h.connect("value-changed", self.scale_callback) | |
scale_h_label = gtk.Label("hue") | |
#-SATURATION SCALE | |
scale_t = gtk.HScale() | |
scale_t.set_update_policy(gtk.UPDATE_CONTINUOUS) | |
scale_t.set_name("sat") | |
scale_t.set_range(1, 255) | |
scale_t.set_value(255) | |
scale_t.set_size_request(300, 40) | |
scale_t.set_digits(0) | |
scale_t.connect("value-changed", self.scale_callback) | |
scale_t_label = gtk.Label("saturation") | |
#-LED INDEX TESTING SCALE | |
scale_i = gtk.HScale() | |
scale_i.set_update_policy(gtk.UPDATE_CONTINUOUS) | |
scale_i.set_name("index") | |
scale_i.set_range(0, 22) | |
scale_i.set_value(0) | |
scale_i.set_size_request(300, 40) | |
scale_i.set_digits(0) | |
scale_i.connect("value-changed", self.scale_callback) | |
scale_i_label = gtk.Label("index") | |
#------------WIDGET CONTAINER------------ | |
fixed = gtk.Fixed() | |
fixed.put(button_connect, 0, 0) | |
fixed.put(self.combobox_port, 150, 0) | |
fixed.put(self.entry, 0, 35) | |
fixed.put(button_mode, 0, 70) | |
fixed.put(self.combobox_mode, 150, 70) | |
fixed.put(scale_b, 15, 100) | |
fixed.put(scale_b_label, 320, 115) | |
fixed.put(scale_d, 15, 140) | |
fixed.put(scale_d_label, 320, 155) | |
fixed.put(scale_s, 15, 180) | |
fixed.put(scale_s_label, 320, 195) | |
fixed.put(scale_h, 15, 220) | |
fixed.put(scale_h_label, 320, 235) | |
fixed.put(scale_t, 15, 260) | |
fixed.put(scale_t_label, 320, 275) | |
fixed.put(scale_i, 15, 320) | |
fixed.put(scale_i_label, 320, 335) | |
fixed.put(self.colorsel, 15, 365) | |
#------------INITIALIZE WINDOW------------ | |
window.add(fixed) | |
window.show_all() | |
def main(): | |
gtk.main() | |
return 0 | |
if __name__ == "__main__": | |
myRGBController() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment