Trying to enhance IR_Remote object
Rsadeika
Posts: 3,837
What I am trying to do is enhance the existing IR_Remote.spin object to allow for providing the device number. What I basically did was, in the E_IR_Remote.spin, is add a IRdev variable by masking off the IRcode for it. But, it seems that I am not getting what I expect, which sould be a 1 or 2, which designates the device number. I added the IRdev variable to the program, it did not contain it before hand. I am at a loss as to what to do next.
The program below works, the commented out stuff is what I tried to do to no avail. It seems that IRdev should be holding the device number, 1 or 2, in this case, but when I do the 'if IRdev == 1', that does not work, so I must be getting an unexpected value. I thought this would be simple, and straight forward, but, it is not. Anybody have any suggestions?
Ray
The program below works, the commented out stuff is what I tried to do to no avail. It seems that IRdev should be holding the device number, 1 or 2, in this case, but when I do the 'if IRdev == 1', that does not work, so I must be getting an unexpected value. I thought this would be simple, and straight forward, but, it is not. Anybody have any suggestions?
Ray
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 IRdetpin = 0 VAR byte IRcode byte IRdev OBJ IRrem : "E_IR_Remote" misc : "tools" PUB IRremote | cog, scode, scode2 cog := IRrem.start(IRdetpin, @IRcode, @IRdev) if cog > 0 repeat ''if IRcode <> IRrem#NoNewCode AND IRrem#NoNewDev if IRdev <> IRrem#NoNewCode and IRrem#NoNewDev ''scode2 := IRdev ''if IRdev == 1 scode := IRcode ''if IRdev == 1 ''Check for device number 1 or 2 IRrem.Start(IRdetpin, @IRcode, @IRdev) case scode IRrem#power : Pwr_btn IRrem#chup : Ch_up IRrem#one : One ''if IRdev == 2 ''IRrem.Start(IRdetpin, @IRdev, @IRcode) ''scode2 := IRcode ''case scode2 ''IRrem#power2 : Pwr2_btn PRI Pwr_btn LED1 PRI Ch_up LED1 PRI One LED1 PRI Pwr2_btn LED1 PUB LED1 misc.high(1) misc.waitms(250) misc.low(1)
''E_IR_Remote.spin CON NoNewCode = 255 NoNewDev = 255 gapMin = 2000 startBitMin = 2000 startBitMax = 2800 oneBitMin = 1000 oneBitMax = 1400 one = 0 chup = 16 power = 21 power2 = 21 VAR byte cog long stack[noparse][[/noparse]20] PUB Start(Pin, addrMainCode, addrMainDev) : result stop byte[noparse][[/noparse]addrMainCode] := NoNewCode byte[noparse][[/noparse]addrMainDev] := NoNewDev cog := cognew(getSonyCode(Pin, addrMainCode, addrMainDev), @stack) + 1 result := cog PUB stop if cog cogstop(cog~ -1) PUB getSonyCode(Pin, addrMainCode, addrMainDev) | irCode, irDev, index, pulseWidth, lockID frqa := 1 ctra := 0 dira[noparse][[/noparse]Pin]~ repeat ctra := (%10101 << 26) | (Pin) waitpne(0 << Pin, |< Pin, 0) phsa := 0 waitpeq(0 << Pin, |< Pin, 0) waitpne(0 << Pin, |< Pin, 0) pulseWidth := phsa / (clkfreq / 1_000_000) + 1 while (( pulseWidth < startBitMin) OR (pulseWidth > startBitMax)) index := 0 irCode := 0 repeat ctra := (%10101 << 26) | (Pin) waitpne(0 << Pin, |< Pin, 0) phsa := 0 waitpeq(0 << Pin, |< Pin, 0) waitpne(0 << Pin, |< Pin, 0) pulseWidth := phsa / (clkfreq / 1_000_000) + 1 if (pulseWidth > oneBitMin) AND (pulseWidth < oneBitMax) irCode := irCode + (1 << index) index++ while index < 11 irCode := irCode & $7f ''Masking of lower 7 bits irDev := irCode & $f80 ''Masking of upper 5 bits? byte[noparse][[/noparse]addrMainCode] := irCode byte[noparse][[/noparse]addrMainDev] := irDev ''byte[noparse][[/noparse]addrMainDev] = upper 5 bits?
Comments
The second line will always result in 0 because you cleared the upper bits in line one (irCode). May I suggest something like this:
If irCode is only 12bit in size then irCode >> 7 should be enough.
HTH
Ray
1
21
255
255
on the screen. Now I cannot figure out where the 255's are coming from. I see I get 1 for the device number, 21 for the pwr_btn, which is correct. I still do not get anything from the device 2, that is the first problem; the second problem is, where is the 255 coming from. I sure could use more help on this.
Ray
Ray, look at the TvFavorites package in this thread:
http://forums.parallax.com/forums/default.aspx?f=25&m=361625
It contains TvRemote.spin - the file allows you to acquire a bit-stream from an IR detector and check for matches. The remote I tested was a Sony. The demo would display a set of waveforms and is for the Nokia/Phillips LCD/controller, but can be adapted with some work to other devices.
Not sure if it will be of any help and some of the code is experimental (ignore commented parts in dat section[noparse]:)[/noparse], but it is at least an example that you could study.
PUB getSonyCode(pin, addrMainCode) | irCode, index, pulseWidth, lockID·································
{{·····································································································
·· Decode the Sony TV Remote key code from pulses received by the IR receiver··························
}}·····································································································
·······································································································
·· ' wait for idle period (ir receiver output = 1 for gapMin)··········································
·· ' comment out "auto repeat" code if auto key repeat is desired······································
·······································································································
·· ' start of "auto repeat" code section·······························································
·· dira[noparse][[/noparse]pin]~··························································································
·· index := 0··························································································
·repeat {{DR - added this extra repeat to not let cog die and keep updating addrmaincode}}·············
·· repeat······························································································
···· if ina[noparse][[/noparse]Pin] == 1··················································································
······ index++·························································································
···· else······························································································
······ index := 0······················································································
·· while index < gapMin················································································
·· ' end of "auto repeat" code section·································································
·······································································································
·· byte[noparse][[/noparse]addrMainCode] := 255 {{DR - added this to 0 out addrmaincode when no buttons are pressed}}·····
·· frqa := 1···························································································
·· ctra := 0···························································································
·· dira[noparse][[/noparse]pin]~··························································································
·······································································································
·· ' wait for a start pulse ( width > startBitMin and < startBitMax· )·································
·······································································································
·· repeat······························································································
····· ctra := (%10101 << 26 ) | (PIN)····················· ' accumulate while A = 0····················
····· waitpne(0 << pin, |< Pin, 0)·····································································
····· phsa:=0············································· ' zero width································
····· waitpeq(0 << pin, |< Pin, 0)························ ' start counting····························
····· waitpne(0 << pin, |< Pin, 0)························ ' stop counting·····························
····· pulseWidth := phsa· / (clkfreq / 1_000_000) + 1··················································
·· while ((pulseWidth < startBitMin) OR (pulseWidth > startBitMax))····································
·······································································································
·· ' read in next 12 bits··············································································
·· index := 0··························································································
·· irCode := 0·························································································
·· repeat······························································································
····· ctra := (%10101 << 26 ) | (PIN)····················· ' accumulate while A = 0····················
····· waitpne(0 << pin, |< Pin, 0)·····································································
····· phsa:=0············································· ' zero width································
····· waitpeq(0 << pin, |< Pin, 0)························ ' start counting····························
····· waitpne(0 << pin, |< Pin, 0)························ ' stop counting·····························
····· pulseWidth := phsa· / (clkfreq / 1_000_000) + 1··················································
·······································································································
··· if (pulseWidth > oneBitMin) AND (pulseWidth < oneBitMax)···········································
······ irCode := irCode + (1 << index)·································································
··· index++····························································································
·· while index < 11····················································································
·······································································································
·· irCode := irCode & $7f·································· ' mask off upper 5 bits····················
·······································································································
·· byte[noparse][[/noparse]addrMainCode] := irCode········································································
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
Thanks.
Ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
Thanks
Ray
Edit - then use the new variables to do the decision making, branching etc, not sure what you want to do so take a look at the example using your E_IR_Remote routine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
Post Edited (ratronic) : 2/28/2010 11:30:33 PM GMT
I hope this is working for everybody else, it's just a matter of time before I get it working correctly for me. I guess the official name for this object will be E_IR_Remote.spin, somewhere down the line I might come up with some other little feature to add.
Ray
Edit - only using a cog on demand with your E_IR_Remote routine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
Post Edited (ratronic) : 3/1/2010 1:12:02 PM GMT
Thanks again
Ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
I'd never envisaged project files to be portable, so it's not likely it will work on other peoples system. The reason for that is the paths for the files in the project file are stored as absolute paths. I will now re-think that decision.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
Ray
Translating the signal into timing table and string already works.
A TSOP is just as easy to handle as a IR receiving diode. It already filters out the carrier signal. What's your setup? Is the code above taking care of the carrier signal? Is your receiver a 2 pin IR diode or is it a 3 pin receiver?
Ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
The TvFavorites project with works great for simple remotes - See video www.youtube.com/watch?v=YalcMqkdHEU
The more complicated ATT U-verse remote seems to have a mind of it's own ... the code bit-stream changes every time for the same button although it is similar each time. All other remotes I've tried had simple bit-streams for each button.
The OBEX remote code provides different schemes it seems, so that is helpful if you have a big EEPROM or other media for program storage. I guess if you make an A/V (audio/video) IR related product, the limits should be clearly understood and stated for the consumer.
Have a look at this:
-- http://obex.parallax.com/objects/477/
This object (with demo program) decodes SIRCS signals and reports the number of bits. This is important as TV remotes use 12-bit codes and DVD remotes use 20-bit codes (my Sony SLR's remote also sends 20-bit codes). Knowing the number of bits in the code lets you pull the device code and key code properly.
I even wrote about this in my "Spin Zone" column:
-- http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp4.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Ray