Permalink
Browse files

Code cleanup + corners testing

  • Loading branch information...
1 parent bd8bdb5 commit 707657e76a35e7209fe00fbcb4173f314081369e tociek committed Jul 22, 2015
View
@@ -1,48 +1,39 @@
import xbmc
import os
import sys
-
-
-
import xbmcaddon
import xbmcgui
import time
import subprocess
+
addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')
addon_dir = xbmc.translatePath( addon.getAddonInfo('path') )
-#xbmcgui.Dialog().ok(addonname, os.path.join( addon_dir, 'resources', 'lib' ))
sys.path.append(os.path.join( addon_dir, 'resources', 'lib' ) )
-try:
- import HyperPyCon
-except Exception, e:
- xbmcgui.Dialog().ok(addonname, repr(e)[50:])
+import HyperPyCon
line1 = "Welcome!"
-line2 = "We are about to prepare your hyperion config file in this step-by-step wizard..."
-line3 = "You must complete all steps to have the config file generated.... Lets start!"
+line2 = "We are about to prepare your hyperion config file in this step-by-step wizard."
+line3 = "You must complete all steps to have the config file generated. Let\'s start!"
+
+xbmcgui.Dialog().ok(addonname, line1, line2 + line3)
-zupa = xbmcgui.Dialog().ok(addonname, line1, line2 + line3)
-#if not zupa:
-# return
try:
if "spidev" not in subprocess.check_output(['ls','/dev']):
- xbmcgui.Dialog().ok(addonname, "We have detected that your system does not have spi enabled. You can still continue but leds may not work if you're using GPIO connection.")
-
-
+ xbmcgui.Dialog().ok(addonname, "We have detected that your system does not have spi enabled. You can still continue, but leds may not work if you're using GPIO/SPI connection."+
+ " For USB connection you are safe to proceed")
xbmcgui.Dialog().ok(addonname, "In next two steps please provovide number of leds at the top edge of tv (horizontally)" +
" and number of leds at the side of your tv (count leds at single side only) - horizontally")
-
nol_horizontal = xbmcgui.Dialog().input("Select number of leds horizontally","16",xbmcgui.INPUT_NUMERIC)
nol_vertical = xbmcgui.Dialog().input("Select number of leds vertically","9",xbmcgui.INPUT_NUMERIC)
-# xbmcgui.Dialog().ok(addonname,str(nol_horizontal),str(nol_vertical))
+
hyperion_configuration = HyperPyCon.HyperPyCon(int(nol_horizontal), int(nol_vertical))
options = ["Right bottom corner and goes up","Left bottom corner and goes up"]
selected_index = xbmcgui.Dialog().select("Select where the led chain starts:",options)
-
+
if options[selected_index] == "Left bottom corner and goes up":
hyperion_configuration.led_chain.reverse_direction()
hyperion_configuration.led_chain.set_offset(int(nol_horizontal))
@@ -70,11 +61,17 @@
if not xbmcgui.Dialog().yesno(addonname, "Have you seen the rainbow swirl?"):
xbmcgui.Dialog().ok(addonname, "Something went wrong... Please try running hyperion from command line to see the error...")
sys.exit()
-
+ else:
+ xbmcgui.Dialog().ok(addonname, "For the next 10 seconds you will see leds in 3 corners marked with different colors. Check if they are exactly in the corners."+
+ " If not, start this wizard again and provide correct numbers of leds horizontally and vertically.")
+ hyperion_configuration.test_corners(10)
+
if xbmcgui.Dialog().yesno(addonname, "Do you want us to save this config as your default one?","(if No, changes will be lost after hyperion/system restart)"):
hyperion_configuration.overwrite_default_config()
+ elif xbmcgui.Dialog().yesno(addonname, "Hyperion is now running with the newly created config. Would you like to restart hyperion with previous config?"):
+ hyperion_configuration.restart_hyperion("hyperion.config.json")
- xbmcgui.Dialog().ok(addonname, "[To be added] All hyperion settings are available in the settings of this addon. Enjoy!")
+ xbmcgui.Dialog().ok(addonname, "That\'s all Folks! :) . Enjoy!")
except Exception, e:
xbmcgui.Dialog().ok(addonname, repr(e))
View
@@ -7,13 +7,13 @@
<provides>executable</provides>
</extension>
<extension point="xbmc.addon.metadata">
- <platform>all</platform>
- <summary lang="en">Popup Hello World</summary>
- <description lang="en">Example Plugin to show hello world</description>
+ <platform>linux</platform>
+ <summary lang="en">Hyperion configuration wizard</summary>
+ <description lang="en">Easy to use wizard for vanilla users to create their hyperion config file easily.</description>
<license>GNU General Public License, v2</license>
<language></language>
- <forum>http://forum.kodi.tv/showthread.php?tid=209948</forum>
- <source>https://github.com/zag2me/plugin.program.hello.world</source>
- <email>zag@kodi.org</email>
+ <forum>https://github.com/LightberryEu/plugin.program.hyperion.configurator/issues</forum>
+ <source>https://github.com/LightberryEu/plugin.program.hyperion.configurator</source>
+ <email>jacek@lightberry.eu</email>
</extension>
</addon>
View
@@ -1 +1 @@
-1.0.0 Initial Release
+1.0.0 Initial Release
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -30,7 +30,9 @@ def __init__(self, nol_horizontal, nol_vertical):
self.jsonServer = HyperionConfigSections.json_serverd
self.protoServer = HyperionConfigSections.proto_serverd
self.grabber = HyperionConfigSections.GrabberV4l2()
-
+
+ self.tester = HyperionConfigTester.HyperionConfigTester(self.led_chain)
+
def create_config(self, add_grabber):
self.color.add_transformation(self.transform)
self.color.set_smoothing(self.smoothing)
@@ -46,10 +48,10 @@ def create_config(self, add_grabber):
jsonServer = self.jsonServer,
protoServer = self.protoServer,
endOfJson = 'endOfJson')
-
+
if add_grabber:
hyperion_config_dict.update(OrderedDict(grabber_v4l2 = HyperionConfigSections.GrabberV4l2().to_dict()))
-
+
return json.dumps(hyperion_config_dict,sort_keys=False,indent=4, separators=(',', ': ')).replace("grabber_v4l2","grabber-v4l2")
def save_config_file(self,content,folder,file_name):
@@ -63,8 +65,7 @@ def overwrite_default_config(self):
config_folder = "/storage/.config/"
else:
config_folder = "/etc/"
- raise "It is not OE"
- #return config_folder+"hyperion_config_json" + config_folder+"hyperion_config_json_bak"
+
shutil.copyfile(config_folder+"hyperion.config.json",config_folder+"hyperion.config.json_bak")
shutil.copyfile(self.config_file_path,config_folder+"hyperion.config.json")
@@ -75,10 +76,18 @@ def config_grabber(self,grabber_model):
self.grabber.height = 192
self.grabber.frame_decimation = 2
self.grabber.size_decimation = 20
-
+
def restart_hyperion(self,hyperion_config_file_name):
- HyperionConfigTester.HyperionConfigTester().restart_hyperion(hyperion_config_file_name)
+ self.tester.restart_hyperion(hyperion_config_file_name)
+ def test_corners(self,duration):
+ self.tester.connect_to_hyperion()
+ self.tester.mark_corners()
+ self.tester.change_colors()
+ time.sleep(duration)
+ self.tester.disconnect()
+
+
#h = HyperPyCon(23,23)
@@ -14,42 +14,41 @@ class Device:
output = "/dev/spidev0.0"
rate = 250000
color_order = "rgb"
-
+
def __init__(self):
self.name = "MyPi"
self.type = "ws2801"
self.output = "/dev/spidev0.0"
self.rate = 500000
self.color_order = "rgb"
-
+
def to_dict(self):
return OrderedDict(name = self.name, type = self.type, output = self.output, rate = self.rate, colorOrder = self.color_order)
-
+
class SingleColor:
threshold = 0.0700
gamma = 2.0000
blacklevel = 0.0000
whitelevel = 1.0000
-
+
def __init__(self,threshold,gamma,blacklevel,whitelevel):
self.threshold = threshold
self.gamma = gamma
self.blacklevel = blacklevel
self.whitelevel = whitelevel
-
+
def to_dict(self):
return OrderedDict(threshold = self.threshold, gamma = self.gamma, blacklevel = self.blacklevel, whitelevel = self.whitelevel)
-
-
+
class HSV:
saturation_gain = 1.0000
value_gain = 1.0000
-
+
def __init__(self,saturation_gain,value_gain):
self.saturation_gain = saturation_gain
self.value_gain = value_gain
-
+
def to_dict(self):
return OrderedDict(saturationGain = self.saturation_gain, valueGain = self.value_gain )
@@ -60,7 +59,7 @@ class Transform:
green = None
blue = None
hsv = None
-
+
def __init__(self,tranformation_id, leds_indexes_range, hsv, red, green, blue):
"""red,green,blue must be isntances of SingleColorParms"""
self.tranformation_id = tranformation_id
@@ -69,45 +68,45 @@ def __init__(self,tranformation_id, leds_indexes_range, hsv, red, green, blue):
self.green = green
self.blue = blue
self.hsv = hsv
-
+
def to_dict(self):
return OrderedDict(id = self.tranformation_id, leds = self.leds_indexes_range, hsv = self.hsv.to_dict(), red = self.red.to_dict(), green = self.green.to_dict(), blue = self.blue.to_dict())
-
+
class Smoothing:
type = 'linear'
time_ms = 100
update_frequency = 20.0000
-
+
def __init__(self,type,time_ms,update_frequency):
self.type = type
self.time_ms = time_ms
self.update_frequency = update_frequency
-
+
def to_dict(self):
return OrderedDict(type = self.type,time_ms = self.time_ms,updateFrequency = self.update_frequency)
-
+
class Color:
transformations = []
smoothing = None
-
+
def __init__(self):
self.transformations = []
pass
-
+
def add_transformation(self, transformation):
self.transformations.append(transformation.to_dict())
-
+
def set_smoothing(self, smoothing):
self.smoothing = smoothing
-
+
def to_dict(self):
return OrderedDict(transform = self.transformations,smoothing = self.smoothing.to_dict())
class BootSequence:
def __init__(self):
self.effect = "Rainbow swirl fast"
self.duration_ms = 1000
-
+
def to_dict(self):
return OrderedDict(effect = self.effect, duration_ms = self.duration_ms)
@@ -121,7 +120,7 @@ def __init__(self):
self.grab_menu = False
self.grab_screensaver = True
self.enable_3D_detection = True
-
+
def to_dict(self):
return dict(xbmcAddress = self.xbmc_address, xbmcTcpPort = self.xbmc_tcp_port, grabVideo = self.grab_video, grabPictures = self.grab_pictures,
grabAudio = self.grab_audio, grabMenu = self.grab_menu, grabScreensaver = self.grab_screensaver, enable3DDetection = self.enable_3D_detection)
@@ -144,7 +143,7 @@ def __init__(self):
self.red_signal_threshold = 0.2
self.green_signal_threshold = 0.2
self.blue_signal_threshold = 0.2
-
+
def to_dict(self):
return OrderedDict(
device = self.device,
@@ -166,8 +165,6 @@ def to_dict(self):
)
-
-
@@ -12,36 +12,29 @@ def __init__(self, chain = None):
if os.uname()[1] == "OpenELEC":
self.hyperion_path = "/storage/hyperion/bin/hyperiond.sh"
self.config_folder = "/storage/.config/"
- else: #not test
+ else: #not tested
self.hyperion_path = "hyperiond"
self.config_folder = "/etc/"
def restart_hyperion(self,config_file_name):
subprocess.call(["killall", "hyperiond"])
subprocess.Popen([self.hyperion_path, self.config_folder+config_file_name])
- #hyperion.config.json_new"
- print "hyperion started"
-
+
def connect_to_hyperion(self):
"""Connects to local hyperion"""
self.connection = JsonClient('127.0.0.1', 19444, timeout=10)
self.connection.connect()
-
- #bytearray(number_of_leds*(0,0,0));
def mark_corners(self):
self.led_chain.leds[self.led_chain.nol_vertical].set_color(255,0,0)
self.led_chain.leds[self.led_chain.nol_vertical+self.led_chain.nol_horizontal].set_color(0,255,0)
self.led_chain.leds[(self.led_chain.nol_vertical*2)+self.led_chain.nol_horizontal].set_color(0,0,255)
-
+
def change_colors(self):
self.connection.send_led_data(self.led_chain.leds_to_bytearray())
-
+
def set_single_color(self, red, green, blue):
self.led_chain.set_single_color(red, green, blue)
-
+
def disconnect(self):
self.connection.disconnect()
-
-
-
Oops, something went wrong.

0 comments on commit 707657e

Please sign in to comment.