-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ACTION=="add", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="27b8", ENV{ID_MODEL_ID}=="01ed", MODE="0660", OWNER="2626", GROUP="598" RUN{program}="/bin/systemctl start blinkd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
from multiprocessing import cpu_count | ||
from re import findall | ||
from subprocess import check_call | ||
from time import sleep | ||
|
||
|
||
def cpu_load(): | ||
with open('/proc/loadavg', 'r') as f: | ||
load = float(f.read().split()[0]) | ||
cores = float(cpu_count()) | ||
return load/cores | ||
exit(1) | ||
|
||
|
||
def free_memory(): | ||
with open('/proc/meminfo', 'r') as f: | ||
meminfo = f.readlines() | ||
mem = float(findall('(\d+) kB', meminfo[0])[0]) | ||
frm = float(findall('(\d+) kB', meminfo[1])[0]) | ||
return 1 - frm / mem | ||
exit(1) | ||
|
||
|
||
def blink(n): | ||
check_call(['blink1-tool', '-t 200', '-m 0', '--blink', str(n), '-q']) | ||
|
||
|
||
def show(p): | ||
if p < 0.2: | ||
check_call(['blink1-tool', '--blue', '-m 0', '-q']) | ||
elif p < 0.4: | ||
check_call(['blink1-tool', '--green', '-m 0', '-q']) | ||
elif p < 0.6: | ||
check_call(['blink1-tool', '--yellow', '-m 0', '-q']) | ||
elif p < 0.8: | ||
check_call(['blink1-tool', '--rgb', 'FF8800', '-m 0', '-q']) | ||
else: | ||
check_call(['blink1-tool', '--red', '-m 0', '-q']) | ||
sleep(5) | ||
|
||
|
||
if __name__ == '__main__': | ||
while True: | ||
blink(5) | ||
load = cpu_load() | ||
show(load) | ||
blink(2) | ||
frm = free_memory() | ||
show(frm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Unit] | ||
Description=blinkd | ||
|
||
[Service] | ||
User=it | ||
Group=edv | ||
ExecStart=/lib/udev/blinkd.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters