2020-07-05 14:00:09 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
|
|
|
from PIL import Image
|
|
|
|
from resources.lib.mote import Mote
|
2022-05-02 22:00:44 +02:00
|
|
|
from settings import Settings, Direction
|
2020-07-05 14:00:09 +02:00
|
|
|
|
|
|
|
NUM_PIXEL = 16
|
|
|
|
|
2022-05-02 22:00:44 +02:00
|
|
|
WIDTH, HEIGHT = 32, 32
|
2020-07-05 14:00:09 +02:00
|
|
|
|
|
|
|
mote = Mote()
|
|
|
|
|
|
|
|
mote.configure_channel(1, NUM_PIXEL, True)
|
|
|
|
mote.configure_channel(2, NUM_PIXEL, True)
|
|
|
|
mote.configure_channel(3, NUM_PIXEL, True)
|
|
|
|
mote.configure_channel(4, NUM_PIXEL, True)
|
|
|
|
|
|
|
|
mote.set_clear_on_exit()
|
|
|
|
|
|
|
|
|
|
|
|
def clear_mote():
|
|
|
|
mote.clear()
|
|
|
|
mote.show()
|
|
|
|
|
|
|
|
|
2022-05-02 22:00:44 +02:00
|
|
|
def set_static_color(channels, index, color, brightness=None):
|
|
|
|
for k, v in channels.items():
|
|
|
|
mote.set_pixel(k, index, color.red, color.green, color.blue, brightness)
|
|
|
|
|
|
|
|
|
|
|
|
class BiasLightingMonitor(xbmc.Monitor):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(BiasLightingMonitor, self).__init__()
|
2022-05-03 18:52:41 +02:00
|
|
|
self.settings = Settings(mote=mote)
|
2022-05-02 22:00:44 +02:00
|
|
|
|
|
|
|
def onSettingsChanged(self):
|
|
|
|
self.settings.readSettings()
|
|
|
|
clear_mote()
|
|
|
|
|
|
|
|
def main(self):
|
|
|
|
channels = self.settings.get_channels()
|
2022-05-03 18:52:41 +02:00
|
|
|
while not self.abortRequested():
|
|
|
|
if self.waitForAbort(0.6):
|
|
|
|
break
|
|
|
|
|
|
|
|
if self.settings.get_mode() == 0:
|
|
|
|
if self.settings.get_color() == 0:
|
|
|
|
clear_mote()
|
2022-05-03 20:45:44 +02:00
|
|
|
for pixel in range(NUM_PIXEL):
|
|
|
|
set_static_color(channels, pixel, self.settings.get_color(), self.settings.get_brightness())
|
2022-05-03 18:52:41 +02:00
|
|
|
elif self.settings.get_mode() == 1:
|
2022-05-02 22:00:44 +02:00
|
|
|
capture = xbmc.RenderCapture()
|
|
|
|
capture.capture(WIDTH, HEIGHT)
|
|
|
|
pixels = capture.getImage(1000)
|
|
|
|
|
|
|
|
if not pixels:
|
|
|
|
if self.settings.get_color() == 0:
|
|
|
|
clear_mote()
|
|
|
|
else:
|
|
|
|
for pixel in range(NUM_PIXEL):
|
|
|
|
set_static_color(channels, pixel, self.settings.get_color(), self.settings.get_brightness())
|
|
|
|
mote.show()
|
2020-07-05 14:00:09 +02:00
|
|
|
else:
|
2022-05-02 22:00:44 +02:00
|
|
|
image = Image.frombytes("RGBA", (WIDTH, HEIGHT), bytes(pixels), "raw", "BGRA")
|
|
|
|
|
|
|
|
for k, v in channels.items():
|
|
|
|
channel = k
|
|
|
|
|
|
|
|
invert = v["invert"]
|
2022-05-03 18:52:41 +02:00
|
|
|
|
2022-05-02 22:00:44 +02:00
|
|
|
inv_index = 0
|
2022-05-03 18:52:41 +02:00
|
|
|
|
|
|
|
if invert:
|
2022-05-02 22:00:44 +02:00
|
|
|
inv_index = 15
|
|
|
|
|
|
|
|
direction = v["direction"]
|
|
|
|
start = v["start"]
|
|
|
|
stop = v["stop"]
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
while start < stop:
|
|
|
|
if direction == Direction.TOP:
|
|
|
|
pixel = image.getpixel((start, 0))
|
|
|
|
elif direction == Direction.RIGHT:
|
2022-05-03 18:52:41 +02:00
|
|
|
pixel = image.getpixel((0, start))
|
|
|
|
elif direction == Direction.LEFT:
|
2022-05-02 22:00:44 +02:00
|
|
|
pixel = image.getpixel((WIDTH - 1, start))
|
|
|
|
elif direction == Direction.BOTTOM:
|
|
|
|
pixel = image.getpixel((start, HEIGHT - 1))
|
|
|
|
|
|
|
|
mote.set_pixel(channel, abs(index - inv_index), pixel[0], pixel[1], pixel[2], self.settings.get_brightness())
|
|
|
|
start += 1
|
|
|
|
index += 1
|
2022-05-03 18:52:41 +02:00
|
|
|
mote.show()
|
|
|
|
clear_mote()
|
2020-07-05 14:00:09 +02:00
|
|
|
|
|
|
|
|
2022-05-02 22:00:44 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
server = BiasLightingMonitor()
|
|
|
|
server.main()
|