updated motes when settings are changed

master
Lars Hoogestraat 7 months ago
parent 35bb911bae
commit 673b862c19
  1. 46
      addon.py
  2. 2
      addon.xml
  3. 70
      settings.py

@ -12,8 +12,6 @@ WIDTH, HEIGHT = 32, 32
mote = Mote()
mote.clear()
mote.configure_channel(1, NUM_PIXEL, True)
mote.configure_channel(2, NUM_PIXEL, True)
mote.configure_channel(3, NUM_PIXEL, True)
@ -36,32 +34,27 @@ class BiasLightingMonitor(xbmc.Monitor):
def __init__(self):
super(BiasLightingMonitor, self).__init__()
self.settings = Settings()
self.settings = Settings(mote=mote)
def onSettingsChanged(self):
xbmc.log(msg="ao", level=xbmc.LOGINFO)
self.settings.readSettings()
clear_mote()
def onAbortRequested(self):
clear_mote()
def main(self):
channels = self.settings.get_channels()
if self.settings.get_mode() == 0:
if self.settings.get_color() == 0:
clear_mote()
for c in channels.items():
for pixel in range(NUM_PIXEL):
set_static_color(channels, pixel, self.settings.get_color(), self.settings.get_brightness())
mote.show()
elif self.settings.get_mode() == 1:
while not self.abortRequested():
if self.waitForAbort(0.6):
break
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 c in channels.items():
for pixel in range(NUM_PIXEL):
set_static_color(channels, pixel, self.settings.get_color(), self.settings.get_brightness())
mote.show()
elif self.settings.get_mode() == 1:
capture = xbmc.RenderCapture()
capture.capture(WIDTH, HEIGHT)
pixels = capture.getImage(1000)
@ -80,8 +73,10 @@ class BiasLightingMonitor(xbmc.Monitor):
channel = k
invert = v["invert"]
inv_index = 0
if invert == "true":
if invert:
inv_index = 15
direction = v["direction"]
@ -92,9 +87,9 @@ class BiasLightingMonitor(xbmc.Monitor):
while start < stop:
if direction == Direction.TOP:
pixel = image.getpixel((start, 0))
elif direction == Direction.LEFT:
pixel = image.getpixel((0, start))
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))
@ -102,7 +97,8 @@ class BiasLightingMonitor(xbmc.Monitor):
mote.set_pixel(channel, abs(index - inv_index), pixel[0], pixel[1], pixel[2], self.settings.get_brightness())
start += 1
index += 1
mote.show()
mote.show()
clear_mote()
if __name__ == '__main__':

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.service.biaslightmote" name="Bias lighting for Pimoroni Mote" version="0.1.0" provider-name="snafu">
<addon id="script.service.biaslightmote" name="Bias lighting for Pimoroni Mote" version="0.2.0" provider-name="snafu">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.pyserial"/>

@ -1,6 +1,7 @@
from enum import Enum
import xbmc
import xbmcaddon
import xbmc
from resources.lib.mote import Mote
class Direction(Enum):
@ -9,6 +10,7 @@ class Direction(Enum):
RIGHT = 3
BOTTOM = 4
class Position(Enum):
TOP_LEFT = (0, Direction.TOP, 0, 16)
TOP_MIDDLE = (1, Direction.TOP, 8, 24)
@ -46,8 +48,19 @@ class Color:
self.blue = blue
def set_mote_position(channel, mote_pos):
pos = None
for name, member in Position.__members__.items():
if member.position == mote_pos:
pos = member
channel.update({"direction": pos.direction, "start": pos.start, "stop": pos.end})
class Settings:
def __init__(self):
def __init__(self, mote):
self._mote = mote
self.colors = []
self.colors.append(Color(0, 0, 0))
self.colors.append(Color(255, 0, 0))
@ -88,21 +101,21 @@ class Settings:
return self._brightness
def readSettings(self):
self._mote1 = settings.getSetting("mote1")
self._mote1 = settings.getSetting("mote1") == 'true'
self._mote1_pos = int(settings.getSetting("mote1_position"))
self._mote1_inv = settings.getSetting("mote1_invert")
self._mote1_inv = settings.getSetting("mote1_invert") == 'true'
self._mote2 = settings.getSetting("mote2")
self._mote2 = settings.getSetting("mote2") == 'true'
self._mote2_pos = int(settings.getSetting("mote2_position"))
self._mote2_inv = settings.getSetting("mote2_invert")
self._mote2_inv = settings.getSetting("mote2_invert") == 'true'
self._mote3 = settings.getSetting("mote3")
self._mote3 = settings.getSetting("mote3") == 'true'
self._mote3_pos = int(settings.getSetting("mote3_position"))
self._mote3_inv = settings.getSetting("mote3_invert")
self._mote3_inv = settings.getSetting("mote3_invert") == 'true'
self._mote4 = settings.getSetting("mote4")
self._mote4 = settings.getSetting("mote4") == 'true'
self._mote4_pos = int(settings.getSetting("mote4_position"))
self._mote4_inv = settings.getSetting("mote4_invert")
self._mote4_inv = settings.getSetting("mote4_invert") == 'true'
self._mode = int(settings.getSetting("mode"))
_color = int(settings.getSetting("color"))
@ -121,31 +134,34 @@ class Settings:
self.set_motes_channels()
def set_motes_channels(self):
if self._mote1 == "true":
if self._mote1:
self._channels.update({1: {"invert": self._mote1_inv}})
channel1 = self._channels.get(1)
self.set_mote_position(channel1, self._mote1_pos)
set_mote_position(channel1, self._mote1_pos)
else:
self._channels.pop(1, None)
self._mote.clear(1)
if self._mote2 == "true":
if self._mote2:
self._channels.update({2: {"invert": self._mote2_inv}})
channel2 = self._channels.get(2)
self.set_mote_position(channel2, self._mote2_pos)
set_mote_position(channel2, self._mote2_pos)
else:
self._channels.pop(2, None)
self._mote.clear(2)
if self._mote3 == "true":
if self._mote3:
self._channels.update({3: {"invert": self._mote3_inv}})
channel3 = self._channels.get(3)
self.set_mote_position(channel3, self._mote3_pos)
set_mote_position(channel3, self._mote3_pos)
else:
self._channels.pop(3, None)
self._mote.clear(3)
if self._mote4 == "true":
if self._mote4:
self._channels.update({4: {"invert": self._mote4_inv}})
channel4 = self._channels.get(4)
self.set_mote_position(channel4, self._mote4_pos)
def set_mote_position(self, channel, mote_pos):
pos = None
for name, member in Position.__members__.items():
if member.position == mote_pos:
pos = member
channel.update({"direction": pos.direction, "start": pos.start, "stop": pos.end})
set_mote_position(channel4, self._mote4_pos)
else:
self._channels.pop(4, None)
self._mote.clear(4)

Loading…
Cancel
Save