Compare commits

4 Commits

Author SHA1 Message Date
1ded64275f Generic cleanup
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-04-01 10:45:25 +02:00
4fe12dfc27 K&R style 2019-04-01 10:40:05 +02:00
98a5539dca Basic code formatting
All checks were successful
continuous-integration/drone/push Build is passing
2019-04-01 10:37:42 +02:00
4243b39b1f Cleanup scripts
All checks were successful
continuous-integration/drone/push Build is passing
2019-04-01 10:31:19 +02:00
7 changed files with 59 additions and 256 deletions

View File

@ -1,3 +1,4 @@
[![Build Status](https://build.jcktrue.dk/api/badges/jct/ledcontroller-3bit/status.svg)](https://build.jcktrue.dk/jct/ledcontroller-3bit)
# ledcontroller-3bit # # ledcontroller-3bit #
A Linux command line utility to control usb mail notifiers identified as: A Linux command line utility to control usb mail notifiers identified as:
@ -27,9 +28,8 @@ For example the script `mled-cputemp` will make it respond to your CPU's tempera
$ sudo rm /usr/bin/ledcontroller $ sudo rm /usr/bin/ledcontroller
### Have fun: ### ### Have fun ###
Take a look inside the _scripts_ directory.
## Requisites: ## ## Requisites: ##

View File

@ -1,12 +1,12 @@
#!/bin/bash #!/bin/bash
REFRESHRATE=1 REFRESHRATE=1
LEDCONTROLLER="/usr/bin/ledcontroller" LEDCONTROLLER="./ledcontroller"
while (true); do while (true); do
for discoColor in blue red green aqua purple yellow white; do for discoColor in blue red green aqua purple yellow white; do
echo Set color $discoColor
$LEDCONTROLLER $discoColor $LEDCONTROLLER $discoColor
sleep "$REFRESHRATE" sleep "$REFRESHRATE"

57
main.c
View File

@ -55,9 +55,10 @@ int main(int argc,char** argv)
{ {
int ret; int ret;
unsigned char code = 0; unsigned char code = 0;
if (argc != 2 ) if (argc != 2) {
{ printf
printf("syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",argv[0]); ("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",
argv[0]);
return -1; return -1;
} }
@ -81,53 +82,37 @@ int main(int argc,char** argv)
1 1 0 yellow 0x6 (more of a mustard - green color) 1 1 0 yellow 0x6 (more of a mustard - green color)
1 1 1 white 0x7 (a very blue-ish white) 1 1 1 white 0x7 (a very blue-ish white)
*/ */
if ( strcmp(argv[1],"blue") == 0 ) if (strcmp(argv[1], "blue") == 0) {
{
code = 1; code = 1;
} } else if (strcmp(argv[1], "red") == 0) {
else if ( strcmp(argv[1],"red") == 0 )
{
code = 2; code = 2;
} } else if (strcmp(argv[1], "green") == 0) {
else if ( strcmp(argv[1],"green") == 0 )
{
code = 3; code = 3;
} } else if (strcmp(argv[1], "aqua") == 0) {
else if ( strcmp(argv[1],"aqua") == 0 )
{
code = 4; code = 4;
} } else if (strcmp(argv[1], "purple") == 0) {
else if ( strcmp(argv[1],"purple") == 0 )
{
code = 5; code = 5;
} } else if (strcmp(argv[1], "yellow") == 0) {
else if ( strcmp(argv[1],"yellow") == 0 )
{
code = 6; code = 6;
} } else if (strcmp(argv[1], "white") == 0) {
else if ( strcmp(argv[1],"white") == 0 )
{
code = 7; code = 7;
} else { } else {
printf("invalid color\n"); puts("Invalid color");
return -1; return -1;
} }
libusb_init(NULL); libusb_init(NULL);
devh = libusb_open_device_with_vid_pid(NULL, VID, PID); devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
if (devh == NULL ) if (devh == NULL) {
{ puts("Device not found");
printf("not found\n");
return -1; return -1;
} }
if ( libusb_kernel_driver_active(devh,0) ) if (libusb_kernel_driver_active(devh, 0)) {
{ puts("Detach driver from kernel");
printf("detach from kernel\n");
ret = libusb_detach_kernel_driver(devh, 0); ret = libusb_detach_kernel_driver(devh, 0);
if (ret < 0 ) if (ret < 0) {
{ puts("Could not detach driver");
printf("can't detach\n");
return -1; return -1;
} }
} }
@ -142,9 +127,9 @@ int main(int argc,char** argv)
int dummy; int dummy;
libusb_claim_interface(devh, 0); libusb_claim_interface(devh, 0);
ret = libusb_interrupt_transfer(devh, 0x2, data, 5, &dummy, 0); ret = libusb_interrupt_transfer(devh, 0x2, data, 5, &dummy, 0);
if ( ret < 0 ) if (ret < 0) {
{ perror("libusb error");
perror("error"); return -1;
} }

View File

@ -1,40 +0,0 @@
# Bash Scripts #
I teared the notifier apart and placed the notifier's board inside my home server.
Due to its size, the RGB LED creates some interesting optical effects if you place it 2-4cm
behind the venting holes.
Here are some simple scripts that use various data to set the LED's color.
## mled-discomode ##
This script simply cycles through all available colors. I called it disco mode due to the optical
phenomena that take place as the light crosses the air vents.
## mled-cputemp ##
This script works really well for my machine. It uses the `sensors` program to get the CPU
temperature.
If the CPU is at or under the low threshold, the LED turns blue. If it is at or above the
high threshold, the LED turns red. If it is in the middle, it gets green.
It is actually very informative for the machine's state. You can easily detect CPU load.
## mled-iowait, mled-iowaitdetailed ##
My home server doesn't have any LEDs for HDD activity, though it has plenty of HDDs.
These two scripts attempt to make up for this shortcoming when I need some quick profiling of the machine.
They actually work better than common HDD activity LEDs because they are based on iowait percentage in one
second periods (adjustable).
`mled-iowait` has 3 levels, so you get only to set a low and a high threshold.
`mled-iowaitdetailed` has 6 levels of activity, so you can set 5 thresholds. Also below the lowest threshold,
it sets the notifier to off, which turns to be a good approach.

View File

@ -1,28 +0,0 @@
#!/bin/bash
LOWTEMP=46
HIGHTEMP=53
REFRESHRATE=1
LEDCONTROLLER="/usr/bin/ledcontroller"
while (true); do
temperature="$(sensors|grep 'id 0'|sed -e 's/\.0.*//' -e 's/.*+//')"
if (( "$temperature" <= "$LOWTEMP" )); then
$LEDCONTROLLER blue;
elif (( "$temperature" < "$HIGHTEMP" )); then
$LEDCONTROLLER green;
else $LEDCONTROLLER red;
fi;
sleep "$REFRESHRATE";
done

View File

@ -1,70 +0,0 @@
#!/bin/bash
LOWTHRESHOLD="1.01"
HIGHTHRESHOLD="30.2"
REFRESHRATE=1
LEDCONTROLLER="/usr/bin/ledcontroller"
iostat -c "$REFRESHRATE" | while read iostatOutput; do
iowaitPercent="$(echo "$iostatOutput" | grep -vE "Linux|avg|^$" | awk '{print $4}')"
[ -z "$iowaitPercent" ] || \
if (( $(bc <<< "$iowaitPercent > $LOWTHRESHOLD") == 0 )); then
$LEDCONTROLLER blue
elif (( $(bc <<< "$iowaitPercent > $HIGHTHRESHOLD") == 0 )); then
$LEDCONTROLLER green
else
$LEDCONTROLLER red
fi
done
# This is an older version of the code, which used /proc/stats to do a similar job.
#iowaitCounter="$(grep 'cpu ' /proc/stat | cut -f 9 -d ' ')"
#$LEDCONTROLLER blue
#ledcolor="blue"
#
#while (true); do
#
# iowaitTemp="$(grep 'cpu ' /proc/stat | cut -f 9 -d ' ')"
#
## echo "iowaitCounter=$iowaitCounter, iowaitTemp=$iowaitTemp"
#
# if (( "$iowaitCounter" == "$iowaitTemp" )); then
#
# if [ "$ledcolor" != "blue" ]; then
#
# $LEDCONTROLLER blue
# ledcolor="blue"
#
# fi
#
# else
#
# iowaitCounter="$iowaitTemp"
#
# if [ "$ledcolor" != "red" ]; then
#
# $LEDCONTROLLER red;
# ledcolor="red"
#
# fi
#
# fi
#
# sleep "$REFRESHRATE";
#
#done

View File

@ -1,44 +0,0 @@
#!/bin/bash
THRESH1="1.00"
THRESH2="5.00"
THRESH3="20.00"
THRESH4="40.00"
THRESH5="80.00"
REFRESHRATE=1
LEDCONTROLLER="/usr/bin/ledcontroller"
iostat -c "$REFRESHRATE" | while read iostatOutput; do
iowaitPercent="$(echo "$iostatOutput" | grep -vE "Linux|avg|^$" | awk '{print $4}')"
[ -z "$iowaitPercent" ] || \
if (( $(bc <<< "$iowaitPercent > $THRESH1") == 0 )); then
$LEDCONTROLLER off
elif (( $(bc <<< "$iowaitPercent > $THRESH2") == 0 )); then
$LEDCONTROLLER green
elif (( $(bc <<< "$iowaitPercent > $THRESH3") == 0 )); then
$LEDCONTROLLER aqua # blue and green
elif (( $(bc <<< "$iowaitPercent > $THRESH4") == 0 )); then
$LEDCONTROLLER blue
elif (( $(bc <<< "$iowaitPercent > $THRESH5") == 0 )); then
$LEDCONTROLLER purple # red and blue
else
$LEDCONTROLLER red
fi
done