View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 28 posts ] 
Go to page 1, 2  Next

Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Thu Nov 30, 2006 3:55 am 
Offline
Joined: Tue Jan 24, 2006 1:29 am
Posts: 157
Location: Brisbane, Australia
I have just finished getting a serial port based encoder status LED script working under R5D1

I started with these instructions:
http://www.mythtv.org/wiki/index.php/Us ... ing_Status

Instead of using the power and HDD LEDs in the front of my case, i made up a panel with 2 extra LEDs in a space that used to house front USB ports.

I started with the second version of the script, which uses the http status page output to determine encoder status. In its original form it would only show recording activity, I wanted it to indicate LiveTV useage aswell so i modified the script as below. Also note I am using Com2 instead of Com1 (internal hearder - no messy cables outside the case) and have modified the script to suit.

/usr/bin/recstat.py

Code:
#!/usr/bin/python

import httplib
import serial,time

mythStatus = "localhost:6544"
encoder1 = "Encoder 1 "
encoder2 = "Encoder 2 "
recording = "is local on mythtv and is recording"
watching = "is local on mythtv and is watching"

#Open COM2
s = serial.Serial(1)
#Turn off all lights
s.setDTR(0)
s.setRTS(0)

while(True):
   conn = httplib.HTTPConnection(mythStatus)
   conn.request("GET", "/")
   r1 = conn.getresponse()
   results = r1.read()

   if(results.find(encoder1+recording)!=-1):
      s.setDTR(1)
   elif (results.find(encoder1+watching) !=-1):
      s.setDTR(1)
   else:
      s.setDTR(0)

   if(results.find(encoder2+recording)!=-1):
      s.setRTS(1)
   elif (results.find(encoder2+watching) !=-1):
      s.setRTS(1)
   else:
      s.setRTS(0)

   time.sleep(1)



I have also put together a startup script for KnoppMyth

/etc/init.d/recstat

Code:
#! /bin/sh

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="serial port encoder status script"
NAME=recstat
DAEMON=/usr/bin/$NAME.py
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

#
#       Function that starts the daemon/service.
#
d_start() {
        start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE \
                --exec $DAEMON &
}

#
#       Function that stops the daemon/service.
#
d_stop() {
        kill -9 `cat $PIDFILE`
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
  restart|force-reload)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        sleep 1
        echo "."
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0



Installation is straight forward.

    As root, create /usr/bin/recstat.py and /etc/init.d/recstat as above
    Make any modifications you require to /usr/bin/recstat.py
    chmod +x both of these files.
    update-rc.d recstat defaults 90 will have the script load automatically at bootup (Thanks Cecil!)
    Reboot, or execute /etc/init.d/recstat start and your script will be running.


The original author of the script recommends adjusting the wait comand to 60 seconds, however i wanted mine more responsive and have lowered the wait to 1 second. The result on my P3 1GHz machine is 0.3% CPU useage once per second, with a 0.8% RAM footprint (512MB system RAM)

To avoid possible damage to your serial port, I recommend using a resistor in series with your LEDs. I am using 680ohm as i had some lying around, but anything around 1Kohm will be fine.

The finished product:

Image


Image


Last edited by soundoff on Fri Dec 15, 2006 6:26 am, edited 4 times in total.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 6:12 am 
Offline
Joined: Mon May 10, 2004 8:08 pm
Posts: 1891
Location: Adelaide, Australia
I have a friend who runs Windows on his PVR. The software he uses indicates tuner status with keyboard leds. I wonder how easy that would be to implement with mythtv.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 4:22 pm 
Offline
Joined: Tue Jan 24, 2006 1:29 am
Posts: 157
Location: Brisbane, Australia
Easy, but i figure this mod is most useful for a backend system, which would be unlikely to have a keyboard attached. Thats not to say you couldnt rip the controller out of an old keyboard and use it as your interface

If you do want to go the keyboard route, start with this.

http://martybugs.net/smoothwall/leds.cgi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 12:50 am 
Offline
Joined: Tue Mar 22, 2005 9:18 pm
Posts: 1422
Location: Brisbane, Queensland, Australia
In line with this theory, could it be implmented to have the status on the screen. As in my case the computer is behind the TV unit and I think it would be OK to have the status displayed on the menu screen when you turned on the TV.

I realise that this is a slightly different implementation but just some food for thought.

Great idea soundoff.

_________________
Girkers


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 02, 2006 8:40 am 
Offline
Joined: Thu Feb 23, 2006 8:18 am
Posts: 9
soundoff wrote:
Easy, but i figure this mod is most useful for a backend system, which would be unlikely to have a keyboard attached. Thats not to say you couldnt rip the controller out of an old keyboard and use it as your interface

If you do want to go the keyboard route, start with this.

http://martybugs.net/smoothwall/leds.cgi


One of the many open source projects that I have on the backburner was doing this. Basically, I ripped the notification daemon apart so that it was only interested in capture events. Then I attached it to an led flashing library I found on the net. I even borrowed a wireless keyboard adapter with keyboard status lights on it.

However, I found out 0.20 was on the threshold of being released, I had another issue with running out of inodes on my dev machine, and I haven't touched it since.

I was also concerned that whenever I attached the curses client the machine would crash. But that seemed like someone else's problem.

The other problem is it was an either/or choice - you could use a VFD or the flashing lights.

I also think, however, having it on the screen would be brilliant.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 02, 2006 4:13 pm 
Offline
Joined: Wed Aug 23, 2006 3:07 pm
Posts: 339
Soundoff, no one has actually said it, so I will.

This is very cool!

I want to try it now.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 02, 2006 4:59 pm 
Offline
Joined: Fri Sep 19, 2003 7:05 pm
Posts: 5088
Location: Fontana, Ca
I've added the scripts into the next release. Thanks for contributing! :D

_________________
cesman

When the source is open, the possibilities are endless!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 02, 2006 6:18 pm 
Offline
Joined: Tue Jan 24, 2006 1:29 am
Posts: 157
Location: Brisbane, Australia
whoa! cesman thankyou very much. Im reasonably new to linux i didnt think i would have a script included in knoppmyth!!

Before you do though i need some help with my startup script. I have cleaned it up a bit and made a few small changes (see above) however it doesnt seem to load the script when my system boots.

Code:
update-rc.d recstat defaults


Says it has successfully added the script to the appropriate directories. Being a python script, is there some dependencies that have to be loaded before this script is called? I am thinking that the order of things being loaded at startup is the problem here.

start / stop / restart the script manually all works fine:

Code:
root@mythtv:~# /etc/init.d/recstat start
Starting serial port encoder status script: recstat.


Can anyone help me out here with why the script isnt starting automatically during boot?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 2:35 pm 
Offline
Joined: Mon Aug 29, 2005 4:04 pm
Posts: 729
Location: Philadelphia, PA US
Girkers wrote:
could it be implmented to have the status on the screen. As in my case the computer is behind the TV unit and I think it would be OK to have the status displayed on the menu screen when you turned on the TV.


What about the feh command or xosd ? I think feh is included out of the box in KnoppMyth R5C7. Seem to recall feh could display a graphic on top of mythfrontend, and xosd can output text in different screen areas in different colors. (I use xosd for my callerID on KM).

I don't think mythnotify would work well as only works when Internal player is being used. With feh or xosd could be in MythMusic and have an OSD showing recording happening.

http://www.die.net/doc/linux/man/man1/feh.1.html

http://freshmeat.net/projects/xosd/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 12:11 pm 
Offline
Site Admin
Joined: Fri Sep 19, 2003 6:37 pm
Posts: 2659
Location: Whittier, Ca
When in the boot process is recstat set to start? It maybe that you are starting it too earlier.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:35 pm 
Offline
Joined: Tue Jan 24, 2006 1:29 am
Posts: 157
Location: Brisbane, Australia
Thats what i think is happening aswell, however how do i know when its starting? I have tried searching for recstat in dmesg but its not mentioned.

I added the startup script using update-rc.d recstat defaults i dont know where this puts the script in the boot order.

I am only new to linux ;) sorry for the dumb question

edit: do i need to change the runlevels?

man page for update-rc.d:

If defaults is used then update-rc.d will make links to start the service in runlevels 2345 and stop the service in runlevels 016. By default all the links will have sequence code 20,
but this can be overridden by supplying one or two NN arguments; one argument overrides the sequence code for both start and stop links whereas of two arguments the first overrides the
code for start links and the second that for stop links.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 9:59 am 
Offline
Joined: Tue Sep 12, 2006 6:03 am
Posts: 210
Location: Roseville, MI
I finally sat down and implemented the led status lights. They worked like a champ after I figured out my on-board com header pins. Adjusted my time delay to 5 seconds. Running 2 red LED's for the recording, and moved my power led so I can tell the status of my machine from a distance.

Only thing to still figure out is the auto startup problem that has been mentioned.

Thanks for the script.

_________________
-Roseville, Michigan USA
LinHES R8: FE/BE, FE (x2)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 5:18 pm 
Offline
Joined: Tue Jan 24, 2006 1:29 am
Posts: 157
Location: Brisbane, Australia
cool!!

hopefully someone can help out with the startup script, I am out of my depth trying to solve it..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 2:43 am 
Offline
Joined: Fri Sep 19, 2003 7:05 pm
Posts: 5088
Location: Fontana, Ca
Code:
cd /etc
ls rc*/rec*
returns what?

_________________
cesman

When the source is open, the possibilities are endless!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 2:54 am 
Offline
Joined: Tue Jan 24, 2006 1:29 am
Posts: 157
Location: Brisbane, Australia
root@mythtv:/etc# ls rc*/rec*
ls: rc*/rec*: No such file or directory


that seemed weird so i ran
update-rc.d recstat defaults

and again got

root@mythtv:/etc# ls rc*/rec*
ls: rc*/rec*: No such file or directory


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ] 
Go to page 1, 2  Next



All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu