PDA

View Full Version : Lua IR?



Prasoc
August 12th, 2007, 13:42
in lua is there IR so I can send signals?

edit: whoops, im stupid, i just found out there is >_<

-Xandu-
August 12th, 2007, 13:46
IrDA functions in Lua:


nil System.irdaInit()


Opens the IrDA device. Call this to start the IrDA module.


System.irdaWrite(string)


Writes the string to the IrDA port.


string System.irdaRead()


Reads all available data from the IrDA port. Returns an empty string, if no data was received.

Prasoc
August 12th, 2007, 14:12
I used irdacapture on my remote control for my helicopter, but it came back with like loads of symbols and it doesnt work in Lua, Hoe would I be abnle to figure out what the symbols mean?

if pad:up() then
if System.irdaWrite("Ԅ||8N|||t.||>8N|||||䄄|||||||||>.||䄄|䄄䄀 ||8䄄|䄀|䄄||pĄ|䄄8|䄄|䄈 ||<䄄|N|䄄|N|||| |䄄 ||||p|8<8䄄||Є||pЄ||p|||| ||||||||䄄|䄄|N| ||||N䄄||| 䄄|||䄄|䄄||䄀||䄄|䈀| 䄀|||䄄|||||||8N||||| |p|NpȄ|䄄|~||<||||.>脄|||>|||>|||||||||䄀䄀||䄀|䄄|| 䄄|||||||||.||||| .|||||/8䄄 ||||>||||/||||||||||||䄐|||||| ||||") then
screen:print(0,40,"Going UP!",white)
endthat is what I have, but it doesn't say "Going UP!".

dangee
August 12th, 2007, 21:59
The symbols are bytes outside of the normal range
of printable characters. It looks like your helicopter
uses byte values between 128 and 255 fo take off. U'll
need a hex file reader to see the exact values.
(PSP Filer has a hex reader)
I posted a similar program written in lua a while back in
THIS THREAD- to print raw data
reads from Irda to the PSP screen in decimal

-Xandu-
August 12th, 2007, 22:10
I've been thinking about coding an IRLearner, but I don't think I'll release that in public though.

dangee
August 12th, 2007, 22:55
to get the Irda write statement working, you can
convert the data to decimal byte escape sequences in Lua: \ddd
eg. to output 2 bytes 0x01 0xff , use System.irdaWrite("\1\255")

Prasoc
August 12th, 2007, 23:13
Where would I find the 0xff or whatever they are called?

dangee
August 13th, 2007, 03:20
Where would I find the 0xff or whatever they are called?

think the capture prog sends all its 0xff 's to a file in the root ms0:/
open the file from Lua , then read the string.byte(s)

*edit* the code is like:

System.irdaInit()
codes=io.open("ms0:/capture.dat","rb")
System.irdaWrite(codes:read("*a"))
codes:close()

Prasoc
August 13th, 2007, 18:19
I don't see any file in my mem stick called capture.dat.

edit: u mean the other thread ircapture. yes i have a file called "ircapture" so I work on it

edit2: How would I get a file 1 char at a time? because string.byte() only works on 1 letter rather than a line of it

dangee
August 13th, 2007, 19:50
umm, yeah, Ive D/L'd the prog now; the file paths
"ms0:/irdacapture".

to read bytes into a table:

codes = io.open("ms0:/irdacapture","rb")
Byte,i={},0
repeat
i=i+1
Byte[i]=string.byte(codes:read(1))
until not Byte[i]
codes:close()
to transmit Byte[n] to the helicopter:

System.irdaWrite(string.char(Byte[n]))
to write Byte[n] to screen:

screen:print(10,10,tostring(Byte[n]),Color.new(255,0,0))

Prasoc
August 13th, 2007, 21:10
cheers dude. If there was rep i would give you +5 :D

edit: lua says


error: index.lua:7: bad argument #1 to `byte` (string expected, got nil)

line 7 is "Byte[i]=string.byte(codes:read(1))"

dangee
August 14th, 2007, 16:53
whoops, better retract those +reps..
ok,try replacing the loop with:

repeat
i=i+1
char1 = codes:read(1)
if char1 then Byte[i]=string.byte(char1) end
until not char1
& you may want to add

numberOfCodes = i-1

Prasoc
August 14th, 2007, 19:24
ah i give up. its too hard. whenever i use irdacapture to capture it, it always changes. i cant get it to go up because my capture doesnt change. thanks for the help though.

dangee
August 14th, 2007, 22:50
ah well , it was a good idea, but it sounds like
the helicopter has some kind of recieve/transmit protocol, meaning
you'd have the small matter of a full scale driver to script.
I guess your best bet may be -Xandu-'s (possible) ir learner...

Prasoc
August 15th, 2007, 12:20
epp a full scale driver >_< too much work me thinks

usp8riot
August 31st, 2007, 07:56
So after doing some researching, it seems no one has made an irda capture and transmit application. The most I can find is at the ps2dev forums where it was talked about but standard ir signals for remote signals are spaced out. The ID signal and function signal are separated so simply grabbing the ir data isn't good enough.

apsd wrote an ir emit app along with his ir capture app but because of the signal spacing, it wouldn't work for ir remotes.

Can someone clue me in on how to implement irda timing capture in a lua app? There's already a lua app to capture but how easy would it be or is it possible to implement that feature in the lua app?

I've googled for hours and can hardly find much irda functions for lua. I haven't started any kind of lua programming other than the hello world bit but I just want to make sure it's possible with that language before I go on.

EDIT: Sorry, wrong thread. I suppose it will still fit the topic in this thread anyhow. I've got a dozen tabs open googling around.

dangee
August 31st, 2007, 12:49
Hey,Respect & +rep. I like the way your going about this.
What you found may explain why the helicopter didnt take off.

Luaplayer has millisecond Timer functions; should be
accurate enough for signal Spacing, so no probs. there.
It may be ok just to transmit Bytes at some slow speed -say
10 per second,at least for a simple device

ID/function separation: Not sure about this. Think its to
distinguish signals in a multi-Irda device environment, and
handled automatically in the PSP F/wares' Irda module..

usp8riot
August 31st, 2007, 13:38
By the way, there's a lot of possibilities for the ir port but no licensed software by Sony that makes use of it? So what was Sony's intention with this?

Anyhow, I'm sure you're right about the ID/function signals being mainly for electronically noisy environments. Although, I do believe the PSP's ID/function data is not sent in an ir signal. I believe when capturing the ir packets, the original device ID is recorded and sent to the receiving device, at least, my take on it.

The problem, from what I read, is that all signal spacing in ir transmissions are different on a couple levels. I thought of making a program that would detect the device ID from the ir data and call on pre-fabbed codes based on that, but the number of codes would be too great, come to find out due to all the variations between models and manufacturers.

I'm obviously a noob at coding but would it be feasible to count every break in the ir signal with lua, as in, keep the timer running so we can record true-to-timing signals?

There's been others that have sort of delved into this and before I waste my time, I'm just wondering if it's all possible since I haven't heard of this kind of app before for the psp. And with all the talented coders, I may be just spinning my wheels if I found out it's been done before or just unfeasible to implement.

I've heard of devices being able to be used as remotes by converting ir signals to audio and then back to ir for mobile PC's and even ipods, so the PSP definitely seems capable one way or another. I just want ultimately to take ir data and spit it back out as perfectly as it received it, that way I could duplicate pretty much any remote or remotely control my car radio if I so wish or possibly duplicate my PS2 wireless controller so the PSP is now a PS2 controller. Yes, there's less buttons but proof of concept and boredom reign superior to needs sometime. Also, to record that data into .rdf code for use in irshell or ircommander for all other PSP owners to use if so wished.

dangee
August 31st, 2007, 14:49
Irda data transfer is slow,even compared
to a Lua program(interpreter,garbage collector,FW overheads
& all),so to accurately record every Byte detected by System.irdaRead(),
along with its time of transmission, and to replay the same
data,with the same timing, with System.irdaWrite(), appears feasible,
assuming that System.irdaInit() sets any ID correctly.
Luaplayer Timers can be started,stopped,read,or reset as
required.
At this stage a simple test script would be useful to find
any possible problems.

Sullivan
February 17th, 2008, 03:34
So was anyone able to get the data to transmit back to the device?
Since the app gets/dumps RAW data, RAW data changes everytime. So it will never be the same.

But we need something to dump PRONTO codes to a file on the memory card.

dangee
February 19th, 2008, 19:11
dcemu member pacopad released "picoozir" a while back
- a IR helicopter controller,
but didnt reveal what the raw codes were,
or how they were captured...