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

Login:
Pass:
 
 

Page 1 of 2
Topic:
CD jukebox implementation suggestions solicited...
This thread has 15 replies. Displaying all posts.
Post 1 made on Sunday October 10, 2010 at 18:13
rap
Long Time Member
Joined:
Posts:
September 2006
59
I am implementing a CD jukebox that, now, has some 200 CDs in it. I have an Excel database of all the CDs in four fields: disc#, Category, artist, album title

So not to create 200+ buttons! I created one panel with ten buttons and implemented a simple scroll where each page down/up refreshes the ten button labels. Further I use tabs to separate the categories to allow the user to easily filter.

Right now I use an array[1..200] that holds artist + title as a string and this array is used to refresh the list. The cursor up/down buttons allow the user to navigate the list - i.e. highlight one item at a time.

What's not clear to me is how to implement sending out the correct IR (disc# + "OK") depending on what's highlighted. I can put the disc# field in a parallel array to reference but I don't think you can send IR from PS.

I have novice++ programming skills and I'd like some suggestions on how to proceed.

Thanks!
Post 2 made on Sunday October 10, 2010 at 19:06
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
You cannot send IR but you can execute/schedule actions. Put all your IR commands (keypad digits, track, disc, Enter) on buttons and assign ProntoScript names to these.

Finally, use CF.widget('Keypad' + digit',...,...).scheduleActions() to send the 1+ IR commands. If you need delays, use scheduleActions() to schedule execution of a widget with a small delay in it.

scheduleActions() comes in really handy here. ;-)
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Sunday October 10, 2010 at 19:53
alpha
Long Time Member
Joined:
Posts:
September 2003
258
Create a second panel ( "Codes-Page" ) thats hidden. Add the numeric buttons, disc, enter, ok and menu buttons to operate the equipment. Add a small delay ( .4 seconds) at the beginning of the action list on each button. Place a Blank Label ( "Disc Label" ) on the your first page for the Disc Number.

When you press the button on the first page, it should change the label on "Disc Label" to the number associated with the disc number.
Then read off the number one digit at a time and execute them as actions.
Then change the disc label back to a blank label.

I used this method with my Channel Blaster in Project Boredom 2.

You should add categories for your music like Rock ,Classical My Favorites .

Add a Random Music button ( random number between 0 and 201 ).

If there are only 200 CD's add Album Art . It should not take up much space. Create a third or fourth hidden page called " Album-Art " . Use the setImage/getImage functions. Make all the images the same size for uniformity.
Project Boredom 2 is here. [Link: mediafire.com]
------------------------
Check Version 1 & 2 out in the files section.
Post 4 made on Sunday October 10, 2010 at 20:04
buzz
Super Member
Joined:
Posts:
May 2003
4,383
rap,

As part of your disc array, store or deduce the disc & track number. Set up a page of player command IR buttons and use scripts on the track buttons rather than directly emiting IR commands.

I use a similar scheme for cable channels. I store the master channel assignments in a spreadsheet. The sheet prepares a station array and button commands that I simply copy and paste into my Pronto program.
OP | Post 5 made on Monday October 11, 2010 at 08:36
rap
Long Time Member
Joined:
Posts:
September 2006
59
Thanks for the suggestions and inspiration, I think I'm off and running now.


I'm using two arrays for each category e.g. jazz[] and jazzDisc[]/

The category[] array hold the Title/Artist and the xyzDisc[] array holds the disc number for the same index.
OP | Post 6 made on Monday October 11, 2010 at 20:56
rap
Long Time Member
Joined:
Posts:
September 2006
59
Can I pass an Array() as an argument to a function?

oversimplified example...

var category = new Array();

function displayPage(x, a) {
for (i = x, i = x + 8, i++) { ...do stuff with a[i] }
}

displayPage(category);

This would be the display routine that I would call with different arrays/categories of CDs. When I hit a line like:

widget().label = a[i];

I get a no properties error.
If i substitute category[i] for a[i] all is well.
Post 7 made on Monday October 11, 2010 at 21:37
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Your function declares 2 parameters yet you are only passing 1 parameter.

Have a look at the www.w3schools javascript tutorials for function.

Either see the ProntoScript FAQ on Philips site for a link or google for +w3schools +javascript +function +tutorial
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 8 made on Monday October 11, 2010 at 21:45
rap
Long Time Member
Joined:
Posts:
September 2006
59
Hi Lyndel,

Sorry, in my haste to prep an example I left off a parameter in the function call. However, that's not the crux of my question. I have many functions that I use to pass one or more parameters.

I searched w3 schools and elsewhere but could not find anything specific about passing an array as an argument.

I gather from your reponse, it can be done. I'll keep searching.

++update, just tested this an it works fine. I must have some other issue.

var a = new Array();

a[1] = "a";
a[2] = "b";
a[3] = "c";

function foo(x) {
for (i=1; i<=3; i++) System.print( x[i] );
}

foo(a);
Post 9 made on Tuesday October 12, 2010 at 01:22
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
May want to paste your script into a JSLint page on the web. The issue that bites me usually is one of misspelling or case mismatch on variable name.

As you have seen, passing arrays is indeed perfectly legal.

Here's the link I was hoping you'd find @ w3schools:

[Link: w3schools.com]


As a debug tip - Use try/catch

try
{

// do something

}
catch (e)
{
System.print('Error:' + e);
Diagnostics.log('Error:' + e);
}

To try and find your problem. If you can simulate the script, then you can use ProntoScript console to isolate the problem. Note that if you are doing this in an Activity Script, you cannot rely on the _PS_DEBUG_ panel to display the error, you must rely on external debugger (Barry's DS mod + code) or the Simulator's ProntoScript console.

Note that you can declare arrays using shorthand notations:

var a = [];

Also note that array indices start at 0 so you are in effect wasting a slot/index.

Very important to note a.length === 4 in this example with element 0 being null, IIRC. If you switch to 0-based index then use elements 0,1, 2 you can set your loop termination as (i < x.length).

Here's the link that you may want to file away as I also use this as well as you can test out simple stuff via HTML page.

[Link: w3schools.com]

This link is can be referenced @ www.w3schools.com by clicking Learn Javascript on left sidebar under Browser Scripting.


This link is also currently referenced by the ProntoScript FAQ - Creating ProntoScript Modules at:

[Link: pronto.philips.com]

Last edited by Lyndel McGee on October 12, 2010 01:36.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 10 made on Tuesday October 12, 2010 at 17:32
rap
Long Time Member
Joined:
Posts:
September 2006
59
Thanks for the references to w3schools. I refer to that a lot. It is very useful and a great resource. Also, I appreciate the other tips. I will try the catch(e) for additional trouble shooting. For now here are two functions. One works with explict references to the arrays and the second only works on the first call. Has me baffled. I have captured the following as the troubleshoting so far:



This function works with out error when called with pg=1,2,3...:
maxlist = 8, I have used 10 also

function displayList(pg) {
for (i = 1; i <= maxlist; i++) {
arrayIndex = (pg * maxlist) - maxlist + i;
wname = "BUTTON_" + i;//refresh on one page, buttons 1..maxList
System.print("Page: " + pg + "arrayIndex= " + arrayIndex + " i " + i);
System.print(wname);
System.print(classical[arrayIndex]);
widget(wname).setColor(0xffffff);//each page refresh default color for all labels
widget(wname).label = classical[arrayIndex];
if ( i == 1 ) {
wnameDisc = "DISC_" + i;//for refresh on one page, disc# labels 1-10
widget(wnameDisc).label = classicalDisc[arrayIndex];
} else {
wnameDisc = "DISC_" + i;//for refresh on one page, disc# labels 1-10
widget(wnameDisc).label = "";
}

}
}

When trying to pass in two arrays, the first call with pg=1 is fine...

function displayList(pg, cat, catDisc) {
for (i = 1; i <= maxlist; i++) {
arrayIndex = (pg * maxlist) - maxlist + i;
wname = "BUTTON_" + i;//refresh on one page, buttons 1..maxList
System.print("Page: " + pg + "arrayIndex= " + arrayIndex + " i " + i);
System.print(wname);
System.print(cat[arrayIndex]);
widget(wname).setColor(0xffffff);//each page refresh default color for all labels
widget(wname).label = cat[arrayIndex];
if ( i == 1 ) {
wnameDisc = "DISC_" + i;//for refresh on one page, disc# labels 1-10
widget(wnameDisc).label = catDisc[arrayIndex];
} else {
wnameDisc = "DISC_" + i;//for refresh on one page, disc# labels 1-10
widget(wnameDisc).label = "";
}

}
}


On the second call where pg=2,3 the following error is generated


Output just before error shows - Page:2 arrayIndex= 9 i=1

ProntoScript error: TypeError: cat has no properties
Offending activity script: (untagged)
Offending line #33: "System.print(cat[arrayIndex]);"

I understand the error to be that cat[9] - classical[9] - has no value...but it does.
Post 11 made on Tuesday October 12, 2010 at 18:46
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Note that 'try' is a javascript keyword and must be included.

try
{
// do something
}
catch(e)
{
}

You've shown us how the function is being declared, but how is it being called? What is the exact line you are using? How can pg=2,3? Is this what you are passing as parameters?

assuming your arrays are classical and classicalDisc, your function call should have 3 parameter values and be something like:

displayList(2, classical, classicalDisc);

I don't mind debugging code on occasion but I suspect that you have something really simple you are missing.

Also note that you are REALLY asking for trouble by using variables maxList inside the function(can't see on edit - is it maxlist???) and not relying on the length of the arrays passed to the function. maxlist can be modified elsewhere to be a value that does not coincide with the length of the current array being passed to your function. Either use the length property of the array as I suggested earlier or I STRONGLY suggest that you pass all array-based criteria (length, index, and the arrays themselves) as parameters to your function.

Last edited by Lyndel McGee on October 12, 2010 19:12.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 12 made on Tuesday October 12, 2010 at 21:25
rap
Long Time Member
Joined:
Posts:
September 2006
59
maxlist is defined at the activity level. It defines how many items will be displayed on the page for the user to select. e.g. If classical has 100 CDs then display 8 per page. Here is how it's called from the page script:

page = 1;

displayList(page, classical, classicalDisc);

Each press of the pageUp/pageDwn key increments or decrements page and calls displayList(...) again, so if page=1, then show classical titles and classicalDiscs 1..8. When page=2, show 2..16 ...etc. maxlist is independent of how many elements are in the array. The goal is to reuse these functions with jazz/jazzDisc, pop/popDisc...etc

When a page # (by page down firm key) finds:

wname = "BUTTON_" + maxlist;//check last item on screen
if (widget(wname).label === "undefined") page = 1;//if undefined scroll back to page 1

I set page to 1 and just start from the beginning.

All works pretty well with the arrays explicitly defined in the functions.
I thought there was something blatant that I'm doing wrong and don't understand about PS that I could not see. I'll keep at it. Please don't spend further time on this.

Thank you.
Post 13 made on Wednesday October 13, 2010 at 00:21
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
My apologies. Flying a bit blind here.

In order to get to the root of the problem, I would need to see the full picture which would mean you sending me a copy of your config via email.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 14 made on Wednesday October 13, 2010 at 12:49
rap
Long Time Member
Joined:
Posts:
September 2006
59
SOLVED! How stupid?!

Once I determined that it should work, it was clear that I could make it work. Lyndel encouraged me to keep on debugging and go figure it out for myself, I was determined.

I re-read the issue described above an realized that I was pointing to the problem area but... '...the first call to the function worked but subsequent ones did not..."

That's because the first call came from entering activity on the page script:
displayList(page, classical, classicalDisc);

The subsequent calls came from the page up/dwn firm keys with page incremented or decremented:
displayList(page);
which omitted the required parameters!

Now, off to the rotary wheel for on page scrolling versus the index keys... :)

Thank you Lyndel.
Post 15 made on Wednesday October 13, 2010 at 23:45
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
I am very glad you worked it out. I suspected that was the problem and I was hoping you'd checked this after Posts 7 and 11.

Now, you are well on your way to having a solid set of Prontoscript debugging skills.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Page 1 of 2


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse