-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddon.py
103 lines (77 loc) · 3.4 KB
/
addon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
import xbmc
import xbmcaddon
from PIL import Image
from resources.lib.mote import Mote
from settings import Settings, Direction
NUM_PIXEL = 16
WIDTH, HEIGHT = 32, 32
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()
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__()
self.settings = Settings(mote=mote)
def onSettingsChanged(self):
self.settings.readSettings()
clear_mote()
def main(self):
channels = self.settings.get_channels()
while not self.abortRequested():
if self.waitForAbort(0.6):
break
if self.settings.get_mode() == 0:
if self.settings.get_color() == 0:
clear_mote()
for pixel in range(NUM_PIXEL):
set_static_color(channels, pixel, self.settings.get_color(), self.settings.get_brightness())
elif self.settings.get_mode() == 1:
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()
else:
image = Image.frombytes("RGBA", (WIDTH, HEIGHT), bytes(pixels), "raw", "BGRA")
for k, v in channels.items():
channel = k
invert = v["invert"]
inv_index = 0
if invert:
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:
pixel = image.getpixel((0, start))
elif direction == Direction.LEFT:
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
mote.show()
clear_mote()
if __name__ == '__main__':
server = BiasLightingMonitor()
server.main()