Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 23 made on Wednesday October 29, 2014 at 03:28
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
I gave up sometime ago trying to get a slider working with http commands to control my lighting, however I decided to try and give it another go. I downloaded 'Rick's Slider Control'

[Link: files.remotecentral.com]

Looking at Rick’s code there is an option to change the slider from a vertical slider to horizontal slider by changing dimmer orientation variable to a ‘0’ from the default ‘1’. I also rotated the images to horizontal and the slider demo seems to work ok apart from it not remembering its position when I exit the page and re-enter. If I change it back to vertical it remembers just fine. I must be missing something in the code to enable this position memory but I'm not sure what I am looking for.

For information, I want to use a dimmer scale of 0-100. In my copy of the code I changed all the ‘15’s in the code below to ‘100’

Any help would be much appreciated.

Many thanks

Steve

Rick’s Code-
-----------------------------------------------------------------------------------------------------
@author Rick
*/
// skeleton coded for speed no error checking
// add Dimmer.js to activity properties (PS libraries)
//call dslider from knob page properties(advanced) to initialise.
//call dslider from button properties(actions)
// check prontoscript tag names are consistant

var dir,// dimmer orientation 0 = horizontal 1 = verticle
gmin,gmax,// dimmer graphic extents
scale,// dimmer scale, this case is 0 - 15
res, lres,// knob scale position, last knob position
pos, irpage,// ir button tag, ir dim code page tag
lab;// dimmer label tag

function dslider(wk, wg, wl, wpd, hv){
var xp, yp, xk, yk;// knob position
// get dimmer graphic extents
lab = wl; dir = hv; irpage = wpd;
if(dir == 0){
gmin = wg.left;
gmax = wg.left + wg.width - wk.width;}
else{
gmax = wg.top + wg.height - wk.height;
gmin = wg.top;}
scale = (gmax - gmin) / 15;

// note setGlobal used here only on first use to initialise
// getGlobal thereafter to remember and set knob position on re-entry
if (System.getGlobal(wk.tag) == null) System.setGlobal(wk.tag , 8);
res = System.getGlobal(wk.tag);
if(dir == 0) wk.left = gmin + (scale * res);
else wk.top = gmin + (scale * (15 - res)); // scaled from bottom to top. remove 15 to reverse.
lab.label = res;
////
//get knob position
wk.onPress = function(x, y) {
xp = x; yp = y;
xk = this.left; yk = this.top;}
/////
//see which way knob moves and increment or decrement position
//and keep within bounds of dimmer graphic
//save knob scale position in res
//display integer res in our label
wk.onMove = function(x, y) {
if(dir == 0 ){ // horizontal
if((x - 3) > xp) xk +=3; else if((x+3) < xp) xk -=3;
if(xk > gmax) {xk = gmax; return ;}
if(xk < gmin) {xk = gmin; return ;}
this.left = xk ;
res = (xk - gmin) / scale; }
else{
if((y - 3) > yp) yk +=3; else if((y +3) < yp) yk -=3;
if(yk > gmax) {yk = gmax; return ;}
if(yk < gmin) {yk = gmin; return ;}
this.top = yk ;
res = 15 - ((yk - gmin) / scale) ; }

res = Math.round(res);
if(res == lres) return ;
lab.label = res;
lres = res;}
//////
//save knob position res for page re-entry

-------------------------------------------------------------------------------------

Last edited by Stealth on October 29, 2014 03:45.


Hosting Services by ipHouse