From ba33d03004bc6dc69e1909a8d4a8e390123b546f Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 16:40:04 -0500 Subject: [PATCH 01/32] Add new author name --- .../EventGhost/Prismatik/__init__.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 109091ec..9575c0b5 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -3,7 +3,7 @@ eg.RegisterPlugin( name = "Prismatik for Eventghost", - author = "Lucleonhart, 0xdefec", + author = "Lucleonhart, 0xdefec, SaladFork", version = "1.0", kind = "external", description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings (leave the key empty and port at 3636)." @@ -18,7 +18,7 @@ def __init__(self): self.AddAction(LowBrightness) self.AddAction(MaxBrightness) self.AddAction(NextProfile) - + self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ) self.lpack.connect() @@ -35,10 +35,10 @@ def __call__(self): print "Lightpack lights are on now" class TurnOff(eg.ActionBase): - + name = "Turn off" description = "Turn off the Lights." - + def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.turnOff() @@ -46,10 +46,10 @@ def __call__(self): print "Lightpack lights are off now" class Toggle(eg.ActionBase): - + name = "Toggle lights on/off" description = "Toggles the lights on or off" - + def __call__(self): self.plugin.lpack.lock() status = self.plugin.lpack.getStatus() @@ -63,10 +63,10 @@ def __call__(self): print "Lightpack lights are "+self.plugin.lpack.getStatus().strip()+" now" class LowBrightness(eg.ActionBase): - + name = "Low Brightness" description = "Sets the brightness to 20%" - + def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.setBrightness(20) @@ -74,10 +74,10 @@ def __call__(self): print "Brightness now at 20%" class MaxBrightness(eg.ActionBase): - + name = "Maximum Brightness" description = "Sets the brightness to 100%" - + def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.setBrightness(100) @@ -85,10 +85,10 @@ def __call__(self): print "Brightness now at 100%" class NextProfile(eg.ActionBase): - + name = "Next profile" description = "Switches to the next prismatik profile" - + def __call__(self): self.plugin.lpack.lock() profiles = self.plugin.lpack.getProfiles() From 1e891d0c3c96ed5e4df33378d8588f5ac7750879 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 16:52:55 -0500 Subject: [PATCH 02/32] Switch to unix line endings --- .../EventGhost/Prismatik/__init__.py | 206 ++++++++--------- .../EventGhost/Prismatik/lightpack.py | 216 +++++++++--------- 2 files changed, 211 insertions(+), 211 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 9575c0b5..6ffc008e 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -1,103 +1,103 @@ -import eg -import lightpack - -eg.RegisterPlugin( - name = "Prismatik for Eventghost", - author = "Lucleonhart, 0xdefec, SaladFork", - version = "1.0", - kind = "external", - description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings (leave the key empty and port at 3636)." -) - -class Lightpack(eg.PluginBase): - - def __init__(self): - self.AddAction(TurnOn) - self.AddAction(TurnOff) - self.AddAction(Toggle) - self.AddAction(LowBrightness) - self.AddAction(MaxBrightness) - self.AddAction(NextProfile) - - self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ) - self.lpack.connect() - - -class TurnOn(eg.ActionBase): - - name = "Turn on" - description = "Turn on the Lights." - - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.turnOn() - self.plugin.lpack.unlock() - print "Lightpack lights are on now" - -class TurnOff(eg.ActionBase): - - name = "Turn off" - description = "Turn off the Lights." - - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.turnOff() - self.plugin.lpack.unlock() - print "Lightpack lights are off now" - -class Toggle(eg.ActionBase): - - name = "Toggle lights on/off" - description = "Toggles the lights on or off" - - def __call__(self): - self.plugin.lpack.lock() - status = self.plugin.lpack.getStatus() - if status.strip() == 'on': - self.plugin.lpack.turnOff() - print "turning off" - else: - self.plugin.lpack.turnOn() - print "turning on" - self.plugin.lpack.unlock() - print "Lightpack lights are "+self.plugin.lpack.getStatus().strip()+" now" - -class LowBrightness(eg.ActionBase): - - name = "Low Brightness" - description = "Sets the brightness to 20%" - - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.setBrightness(20) - self.plugin.lpack.unlock() - print "Brightness now at 20%" - -class MaxBrightness(eg.ActionBase): - - name = "Maximum Brightness" - description = "Sets the brightness to 100%" - - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.setBrightness(100) - self.plugin.lpack.unlock() - print "Brightness now at 100%" - -class NextProfile(eg.ActionBase): - - name = "Next profile" - description = "Switches to the next prismatik profile" - - def __call__(self): - self.plugin.lpack.lock() - profiles = self.plugin.lpack.getProfiles() - currentProfile = self.plugin.lpack.getProfile().strip() - profilePos = profiles.index(currentProfile) - if profilePos == len(profiles)-1: - next = 0 - else: - next = profilePos+1 - self.plugin.lpack.setProfile(profiles[next]) - self.plugin.lpack.unlock() - print "Switched profile to "+profiles[next] +import eg +import lightpack + +eg.RegisterPlugin( + name = "Prismatik for Eventghost", + author = "Lucleonhart, 0xdefec, SaladFork", + version = "1.0", + kind = "external", + description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings (leave the key empty and port at 3636)." +) + +class Lightpack(eg.PluginBase): + + def __init__(self): + self.AddAction(TurnOn) + self.AddAction(TurnOff) + self.AddAction(Toggle) + self.AddAction(LowBrightness) + self.AddAction(MaxBrightness) + self.AddAction(NextProfile) + + self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ) + self.lpack.connect() + + +class TurnOn(eg.ActionBase): + + name = "Turn on" + description = "Turn on the Lights." + + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.turnOn() + self.plugin.lpack.unlock() + print "Lightpack lights are on now" + +class TurnOff(eg.ActionBase): + + name = "Turn off" + description = "Turn off the Lights." + + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.turnOff() + self.plugin.lpack.unlock() + print "Lightpack lights are off now" + +class Toggle(eg.ActionBase): + + name = "Toggle lights on/off" + description = "Toggles the lights on or off" + + def __call__(self): + self.plugin.lpack.lock() + status = self.plugin.lpack.getStatus() + if status.strip() == 'on': + self.plugin.lpack.turnOff() + print "turning off" + else: + self.plugin.lpack.turnOn() + print "turning on" + self.plugin.lpack.unlock() + print "Lightpack lights are "+self.plugin.lpack.getStatus().strip()+" now" + +class LowBrightness(eg.ActionBase): + + name = "Low Brightness" + description = "Sets the brightness to 20%" + + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.setBrightness(20) + self.plugin.lpack.unlock() + print "Brightness now at 20%" + +class MaxBrightness(eg.ActionBase): + + name = "Maximum Brightness" + description = "Sets the brightness to 100%" + + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.setBrightness(100) + self.plugin.lpack.unlock() + print "Brightness now at 100%" + +class NextProfile(eg.ActionBase): + + name = "Next profile" + description = "Switches to the next prismatik profile" + + def __call__(self): + self.plugin.lpack.lock() + profiles = self.plugin.lpack.getProfiles() + currentProfile = self.plugin.lpack.getProfile().strip() + profilePos = profiles.index(currentProfile) + if profilePos == len(profiles)-1: + next = 0 + else: + next = profilePos+1 + self.plugin.lpack.setProfile(profiles[next]) + self.plugin.lpack.unlock() + print "Switched profile to "+profiles[next] diff --git a/Software/apiexamples/EventGhost/Prismatik/lightpack.py b/Software/apiexamples/EventGhost/Prismatik/lightpack.py index 07634ba2..9758abbf 100755 --- a/Software/apiexamples/EventGhost/Prismatik/lightpack.py +++ b/Software/apiexamples/EventGhost/Prismatik/lightpack.py @@ -1,108 +1,108 @@ -import socket, time, imaplib, re, sys - -class lightpack: - def __init__(self, _host, _port, _apikey, _ledMap): - self.host = _host - self.port = _port - self.apikey = _apikey - self.ledMap = _ledMap - - def __readResult(self): # Return last-command API answer (call in every local method) - total_data=[] - data = self.connection.recv(8192) - total_data.append(data) - return ''.join(total_data) - - def getProfiles(self): - cmd = 'getprofiles\n' - self.connection.send(cmd) - profiles = self.__readResult() - return profiles.split(':')[1].strip(';\n\r').split(';') - - def getProfile(self): - cmd = 'getprofile\n' - self.connection.send(cmd) - profile = self.__readResult() - profile = profile.split(':')[1] - return profile - - def getStatus(self): - cmd = 'getstatus\n' - self.connection.send(cmd) - status = self.__readResult() - status = status.split(':')[1] - return status - - def getAPIStatus(self): - cmd = 'getstatusapi\n' - self.connection.send(cmd) - status = self.__readResult() - status = status.split(':')[1] - return status - - def connect (self): - try: #Try to connect to the server API - self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.connection.connect((self.host, self.port)) - self.__readResult() - cmd = 'apikey:' + self.apikey + '\n' - self.connection.send(cmd) - self.__readResult() - return 0 - except: - print 'Lightpack API server is missing' - return -1 - - def setColor(self, n, r, g, b): # Set color to the define LED - cmd = 'setcolor:{0}-{1},{2},{3}\n'.format(self.ledMap[n-1], r, g, b) - self.connection.send(cmd) - self.__readResult() - - def setColorToAll(self, r, g, b): # Set one color to all LEDs - cmdstr = '' - for i in self.ledMap: - cmdstr = str(cmdstr) + str(i) + '-{0},{1},{2};'.format(r,g,b) - cmd = 'setcolor:' + cmdstr + '\n' - self.connection.send(cmd) - self.__readResult() - - def setGamma(self, g): - cmd = 'setgamma:{0}\n'.format(g) - self.connection.send(cmd) - self.__readResult() - - def setSmooth(self, s): - cmd = 'setsmooth:{0}\n'.format(s) - self.connection.send(cmd) - self.__readResult() - - def setProfile(self, p): - #cmd = 'setprofile:{0}\n'.format(p) - cmd = 'setprofile:%s\n' % p - self.connection.send(cmd) - self.__readResult() - - def lock(self): - cmd = 'lock\n' - self.connection.send(cmd) - self.__readResult() - - def unlock(self): - cmd = 'unlock\n' - self.connection.send(cmd) - self.__readResult() - - def turnOn(self): - cmd = 'setstatus:on\n' - self.connection.send(cmd) - self.__readResult() - - def turnOff(self): - cmd = 'setstatus:off\n' - self.connection.send(cmd) - self.__readResult() - - def disconnect(self): - self.unlock() - self.connection.close() - \ No newline at end of file +import socket, time, imaplib, re, sys + +class lightpack: + def __init__(self, _host, _port, _apikey, _ledMap): + self.host = _host + self.port = _port + self.apikey = _apikey + self.ledMap = _ledMap + + def __readResult(self): # Return last-command API answer (call in every local method) + total_data=[] + data = self.connection.recv(8192) + total_data.append(data) + return ''.join(total_data) + + def getProfiles(self): + cmd = 'getprofiles\n' + self.connection.send(cmd) + profiles = self.__readResult() + return profiles.split(':')[1].strip(';\n\r').split(';') + + def getProfile(self): + cmd = 'getprofile\n' + self.connection.send(cmd) + profile = self.__readResult() + profile = profile.split(':')[1] + return profile + + def getStatus(self): + cmd = 'getstatus\n' + self.connection.send(cmd) + status = self.__readResult() + status = status.split(':')[1] + return status + + def getAPIStatus(self): + cmd = 'getstatusapi\n' + self.connection.send(cmd) + status = self.__readResult() + status = status.split(':')[1] + return status + + def connect (self): + try: #Try to connect to the server API + self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.connection.connect((self.host, self.port)) + self.__readResult() + cmd = 'apikey:' + self.apikey + '\n' + self.connection.send(cmd) + self.__readResult() + return 0 + except: + print 'Lightpack API server is missing' + return -1 + + def setColor(self, n, r, g, b): # Set color to the define LED + cmd = 'setcolor:{0}-{1},{2},{3}\n'.format(self.ledMap[n-1], r, g, b) + self.connection.send(cmd) + self.__readResult() + + def setColorToAll(self, r, g, b): # Set one color to all LEDs + cmdstr = '' + for i in self.ledMap: + cmdstr = str(cmdstr) + str(i) + '-{0},{1},{2};'.format(r,g,b) + cmd = 'setcolor:' + cmdstr + '\n' + self.connection.send(cmd) + self.__readResult() + + def setGamma(self, g): + cmd = 'setgamma:{0}\n'.format(g) + self.connection.send(cmd) + self.__readResult() + + def setSmooth(self, s): + cmd = 'setsmooth:{0}\n'.format(s) + self.connection.send(cmd) + self.__readResult() + + def setProfile(self, p): + #cmd = 'setprofile:{0}\n'.format(p) + cmd = 'setprofile:%s\n' % p + self.connection.send(cmd) + self.__readResult() + + def lock(self): + cmd = 'lock\n' + self.connection.send(cmd) + self.__readResult() + + def unlock(self): + cmd = 'unlock\n' + self.connection.send(cmd) + self.__readResult() + + def turnOn(self): + cmd = 'setstatus:on\n' + self.connection.send(cmd) + self.__readResult() + + def turnOff(self): + cmd = 'setstatus:off\n' + self.connection.send(cmd) + self.__readResult() + + def disconnect(self): + self.unlock() + self.connection.close() + From e8620dc50e52711beb9f1cca8bd324e68376b42e Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 16:59:48 -0500 Subject: [PATCH 03/32] Correct EventGhost name in plugin name --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 6ffc008e..47471f5a 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -2,7 +2,7 @@ import lightpack eg.RegisterPlugin( - name = "Prismatik for Eventghost", + name = "Prismatik for EventGhost", author = "Lucleonhart, 0xdefec, SaladFork", version = "1.0", kind = "external", From 95d2d6d49a7c80c638ffc54c0d7cba5c71915697 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 17:25:09 -0500 Subject: [PATCH 04/32] Switch to using start/stop for connecting and disconnecting --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 47471f5a..dec7c62e 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -19,9 +19,16 @@ def __init__(self): self.AddAction(MaxBrightness) self.AddAction(NextProfile) - self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ) + def __start__(self): + self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) self.lpack.connect() + def __stop__(self): + self.lpack.disconnect() + + def __close__(self): + pass + class TurnOn(eg.ActionBase): From 52065b14fe006f264195759ac61cec57a4893972 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 17:32:41 -0500 Subject: [PATCH 05/32] Switch indentation to spaces --- .../EventGhost/Prismatik/__init__.py | 152 +++++++++--------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index dec7c62e..6cf09ceb 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -2,109 +2,109 @@ import lightpack eg.RegisterPlugin( - name = "Prismatik for EventGhost", - author = "Lucleonhart, 0xdefec, SaladFork", - version = "1.0", - kind = "external", - description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings (leave the key empty and port at 3636)." + name = "Prismatik for EventGhost", + author = "Lucleonhart, 0xdefec, SaladFork", + version = "1.0", + kind = "external", + description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings (leave the key empty and port at 3636)." ) class Lightpack(eg.PluginBase): - def __init__(self): - self.AddAction(TurnOn) - self.AddAction(TurnOff) - self.AddAction(Toggle) - self.AddAction(LowBrightness) - self.AddAction(MaxBrightness) - self.AddAction(NextProfile) + def __init__(self): + self.AddAction(TurnOn) + self.AddAction(TurnOff) + self.AddAction(Toggle) + self.AddAction(LowBrightness) + self.AddAction(MaxBrightness) + self.AddAction(NextProfile) - def __start__(self): - self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) - self.lpack.connect() + def __start__(self): + self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) + self.lpack.connect() - def __stop__(self): - self.lpack.disconnect() + def __stop__(self): + self.lpack.disconnect() - def __close__(self): - pass + def __close__(self): + pass class TurnOn(eg.ActionBase): - name = "Turn on" - description = "Turn on the Lights." + name = "Turn on" + description = "Turn on the Lights." - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.turnOn() - self.plugin.lpack.unlock() - print "Lightpack lights are on now" + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.turnOn() + self.plugin.lpack.unlock() + print "Lightpack lights are on now" class TurnOff(eg.ActionBase): - name = "Turn off" - description = "Turn off the Lights." + name = "Turn off" + description = "Turn off the Lights." - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.turnOff() - self.plugin.lpack.unlock() - print "Lightpack lights are off now" + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.turnOff() + self.plugin.lpack.unlock() + print "Lightpack lights are off now" class Toggle(eg.ActionBase): - name = "Toggle lights on/off" - description = "Toggles the lights on or off" - - def __call__(self): - self.plugin.lpack.lock() - status = self.plugin.lpack.getStatus() - if status.strip() == 'on': - self.plugin.lpack.turnOff() - print "turning off" - else: - self.plugin.lpack.turnOn() - print "turning on" - self.plugin.lpack.unlock() - print "Lightpack lights are "+self.plugin.lpack.getStatus().strip()+" now" + name = "Toggle lights on/off" + description = "Toggles the lights on or off" + + def __call__(self): + self.plugin.lpack.lock() + status = self.plugin.lpack.getStatus() + if status.strip() == 'on': + self.plugin.lpack.turnOff() + print "turning off" + else: + self.plugin.lpack.turnOn() + print "turning on" + self.plugin.lpack.unlock() + print "Lightpack lights are "+self.plugin.lpack.getStatus().strip()+" now" class LowBrightness(eg.ActionBase): - name = "Low Brightness" - description = "Sets the brightness to 20%" + name = "Low Brightness" + description = "Sets the brightness to 20%" - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.setBrightness(20) - self.plugin.lpack.unlock() - print "Brightness now at 20%" + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.setBrightness(20) + self.plugin.lpack.unlock() + print "Brightness now at 20%" class MaxBrightness(eg.ActionBase): - name = "Maximum Brightness" - description = "Sets the brightness to 100%" + name = "Maximum Brightness" + description = "Sets the brightness to 100%" - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.setBrightness(100) - self.plugin.lpack.unlock() - print "Brightness now at 100%" + def __call__(self): + self.plugin.lpack.lock() + self.plugin.lpack.setBrightness(100) + self.plugin.lpack.unlock() + print "Brightness now at 100%" class NextProfile(eg.ActionBase): - name = "Next profile" - description = "Switches to the next prismatik profile" - - def __call__(self): - self.plugin.lpack.lock() - profiles = self.plugin.lpack.getProfiles() - currentProfile = self.plugin.lpack.getProfile().strip() - profilePos = profiles.index(currentProfile) - if profilePos == len(profiles)-1: - next = 0 - else: - next = profilePos+1 - self.plugin.lpack.setProfile(profiles[next]) - self.plugin.lpack.unlock() - print "Switched profile to "+profiles[next] + name = "Next profile" + description = "Switches to the next prismatik profile" + + def __call__(self): + self.plugin.lpack.lock() + profiles = self.plugin.lpack.getProfiles() + currentProfile = self.plugin.lpack.getProfile().strip() + profilePos = profiles.index(currentProfile) + if profilePos == len(profiles)-1: + next = 0 + else: + next = profilePos+1 + self.plugin.lpack.setProfile(profiles[next]) + self.plugin.lpack.unlock() + print "Switched profile to "+profiles[next] From d9e91bc7d4ea89ad9cf7b8efbfc4c45241404150 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 17:33:22 -0500 Subject: [PATCH 06/32] Allow user to configure connection settings --- .../EventGhost/Prismatik/__init__.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 6cf09ceb..de7f540e 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -6,7 +6,7 @@ author = "Lucleonhart, 0xdefec, SaladFork", version = "1.0", kind = "external", - description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings (leave the key empty and port at 3636)." + description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings." ) class Lightpack(eg.PluginBase): @@ -19,8 +19,8 @@ def __init__(self): self.AddAction(MaxBrightness) self.AddAction(NextProfile) - def __start__(self): - self.lpack = lightpack.lightpack("127.0.0.1", 3636, "", [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) + def __start__(self, host, port, apikey): + self.lpack = lightpack.lightpack(host, int(port), apikey, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) self.lpack.connect() def __stop__(self): @@ -29,6 +29,24 @@ def __stop__(self): def __close__(self): pass + def Configure(self, host="127.0.0.1", port="3636", apikey=""): + panel = eg.ConfigPanel() + sizer = panel.sizer + + txtHost = wx.TextCtrl(panel, -1, host) + txtPort = wx.TextCtrl(panel, -1, port) + txtApikey = wx.TextCtrl(panel, -1, apikey) + + sizer.Add(panel.StaticText("Host: ")) + sizer.Add(txtHost) + sizer.Add(panel.StaticText("Port: ")) + sizer.Add(txtPort) + sizer.Add(panel.StaticText("API Key: ")) + sizer.Add(txtApikey) + + while panel.Affirmed(): + panel.SetResult(txtHost.GetValue(), txtPort.GetValue(), txtApikey.GetValue()) + class TurnOn(eg.ActionBase): From 72964b475f4c1e0d4a6e1ae4bb403e32823821f5 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Wed, 12 Feb 2014 17:34:02 -0500 Subject: [PATCH 07/32] Bump version number --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index de7f540e..a951437d 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -4,7 +4,7 @@ eg.RegisterPlugin( name = "Prismatik for EventGhost", author = "Lucleonhart, 0xdefec, SaladFork", - version = "1.0", + version = "1.0.1", kind = "external", description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings." ) From 385d3c6bd7ef9fd4260b1a0eaf6a6718e39caec5 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 16:00:26 -0500 Subject: [PATCH 08/32] Switch to using range built-in --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index a951437d..c55e69d9 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -20,7 +20,7 @@ def __init__(self): self.AddAction(NextProfile) def __start__(self, host, port, apikey): - self.lpack = lightpack.lightpack(host, int(port), apikey, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) + self.lpack = lightpack.lightpack(host, int(port), apikey, range(1, 20)) self.lpack.connect() def __stop__(self): From 73673008d15c02d14b2ff56bf3bf7aed720be326 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 16:37:22 -0500 Subject: [PATCH 09/32] Make configurable text boxes wider --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index c55e69d9..86fc2de7 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -33,9 +33,9 @@ def Configure(self, host="127.0.0.1", port="3636", apikey=""): panel = eg.ConfigPanel() sizer = panel.sizer - txtHost = wx.TextCtrl(panel, -1, host) - txtPort = wx.TextCtrl(panel, -1, port) - txtApikey = wx.TextCtrl(panel, -1, apikey) + txtHost = wx.TextCtrl(panel, -1, host, size=(250, -1)) + txtPort = wx.TextCtrl(panel, -1, port, size=(250, -1)) + txtApikey = wx.TextCtrl(panel, -1, apikey, size=(250, -1)) sizer.Add(panel.StaticText("Host: ")) sizer.Add(txtHost) From e10bf734cfa7bab423807454d49e4221c536a445 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 16:37:57 -0500 Subject: [PATCH 10/32] Switch to using panel sizer's AddMany instead of using multiple Add calls --- .../apiexamples/EventGhost/Prismatik/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 86fc2de7..98fde35d 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -37,12 +37,14 @@ def Configure(self, host="127.0.0.1", port="3636", apikey=""): txtPort = wx.TextCtrl(panel, -1, port, size=(250, -1)) txtApikey = wx.TextCtrl(panel, -1, apikey, size=(250, -1)) - sizer.Add(panel.StaticText("Host: ")) - sizer.Add(txtHost) - sizer.Add(panel.StaticText("Port: ")) - sizer.Add(txtPort) - sizer.Add(panel.StaticText("API Key: ")) - sizer.Add(txtApikey) + sizer.AddMany([ + (panel.StaticText("Host: ")), + (txtHost), + (panel.StaticText("Port: ")), + (txtPort), + (panel.StaticText("API Key: ")), + (txtApikey) + ]) while panel.Affirmed(): panel.SetResult(txtHost.GetValue(), txtPort.GetValue(), txtApikey.GetValue()) From b7fd85dab069f052a389883a42327eb38e78041a Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 16:49:26 -0500 Subject: [PATCH 11/32] Remove unnecessary debug printing: EventGhost prints macros/events/actions as they're triggered --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 98fde35d..b8037727 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -59,7 +59,6 @@ def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.turnOn() self.plugin.lpack.unlock() - print "Lightpack lights are on now" class TurnOff(eg.ActionBase): @@ -70,7 +69,6 @@ def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.turnOff() self.plugin.lpack.unlock() - print "Lightpack lights are off now" class Toggle(eg.ActionBase): @@ -87,7 +85,6 @@ def __call__(self): self.plugin.lpack.turnOn() print "turning on" self.plugin.lpack.unlock() - print "Lightpack lights are "+self.plugin.lpack.getStatus().strip()+" now" class LowBrightness(eg.ActionBase): @@ -98,7 +95,6 @@ def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.setBrightness(20) self.plugin.lpack.unlock() - print "Brightness now at 20%" class MaxBrightness(eg.ActionBase): @@ -109,7 +105,6 @@ def __call__(self): self.plugin.lpack.lock() self.plugin.lpack.setBrightness(100) self.plugin.lpack.unlock() - print "Brightness now at 100%" class NextProfile(eg.ActionBase): @@ -127,4 +122,3 @@ def __call__(self): next = profilePos+1 self.plugin.lpack.setProfile(profiles[next]) self.plugin.lpack.unlock() - print "Switched profile to "+profiles[next] From 2cf65589e9c8eb900f57f46fea695c6e6b7c7a45 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 16:55:09 -0500 Subject: [PATCH 12/32] Remove toggle action: should use EventGhost enable/disable macros to accomplish this --- .../EventGhost/Prismatik/__init__.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index b8037727..fd1c6b1d 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -14,7 +14,6 @@ class Lightpack(eg.PluginBase): def __init__(self): self.AddAction(TurnOn) self.AddAction(TurnOff) - self.AddAction(Toggle) self.AddAction(LowBrightness) self.AddAction(MaxBrightness) self.AddAction(NextProfile) @@ -70,22 +69,6 @@ def __call__(self): self.plugin.lpack.turnOff() self.plugin.lpack.unlock() -class Toggle(eg.ActionBase): - - name = "Toggle lights on/off" - description = "Toggles the lights on or off" - - def __call__(self): - self.plugin.lpack.lock() - status = self.plugin.lpack.getStatus() - if status.strip() == 'on': - self.plugin.lpack.turnOff() - print "turning off" - else: - self.plugin.lpack.turnOn() - print "turning on" - self.plugin.lpack.unlock() - class LowBrightness(eg.ActionBase): name = "Low Brightness" From 4b70e9c7ee91eb55c0411ab6cb8b3aed7eee986a Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 17:13:02 -0500 Subject: [PATCH 13/32] Make grammar/capitalization in action names and descriptions more consistent --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index fd1c6b1d..1db5468c 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -52,7 +52,7 @@ def Configure(self, host="127.0.0.1", port="3636", apikey=""): class TurnOn(eg.ActionBase): name = "Turn on" - description = "Turn on the Lights." + description = "Turns on the lights" def __call__(self): self.plugin.lpack.lock() @@ -62,7 +62,7 @@ def __call__(self): class TurnOff(eg.ActionBase): name = "Turn off" - description = "Turn off the Lights." + description = "Turns off the Lights" def __call__(self): self.plugin.lpack.lock() @@ -71,7 +71,7 @@ def __call__(self): class LowBrightness(eg.ActionBase): - name = "Low Brightness" + name = "Low brightness" description = "Sets the brightness to 20%" def __call__(self): @@ -81,7 +81,7 @@ def __call__(self): class MaxBrightness(eg.ActionBase): - name = "Maximum Brightness" + name = "Maximum brightness" description = "Sets the brightness to 100%" def __call__(self): From f59f3df5ed00de351f817a683241ae975315fca6 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Mon, 3 Mar 2014 17:13:31 -0500 Subject: [PATCH 14/32] Add new action for switching to a specific profile --- .../EventGhost/Prismatik/__init__.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 1db5468c..3e2e4824 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -17,6 +17,7 @@ def __init__(self): self.AddAction(LowBrightness) self.AddAction(MaxBrightness) self.AddAction(NextProfile) + self.AddAction(SetProfile) def __start__(self, host, port, apikey): self.lpack = lightpack.lightpack(host, int(port), apikey, range(1, 20)) @@ -105,3 +106,32 @@ def __call__(self): next = profilePos+1 self.plugin.lpack.setProfile(profiles[next]) self.plugin.lpack.unlock() + +class SetProfile(eg.ActionBase): + + name = "Set profile" + description = "Switches to a specific profile" + + def __call__(self, profile): + self.plugin.lpack.lock() + self.plugin.lpack.setProfile(profile) + self.plugin.lpack.unlock() + + setProfile = self.plugin.lpack.getProfile().strip() + + if setProfile != profile: + self.PrintError("Could not switch to profile '%s'!" % profile); + + def Configure(self, profile="Lightpack"): + profiles = self.plugin.lpack.getProfiles() + + panel = eg.ConfigPanel() + sizer = panel.sizer + + cmbProfiles = wx.ComboBox(panel, -1, profile, choices=profiles, size=(250, -1)) + + sizer.Add(panel.StaticText("Profile: ")) + sizer.Add(cmbProfiles) + + while panel.Affirmed(): + panel.SetResult(cmbProfiles.GetValue()) From df492a9f500f14a64659afaff8cfcbfab37710db Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 11:46:01 -0500 Subject: [PATCH 15/32] Switch indentation from tabs to spaces --- .../EventGhost/Prismatik/lightpack.py | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/lightpack.py b/Software/apiexamples/EventGhost/Prismatik/lightpack.py index 9758abbf..f8edd744 100755 --- a/Software/apiexamples/EventGhost/Prismatik/lightpack.py +++ b/Software/apiexamples/EventGhost/Prismatik/lightpack.py @@ -1,108 +1,108 @@ import socket, time, imaplib, re, sys class lightpack: - def __init__(self, _host, _port, _apikey, _ledMap): - self.host = _host - self.port = _port - self.apikey = _apikey - self.ledMap = _ledMap - - def __readResult(self): # Return last-command API answer (call in every local method) - total_data=[] - data = self.connection.recv(8192) - total_data.append(data) - return ''.join(total_data) - - def getProfiles(self): - cmd = 'getprofiles\n' - self.connection.send(cmd) - profiles = self.__readResult() - return profiles.split(':')[1].strip(';\n\r').split(';') - - def getProfile(self): - cmd = 'getprofile\n' - self.connection.send(cmd) - profile = self.__readResult() - profile = profile.split(':')[1] - return profile - - def getStatus(self): - cmd = 'getstatus\n' - self.connection.send(cmd) - status = self.__readResult() - status = status.split(':')[1] - return status - - def getAPIStatus(self): - cmd = 'getstatusapi\n' - self.connection.send(cmd) - status = self.__readResult() - status = status.split(':')[1] - return status - - def connect (self): - try: #Try to connect to the server API - self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.connection.connect((self.host, self.port)) - self.__readResult() - cmd = 'apikey:' + self.apikey + '\n' - self.connection.send(cmd) - self.__readResult() - return 0 - except: - print 'Lightpack API server is missing' - return -1 - - def setColor(self, n, r, g, b): # Set color to the define LED - cmd = 'setcolor:{0}-{1},{2},{3}\n'.format(self.ledMap[n-1], r, g, b) - self.connection.send(cmd) - self.__readResult() - - def setColorToAll(self, r, g, b): # Set one color to all LEDs - cmdstr = '' - for i in self.ledMap: - cmdstr = str(cmdstr) + str(i) + '-{0},{1},{2};'.format(r,g,b) - cmd = 'setcolor:' + cmdstr + '\n' - self.connection.send(cmd) - self.__readResult() - - def setGamma(self, g): - cmd = 'setgamma:{0}\n'.format(g) - self.connection.send(cmd) - self.__readResult() - - def setSmooth(self, s): - cmd = 'setsmooth:{0}\n'.format(s) - self.connection.send(cmd) - self.__readResult() - - def setProfile(self, p): - #cmd = 'setprofile:{0}\n'.format(p) - cmd = 'setprofile:%s\n' % p - self.connection.send(cmd) - self.__readResult() - - def lock(self): - cmd = 'lock\n' - self.connection.send(cmd) - self.__readResult() - - def unlock(self): - cmd = 'unlock\n' - self.connection.send(cmd) - self.__readResult() - - def turnOn(self): - cmd = 'setstatus:on\n' - self.connection.send(cmd) - self.__readResult() - - def turnOff(self): - cmd = 'setstatus:off\n' - self.connection.send(cmd) - self.__readResult() - - def disconnect(self): - self.unlock() - self.connection.close() + def __init__(self, _host, _port, _apikey, _ledMap): + self.host = _host + self.port = _port + self.apikey = _apikey + self.ledMap = _ledMap + + def __readResult(self): # Return last-command API answer (call in every local method) + total_data=[] + data = self.connection.recv(8192) + total_data.append(data) + return ''.join(total_data) + + def getProfiles(self): + cmd = 'getprofiles\n' + self.connection.send(cmd) + profiles = self.__readResult() + return profiles.split(':')[1].strip(';\n\r').split(';') + + def getProfile(self): + cmd = 'getprofile\n' + self.connection.send(cmd) + profile = self.__readResult() + profile = profile.split(':')[1] + return profile + + def getStatus(self): + cmd = 'getstatus\n' + self.connection.send(cmd) + status = self.__readResult() + status = status.split(':')[1] + return status + + def getAPIStatus(self): + cmd = 'getstatusapi\n' + self.connection.send(cmd) + status = self.__readResult() + status = status.split(':')[1] + return status + + def connect (self): + try: #Try to connect to the server API + self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.connection.connect((self.host, self.port)) + self.__readResult() + cmd = 'apikey:' + self.apikey + '\n' + self.connection.send(cmd) + self.__readResult() + return 0 + except: + print 'Lightpack API server is missing' + return -1 + + def setColor(self, n, r, g, b): # Set color to the define LED + cmd = 'setcolor:{0}-{1},{2},{3}\n'.format(self.ledMap[n-1], r, g, b) + self.connection.send(cmd) + self.__readResult() + + def setColorToAll(self, r, g, b): # Set one color to all LEDs + cmdstr = '' + for i in self.ledMap: + cmdstr = str(cmdstr) + str(i) + '-{0},{1},{2};'.format(r,g,b) + cmd = 'setcolor:' + cmdstr + '\n' + self.connection.send(cmd) + self.__readResult() + + def setGamma(self, g): + cmd = 'setgamma:{0}\n'.format(g) + self.connection.send(cmd) + self.__readResult() + + def setSmooth(self, s): + cmd = 'setsmooth:{0}\n'.format(s) + self.connection.send(cmd) + self.__readResult() + + def setProfile(self, p): + #cmd = 'setprofile:{0}\n'.format(p) + cmd = 'setprofile:%s\n' % p + self.connection.send(cmd) + self.__readResult() + + def lock(self): + cmd = 'lock\n' + self.connection.send(cmd) + self.__readResult() + + def unlock(self): + cmd = 'unlock\n' + self.connection.send(cmd) + self.__readResult() + + def turnOn(self): + cmd = 'setstatus:on\n' + self.connection.send(cmd) + self.__readResult() + + def turnOff(self): + cmd = 'setstatus:off\n' + self.connection.send(cmd) + self.__readResult() + + def disconnect(self): + self.unlock() + self.connection.close() From 48bfe1c3f0d142e77257ee5387eada2d9fbebb54 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:14:24 -0500 Subject: [PATCH 16/32] Switch to using plugin variable instead of class variable --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 3e2e4824..38a21008 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -20,11 +20,11 @@ def __init__(self): self.AddAction(SetProfile) def __start__(self, host, port, apikey): - self.lpack = lightpack.lightpack(host, int(port), apikey, range(1, 20)) - self.lpack.connect() + self.plugin.lpack = lightpack.lightpack(host, int(port), apikey, range(1, 20)) + self.plugin.lpack.connect() def __stop__(self): - self.lpack.disconnect() + self.plugin.lpack.disconnect() def __close__(self): pass From eed4b48762d24a1e70b81b794cb96f3e1ac43f73 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:14:51 -0500 Subject: [PATCH 17/32] Remove unnecessary semicolon --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 38a21008..d17b8458 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -120,7 +120,7 @@ def __call__(self, profile): setProfile = self.plugin.lpack.getProfile().strip() if setProfile != profile: - self.PrintError("Could not switch to profile '%s'!" % profile); + self.PrintError("Could not switch to profile '%s'!" % profile) def Configure(self, profile="Lightpack"): profiles = self.plugin.lpack.getProfiles() From 4d51005f7117d9e44a9596aceaeaf8f2d79b75db Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:29:33 -0500 Subject: [PATCH 18/32] Switch to latest lightpack.py --- .../EventGhost/Prismatik/__init__.py | 4 +-- .../EventGhost/Prismatik/lightpack.py | 31 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index d17b8458..e32194e8 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -20,7 +20,7 @@ def __init__(self): self.AddAction(SetProfile) def __start__(self, host, port, apikey): - self.plugin.lpack = lightpack.lightpack(host, int(port), apikey, range(1, 20)) + self.plugin.lpack = lightpack.lightpack(host, int(port), apikey or None, range(1, 20)) self.plugin.lpack.connect() def __stop__(self): @@ -29,7 +29,7 @@ def __stop__(self): def __close__(self): pass - def Configure(self, host="127.0.0.1", port="3636", apikey=""): + def Configure(self, host="127.0.0.1", port="3636", apikey=None): panel = eg.ConfigPanel() sizer = panel.sizer diff --git a/Software/apiexamples/EventGhost/Prismatik/lightpack.py b/Software/apiexamples/EventGhost/Prismatik/lightpack.py index f8edd744..5acff7dd 100755 --- a/Software/apiexamples/EventGhost/Prismatik/lightpack.py +++ b/Software/apiexamples/EventGhost/Prismatik/lightpack.py @@ -1,11 +1,17 @@ import socket, time, imaplib, re, sys class lightpack: - def __init__(self, _host, _port, _apikey, _ledMap): + +# host = '127.0.0.1' # The remote host +# port = 3636 # The same port as used by the server +# apikey = 'key' # Secure API key which generates by Lightpack software on Dev tab +# ledMap = [1,2,3,4,5,6,7,8,9,10] #mapped LEDs + + def __init__(self, _host, _port, _ledMap, _apikey = None): self.host = _host self.port = _port - self.apikey = _apikey self.ledMap = _ledMap + self.apikey = _apikey def __readResult(self): # Return last-command API answer (call in every local method) total_data=[] @@ -17,7 +23,7 @@ def getProfiles(self): cmd = 'getprofiles\n' self.connection.send(cmd) profiles = self.__readResult() - return profiles.split(':')[1].strip(';\n\r').split(';') + return profiles.split(':')[1].rstrip(';\n').split(';') def getProfile(self): cmd = 'getprofile\n' @@ -33,6 +39,13 @@ def getStatus(self): status = status.split(':')[1] return status + def getCountLeds(self): + cmd = 'getcountleds\n' + self.connection.send(cmd) + count = self.__readResult() + count = count.split(':')[1] + return count + def getAPIStatus(self): cmd = 'getstatusapi\n' self.connection.send(cmd) @@ -45,9 +58,10 @@ def connect (self): self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connection.connect((self.host, self.port)) self.__readResult() - cmd = 'apikey:' + self.apikey + '\n' - self.connection.send(cmd) - self.__readResult() + if self.apikey is not None: + cmd = 'apikey:' + self.apikey + '\n' + self.connection.send(cmd) + self.__readResult() return 0 except: print 'Lightpack API server is missing' @@ -76,6 +90,11 @@ def setSmooth(self, s): self.connection.send(cmd) self.__readResult() + def setBrightness(self, s): + cmd = 'setbrightness:{0}\n'.format(s) + self.connection.send(cmd) + self.__readResult() + def setProfile(self, p): #cmd = 'setprofile:{0}\n'.format(p) cmd = 'setprofile:%s\n' % p From 5da5e443e8be745ad48285dd64971a66a1175be1 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:40:46 -0500 Subject: [PATCH 19/32] Fix error due to None default value --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index e32194e8..31495e88 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -29,7 +29,7 @@ def __stop__(self): def __close__(self): pass - def Configure(self, host="127.0.0.1", port="3636", apikey=None): + def Configure(self, host="127.0.0.1", port="3636", apikey=""): panel = eg.ConfigPanel() sizer = panel.sizer From 51295c4359ea653865d1a8b64f7495763e337be9 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:41:32 -0500 Subject: [PATCH 20/32] Correct minor wording differences --- .../EventGhost/Prismatik/__init__.py | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 31495e88..5fb671f3 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -90,10 +90,34 @@ def __call__(self): self.plugin.lpack.setBrightness(100) self.plugin.lpack.unlock() +class SetBrightness(eg.ActionBase): + + name = "Set brightness" + description = "Sets the LED brightness to a specific value" + + def __call__(self, brightness): + self.plugin.lpack.lock() + self.plugin.lpack.setBrightness(brightness) + self.plugin.lpack.unlock() + + def Configure(self, brightness="100"): + profiles = self.plugin.lpack.getProfiles() + + panel = eg.ConfigPanel() + sizer = panel.sizer + + txtBrightness = wx.TextCtrl(panel, -1, brightness, size=(250, -1)) + + sizer.Add(panel.StaticText("Brightness (%): ")) + sizer.Add(txtBrightness) + + while panel.Affirmed(): + panel.SetResult(txtBrightness.GetValue()) + class NextProfile(eg.ActionBase): name = "Next profile" - description = "Switches to the next prismatik profile" + description = "Switches to the next Prismatik profile" def __call__(self): self.plugin.lpack.lock() @@ -110,7 +134,7 @@ def __call__(self): class SetProfile(eg.ActionBase): name = "Set profile" - description = "Switches to a specific profile" + description = "Switches to a specific Prismatik profile" def __call__(self, profile): self.plugin.lpack.lock() From 390640f273698f7827d31f3ea66f16f2495e54e7 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:49:09 -0500 Subject: [PATCH 21/32] Revert "Switch to using plugin variable instead of class variable" This reverts commit 48bfe1c3f0d142e77257ee5387eada2d9fbebb54. --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 5fb671f3..238e02d1 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -20,11 +20,11 @@ def __init__(self): self.AddAction(SetProfile) def __start__(self, host, port, apikey): - self.plugin.lpack = lightpack.lightpack(host, int(port), apikey or None, range(1, 20)) - self.plugin.lpack.connect() + self.lpack = lightpack.lightpack(host, int(port), apikey or None, range(1, 20)) + self.lpack.connect() def __stop__(self): - self.plugin.lpack.disconnect() + self.lpack.disconnect() def __close__(self): pass From 64e01e6221cd06a555abdaf9a55b6b59c4c63d85 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 13:49:54 -0500 Subject: [PATCH 22/32] Remove unncessary call to getProfiles in SetBrightness --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 238e02d1..b708233e 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -101,8 +101,6 @@ def __call__(self, brightness): self.plugin.lpack.unlock() def Configure(self, brightness="100"): - profiles = self.plugin.lpack.getProfiles() - panel = eg.ConfigPanel() sizer = panel.sizer From a67503f6ab7fdc81e05a5dfe1747f66b60d9b79a Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 14:07:45 -0500 Subject: [PATCH 23/32] Switch keyword order for lightpack init to match new lightpack.py version --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index b708233e..cf2f9114 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -20,7 +20,7 @@ def __init__(self): self.AddAction(SetProfile) def __start__(self, host, port, apikey): - self.lpack = lightpack.lightpack(host, int(port), apikey or None, range(1, 20)) + self.lpack = lightpack.lightpack(host, int(port), range(1, 20), apikey or None) self.lpack.connect() def __stop__(self): From e4818daa11a10cbddf6677dcf902748ab2220435 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 14:12:05 -0500 Subject: [PATCH 24/32] Remove Low/MaxBrightness and add SetBrightness --- .../EventGhost/Prismatik/__init__.py | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index cf2f9114..775d7b83 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -14,8 +14,7 @@ class Lightpack(eg.PluginBase): def __init__(self): self.AddAction(TurnOn) self.AddAction(TurnOff) - self.AddAction(LowBrightness) - self.AddAction(MaxBrightness) + self.AddAction(SetBrightness) self.AddAction(NextProfile) self.AddAction(SetProfile) @@ -70,26 +69,6 @@ def __call__(self): self.plugin.lpack.turnOff() self.plugin.lpack.unlock() -class LowBrightness(eg.ActionBase): - - name = "Low brightness" - description = "Sets the brightness to 20%" - - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.setBrightness(20) - self.plugin.lpack.unlock() - -class MaxBrightness(eg.ActionBase): - - name = "Maximum brightness" - description = "Sets the brightness to 100%" - - def __call__(self): - self.plugin.lpack.lock() - self.plugin.lpack.setBrightness(100) - self.plugin.lpack.unlock() - class SetBrightness(eg.ActionBase): name = "Set brightness" From 2474d6bde99c548977fb35c93581e7589c9fa87b Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 14:47:19 -0500 Subject: [PATCH 25/32] Remove redundant 'for Eventghost' from plugin name --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 775d7b83..929d989c 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -2,7 +2,7 @@ import lightpack eg.RegisterPlugin( - name = "Prismatik for EventGhost", + name = "Prismatik", author = "Lucleonhart, 0xdefec, SaladFork", version = "1.0.1", kind = "external", From 9a084a775cde09970e6339906a752847263bfd38 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 14:49:00 -0500 Subject: [PATCH 26/32] Switch to building controls from the current panel instead of wx class --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 929d989c..eddb7efc 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -32,9 +32,9 @@ def Configure(self, host="127.0.0.1", port="3636", apikey=""): panel = eg.ConfigPanel() sizer = panel.sizer - txtHost = wx.TextCtrl(panel, -1, host, size=(250, -1)) - txtPort = wx.TextCtrl(panel, -1, port, size=(250, -1)) - txtApikey = wx.TextCtrl(panel, -1, apikey, size=(250, -1)) + txtHost = panel.TextCtrl(host, size=(250, -1)) + txtPort = panel.TextCtrl(port, size=(250, -1)) + txtApikey = panel.TextCtrl(apikey, size=(250, -1)) sizer.AddMany([ (panel.StaticText("Host: ")), @@ -83,7 +83,7 @@ def Configure(self, brightness="100"): panel = eg.ConfigPanel() sizer = panel.sizer - txtBrightness = wx.TextCtrl(panel, -1, brightness, size=(250, -1)) + txtBrightness = panel.TextCtrl(brightness, size=(250, -1)) sizer.Add(panel.StaticText("Brightness (%): ")) sizer.Add(txtBrightness) @@ -129,7 +129,7 @@ def Configure(self, profile="Lightpack"): panel = eg.ConfigPanel() sizer = panel.sizer - cmbProfiles = wx.ComboBox(panel, -1, profile, choices=profiles, size=(250, -1)) + cmbProfiles = panel.ComboBox(profile, choices=profiles, size=(250, -1)) sizer.Add(panel.StaticText("Profile: ")) sizer.Add(cmbProfiles) From 71e8b92cd5d231b21cda8bf43b17736a8b5a597f Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 15:34:47 -0500 Subject: [PATCH 27/32] Add SetColor and SetColorToAll actions --- .../EventGhost/Prismatik/__init__.py | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index eddb7efc..4024e1e6 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -17,9 +17,14 @@ def __init__(self): self.AddAction(SetBrightness) self.AddAction(NextProfile) self.AddAction(SetProfile) + self.AddAction(SetColor) + self.AddAction(SetColorToAll) + + self.numLeds = 20 def __start__(self, host, port, apikey): - self.lpack = lightpack.lightpack(host, int(port), range(1, 20), apikey or None) + self.ledMap = range(1, self.numLeds + 1) + self.lpack = lightpack.lightpack(host, int(port), self.ledMap, apikey or None) self.lpack.connect() def __stop__(self): @@ -136,3 +141,58 @@ def Configure(self, profile="Lightpack"): while panel.Affirmed(): panel.SetResult(cmbProfiles.GetValue()) + +class SetColor(eg.ActionBase): + + name = "Set LED light color" + description = "Sets the color of a specific LED light" + + def __call__(self, n, r, g, b): + self.plugin.lpack.lock() + self.plugin.lpack.setColor(n, r, g, b) + self.plugin.lpack.unlock() + + def Configure(self, n=1, r=0, g=0, b=0): + panel = eg.ConfigPanel() + sizer = panel.sizer + + leds = [str(led) for led in range(1, self.plugin.numLeds + 1)] + + cmbLeds = panel.ComboBox(str(n), choices=leds, size=(75, -1)) + colorCtrl = wx.ColourPickerCtrl(panel, col=wx.Colour(r, g, b), size=wx.Size(75, -1)) + + sizer.AddMany([ + panel.StaticText("LED: "), + cmbLeds, + panel.StaticText("Color: "), + colorCtrl + ]) + + while panel.Affirmed(): + color = colorCtrl.GetColour() + panel.SetResult(cmbLeds.GetValue(), color[0], color[1], color[2]) + +class SetColorToAll(eg.ActionBase): + + name = "Set all LED lights color" + description = "Sets the color of all LED light" + + def __call__(self, r, g, b): + self.plugin.lpack.lock() + self.plugin.lpack.setColorToAll(r, g, b) + self.plugin.lpack.unlock() + + def Configure(self, r=0, g=0, b=0): + panel = eg.ConfigPanel() + sizer = panel.sizer + + colorCtrl = wx.ColourPickerCtrl(panel, col=wx.Colour(r, g, b), size=wx.Size(75, -1)) + + sizer.AddMany([ + panel.StaticText("Color: "), + colorCtrl + ]) + + while panel.Affirmed(): + color = colorCtrl.GetColour() + panel.SetResult(color[0], color[1], color[2]) From b4c0041037d8c847359f1dca816ffc2664138f33 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 15:36:31 -0500 Subject: [PATCH 28/32] Reorder actions slightly --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 4024e1e6..e6177a12 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -14,9 +14,9 @@ class Lightpack(eg.PluginBase): def __init__(self): self.AddAction(TurnOn) self.AddAction(TurnOff) - self.AddAction(SetBrightness) - self.AddAction(NextProfile) self.AddAction(SetProfile) + self.AddAction(NextProfile) + self.AddAction(SetBrightness) self.AddAction(SetColor) self.AddAction(SetColorToAll) From bb7cab2d37dcf5ca6650f1504e0a0456b4443d4d Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 15:36:53 -0500 Subject: [PATCH 29/32] Pluralize 'lights' in action description --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index e6177a12..ff9ea5c4 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -175,7 +175,7 @@ def Configure(self, n=1, r=0, g=0, b=0): class SetColorToAll(eg.ActionBase): name = "Set all LED lights color" - description = "Sets the color of all LED light" + description = "Sets the color of all LED lights" def __call__(self, r, g, b): self.plugin.lpack.lock() From c32079aa72e63772095e606d2220a9718f4c51af Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 15:58:11 -0500 Subject: [PATCH 30/32] Add SetSmooth and SetGamma actions --- .../EventGhost/Prismatik/__init__.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index ff9ea5c4..01fcc490 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -17,6 +17,8 @@ def __init__(self): self.AddAction(SetProfile) self.AddAction(NextProfile) self.AddAction(SetBrightness) + self.AddAction(SetSmooth) + self.AddAction(SetGamma) self.AddAction(SetColor) self.AddAction(SetColorToAll) @@ -96,6 +98,50 @@ def Configure(self, brightness="100"): while panel.Affirmed(): panel.SetResult(txtBrightness.GetValue()) +class SetSmooth(eg.ActionBase): + + name = "Set smoothness" + description = "Sets how many steps the LEDs will take to change color" + + def __call__(self, smoothness): + self.plugin.lpack.lock() + self.plugin.lpack.setSmooth(smoothness) + self.plugin.lpack.unlock() + + def Configure(self, smoothness="100"): + panel = eg.ConfigPanel() + sizer = panel.sizer + + spinSmoothness = wx.SpinCtrl(panel, value=smoothness, min=0, max=255, size=(100, -1)) + + sizer.Add(panel.StaticText("Smoothness: ")) + sizer.Add(spinSmoothness) + + while panel.Affirmed(): + panel.SetResult(spinSmoothness.GetValue()) + +class SetGamma(eg.ActionBase): + + name = "Set gamma correction" + description = "Sets the level of saturation of the LED lights" + + def __call__(self, gamma): + self.plugin.lpack.lock() + self.plugin.lpack.setGamma(gamma) + self.plugin.lpack.unlock() + + def Configure(self, gamma="2.00"): + panel = eg.ConfigPanel() + sizer = panel.sizer + + txtGamma = panel.TextCtrl(gamma, size=(150, -1)) + + sizer.Add(panel.StaticText("Gamma: ")) + sizer.Add(txtGamma) + + while panel.Affirmed(): + panel.SetResult(txtGamma.GetValue()) + class NextProfile(eg.ActionBase): name = "Next profile" From 3ccc44e4bbe931fed8cc2685186da861d914d6d0 Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 15:58:44 -0500 Subject: [PATCH 31/32] Send LED number as an integer to fix error --- Software/apiexamples/EventGhost/Prismatik/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/__init__.py b/Software/apiexamples/EventGhost/Prismatik/__init__.py index 01fcc490..cac23e1e 100755 --- a/Software/apiexamples/EventGhost/Prismatik/__init__.py +++ b/Software/apiexamples/EventGhost/Prismatik/__init__.py @@ -195,7 +195,7 @@ class SetColor(eg.ActionBase): def __call__(self, n, r, g, b): self.plugin.lpack.lock() - self.plugin.lpack.setColor(n, r, g, b) + self.plugin.lpack.setColor(int(n), r, g, b) self.plugin.lpack.unlock() def Configure(self, n=1, r=0, g=0, b=0): From fbd7d87c97f9bf314106ee0c924d57d76eeed07c Mon Sep 17 00:00:00 2001 From: Elad Shahar Date: Fri, 7 Mar 2014 16:04:59 -0500 Subject: [PATCH 32/32] Remove extra blank profile in getProfiles call --- Software/apiexamples/EventGhost/Prismatik/lightpack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/apiexamples/EventGhost/Prismatik/lightpack.py b/Software/apiexamples/EventGhost/Prismatik/lightpack.py index 5acff7dd..35c7d041 100755 --- a/Software/apiexamples/EventGhost/Prismatik/lightpack.py +++ b/Software/apiexamples/EventGhost/Prismatik/lightpack.py @@ -23,7 +23,7 @@ def getProfiles(self): cmd = 'getprofiles\n' self.connection.send(cmd) profiles = self.__readResult() - return profiles.split(':')[1].rstrip(';\n').split(';') + return profiles.split(':')[1].rstrip(';\n').split(';')[:-1] def getProfile(self): cmd = 'getprofile\n'