print-service.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. !#/usr/bin/python
  2. import RPi.GPIO as GPIO # import RPi.GPIO module
  3. import time
  4. import os
  5. GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
  6. GPIO.setup(23, GPIO.OUT) # set a port/pin as an output
  7. GPIO.setup(24, GPIO.IN) # set a port/pin as an input
  8. printer_state = GPIO.input(24)
  9. if printer_state = 0: #printer on
  10. print "Printer state is on, state =", printer_state
  11. else:
  12. while printer_state != 0: #while printer is off
  13. printer_state = GPIO.input(24)
  14. GPIO.output(23, 1) #Turn on printer
  15. time.sleep(30)
  16. print "Done resting"
  17. qstate = 0 ##initialize queue as empty
  18. mystring = "none" ##initialize mystring
  19. while qstate != 0:
  20. if mystring.find("no entries"): ## Check for print jobs
  21. qstate = 0 ##queue is empty
  22. print "queue state is:", qstate
  23. else:
  24. os.popen('lpc restart') ## Restart print queue if needed
  25. print "Passed qstate test" ## print qstate ##qstate is 1 for jobs in queue and 0 for queue empty
  26. ## Turn off printer
  27. ## Check if successful, if not, send signal again to power off.
  28. while printer_state != 1: #1 equals off
  29. printer_state = GPIO.input(24)
  30. GPIO.output(23, 0) #Turn printer off
  31. GPIO.cleanup()