123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- !#/usr/bin/python
- import RPi.GPIO as GPIO # import RPi.GPIO module
- import time
- import os
- GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
- GPIO.setup(23, GPIO.OUT) # set a port/pin as an output
- GPIO.setup(24, GPIO.IN) # set a port/pin as an input
- printer_state = GPIO.input(24)
- if printer_state = 0: #printer on
- print "Printer state is on, state =", printer_state
-
- else:
- while printer_state != 0: #while printer is off
- printer_state = GPIO.input(24)
- GPIO.output(23, 1) #Turn on printer
- time.sleep(30)
- print "Done resting"
- qstate = 0 ##initialize queue as empty
- mystring = "none" ##initialize mystring
- while qstate != 0:
- if mystring.find("no entries"): ## Check for print jobs
- qstate = 0 ##queue is empty
- print "queue state is:", qstate
- else:
- os.popen('lpc restart') ## Restart print queue if needed
- print "Passed qstate test" ## print qstate ##qstate is 1 for jobs in queue and 0 for queue empty
- ## Turn off printer
- ## Check if successful, if not, send signal again to power off.
- while printer_state != 1: #1 equals off
- printer_state = GPIO.input(24)
- GPIO.output(23, 0) #Turn printer off
- GPIO.cleanup()
|