Advertisement
pyroxide

Raspberry Pi Filesystem Activity Fading LED indicator

Jan 5th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Raspberry Pi Filesystem Activity Fading LED indicator
  2. # by pyroxide (pyroxi.de)
  3. #
  4. # RPi.GPIO as well as psutil is required
  5. #
  6. # Both may be installed using pip:
  7. # $ sudo pip install RPi.GPIO
  8. # $ sudo pip install psutil
  9. #
  10. # or manually:
  11. # RPi.GPIO: https://aur.archlinux.org/packages/python-raspberry-gpio/
  12. # psutil: https://pypi.python.org/pypi/psutil/#downloads
  13. import RPi.GPIO as GPIO
  14. import time, psutil
  15.  
  16. GPIO.setmode(GPIO.BCM)
  17. GPIO.setwarnings(False)
  18.  
  19. sleepTime = 0.01 #length of time between activity checks
  20. hddled = 3 # hdd activity led GPIO pin number
  21. dbg = True # debug messages
  22. increment = 2
  23. rampingIncrement = 4
  24.  
  25. GPIO.setup(hddled, GPIO.OUT)
  26. led = GPIO.PWM(hddled,100)
  27. value = 0
  28. lastValue = 0
  29. led.start(value)
  30. oldact = psutil.disk_io_counters()
  31. ramping = False
  32. try:
  33.     while (True):
  34.         newact = psutil.disk_io_counters()
  35.         if (ramping):
  36.             value += rampingIncrement
  37.             ramping = (value < 100)
  38.             if ((dbg) and (not ramping)):
  39.                 print("ramping=",ramping)
  40.         elif ((newact.read_count > oldact.read_count) or (newact.write_count > oldact.write_count)):
  41.             value = 24
  42.             ramping = True
  43.             if (dbg):
  44.                 print("ramping=",ramping)
  45.         else:
  46.             value = max(0,value-increment)
  47.         led.ChangeDutyCycle(max(min(value,100),0))
  48.         if ((dbg) and (value != lastValue)):
  49.             print("value=",value)
  50.         oldact = newact
  51.         time.sleep(sleepTime)
  52.  
  53. except KeyboardInterrupt:
  54.     led.stop()
  55.     GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement