Slider Widget

Hi Brett

 

Im trying to implement a slider for dimmer control using Garrys Dimmable endpoint lua -/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

Member for

16 years 10 months

brett

13 years ago

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

Member for

13 years 11 months

AndrewJ

13 years ago

Thanks Brett,

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

Andrew

Member for

16 years 10 months

brett

12 years 12 months ago

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

Member for

13 years 11 months

AndrewJ

12 years 12 months ago

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

 

Member for

14 years 5 months

mark_baldwin

12 years 12 months ago

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.

Member for

14 years 5 months

mark_baldwin

12 years 12 months ago

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

Member for

14 years 5 months

mark_baldwin

12 years 12 months ago

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)

Attachments

Member for

13 years 11 months

AndrewJ

12 years 12 months ago

Thanks Mark,

 

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

 

Andrew

Member for

17 years

admin

12 years 12 months ago

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

Member for

16 years 10 months

brett

12 years 12 months ago

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

Member for

14 years 5 months

mark_baldwin

12 years 12 months ago

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