def __init__(self, lpackHost, lpackPort, ledMap, oscHost, oscPort): """ установка начальных значений, создание OSC-сервера, назначение обработчиков, инициализация lightpack lpackHost, lpackPort - IP и порт хоста с Лайтпаком ledMap - массив для переопределения порядка светодиодов Лайтпака oscHost, oscPort - IP и порт на котором будет запущен OSC-сервер """ self.r = 127 self.g = 127 self.b = 127 self.smooth = 127 self.brightness = 0.5 self.ledMap = [[3,2,1],[4,-1,10],[5,-1,9],[6,7,8]] self.enabledLeds = Set([1,2,3,4,5,6,7,8,9,10]) self.gamma = 2 self.lpack = lightpack.lightpack(lpackHost, lpackPort, ledMap) self.lpack.connect() self.oscServer = OSC.ThreadingOSCServer((oscHost, oscPort)) self.oscServer.addDefaultHandlers() self.oscClient = OSC.OSCClient() self.profiles = self.lpack.getProfiles() self.currentProfileIndex = 0 self.mapControls() print "Registered Callback-functions are :" for addr in self.oscServer.getOSCAddressSpace(): print addr
def __init__(self, settings): self.settings = settings self.ambilight = lightpack.lightpack(settings.host, settings.port, None, settings.api_key) self.initial_on = False self.__last_blink = time.time()
def ConnectToLightpack(self): try: self.host = self.config.get('Lightpack', 'host') self.port = self.config.getint('Lightpack', 'port') self.lpack = lightpack.lightpack(self.host, self.port) self.lpack.connect() return True except: return False
def LightpackConnect(): remote_ip = Prefs['prismatik_ip'] remote_port = Prefs['prismatik_port'] lpack = lightpack.lightpack(remote_ip,int(remote_port),[1,2,3,4,5,6,7,8,9,10], " ") out=lpack.connect() if ( out == -1 ): raise Exception('Connection Error') else: lpack.lock() return lpack
def _connect_to_lightpack(self): try: lightpack_host = self.config.get('Lightpack', 'host') lightpack_port = self.config.getint('Lightpack', 'port') lightpack_api_key = self.config.get('Lightpack', 'key') self.lp = lightpack.lightpack(lightpack_host, lightpack_port, None, lightpack_api_key) if self.lp.connect() == -1: self._report_error('Lightpack API server is missing') except lightpack.CannotConnectError as e: self._report_error(e)
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()
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()
def ResetPreferences(self): config = ConfigParser.ConfigParser() if os.path.isfile(self.scriptDir + '/DirectLight.ini'): self.serverType = PRISMATIK config.read(self.scriptDir + '/DirectLight.ini') else: self.serverType = AMBIBOX config.read(sys.path[-1] + '/DirectLight.ini') print 'serverType: ' + str(self.serverType) self.host = config.get('Lightpack', 'host') self.port = config.getint('Lightpack', 'port') self.lpack = lightpack.lightpack(self.host, self.port) #default capture values self.videoX = config.getint('Capture', 'videoWidth') self.videoY = config.getint('Capture', 'videoHeight') self.videoFps = config.getfloat('Capture', 'videoFramerate') self.videoDevice = config.getint('Capture', 'videoDevice') self.videoDeviceName = config.get('Capture', 'videoDeviceName') self.videoRenderX = config.getint('Render', 'renderWidth') self.videoRenderY = config.getint('Render', 'renderHeight') if self.serverType == PRISMATIK: self.screenX = config.getint('Display', 'displayWidth') self.screenY = config.getint('Display', 'displayHeight') else: self.screenX = 10000 self.screenY = 10000 self.cropTop = config.getint('Cropping', 'cropTop') self.cropBottom = config.getint('Cropping', 'cropBottom') self.cropLeft = config.getint('Cropping', 'cropLeft') self.cropRight = config.getint('Cropping', 'cropRight') tempServerType = config.get('Switches', 'serverType') self.serverType = AMBIBOX if tempServerType.strip( ) == 'ambibox' else PRISMATIK self.useFfmpeg = config.getboolean('Switches', 'useFfmpeg') self.labColorspace = config.getboolean('Switches', 'labColorspace') self.enableStandby = config.getboolean('Switches', 'enableStandby') self.standbyTimeoutSeconds = config.getint('Switches', 'standbyTimeoutSeconds') self.standby = False
import lightpack, time lpack = lightpack.lightpack('127.0.0.1', 3636, [2,3,6,7,1,1,1,4,5,1] ) lpack.connect() print("Lock: %s" % lpack.lock()) print("turnOn: %s" % lpack.turnOn()) print("LED map: %s" % lpack.getLeds()) num = int(lpack.getCountLeds()) print("Num leds: %s" % num) print("Status: %s" % lpack.getStatus()) print("Profile: %s" % lpack.getProfile()) print("Profiles: %s" % lpack.getProfiles()) print("getAPIStatus: %s" % lpack.getAPIStatus()) for i in range(1, num+1): print("setColor%d: %s" % (i, lpack.setColor(i, 255, 0, 0))) time.sleep(0.1) time.sleep(1) print("setColorToAll: %s" % lpack.setColorToAll(127, 127, 127)) time.sleep(1) print("setColorToAll: %s" % lpack.setColorToAll(0, 0, 0)) print("turnOff: %s" % lpack.turnOff()); lpack.disconnect()
# Modules General import os, lightpack from sys import argv # Modules XBMC import xbmc, xbmcgui, xbmcaddon __settings__ = xbmcaddon.Addon("script.lightpack") __language__ = __settings__.getLocalizedString lphost = __settings__.getSetting("host") lpport = int(__settings__.getSetting("port")) lpapikey = __settings__.getSetting("apikey") lpack = lightpack.lightpack(lphost, lpport, lpapikey, range(1, 11)) lpack.connect() profiles = lpack.getProfiles() del profiles[-1] profiles.append(__language__(32071)) off = len(profiles)-1 last_profile = __settings__.getSetting("last_profile") if last_profile == "": last_profile_index = -1 else: last_profile_index = profiles.index(last_profile) next_profile_index = last_profile_index + 1 if next_profile_index > len(profiles)-1: next_profile_index = 0
if len(sys.argv) > 1 : delay = float(sys.argv[1]) print ("Set delay: {0} (input:{1})".format(delay, sys.argv[1])) print ('') if len(sys.argv) > 2 : brightness = float(sys.argv[2]) print ("Set brightness: {0} (input:{1})".format(brightness, sys.argv[2])) print ('') print ('Delay {0} sec.'.format(delay)) print ('Brightness {0}%.'.format(brightness*100)) color = int(255 * brightness) lpack = lightpack.lightpack('127.0.0.1', 3636, [5,4,3,1,2,6,7,8,9,10]) lpack.connect() lpack.lock() lpack.turnOn() lpack.setSmooth(0) # simple testing procedure while True : print ('1. set all LEDs BLACK.') lpack.setColorToAll(0, 0, 0) time.sleep(delay) print ('2. set all LEDs WHITE.') lpack.setColorToAll(255, 255, 255) time.sleep(delay) print ('3. set all LEDs RED.') lpack.setColorToAll(255,0,0)
import lightpack, time, imaplib, re, getpass def gmail_checker(username,password): import imaplib,re i=imaplib.IMAP4_SSL('imap.gmail.com') try: i.login(username,password) x,y=i.status('INBOX','(MESSAGES UNSEEN)') messages=int(re.search('MESSAGES\s+(\d+)',y[0]).group(1)) unseen=int(re.search('UNSEEN\s+(\d+)',y[0]).group(1)) return (messages,unseen) except: return False,0 lpack = lightpack.lightpack('127.0.0.1', 3636, [2,3,6,7,8,9,10,4,5,1], 'mySecureAPIkey') lpack.connect() mail = raw_input('Gmail: ') passwd = getpass.getpass('password: '******' @ ' + time.ctime() if unseen > 0 : lpack.lock() lpack.setColorToAll(0,0,0) time.sleep(2) lpack.setSmooth(8) i = 1 while i < 80 : i = i+1 for k in range (0, 10) :
import lightpack, time, pygame, random # CONNECT TO LOCALHOST lpack = lightpack.lightpack('127.0.0.1', 3636, [2,3,6,7,1,1,1,4,5,1] ) lpack.connect() print("Lock: %s" % lpack.lock()) print("turnOn: %s" % lpack.turnOn()) print("LED map: %s" % lpack.getLeds()) # COUNT NUMBER OF LEDs to control num = int(lpack.getCountLeds()) print("Num leds: %s" % num) print("Status: %s" % lpack.getStatus()) print("Profile: %s" % lpack.getProfile()) print("Profiles: %s" % lpack.getProfiles()) print("getAPIStatus: %s" % lpack.getAPIStatus()) # INITIALIZE LED POSITIONS FOR EACH BIRD # create alltogether function def alltogether(time_diff): lpack.setSmooth(10) # Tiny Cylone lpack.setColorToAll(0,0,0) left = [10, 9, 8, 10] top = [7,6,5,4,7] right = [3,2,1,3] lpack.setSmooth(45)
from xml.dom import minidom from xml.dom import EMPTY_NAMESPACE try: import json except ImportError: import simplejson as json import lightpack import time import urllib import urllib2 username = '******' password = '******' lpack = lightpack.lightpack('127.0.0.1', 3636, [2,3,6,7,8,9,10,4,5,1] ) lpack.connect() # Authenticate to obtain Auth auth_url = 'https://www.google.com/accounts/ClientLogin' auth_req_data = urllib.urlencode({ 'Email': username, 'Passwd': password, 'service': 'reader' }) auth_req = urllib2.Request(auth_url, data=auth_req_data) auth_resp = urllib2.urlopen(auth_req) auth_resp_content = auth_resp.read() auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x) AUTH = auth_resp_dict["Auth"] # Create a cookie in the header using the Auth header = {'Authorization': 'GoogleLogin auth=%s' % AUTH}
notification(__language__(32081)) lpack.turnOff() elif enable == 'true': notification(__language__(32082) % profile) lpack.turnOn() lpack.setProfile(profile) else: notification(__language__(32081)) lpack.turnOff() print "service Lightpack" notification(__language__(32080)) print "service Lightpack connect" lpack = lightpack.lightpack(lphost, lpport, lpapikey, range(1, 11)) if lpack.connect() == 0 and lpapikey: oldstatus = -1 while not xbmc.abortRequested: newstatus = 0 player = xbmc.Player() audioIsPlaying = player.isPlayingAudio() videoIsPlaying = player.isPlayingVideo() if videoIsPlaying: newstatus = 1 if audioIsPlaying: newstatus = 2 if oldstatus != newstatus: oldstatus = newstatus lpack.lock()
if len(sys.argv) > 1: delay = float(sys.argv[1]) print("Set delay: {0} (input:{1})".format(delay, sys.argv[1])) print('') if len(sys.argv) > 2: brightness = float(sys.argv[2]) print("Set brightness: {0} (input:{1})".format(brightness, sys.argv[2])) print('') print('Delay {0} sec.'.format(delay)) print('Brightness {0}%.'.format(brightness * 100)) color = int(255 * brightness) lpack = lightpack.lightpack('127.0.0.1', 3636, [5, 4, 3, 1, 2, 6, 7, 8, 9, 10]) lpack.connect() lpack.lock() lpack.turnOn() lpack.setSmooth(0) # simple testing procedure while True: print('1. set all LEDs BLACK.') lpack.setColorToAll(0, 0, 0) time.sleep(delay) print('2. set all LEDs WHITE.') lpack.setColorToAll(255, 255, 255) time.sleep(delay) print('3. set all LEDs RED.') lpack.setColorToAll(255, 0, 0)
#Skype contact waiting script. It flashes Lightpack when target buddy in contact list are changed his online status. #You need Skype4Py module and lightpack.py class for using it. import Skype4Py, lightpack, time, sys skype = Skype4Py.Skype() # Create an instance of the Skype class lpack = lightpack.lightpack('127.0.0.1', 3636, [2, 3, 6, 7, 8, 9, 10, 4, 5, 1]) skype.Attach() # Connect the Skype object to the Skype client targetstat = ['ONLINE', 'DND', 'SKYPEME'] # Array of target user statuses lpack.connect() contact = raw_input('Input Skype username for waiting: ' ) # Skype username which we waiting for while True: if skype.User( contact ).OnlineStatus in targetstat: # If current buddy online status in targetstat array turn animation on print skype.User(contact).FullName + ' is ' + skype.User( contact).OnlineStatus + ' @ ' + time.ctime() lpack.lock() lpack.setSmooth(100) lpack.setColorToAll(0, 0, 0) time.sleep(0.3) for k in range(0, 5): lpack.setColorToAll(0, 255, 0) time.sleep(1) lpack.setColorToAll(0, 0, 0) time.sleep(1) lpack.unlock() else:
import lightpack, math, time, re, random lpack = lightpack.lightpack('127.0.0.1', 3636, range(1,11) ) lpack.connect() lpack.lock() leds = 10 # beats per minute bpm = 120 lpack.lock() while True : bpm_time = 60.0 / bpm bpm_wait = bpm_time - 0.05 for k in range (0, leds): lpack.setColor(k+1, 255, 255, 255) time.sleep(0.05) for k in range (0, leds): lpack.setColor(k+1, 0, 0, 0) time.sleep(bpm_time) bpm = bpm + 1 lpack.unlock()
# # Configuration of zones placement for ultrawide # @2560x1080 import lightpack import time import ctypes user32 = ctypes.windll.user32 lpack = lightpack.lightpack('127.0.0.1', 3636, list(range(50)),'{c2ef0ccd-dd8a-4e25-8ab3-8d17ce25b20c}' ) print("Width =", user32.GetSystemMetrics(0)) print("Height =", user32.GetSystemMetrics(1)) def setleds(totleds,ledsx,ledsy,screenWidth,screenHeigth,xMargin,yMargin,sidesWidth,topBotHeigth): maxwidth=user32.GetSystemMetrics(0) maxheight=user32.GetSystemMetrics(1) lpack.connect() print("Lock: %s" % lpack.lock()) # sets de x # print(maxwidth,maxwidth-xMargin*2,round((maxwidth-xMargin*2)/ledsx)) # print(maxheight,ledsy,round((maxheight-yMargin*2)/ledsy)) xWidth=round((maxwidth-xMargin*2)/ledsx) arr=[None] * totleds x,y=0+xMargin,screenHeigth w,h=xWidth,topBotHeigth # set xleds- 1 al 9