Compare commits

...

20 Commits

Author SHA1 Message Date
1cff2d3ea4 S3 Removed
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-06-20 09:27:18 +00:00
23db3866b3 Attempt 2
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-06-20 09:03:18 +00:00
c3345562cd Test of S3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-06-20 08:56:47 +00:00
f5c12c8180 CI/CD
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-06-22 07:57:17 +00:00
64610083eb Woodpecker CI format 2022-06-22 07:09:05 +00:00
68ab3726c3 Woodpecker port 2022-06-22 06:25:17 +00:00
9bde54d21e Syntax error
All checks were successful
continuous-integration/drone/push Build is passing
2022-01-04 13:32:16 +00:00
ee24d95a65 CppCheck added 2022-01-04 13:31:31 +00:00
1a93b07f73 Corrected install docs
All checks were successful
continuous-integration/drone/push Build is passing
2021-12-09 12:43:08 +00:00
f1ec272e28 Cleanup copyright notices
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-30 10:53:13 +00:00
25a4be50ee Cleanup
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-30 10:49:26 +00:00
17040eeed4 Tables and proper doxygen comments
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-30 10:31:00 +00:00
131450569f Folder creation
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-30 10:14:10 +00:00
40cc4ee5a8 Indentation is hard
Some checks failed
continuous-integration/drone/push Build is failing
2021-11-30 10:07:28 +00:00
65f0450f8d Modernize 2021-11-30 10:01:28 +00:00
jct
e16c7a34fd Use drone secrets
All checks were successful
continuous-integration/drone/push Build is passing
2019-10-25 08:08:36 +00:00
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
13 changed files with 195 additions and 348 deletions

@ -1,18 +0,0 @@
kind: pipeline
name: default
steps:
- name: build
image: gcc
commands:
- apt-get -y update
- apt-get -y install libusb-1.0
- make
- name: release
image: plugins/gitea-release
settings:
api_key: a7f3afc9f77e721951e48b4af66d7565700b7a2e
base_url: https://code.jcktrue.dk
files:
- ledcontroller
when:
event: tag

1
.gitignore vendored

@ -1,3 +1,4 @@
*~ *~
*.swp *.swp
ledcontroller ledcontroller
docs/

17
.vscode/c_cpp_properties.json vendored Normal file

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/libusb-1.0"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

17
.woodpecker.yml Normal file

@ -0,0 +1,17 @@
pipeline:
build:
image: gcc
commands:
- apt-get -y update
- apt-get -y install libusb-1.0
- make
check:
image: neszt/cppcheck-docker
commands:
- cppcheck *.c
docs:
image: corentinaltepe/doxygen
commands:
- doxygen

7
Doxyfile Normal file

@ -0,0 +1,7 @@
PROJECT_NAME = "ledcontroller-3bit"
OUTPUT_DIRECTORY = "docs/"
INPUT = "README.md" "main.c"
RECURSIVE = YES
WARNINGS = YES
GENERATE_LATEX = NO
USE_MDFILE_AS_MAINPAGE = README.md

@ -1,9 +1,11 @@
all: ledcontroller all: ledcontroller
ledcontroller: main.c ledcontroller: main.c
gcc -o $@ $^ `pkg-config libusb-1.0 --cflags --libs` gcc -o $@ $^ `pkg-config libusb-1.0 --cflags --libs`
docs:
doxygen
clean: clean:
rm ledcontroller rm -f ledcontroller
rm -rf docs

