Slider Widget
Hi Brett
Im trying to implement a slider for dimmer control using Garrys Dimmable endpoint lua -http://homeautomationhub.com/content/he107-switch#comment-2936
I've created a slider listener event as below, can i specify the xapSource this way? - Im not seeing any BSC levels in XFX Viewer
-- Slider listener
local function sliderListener( event )
local slider = event.target
local value = event.value
xapSource="dbzoo.livebox.Plugboard:LoungeLights." .. value
print( "Slider at " .. value .. "%" )
end
local slider = widget.newSlider
{
top = 200,
left = 50,
width = 200,
listener = sliderListener
}
I've added a corona demo of how to control a xAPBSC endpoint that is of the LEVEL type using a Slider.
http://livebox-hah.googlecode.com/svn/trunk/userapps/HAHCorona/
Don't forget to copy the hahlib folder into silderControl so the demo will run.
Brett
Andrew I take it you got this Corona slider demo to work for you? I never got any feedback on this code.
Yes Brett we got it going nicely as Andrew said. I'll post the code up in a day or so and add some working codes for the 15 dim levels.
Yes Brett we got it going nicely as Andrew said. I'll post the code up in a day or so and add some working codes for the 15 dim levels.
duplicate post due to slow connection and the 'form reuse detected' lol
As promised here is the info Andrew and myself have come up with. Brett please feel to correct my work ;) Attached are 2 plugboard scripts, one for an even addressed HE and one for an odd addressed HE. All odd ones use the odd dim suffix list and all even use the even dim suffix list. There is also a text file listing my currently active controllers with addresses, on/off commands, dim prefix and 15 dim commands. Finally there is the corona code that will need to be placed inside the createScene (I have it before the UI helpers)
Attachment | Size |
---|---|
Lounge1Applet.lua.zip | 1.61 KB |
Lounge2Applet.lua.zip | 1.59 KB |
Lamp Dim Settings.txt | 6.53 KB |
corona_bit.txt | 2.59 KB |
Mark,
I would simplify the BSC level output for the slider to be in this format.
opt.listener(opt.states[idx])
if event.synthetic ~= true and event.phase == "ended" then
local lvl = string.format("%s/%s", idx, #opt.states)
bscSend{target=opt.xapTarget, level=lvl}
--print(string.format("bsc.sendLevel(%s, %s)", opt.xapTarget, lvl))
end
That is you get back 1/15 -> 15/15 its the level and the number of levels.
This will simplify the endpoint logic and remove this math.
dimLevel = xap.getValue("output.state.1","level") -- value received 0 - 150
dimsetting = math.floor((dimLevel/10)+0.5) -- set display text to be between 0-15
That can now become
dimLevel = xap.getValue("output.state.1","level") -- value received x/y
(dimsetting, range) = dimLevel:match("(%d+)/(%d+)")
You could do some range validation here too to make sure that its within what you are expecting.
Be aware there is no ZERO 0/15 strictly speaking 0/15 would be a 16th state.
Brett
Lets have another crack at that - if you have 3 states (ON,DIM,OFF) then you have the range 0/2
0/2, 1/2, 2/2 - being your 3 states. So the correct logic looks like this:
function levelController(opt)
return function(event)
-- Normalize the slider 0-100 value into the range 0->(states-1)
local idx = math.ceil(event.value / (100/#opt.states))-1
opt.listener(opt.states[idx+1])
if event.synthetic ~= true and event.phase == "ended" then
local lvl = string.format("%s/%s", idx, #opt.states-1)
bscSend{target=opt.xapTarget, level=lvl}
--print(string.format("bsc.sendLevel(%s, %s)", opt.xapTarget, lvl))
end
end
end
You're endpoint for the lounge lights uses the range 0-15 which is 16 states (4 bits) which is 0/15 as a level.
I already posted how to strip the x/y level reading into its part so you are good from there.
Brett
The original code was lifted from Garry's (thanks Garry) I know the hacks weren't pretty but worked.
So this is a combination of simplifying the code and bringing in BSC compliance. Cheers Brett
Now I'm almost set back up again let me have a poke about with sliders with both Corona and on the Joggler and see how they work. I'll amend the wiki and post here with my findings.
Brett