Skip to content

Commit 707657e

Browse files
author
tociek
committed
Code cleanup + corners testing
1 parent bd8bdb5 commit 707657e

File tree

8 files changed

+92
-101
lines changed

8 files changed

+92
-101
lines changed

addon.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
11
import xbmc
22
import os
33
import sys
4-
5-
6-
74
import xbmcaddon
85
import xbmcgui
96
import time
107
import subprocess
8+
119
addon = xbmcaddon.Addon()
1210
addonname = addon.getAddonInfo('name')
1311
addon_dir = xbmc.translatePath( addon.getAddonInfo('path') )
14-
#xbmcgui.Dialog().ok(addonname, os.path.join( addon_dir, 'resources', 'lib' ))
1512
sys.path.append(os.path.join( addon_dir, 'resources', 'lib' ) )
16-
try:
17-
import HyperPyCon
18-
except Exception, e:
19-
xbmcgui.Dialog().ok(addonname, repr(e)[50:])
13+
import HyperPyCon
2014

2115
line1 = "Welcome!"
22-
line2 = "We are about to prepare your hyperion config file in this step-by-step wizard..."
23-
line3 = "You must complete all steps to have the config file generated.... Lets start!"
16+
line2 = "We are about to prepare your hyperion config file in this step-by-step wizard."
17+
line3 = "You must complete all steps to have the config file generated. Let\'s start!"
18+
19+
xbmcgui.Dialog().ok(addonname, line1, line2 + line3)
2420

25-
zupa = xbmcgui.Dialog().ok(addonname, line1, line2 + line3)
26-
#if not zupa:
27-
# return
2821
try:
2922
if "spidev" not in subprocess.check_output(['ls','/dev']):
30-
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.")
31-
32-
23+
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."+
24+
" For USB connection you are safe to proceed")
3325

3426
xbmcgui.Dialog().ok(addonname, "In next two steps please provovide number of leds at the top edge of tv (horizontally)" +
3527
" and number of leds at the side of your tv (count leds at single side only) - horizontally")
3628

37-
3829
nol_horizontal = xbmcgui.Dialog().input("Select number of leds horizontally","16",xbmcgui.INPUT_NUMERIC)
3930
nol_vertical = xbmcgui.Dialog().input("Select number of leds vertically","9",xbmcgui.INPUT_NUMERIC)
40-
# xbmcgui.Dialog().ok(addonname,str(nol_horizontal),str(nol_vertical))
31+
4132
hyperion_configuration = HyperPyCon.HyperPyCon(int(nol_horizontal), int(nol_vertical))
4233

4334
options = ["Right bottom corner and goes up","Left bottom corner and goes up"]
4435
selected_index = xbmcgui.Dialog().select("Select where the led chain starts:",options)
45-
36+
4637
if options[selected_index] == "Left bottom corner and goes up":
4738
hyperion_configuration.led_chain.reverse_direction()
4839
hyperion_configuration.led_chain.set_offset(int(nol_horizontal))
@@ -70,11 +61,17 @@
7061
if not xbmcgui.Dialog().yesno(addonname, "Have you seen the rainbow swirl?"):
7162
xbmcgui.Dialog().ok(addonname, "Something went wrong... Please try running hyperion from command line to see the error...")
7263
sys.exit()
73-
64+
else:
65+
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."+
66+
" If not, start this wizard again and provide correct numbers of leds horizontally and vertically.")
67+
hyperion_configuration.test_corners(10)
68+
7469
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)"):
7570
hyperion_configuration.overwrite_default_config()
71+
elif xbmcgui.Dialog().yesno(addonname, "Hyperion is now running with the newly created config. Would you like to restart hyperion with previous config?"):
72+
hyperion_configuration.restart_hyperion("hyperion.config.json")
7673

77-
xbmcgui.Dialog().ok(addonname, "[To be added] All hyperion settings are available in the settings of this addon. Enjoy!")
74+
xbmcgui.Dialog().ok(addonname, "That\'s all Folks! :) . Enjoy!")
7875

7976
except Exception, e:
8077
xbmcgui.Dialog().ok(addonname, repr(e))

addon.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<provides>executable</provides>
88
</extension>
99
<extension point="xbmc.addon.metadata">
10-
<platform>all</platform>
11-
<summary lang="en">Popup Hello World</summary>
12-
<description lang="en">Example Plugin to show hello world</description>
10+
<platform>linux</platform>
11+
<summary lang="en">Hyperion configuration wizard</summary>
12+
<description lang="en">Easy to use wizard for vanilla users to create their hyperion config file easily.</description>
1313
<license>GNU General Public License, v2</license>
1414
<language></language>
15-
<forum>http://forum.kodi.tv/showthread.php?tid=209948</forum>
16-
<source>https://github.com/zag2me/plugin.program.hello.world</source>
17-
<email>zag@kodi.org</email>
15+
<forum>https://github.com/LightberryEu/plugin.program.hyperion.configurator/issues</forum>
16+
<source>https://github.com/LightberryEu/plugin.program.hyperion.configurator</source>
17+
<email>jacek@lightberry.eu</email>
1818
</extension>
1919
</addon>

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0 Initial Release
1+
1.0.0 Initial Release

icon.png

5 KB
Loading

resources/lib/HyperPyCon.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def __init__(self, nol_horizontal, nol_vertical):
3030
self.jsonServer = HyperionConfigSections.json_serverd
3131
self.protoServer = HyperionConfigSections.proto_serverd
3232
self.grabber = HyperionConfigSections.GrabberV4l2()
33-
33+
34+
self.tester = HyperionConfigTester.HyperionConfigTester(self.led_chain)
35+
3436
def create_config(self, add_grabber):
3537
self.color.add_transformation(self.transform)
3638
self.color.set_smoothing(self.smoothing)
@@ -46,10 +48,10 @@ def create_config(self, add_grabber):
4648
jsonServer = self.jsonServer,
4749
protoServer = self.protoServer,
4850
endOfJson = 'endOfJson')
49-
51+
5052
if add_grabber:
5153
hyperion_config_dict.update(OrderedDict(grabber_v4l2 = HyperionConfigSections.GrabberV4l2().to_dict()))
52-
54+
5355
return json.dumps(hyperion_config_dict,sort_keys=False,indent=4, separators=(',', ': ')).replace("grabber_v4l2","grabber-v4l2")
5456

5557
def save_config_file(self,content,folder,file_name):
@@ -63,8 +65,7 @@ def overwrite_default_config(self):
6365
config_folder = "/storage/.config/"
6466
else:
6567
config_folder = "/etc/"
66-
raise "It is not OE"
67-
#return config_folder+"hyperion_config_json" + config_folder+"hyperion_config_json_bak"
68+
6869
shutil.copyfile(config_folder+"hyperion.config.json",config_folder+"hyperion.config.json_bak")
6970
shutil.copyfile(self.config_file_path,config_folder+"hyperion.config.json")
7071

@@ -75,10 +76,18 @@ def config_grabber(self,grabber_model):
7576
self.grabber.height = 192
7677
self.grabber.frame_decimation = 2
7778
self.grabber.size_decimation = 20
78-
79+
7980
def restart_hyperion(self,hyperion_config_file_name):
80-
HyperionConfigTester.HyperionConfigTester().restart_hyperion(hyperion_config_file_name)
81+
self.tester.restart_hyperion(hyperion_config_file_name)
8182

83+
def test_corners(self,duration):
84+
self.tester.connect_to_hyperion()
85+
self.tester.mark_corners()
86+
self.tester.change_colors()
87+
time.sleep(duration)
88+
self.tester.disconnect()
89+
90+
8291

8392

8493
#h = HyperPyCon(23,23)

resources/lib/HyperionConfigSections.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,41 @@ class Device:
1414
output = "/dev/spidev0.0"
1515
rate = 250000
1616
color_order = "rgb"
17-
17+
1818
def __init__(self):
1919
self.name = "MyPi"
2020
self.type = "ws2801"
2121
self.output = "/dev/spidev0.0"
2222
self.rate = 500000
2323
self.color_order = "rgb"
24-
24+
2525
def to_dict(self):
2626
return OrderedDict(name = self.name, type = self.type, output = self.output, rate = self.rate, colorOrder = self.color_order)
2727

28-
28+
2929
class SingleColor:
3030
threshold = 0.0700
3131
gamma = 2.0000
3232
blacklevel = 0.0000
3333
whitelevel = 1.0000
34-
34+
3535
def __init__(self,threshold,gamma,blacklevel,whitelevel):
3636
self.threshold = threshold
3737
self.gamma = gamma
3838
self.blacklevel = blacklevel
3939
self.whitelevel = whitelevel
40-
40+
4141
def to_dict(self):
4242
return OrderedDict(threshold = self.threshold, gamma = self.gamma, blacklevel = self.blacklevel, whitelevel = self.whitelevel)
43-
44-
43+
4544
class HSV:
4645
saturation_gain = 1.0000
4746
value_gain = 1.0000
48-
47+
4948
def __init__(self,saturation_gain,value_gain):
5049
self.saturation_gain = saturation_gain
5150
self.value_gain = value_gain
52-
51+
5352
def to_dict(self):
5453
return OrderedDict(saturationGain = self.saturation_gain, valueGain = self.value_gain )
5554

