View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 1 post ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sun Oct 21, 2007 1:27 am 
Offline
Joined: Sat Feb 03, 2007 12:52 am
Posts: 187
Location: Manitoba, Canada
Hi. I had a problem with people changing the channel on the satellite box mid recording so was looking for a way to indicate recorder status. This thread got me started, http://mysettopbox.tv/phpBB2/viewtopic.php?t=12786, but my only serial port is tied up with my IR blaster/receiver and didn’t want to break that. I have one of these relay cards that got me familiar with the parallel port hardware so thought I’d try that. I also added an LED to show commflaging. I posted all the steps I took, I find it easier to learn new stuff if I see where it came from rather than a step by step drunk monkey approach (although those are nice too)

I robbed +5V from unused hard drive connector, ran through 470ohm resistor to limit current, different colored LEDs, and connect to pins 2 – 9.
Code:
apt-get install python-parallel

edited /usr/bin/recstat.py as follows:
Code:
#!/usr/bin/python

import httplib
import parallel
import 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"
commflag = "<font class=\"jobrunning\">Flag Commercials</font>"

p = parallel.Parallel() #opens LPT1
p.setData(0) #turn off all lights

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

   if (results.find(encoder1+recording)!=-1):
      total = total + 1
   elif (results.find(encoder1+watching)!=-1):
      total = total + 1
   elif (results.find(encoder2+recording)!=-1):
      total = total + 2
   elif (results.find(encoder2+watching)!=-1):
      total = total + 2
   elif(results.find(commflag)!=-1):
       total = total + 4

   p.setData(total)
   time.sleep(60)

the first time I ran it it complained about /dev/parport0 not existing so
Code:
mknod /dev/parport0 c 99 0
chown root:lp /dev/parport0

The above script ran fine (turned lights on and off) but I noticed that while watching live tv or recorded tv, about every minute the video would stutter. I stopped the script and it went away. I tried modifying thornsoft’s babysitt_commflag script to renice to 19 but that didn’t help at all. I found that I coud duplicate the stuttering by hitting refresh on the mythweb/status page in the browser on my laptop while watching videos on my mythbox. So I started looking for a new way to determine encoder status. I found that the inuseprograms table in mythconverg tells me when stuff is recording. Modified again as follows:
Code:
#!/usr/bin/python

import parallel
import time
import MySQLdb

#Connect to mythconverg
db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="mythconverg")
cursor = db.cursor()

p = parallel.Parallel() #opens LPT1
p.setData(0) #turn off all lights  TODO: find current state on pins so other pins can be used for other things

while(True):
   total = 0
   #select data only if recording or flagging on localhost
   cursor.execute("SELECT chanid,recusage FROM inuseprograms WHERE (recusage = 'recorder' AND hostname = 'machinehostname') OR (recusage = 'flagger' AND hostname = 'machinehostname')")
   results = cursor.fetchall()

   for record in results:
       if record[1] == 'flagger':
           total = total + 4  # TODO: math to determine if pin is already on or not
       elif (record[0] / 1000) == 1: #encoder 1
           total = total + 1
       elif (record[0] / 1000) == 2: #encoder 2
           total = toatl + 2
   p.setData(total)  #turn on lights  TODO: math to turn on LED’s without affecting other pins
   time.sleep(30)

This script seems to work better (no stuttering). Start and stop using
Code:
/etc/init.d/recstat {start|stop|restart|force-reload}

There are a few things I’d like to change but not sure how at this point. Will keep working on it unless one of you gurus wants to fill me in. I only have one encoder right now but hope to add later. My channels show up as 1505 for 505 so assuming that the 1 would be encoder 1 and if I had a second encoder it would be 2505. I divided 1000 or 2000 to determine encoder. Tried '^1' instead but it didn’t seem to like that. Also if I had 2 flagger instances running it would add again and give me a wrong value.

Anyways…Enjoy. Warren.

And of course…Disclaimer. Mechanic by trade with no formal computer training. New to linux and knoppmyth. Started with R5E50 now running R5F27. First time ever using python.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 8 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:  
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu