PDA

View Full Version : 3 digit input from remote



Trick_McDave
November 25th, 2006, 09:57 AM
hi there
hope the title didnt confuse you ;)

what i want to do:
a little event in grider 4.0 where i can press
a 3 digit number on my streamrap remote and
then a winamp playlist gets loaded.

like
100: band a1
101: band a2
200: band b1
and so on.

with only one digits it's no problem, but not with
more than 1 digit.

any help or hints how i could solve this problem?

harleydude
November 25th, 2006, 05:47 PM
Below is something I put together the other day to work with my remote and the USB-UIRT. I want to be able to do something similar to what you requested.


local VCRCodes = {
[0] = "430D401545F5",
"430D540145F5",
"430D451045F5",
"430D510445F5",
"430D011405F5",
"430D150005F5",
"430D041105F5",
"430D100505F5",
"430D101515F5",
"430D040115F5",
"430D401545F5",
}
--VCRCodes = table.indexvalues (VCRCodes)


MyRemote = {

LastCommand = nil,
LastCommandTime = 0,
VCRCodes = VCRCodes,
Command = '',

Initialize = function (self)
self.UIRTHandler = gir.AddEventHandler("*", 75, 75, function (...) return self:Event(unpack (arg)) end)
end,

Terminate = function (self)
gir.RemoveEventHandler(self.UIRTHandler)
end,

-- arg[1] = command
-- arg[2] = 75
Event = function (self, ...)
local ticks = win.GetTickCount()
if (ticks - self.LastCommandTime > 500 or self.LastCommand ~= arg[1]) then
print ("MyRemote Event", arg[1])
self.LastCommandTime = ticks
self.LastCommand = arg[1]
local index = table.findvalue(self.VCRCodes, arg[1])
print (index,self.VCRCodes[index])
self.Command = self.Command..index
if string.len(self.Command) == 3 then
print ("Execute command:", self.Command)
self.Command = ''
end
end
end,
}

MyRemote:Initialize()


The VCRCodes coorespond to the keys 0-9 on my remote.

Hope that helps.

Rick

Trick_McDave
November 26th, 2006, 02:54 AM
thank your for this little script!



self.Command = self.Command..index

2 points? are they needed or is it a mistake?



if string.len(self.Command) == 3 then
print ("Execute command:", self.Command)
self.Command = ''
end

is it right that the input from the remote is stored in self.Command?

is there something like this which i can use to determine the typed number?


switch(variable):
{
case '100':
do_this;

case '101':
do_something_else;

default:
do_nothing;
}

(all what i can remember from ol'school days :) )

is there a function where i can directly execute a file
from the script like

execute('c:\abc\playlist.m3u', maximized); or something?

thanks!

Promixis
November 26th, 2006, 06:41 AM
Guys,

Put the .lua folder in the luascript\classes dir.

Load the GML.

This will build 4 digit numbers.

harleydude
November 26th, 2006, 08:28 AM
Thanks Mike, I was hoping that someone would post something a little more refined.

With my remote, Radio Shack 6 in One, I am seeing the following in the Lua Console.


Build Add 1
Build Add 1
Build Add 2
Build Add 2
Build Complete 1122


And I have only pressed 2 buttons, 1 & 2. Looks like my remote is sending the same signal multiple times. Is there a way to trap for this with this new class?

Rick

PS Nevermind, did not think about changing the AntiRepeat setting in the event. All is well now.

Trick_McDave
November 26th, 2006, 09:46 AM
sorry to bother again:
i placed the file in the folder, loaded the gml and got a
Script Error: Logic Error in the log and this in the LUA-console:


Welcome to Promixis Girder 4.0!
...:\Programme\Girder\luascript\Classes/BuildString.lua:24: attempt to call field `makeset' (a nil value)
stack traceback:
...:\Programme\Girder\luascript\Classes/BuildString.lua:24: in function `f'
C:\Programme\Girder\\luascript\compat-5.1.lua:78: in function `require'
[string "Build Channel Number Example.gml:\Startup\S..."]:2: in main chunk
[string "Build Channel Number Example.gml:\Numbers\5"]:3: attempt to index global `Channel' (a nil value)
stack traceback:
[string "Build Channel Number Example.gml:\Numbers\5"]:3: in main chunk

any hints what i should do to resolve this error?

in which variabel is the 4digit value stored and how can i access this variable?

Rob H
November 26th, 2006, 10:52 AM
Update to the latest version of Girder - I'm guessing you're running 4.0.5.2

Mastiff
November 26th, 2006, 12:28 PM
I have a group that does just this. You'll find it at http://www.hardware.no/guider/htpc_123/del11/mastiff_playlist_selecter_v2_gml.zip

Trick_McDave
November 26th, 2006, 12:52 PM
thank for the gml-files.

now i've loaded the files (both Mastiff & Mike C) and now
the gml-files are in my girder window. but unfortunately
i have no clue what to do now.
my programming skills are around :-(

do i have to press (or assign) a button to start the
scripts?

any existing guides or step-by-step explanations for noobs like me?

harleydude
November 26th, 2006, 01:16 PM
Using the GML Mike posted, the script will start automatically upon restart. If your remote is already assigned with Girder you should be able to start pressing the numeric keys and see data in the Lua Console like I posted earlier.

To change the code length edit the following line in the scripting action under the startup group of the GML

Channel = Classes.BuildString:New ({ Timeout = 3000, EventString = 'Channel:',Length = 3})
to reflect the length you are wanting, then restart.

Not sure about the GML Mastiff posted.

Rick

Trick_McDave
November 26th, 2006, 01:38 PM
when i load mike's.gml, it states


23:34:42:589 11/26/2006 Scripting Lua Success (Nothing Triggered)Build Channel Number Example.gml:\Startup\Scripting

but when i press a code, nothing happens nor can i see anything in the interactive lua console.
i've loaded the gml, saved (just to be sure) and restarted girder so it
gets loaded every time i start girder.

when i load mastiffs.gml, it states

Mastiff's playlist selecter initiated
in the interactive lua console, but also nothing happens when i press the buttons.

dunno if this has something to do with it, but when i start girder, there is one negativ entry in the log:


23:41:40:059 11/26/2006 Girder Core Could not aquire mutex for Device Table

no clue what a mutex is!?

Promixis
November 26th, 2006, 01:41 PM
You need to map your remote in G4. See the manual.

harleydude
November 26th, 2006, 01:42 PM
Do you have the StreamZap plugin loaded in Girder?

Trick_McDave
November 27th, 2006, 03:05 AM
ok, it got it working now!

now, where can i define which playlists gets played
with each code? there is the Execution Script with some
elseif's, but i dont think this is the right place.

where do i have to add the codes for the different playlists?
(the default directory for the playlists is set)

can you explain why you need the zones 0 - 5?
or what can i do with them?

and, is there a possibility to define a triggerbutton to run
the script? unless the triggerbutton is pressed, girder doesnt
build the 4digit code.

Promixis
November 27th, 2006, 10:33 AM
The generates 2 events...

One with the channel number in the event, the other with a common event and the channel number in pld1

The easiest will be to have a seperate action for each playlist. The best would be to have a single action that acts on the value in pld1. But this will require some lua coding.

Trick_McDave
November 27th, 2006, 12:12 PM
i'll do whatever is the most simple method.

my problem is that i dont know how i can use the 4digit code i've entered.
this code is somewhere stored in a variable but i dont know how to access
and reuse it.

can i define an actions (OS -> File Execute) for each playlist
and define that this action will be executed when the variable with the
4digit code has a specific value?
do i have to add an event or macro event to the action?


sorry to ask stupid question like this repeatedly, but everything
above the basic functions is totally uncommon for me.

harleydude
November 27th, 2006, 12:16 PM
Look in the logger. When you enter in a code there will be 2 events.

Channel:
Channel:XXXX -> where XXXX is the 4 digit code you entered.

Create the action you want to activiate when code 1234 is entered, then enter the code 1234 with your remote. Drag the event Channel:1234 from the logger to the new action you created. Reenter to code to verify the action works correctly.

Rick

Trick_McDave
November 27th, 2006, 01:33 PM
thank god, it's working! hoooray!

only one little question left :rolleyes:
if i pressed only two numbers, after the timeout
the returnt value gets returned.

when i press another number, this number gets
added to the previous string. how can i stop this?
i think this has to be done in the BuiltString.lua,
that after the value gets returned the string is
set to '0000' or something. so the next number(s)
will be added to a new string.

harleydude
November 27th, 2006, 01:36 PM
I will have a look when I get home. Unless Mike chimes in before that.

Glad you got it working.

Rick

harleydude
November 27th, 2006, 03:59 PM
I am seeing the same problem here. The TimeoutHandler needs to reset the self.String.

Rick

Trick_McDave
December 1st, 2006, 11:52 PM
any news on that?

Trick_McDave
December 17th, 2006, 07:57 AM
sorry to bump this thread, but how can i make that the channel will be
reseted or deleted after the timeout?

if i press only 1 - 3 numbers instead of four, the numbers will be added to the channel, but the channel doenst get built completely. next time if i press
a number the channel is completed.

the problem is that if i press a number by mistake i've to press 3 additional numbers to restart pressing the desired number.

i'm looking for something like this:


while(!not_timeout) //as long as timeout is not reached
{
addtochannel(pressed_number);
}
if(str.len(channel) <= 3)
channel = '0000';
else
return(channel);

hope you understood what i want to achieve.

thx in advance!

harleydude
December 17th, 2006, 09:50 AM
You need to edit the BuildString.lua file in the luascript\classes folder. Look for the TimeoutHandler() routine. Modify to look like below.


TimeoutHandler = function ( self )
self:Complete ()
end,


When the timeout triggers it will send an event but one that you are not looking for so it should not really matter.

Rick