View difference between Paste ID: 0zmg4chN and VhqtdmMd
SHOW: | | - or go back to the newest paste.
1-
# Raspberry Pi Filesystem Activity LED indicator
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.04 #length of time between activity checks
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-
#GPIO.output(hddled, activity)
22+
increment = 2
23
rampingIncrement = 4
24-
while (True):
24+
25-
	newact = psutil.disk_io_counters()
25+
26-
	GPIO.output(hddled, ((newact.read_count > oldact.read_count) or (newact.write_count > oldact.write_count)))
26+
led = GPIO.PWM(hddled,100)
27-
	oldact = newact
27+
value = 0
28-
	time.sleep(sleepTime)
28+
lastValue = 0
29
led.start(value)
30-
GPIO.cleanup()
30+
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()