Problem with Spin case statement
In the 'main', the 'repeat' statement has a 'case' statement which is not working as expected, and I cannot figure out why. What I expect to occur is when I select the device 'tv', I only should get an LED activity on the power btn, but I am also getting an LED activity on the 'r arrow head' btn, which should only become active when the device is set to 'vcr'. I double checked my 'indents', and they seem to be in the correct position, so what is wrong with this?
Thanks
Ray
Thanks
Ray
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
con
' PST formmatting control
#1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS
obj
ir : "jm_sircs_rx" ' sircs decoding
term : "jm_txserial" ' tx serial
misc : "tools"
pub main | code, bc, devcode, keycode
ir.init(0)
''ir.init(27) ' IR demod on p27
term.init(30, 115_200) ' term on programming port
misc.waitms(1000)
repeat
code := ir.getir
devcode := code & $f80
keycode := code & $7f ' wait for key
bc := ir.bitcount ' get bitcount
''case bc
''12:
case devcode
%000010000000 : ''device tv
showcode(devcode) ''devcode = %000010000000
case keycode
%000000010101 : ''Power key
LED1
term.bin(devcode, 12)
term.tx(CR)
term.bin(keycode, 12)
term.tx(CR)
%010110000000 : ''device vcr
showcode(devcode) ''devcode = %010110000000
case keycode
%000000011010 : ''r arrow head
LED1
term.bin(devcode, 12)
term.tx(CR)
term.bin(keycode, 12)
term.tx(CR)
misc.waitms(400)
devcode := 0
keycode := 0
PRI tv_power
LED1
PRI vcr_r_a_head
LED1
PRI showcode(devcode)
term.bin(devcode, 12)
term.tx(CR)
PRI LED1
misc.high(1)
misc.waitms(250)
misc.low(1)

Comments
repeat code := ir.getir devcode := code & $f80 keycode := code & $7f ' wait for key bc := ir.bitcount ' get bitcount if (ir.bitcount == 12) ' tv code case keycode %0010101 : LED1 other : LED2 term.bin(devcode, 5) else case keycode %0011010 : LED1 other : LED2 term.bin(devcode, 13) term.tx(".") term.bin(keycode, 7)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
case code '' codes for tv start with %00001_ %00001_0010101 : ''device tv showcode(code>>7) '' get rid of the key-code-part LED1 term.bin(code>>7, 12) term.tx(CR) term.bin(code & $7f, 12) term.tx(CR) '' codes for vcr start with %01011_ %01011_0011010 : ''device vcr showcode(code>>7) '' LED1 term.bin(code>>7, 12) term.tx(CR) term.bin(code & $7f, 12) term.tx(CR)Post Edited (MagIO2) : 3/3/2010 2:21:48 PM GMT
This investigation started with the fact that I was not certain as to what variable value 'devcode := (code & $f80) >> 7' was providing. So, I borrowed some of JonnyMac's code to find out exactly what the values are, since I am certain that his program is providing the correct values. The first thing I noticed was that devcode = 0, when I used 'devcode := (code & $f80) >> 7', I changed it to 'devcode := code & $f80' which is now providing the type of value that I was expecting.
The thing that has me a bit flustered is that in the program above, I have applied some sensible logic IMO, but the outcome is not what I am expecting. So, now I have to figure out what part of my logic is not translating to the programs functionality, to provide the correct outcome; using the saying of "garbage in, garbage out", it must BE MY FAULT. I think this is going to take awhile ...
Ray
Ray
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 con ' PST formmatting control #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS obj ir : "jm_sircs_rx" ' sircs decoding term : "jm_txserial" ' tx serial misc : "tools" pub main | code, bc, devcode, keycode ir.init(0) ''ir.init(27) ' IR demod on p27 term.init(30, 115_200) ' term on programming port misc.waitms(1000) repeat code := ir.getir devcode := code & $f80 keycode := code & $7f ' wait for key ''bc := ir.bitcount ' get bitcount ''case bc ''12: case code %000010010101 : ''device tv showcode(code) ''devcode = %000010000000 ''case keycode '' %000000010101 : ''Power key LED1 term.bin(devcode, 12) term.tx(CR) term.bin(keycode, 12) term.tx(CR) %010110011010 : ''device vcr showcode(code) ''devcode = %010110000000 ''case keycode ''%000000011010 : ''r arrow head LED1 term.bin(devcode, 12) term.tx(CR) term.bin(keycode, 12) term.tx(CR) misc.waitms(400) PRI tv_power LED1 PRI vcr_r_a_head LED1 PRI showcode(devcode) term.bin(devcode, 12) term.tx(CR) PRI LED1 misc.high(1) misc.waitms(250) misc.low(1)But I can't believe what you say about the devcode:
assume code is $00001_0010101
then code & $f80 (which is %11111_0000000) will give you %00001_0000000
and %00001_0000000 >> 7 is %00001
I ran across a bit of information on the codes that is new to me:
The 15-bit code is a wired code; the device code is eight bits, the key code is seven bits. The 20-bit code is 8 + 12 (not confirmed yet). Based on that you might do something like this:
raw := ir.getir bc := ir.bitcount case bc 12: keycode := raw & $3F devcode := (raw >> 7) & $1F extcode := 0 15: keycode := raw & $3F devcode := (raw >> 7) & $FF extcode := 0 20: keycode := raw & $3F devcode := (raw >> 7) & $1F extcode := (raw >> 12) & $FFWith this structure you've got the constituent parts of the code that just came in and it might be easier to work with.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA