Author Topic: LG LCD Template  (Read 15408 times)

ladekribs

  • Veteran
  • ***
  • Posts: 83
    • View Profile
Re: LG LCD Template
« Reply #15 on: October 04, 2010, 09:00:50 am »
Hi Barney,

how does Your #313 Set Volume look like now?
I get errors when using it.

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #16 on: October 04, 2010, 05:35:16 pm »
<removed link> please see solution further down the thread:
http://forum.linuxmce.org/index.php?topic=9729.msg74457#msg74457

From memory you need to change the device id number on line 10 to your LG device id. I think I changed it in around 4 places in total on the template.

Also, check for a space in the 'ilevel.to_s' reference on line 10. I had a space after the dot (period) which broke mine.

My volume leap from 9 to 16 must be to do with the #313 script. There is a 64% reduction which works on values less than 10 but not above. Still trying to figure it out.

Barney

<edit>That space is also in the wiki referenced in post 1 of this thread. I have just removed that space in the wiki article.</edit>
« Last Edit: October 11, 2010, 10:04:52 pm by b4rney »

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #17 on: October 05, 2010, 12:22:00 am »
Got a bit further. It seems the LG is expecting a hex value but we are sending decimal.
09 hex = 09 dec
10 hex = 16 dec

Now learning ruby syntax.
Barney

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #18 on: October 05, 2010, 01:48:44 am »
OK fixed the dec to hex problem. Here is #313 set volume:
Barney
Code: [Select]
@volume=level.to_i()
ilevel = (@volume).to_i
print "setting volume to ", ilevel , "\n"

if ilevel <16
  SendCommand("kf 01 0" + "%x" % ilevel,1000,4)
else
  SendCommand("kf 01 " + "%x" % ilevel,1000,4)
end
SetDeviceDataInDB( device_.devid_,device_.devid_.to_i , ilevel.to_s) # 120 = DEVICEDATA_Volume_Level_CONST
print "volume and corresponding device data set\n"

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #19 on: October 05, 2010, 01:52:05 am »
Looks like all we need to do to fix the template is replace the hard-coded device ids with:
Code: [Select]
device_.devid_.to_i
Can someone confirm this? My brain is fried.
Barney

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5495
  • DOES work for LinuxMCE.
    • View Profile
Re: LG LCD Template
« Reply #20 on: October 08, 2010, 07:51:47 am »
correct.

-Thom

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #21 on: October 08, 2010, 01:24:47 pm »
Thanks Thom,

OK, if anyone wants to test my working LG TV template please follow these steps.

1. Ensure that your LG TV has the same commands as device template 2126. Check your manual. As far as I can see (looking at recent LG manuals) most LGs share mostly the same RS232 commands.

2. Change the Plug and Play script  on your MD in /usr/pluto/pnp/20_LG_TV.sh to point to device template 2126. It should look like this.
Code: [Select]
#!/bin/bash

echo "LG TV Detection script queue $2"
/usr/pluto/bin/TestSerialPort -p $3 -P N81 -b 9600 -t "ka 01 01\r\n" -s "a 01 " -i 8

if [[ "$?" -ne 0 ]]; then
echo "It's not a LG TV"
/usr/pluto/bin/MessageSend dcerouter -r 0 $1 1 806 224 $2 13 "$4" 44 0
else
echo "It is an LG TV"
/usr/pluto/bin/MessageSend dcerouter -r 0 $1 1 806 224 $2 13 "$4" 44 2126
fi
Note! This is where we can add support for different models later. We can issue model specific commands and if we get a good ack we point to the relevant template, if not try the next one etc.

3. In Web Admin go to Advanced > Configuration > Device Templates. Select LG in the first box and 'apply filter' then find '37LH30 RS232' in the 'Device Template' box (or type 2126 in the bottom box and type 'GO'). Then click 'Pick Device Template'.

4. A new window will open. Near the top click 'Edit Ruby Codes'.

5. Another window will open with the codes.

6. Go to the inputs section. There are lots of different inputs (hdmi 1, hdmi2, AV1 etc). Change all the input commands from 'kb' to 'xb'. Check your manual to confirm this.

7. Go to #355 Process Initialize and copy and paste this:
Code: [Select]
# Initialize --- Date: 28.02.2008
# the docs are wrong.  they say responses are terminated with a \r.  In reality some sets do, others don't.
# some sets won't respond to ka 01 ff when the tv is off.  others do.
@mute = false;

# unfortunately we have to turn the device on if it's off to know that it's alive or else it won't respond to anything
@input=-1
for iRetry in 0...4
    print "Initializing unit\n"
# Query the current volume level
    conn_.Send("kf 1 ff\r")
    # wait 4 seconds for the status command, which won't work if the tv is off
    $buf = conn_.RecvDelimited("x", 4000)
    if( !$buf.nil? && !$buf.index("01 OK").nil? )
        print "Initialized ok - tv is on\n"
        # Use the returned response to set the volume
x = $buf.index("OK")
volume_level =$buf[x+2,2].to_i(16)
print "Setting volume to ", volume_level, "\n"
cmd_313(volume_level)
        return
    end
    print "TV is either off or not connected\n"

# try turning it on
    conn_.Send("ka 1 01\r")
    # wait 10 seconds for the TV to respond
sleep(10)
# Query the current volume level
    conn_.Send("kf 1 ff\r")
    # wait 4 seconds for the status command, which won't work if the tv is off
    $buf = conn_.RecvDelimited("x", 4000)
    if( !$buf.nil? && !$buf.index("01 OK").nil? )
        print "Initialized ok - tv was off\n"
        # Use the returned response to set the volume
x = $buf.index("OK")
volume_level =$buf[x+2,2].to_i(16)
print "Setting volume to ", volume_level, "\n"
cmd_313(volume_level)
# Turn TV off again
    conn_.Send("ka 1 00\r")
        return
    end

    print "TV is not connected\n"

    sleep(1)
end

#DisableDevice( device_.devid_, true )
print "The device wouldn't respond. Disabling it.\n"

8. Go to #313 Set Volume and copy and paste this.
Code: [Select]
@volume=level.to_i()
ilevel = (@volume).to_i
print "setting volume to ", ilevel , "\n"

if ilevel <16
  SendCommand("kf 01 0" + "%x" % ilevel,1000,4)
else
  SendCommand("kf 01 " + "%x" % ilevel,1000,4)
end
SetDeviceDataInDB( device_.devid_,device_.devid_.to_i , ilevel.to_s)
print "volume and corresponding device data set\n"

9. At the bottom of the page click 'Update'

