Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ba33d03
Add new author name
SaladFork Feb 12, 2014
1e891d0
Switch to unix line endings
SaladFork Feb 12, 2014
e8620dc
Correct EventGhost name in plugin name
SaladFork Feb 12, 2014
95d2d6d
Switch to using start/stop for connecting and disconnecting
SaladFork Feb 12, 2014
52065b1
Switch indentation to spaces
SaladFork Feb 12, 2014
d9e91bc
Allow user to configure connection settings
SaladFork Feb 12, 2014
72964b4
Bump version number
SaladFork Feb 12, 2014
385d3c6
Switch to using range built-in
SaladFork Mar 3, 2014
7367300
Make configurable text boxes wider
SaladFork Mar 3, 2014
e10bf73
Switch to using panel sizer's AddMany instead of using multiple Add c…
SaladFork Mar 3, 2014
b7fd85d
Remove unnecessary debug printing: EventGhost prints macros/events/ac…
SaladFork Mar 3, 2014
2cf6558
Remove toggle action: should use EventGhost enable/disable macros to …
SaladFork Mar 3, 2014
4b70e9c
Make grammar/capitalization in action names and descriptions more con…
SaladFork Mar 3, 2014
f59f3df
Add new action for switching to a specific profile
SaladFork Mar 3, 2014
df492a9
Switch indentation from tabs to spaces
SaladFork Mar 7, 2014
48bfe1c
Switch to using plugin variable instead of class variable
SaladFork Mar 7, 2014
eed4b48
Remove unnecessary semicolon
SaladFork Mar 7, 2014
4d51005
Switch to latest lightpack.py
SaladFork Mar 7, 2014
5da5e44
Fix error due to None default value
SaladFork Mar 7, 2014
51295c4
Correct minor wording differences
SaladFork Mar 7, 2014
390640f
Revert "Switch to using plugin variable instead of class variable"
SaladFork Mar 7, 2014
64e01e6
Remove unncessary call to getProfiles in SetBrightness
SaladFork Mar 7, 2014
a67503f
Switch keyword order for lightpack init to match new lightpack.py ver…
SaladFork Mar 7, 2014
e4818da
Remove Low/MaxBrightness and add SetBrightness
SaladFork Mar 7, 2014
2474d6b
Remove redundant 'for Eventghost' from plugin name
SaladFork Mar 7, 2014
9a084a7
Switch to building controls from the current panel instead of wx class
SaladFork Mar 7, 2014
71e8b92
Add SetColor and SetColorToAll actions
SaladFork Mar 7, 2014
b4c0041
Reorder actions slightly
SaladFork Mar 7, 2014
bb7cab2
Pluralize 'lights' in action description
SaladFork Mar 7, 2014
c32079a
Add SetSmooth and SetGamma actions
SaladFork Mar 7, 2014
3ccc44e
Send LED number as an integer to fix error
SaladFork Mar 7, 2014
fbd7d87
Remove extra blank profile in getProfiles call
SaladFork Mar 7, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
347 changes: 244 additions & 103 deletions Software/apiexamples/EventGhost/Prismatik/__init__.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,244 @@
import eg
import lightpack

eg.RegisterPlugin(
name = "Prismatik for Eventghost",
author = "Lucleonhart, 0xdefec",
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",
author = "Lucleonhart, 0xdefec, SaladFork",
version = "1.0.1",
kind = "external",
description = "Control the Lightpack's Prismatik software. Enable API Server in Prismatik's experimental settings."
)

class Lightpack(eg.PluginBase):

def __init__(self):
self.AddAction(TurnOn)
self.AddAction(TurnOff)
self.AddAction(SetProfile)
self.AddAction(NextProfile)
self.AddAction(SetBrightness)
self.AddAction(SetSmooth)
self.AddAction(SetGamma)
self.AddAction(SetColor)
self.AddAction(SetColorToAll)

self.numLeds = 20

def __start__(self, host, port, apikey):
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):
self.lpack.disconnect()

def __close__(self):
pass

def Configure(self, host="127.0.0.1", port="3636", apikey=""):
panel = eg.ConfigPanel()
sizer = panel.sizer

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: ")),
(txtHost),
(panel.StaticText("Port: ")),
(txtPort),
(panel.StaticText("API Key: ")),
(txtApikey)
])

while panel.Affirmed():
panel.SetResult(txtHost.GetValue(), txtPort.GetValue(), txtApikey.GetValue())


class TurnOn(eg.ActionBase):

name = "Turn on"
description = "Turns on the lights"

def __call__(self):
self.plugin.lpack.lock()
self.plugin.lpack.turnOn()
self.plugin.lpack.unlock()

class TurnOff(eg.ActionBase):

name = "Turn off"
description = "Turns off the Lights"

def __call__(self):
self.plugin.lpack.lock()
self.plugin.lpack.turnOff()
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"):
panel = eg.ConfigPanel()
sizer = panel.sizer

txtBrightness = panel.TextCtrl(brightness, size=(250, -1))

sizer.Add(panel.StaticText("Brightness (%): "))
sizer.Add(txtBrightness)

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"
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()

class SetProfile(eg.ActionBase):

name = "Set profile"
description = "Switches to a specific Prismatik 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 = panel.ComboBox(profile, choices=profiles, size=(250, -1))

sizer.Add(panel.StaticText("Profile: "))
sizer.Add(cmbProfiles)

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(int(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 lights"

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])
Loading