Slider Widget

12 replies [Last post]
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012

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

}

 

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Now I'm almost set back up

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

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Thanks Brett,I've also tried

Thanks Brett,

I've also tried bsc.sendLevel("dbzoo.livebox.Plugboard:LoungeLights", value)

Andrew

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I've added a corona demo of

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

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Andrew I take it you got this

Andrew I take it you got this Corona slider demo to work for you?  I never got any feedback on this code.

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Brett, Yes sorry for the late

Brett,

 

Yes sorry for the late reply, i am indeed, thanks to Mark Baldwin too we have some pretty nifty lua working well now (4 sliders controlling 4 dimmable sockets HE108C)

im sure Mark will be happy to share his mods here when all the bugs are ironed out

thanks for taking time to code the demo

thanks

 

Andrew

 

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Dimming sliders

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.

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Dimming sliders

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

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Slider mods with dim suffix list, corona mods etc

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)

AttachmentSize
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
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Thanks Mark, Big thanks to

Thanks Mark,

 

Big thanks to Garry for the original decoding write up which also helped me understand URF

 

Andrew

admin
Offline
Joined: 26 Oct 2009
Mark,I would simplify the BSC
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
brett
Offline
Providence, United States
Joined: 9 Jan 2010
Lets have another crack at

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

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
not really corrections ;)

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

Hardware Info