Python TSR

5 views
Skip to first unread message

Leslie Rhorer

unread,
Jul 1, 2016, 2:20:24 AM7/1/16
to TuPLE...@googlegroups.com
I need a little coaching.  I know virtually nothing of Python, so please be specific.

I've managed to cobble together a little simple code that does mostly what I want, but I haven't figured out how to finish the code.  Essentially, what I want is a TSR, of sorts.  All I want to do is run the code at startup which looks for one of two I/O interrupts.  I want the main code to go to sleep permanently, or better yet unload itself entirely, leaving only the two interrupt service threads running.  Here is what I have so far:

#!/usr/bin/env python2.7
#
#
import RPi.GPIO as GPIO
import sys
import os, commands
import subprocess

GPIO.setmode(GPIO.BCM)

# GPIO 23 & 24 set up as inputs, pulled up to avoid false detection.
# Both ports are wired to connect to GND on button press.
# So we'll be setting up falling edge detection for both
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# now we'll define two threaded callback functions
# these will run in another thread when our events are detected

def my_callback1(channel):
#   Waiting for Snooze Bar
    subprocess.call("sudo -u lrhorer /home/lrhorer/AlarmClock/Snooze",shell=True)

def my_callback2(channel):
#   Waiting for Toggle Button
    subprocess.call("sudo -u lrhorer /home/lrhorer/AlarmClock/Toggle",shell=True)

GPIO.add_event_detect(23, GPIO.FALLING, callback=my_callback1, bouncetime=300)
GPIO.add_event_detect(24, GPIO.FALLING, callback=my_callback2, bouncetime=300)



So how do I finish up the code?
Reply all
Reply to author
Forward
0 new messages