10. Do a quick reload router. Or even a full reboot (can't remember what I did). The LG TV should be autodetected and you should be presented with the setup wizard to confirm the device and select your inputs etc

11. Come back here and let me know if it works.

Good luck,
Barney
« Last Edit: October 12, 2010, 02:13:16 pm by b4rney »

ladekribs

  • Veteran
  • ***
  • Posts: 83
    • View Profile
Re: LG LCD Template
« Reply #22 on: October 08, 2010, 05:29:20 pm »
Hi barney,

I made a short test before leaving, on my own template using your cmd 313 and 355, but I get errors after about 30 seconds:

Code: [Select]
05 10/08/10 17:23:56.542 GSDMessageTranslator isCmdImplemented = true <0xb5effb90>
05 10/08/10 17:23:56.542 #### Pre-Process Queue = 1 <0xb5effb90>
05 10/08/10 17:23:56.586 _QueueProc Pre - 89 : 0 <0xb7828b90>
05 10/08/10 17:23:56.586 GSD-Sleep Pre 89 : 0 <0xb7828b90>
05 10/08/10 17:23:56.586 Process Queue = 1 <0xb7828b90>
05 10/08/10 17:23:56.586 Parameter:  <0xb56feb90>
01 10/08/10 17:23:56.586 Error while calling method: Cannot call class method: cmd_89
error: undefined method `+' for nil:NilClass, line: 24
backtrace:
in: (eval): 24
from (eval):24:in `cmd_89'
from (eval):31
 <0xb56feb90>
01 10/08/10 17:23:56.586 For obscure reasons could not handle the message <0xb56feb90>
05 10/08/10 17:23:56.843 GSD-Sleep Post 89 : 250 <0xb7828b90>
05 10/08/10 17:23:56.843 _QueueProc Post - 89 : 250 <0xb7828b90>
05 10/08/10 17:24:02.359 GSDMessageTranslator isCmdImplemented = true <0xb5effb90>
05 10/08/10 17:24:02.360 #### Pre-Process Queue = 1 <0xb5effb90>
05 10/08/10 17:24:02.397 _QueueProc Pre - 90 : 0 <0xb7828b90>
05 10/08/10 17:24:02.397 GSD-Sleep Pre 90 : 0 <0xb7828b90>
05 10/08/10 17:24:02.397 Process Queue = 1 <0xb7828b90>
05 10/08/10 17:24:02.418 Parameter:  <0xb56feb90>
01 10/08/10 17:24:02.419 Error while calling method: Cannot call class method: cmd_90
error: undefined method `-' for nil:NilClass, line: 31
backtrace:
in: (eval): 31
from (eval):31:in `cmd_90'
from (eval):24
 <0xb56feb90>
01 10/08/10 17:24:02.419 For obscure reasons could not handle the message <0xb56feb90>
05 10/08/10 17:24:02.667 GSD-Sleep Post 90 : 250 <0xb7828b90>
05 10/08/10 17:24:02.668 _QueueProc Post - 90 : 250 <0xb7828b90>

do I have other faults in the template?


BR Stefan

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #23 on: October 08, 2010, 06:04:46 pm »
Stefan,

Here is my vol up and vol down, in case yours is different.
#89
Code: [Select]
print "raising volume from ", @volume, "\n"
cmd_313(@volume+1)
Vol Down
#90
Code: [Select]
print "raising volume from ", @volume, "\n"
cmd_313(@volume-1)

ladekribs

  • Veteran
  • ***
  • Posts: 83
    • View Profile
Re: LG LCD Template
« Reply #24 on: October 09, 2010, 11:47:40 am »
Barney,

no they are the same, I will try to test Your 313 and 355 on template 37LH30 with my TV on tuesday, when back in place


BR Stefan

huh

  • Guru
  • ****
  • Posts: 235
    • View Profile
Re: LG LCD Template
« Reply #25 on: October 10, 2010, 06:40:38 am »
Barney-

Sorry for the late response- I have been trying to get this going on my 32LH40 but to no avail.  My codes are different, but the one for on and off are as listed in the ruby code. 

I know my serial to usb adapter works- I have a denon receiver that is plug and play and works great.

When I plug in the adapter with the LG TV- the detection script runs and the first time I think it detected the LG tv because I saw the message about it having finished the installation of software.  That said, Sarah did not prompt me to pick a room and the TV does not show up as a device.

I am still playing with the testserialport to make sure the correct signals are being sent.

Thanks

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #26 on: October 10, 2010, 01:22:54 pm »
Huh,

Doesn't sound like your LG is being detected.

I also have a Denon (2310) which works using my USB to RS232 adapter with no additional cables. However I need a cable between the Adapter (male rs232) and the LG TV as it requires a female connector. I'm not sure if I'm using a null modem (crossover) cable or a straight through cable.

I know that if you use the wrong connector it will still run the pnp script but fail to detect it.

I just downloaded the manual for the 32LH40 and the codes look almost identical. Which codes are you referring to?

Which template are you looking at (should be 2126)?

Barney

huh

  • Guru
  • ****
  • Posts: 235
    • View Profile
Re: LG LCD Template
« Reply #27 on: October 11, 2010, 01:27:21 am »
I agree- don't think it is being discovered.  My Denon receiver has a female connection- my usb to serial adapter has a male connection- so these two fit without a gender changer.

The LG tv, however also has a male connector, so I have a couple female/female adapters (not a cable- just a gender changer) that I use between my usb-to-serial and the tv.  I used the same usb-to-serial adapter that works on my denon receiver to connect the tv- but as just discussed, I have the gender changer in place.  I find it hard to believe that the coupler changes the wiring structure- I would guess it is just straight through, but no guarantees.

The manual says that I need to "use a crossed (reverse) cable".  So maybe I need a crossed cable to get it to work....  don't know.

Right now trying to get the TV to respond to a command....  I think I need a different cable.


Yep...   just looked at the AVR-2807 and it looks like it requires a straight through cable, the LG TV needs a null modem/cross over cable.  Have one shipping from CA- will post when I get it and can try again.
« Last Edit: October 11, 2010, 01:59:39 am by huh »

b4rney

  • Guru
  • ****
  • Posts: 454
    • View Profile
Re: LG LCD Template
« Reply #28 on: October 11, 2010, 02:00:23 am »
Very cheap on ebay. I'm buying one of each to test.

Weird thing is I've just received a null modem cable which doesn't work with my usb adapter. So now I don't know if I'm using a null modem usb>RS232 connector. But I also have those gender changes. They don't work either!!

My only working configuration is with an unknown female to female connector.
I'm not helping am I
 ;)
Barney

huh

  • Guru
  • ****
  • Posts: 235
    • View Profile
Re: LG LCD Template
« Reply #29 on: October 11, 2010, 02:32:56 am »
On the contrary- knowing the code works is half the battle  :)

I was misreading the code to acknowledge that the LG tv was a LG tv. 

This part:
/usr/pluto/bin/TestSerialPort -p /dev/ttyS0 -P N81 -b 9600 -t "ka 1 01\r\n" -s "a 01 " -i 8


Where I have inserted my serial port so I could manually run from a command line rather than the $3 (IIRC) that was originally in its place.