Compare commits
2 Commits
v0.1.1
...
98a5539dca
Author | SHA1 | Date | |
---|---|---|---|
98a5539dca | |||
4243b39b1f |
@ -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"
|
145
main.c
145
main.c
@ -51,16 +51,19 @@
|
|||||||
|
|
||||||
static struct libusb_device_handle *devh = NULL;
|
static struct libusb_device_handle *devh = NULL;
|
||||||
|
|
||||||
int main(int argc,char** argv)
|
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("syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",argv[0]);
|
printf
|
||||||
return -1;
|
("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",
|
||||||
|
argv[0]);
|
||||||
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The device has a RGB LED, which has two states for each "sub-LED",
|
The device has a RGB LED, which has two states for each "sub-LED",
|
||||||
@ -81,72 +84,74 @@ 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 {
|
}
|
||||||
printf("invalid color\n");
|
else
|
||||||
return -1;
|
{
|
||||||
}
|
printf ("invalid color\n");
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
printf("not found\n");
|
printf ("not found\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( libusb_kernel_driver_active(devh,0) )
|
if (libusb_kernel_driver_active (devh, 0))
|
||||||
{
|
{
|
||||||
printf("detach from kernel\n");
|
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)
|
||||||
{
|
{
|
||||||
printf("can't detach\n");
|
printf ("can't detach\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char data[5];
|
char data[5];
|
||||||
data[0] = code;
|
data[0] = code;
|
||||||
data[1] = 0x4;
|
data[1] = 0x4;
|
||||||
data[2] = 0x4;
|
data[2] = 0x4;
|
||||||
data[3] = 0x4;
|
data[3] = 0x4;
|
||||||
data[4] = 0x4;
|
data[4] = 0x4;
|
||||||
|
|
||||||
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("error");
|
perror ("error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
@ -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
|
|
Reference in New Issue
Block a user