@ -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:
@ -6,12 +7,10 @@ A Linux command line utility to control usb mail notifiers identified as:
Bus 001 Device 010: ID 1294:1320 RISO KAGAKU CORP. Bus 001 Device 010: ID 1294:1320 RISO KAGAKU CORP.
Inside the scripts folder you will find some simple bash scripts you can use to control the notifier.
For example the script `mled-cputemp` will make it respond to your CPU's temperature.
### Get and compile: ### ### Get and compile: ###
$ git clone https://github.com/andmarios/ledcontroller-3bit.git $ git clone https://github.com/andmarios/ledcontroller-3bit.git
$ sudo apt-get install libusb-1.0-0-dev build-essential pkg-config
$ cd ledcontroller-3bit/ $ cd ledcontroller-3bit/
$ make $ make
@ -27,13 +26,12 @@ 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: ##
+ libusb:1 or libusb-1.0-dev, depending on your distribution + libusb:1, libusb-1.0-dev or libusb-1.0-0-dev, depending on your distribution
+ a system which can compile binaries (package build-essentials for Debian based distributions) + a system which can compile binaries (package build-essentials for Debian based distributions)
## Hardware ## ## Hardware ##
@ -42,7 +40,6 @@ I think [this is my notifier](http://www.andmarios.com/links/mail-usb-notifier)
--- ---
## Copyright ## ## Copyright ##
This code (files `main.c` and `Makefile`) is a fork of the ledcontroller code by jmrobles (<http://robleshermoso.wordpress.com>). This code (files `main.c` and `Makefile`) is a fork of the ledcontroller code by jmrobles (<http://robleshermoso.wordpress.com>).

@ -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"

276
main.c

@ -1,152 +1,158 @@
/* /**
ledcontroller-3bit * @file main.c
* ledcontroller-3bit
This file is a fork of the LedController code. You will find *
the original copyright notice below. * This file is a fork of the LedController code. You will find
* the original copyright notices below.
Copyright (C) 2013 andmarios - http://www.andmarios.com *
* @copyright Copyright (C) 2013 andmarios - http://www.andmarios.com \n
This program is free software: you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
(at your option) any later version. * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. \n
This program is distributed in the hope that it will be useful, *
but WITHOUT ANY WARRANTY; without even the implied warranty of * This program is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. \n
You should have received a copy of the GNU General Public License *
along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
Original Copyright Notice: *
* @copyright Original Copyright Notice: \n
LedController *
Copyright (C) 2011 jmrobles - http://robleshermoso.wordpress.com * LedController \n
* Copyright (C) 2011 jmrobles - http://robleshermoso.wordpress.com \n
This program is free software: you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
(at your option) any later version. * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. \n
This program is distributed in the hope that it will be useful, *
but WITHOUT ANY WARRANTY; without even the implied warranty of * This program is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. \n
You should have received a copy of the GNU General Public License *
along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. \n
*/ */
#include <stdio.h> #include <stdio.h>
#include <libusb.h> #include <libusb.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#define VID 0x1294 #define USB_VID 0x1294 /**< USB Vendor ID */
#define PID 0x1320 #define USB_PID 0x1320 /**< USB Product ID */
#define USB_EP 0x2 /**< USB EndPoint */
static struct libusb_device_handle *devh = NULL; static struct libusb_device_handle *devh = NULL;
/**
int main(int argc,char** argv) * The device has a RGB LED, which has two states for each "sub-LED",
{ * on and off.
int ret; * The "sub-LEDs" are red, green and blue.
unsigned char code = 0; *
if (argc != 2 ) * Obviously there are 8 possible combinations for their state.
{ * It seems there aren't bits mapped to each sub-LED, but instead
printf("syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",argv[0]); * 3-bit values mapped to the 8 combinations.
return -1; *
* | R | G | B | Color | Value | Comment |
} * | - | - | - | ------ | ----- | ------------------------------- |
* | 0 | 0 | 0 | off | 0x0 | |
/* * | 0 | 0 | 1 | blue | 0x1 | |
The device has a RGB LED, which has two states for each "sub-LED", * | 1 | 0 | 0 | red | 0x2 | |
on and off. * | 0 | 1 | 0 | green | 0x3 | |
The "sub-LEDs" are red, green and blue. * | 0 | 1 | 1 | aqua | 0x4 | |
* | 1 | 0 | 1 | purple | 0x5 | |
Obviously there are 8 possible combinations for their state. * | 1 | 1 | 0 | yellow | 0x6 | more of a mustard - green color |
It seems there aren't bits mapped to each sub-LED, but instead * | 1 | 1 | 1 | white | 0x7 | a very blue-ish white |
3-bit values mapped to the 8 combinations. *
* @param argc POSIX number of parameters
R G B Color Value * @param argv Array of parameters
0 0 0 off 0x0 * @return Error code (0 on success)
0 0 1 blue 0x1 */
1 0 0 red 0x2 int main(int argc, char **argv) {
0 1 0 green 0x3 if (argc != 2)
0 1 1 aqua 0x4 {
1 0 1 purple 0x5 printf("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n", argv[0]);
1 1 0 yellow 0x6 (more of a mustard - green color)
1 1 1 white 0x7 (a very blue-ish white)
*/
if ( strcmp(argv[1],"blue") == 0 )
{
code = 1;
}
else if ( strcmp(argv[1],"red") == 0 )
{
code = 2;
}
else if ( strcmp(argv[1],"green") == 0 )
{
code = 3;
}
else if ( strcmp(argv[1],"aqua") == 0 )
{
code = 4;
}
else if ( strcmp(argv[1],"purple") == 0 )
{
code = 5;
}
else if ( strcmp(argv[1],"yellow") == 0 )
{
code = 6;
}
else if ( strcmp(argv[1],"white") == 0 )
{
code = 7;
} else {
printf("invalid color\n");
return -1;
}
libusb_init(NULL);
devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
if (devh == NULL )
{
printf("not found\n");
return -1; return -1;
} }
if ( libusb_kernel_driver_active(devh,0) ) unsigned char color_code = 0;
{ if (strcmp(argv[1], "off") == 0)
printf("detach from kernel\n"); {
ret = libusb_detach_kernel_driver(devh,0); color_code = 0;
if (ret < 0 ) }
else if (strcmp(argv[1], "blue") == 0)
{
color_code = 1;
}
else if (strcmp(argv[1], "red") == 0)
{
color_code = 2;
}
else if (strcmp(argv[1], "green") == 0)
{
color_code = 3;
}
else if (strcmp(argv[1], "aqua") == 0)
{
color_code = 4;
}
else if (strcmp(argv[1], "purple") == 0)
{
color_code = 5;
}
else if (strcmp(argv[1], "yellow") == 0)
{
color_code = 6;
}
else if (strcmp(argv[1], "white") == 0)
{
color_code = 7;
}
else
{
puts("Invalid color");
return -1;
}
libusb_init(NULL);
devh = libusb_open_device_with_vid_pid(NULL, USB_VID, USB_PID);
if (devh == NULL)
{
puts("Device not found");
return -1;
}
if (libusb_kernel_driver_active(devh, 0))
{
puts("Detach driver from kernel");
int ret = libusb_detach_kernel_driver(devh, 0);
if (ret < 0)
{ {
printf("can't detach\n"); puts("Could not detach driver");
return -1; return -1;
} }
} }
char data[5]; char data[5];
data[0] = code; data[0] = color_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; libusb_claim_interface(devh, 0);
libusb_claim_interface(devh,0); int ret = libusb_interrupt_transfer(devh, USB_EP, data, 5, NULL, 0);
ret = libusb_interrupt_transfer(devh,0x2,data,5,&dummy,0); if (ret < 0)
if ( ret < 0 ) {
{ perror("libusb error");
perror("error"); return -1;
} }
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