@@ -60,7 +59,7 @@ class Transform:
6059
green = None
6160
blue = None
6261
hsv = None
63-
62+
6463
def __init__(self,tranformation_id, leds_indexes_range, hsv, red, green, blue):
6564
"""red,green,blue must be isntances of SingleColorParms"""
6665
self.tranformation_id = tranformation_id
@@ -69,45 +68,45 @@ def __init__(self,tranformation_id, leds_indexes_range, hsv, red, green, blue):
6968
self.green = green
7069
self.blue = blue
7170
self.hsv = hsv
72-
71+
7372
def to_dict(self):
7473
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())
75-
74+
7675
class Smoothing:
7776
type = 'linear'
7877
time_ms = 100
7978
update_frequency = 20.0000
80-
79+
8180
def __init__(self,type,time_ms,update_frequency):
8281
self.type = type
8382
self.time_ms = time_ms
8483
self.update_frequency = update_frequency
85-
84+
8685
def to_dict(self):
8786
return OrderedDict(type = self.type,time_ms = self.time_ms,updateFrequency = self.update_frequency)
88-
87+
8988
class Color:
9089
transformations = []
9190
smoothing = None
92-
91+
9392
def __init__(self):
9493
self.transformations = []
9594
pass
96-
95+
9796
def add_transformation(self, transformation):
9897
self.transformations.append(transformation.to_dict())
99-
98+
10099
def set_smoothing(self, smoothing):
101100
self.smoothing = smoothing
102-
101+
103102
def to_dict(self):
104103
return OrderedDict(transform = self.transformations,smoothing = self.smoothing.to_dict())
105104

106105
class BootSequence:
107106
def __init__(self):
108107
self.effect = "Rainbow swirl fast"
109108
self.duration_ms = 1000
110-
109+
111110
def to_dict(self):
112111
return OrderedDict(effect = self.effect, duration_ms = self.duration_ms)
113112

@@ -121,7 +120,7 @@ def __init__(self):
121120
self.grab_menu = False
122121
self.grab_screensaver = True
123122
self.enable_3D_detection = True
124-
123+
125124
def to_dict(self):
126125
return dict(xbmcAddress = self.xbmc_address, xbmcTcpPort = self.xbmc_tcp_port, grabVideo = self.grab_video, grabPictures = self.grab_pictures,
127126
grabAudio = self.grab_audio, grabMenu = self.grab_menu, grabScreensaver = self.grab_screensaver, enable3DDetection = self.enable_3D_detection)
@@ -144,7 +143,7 @@ def __init__(self):
144143
self.red_signal_threshold = 0.2
145144
self.green_signal_threshold = 0.2
146145
self.blue_signal_threshold = 0.2
147-
146+
148147
def to_dict(self):
149148
return OrderedDict(
150149
device = self.device,
@@ -166,8 +165,6 @@ def to_dict(self):
166165
)
167166

168167

169-
170-
171168

172169

173170

resources/lib/HyperionConfigTester.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,29 @@ def __init__(self, chain = None):
1212
if os.uname()[1] == "OpenELEC":
1313
self.hyperion_path = "/storage/hyperion/bin/hyperiond.sh"
1414
self.config_folder = "/storage/.config/"
15-
else: #not test
15+
else: #not tested
1616
self.hyperion_path = "hyperiond"
1717
self.config_folder = "/etc/"
1818

1919
def restart_hyperion(self,config_file_name):
2020
subprocess.call(["killall", "hyperiond"])
2121
subprocess.Popen([self.hyperion_path, self.config_folder+config_file_name])
22-
#hyperion.config.json_new"
23-
print "hyperion started"
24-
22+
2523
def connect_to_hyperion(self):
2624
"""Connects to local hyperion"""
2725
self.connection = JsonClient('127.0.0.1', 19444, timeout=10)
2826
self.connection.connect()
29-
30-
#bytearray(number_of_leds*(0,0,0));
3127

3228
def mark_corners(self):
3329
self.led_chain.leds[self.led_chain.nol_vertical].set_color(255,0,0)
3430
self.led_chain.leds[self.led_chain.nol_vertical+self.led_chain.nol_horizontal].set_color(0,255,0)
3531
self.led_chain.leds[(self.led_chain.nol_vertical*2)+self.led_chain.nol_horizontal].set_color(0,0,255)
36-
32+
3733
def change_colors(self):
3834
self.connection.send_led_data(self.led_chain.leds_to_bytearray())
39-
35+
4036
def set_single_color(self, red, green, blue):
4137
self.led_chain.set_single_color(red, green, blue)
42-
38+
4339
def disconnect(self):
4440
self.connection.disconnect()
45-
46-
47-

0 commit comments

Comments
 (0)