mirror of
https://github.com/miskcoo/ugreen_dx4600_leds_controller.git
synced 2025-07-23 04:13:04 +02:00
update readme; fix some small issues
This commit is contained in:
@@ -69,8 +69,9 @@ $ i2cdetect -y 1
|
||||
There are three methods to control the LEDs: stateless, userspace daemon, kernel module.
|
||||
|
||||
- **stateless**: the simplest way is to directly build and run the `ugreen_leds_cli` tool. It will find and communicate with `/dev/i2c-X`, and does not save the current state of LEDs. Therefore, we are unable to implement the stateful functions like blink an LED once, unless manually maintaining the states.
|
||||
- **userspace daemon**: it also communicates with `/dev/i2c-X`, but will maintain the LEDs' states and create a socket `/tmp/led-ugreen.socket`. The tool `ugreen_leds_cli` will communicate with the daemon via the socket. This method allows a similar function like the `oneshot` trigger in the kernel module. You can run `ugreen_leds_cli disk1 -oneshot 100 100` to setup the trigger and run `ugreen_leds_cli disk1 -shot` to blink `disk1` once. To use this daemon, you should first run `ugreen_daemon` and then use `ugreen_leds_cli` as before. The `ugreen-diskiomon` script requires this control method or the kernel module below.
|
||||
- **kernel module**: it will register LEDs in `/sys/class/leds`, therefore, any triggers supported by the kernel are also usable.
|
||||
- **userspace daemon**: it also communicates with `/dev/i2c-X`, but will maintain the LEDs' states and create a socket `/tmp/led-ugreen.socket`. The tool `ugreen_leds_cli` will communicate with the daemon via the socket. This method allows a similar function like the `oneshot` trigger in the kernel module. You can run `ugreen_leds_cli disk1 -oneshot 100 100` to setup the trigger and run `ugreen_leds_cli disk1 -shot` to blink `disk1` once. To use this daemon, you should first run `ugreen_daemon` (it won't exit, keep it running) and then use `ugreen_leds_cli` as before. The `ugreen-diskiomon` script requires this control method or the kernel module below.
|
||||
- _TL;DR_: copy `ugreen_daemon` and `ugreen_leds_cli` to `/usr/bin`; keep `ugreen_daemon` running; then keep `scripts/ugreen-diskiomon` running.
|
||||
- **kernel module** (suggested): it will register LEDs in `/sys/class/leds`, therefore, any triggers supported by the kernel are also usable.
|
||||
|
||||
The `ugreen_leds_cli` tool is suitable for all three methods. It will first check whether `/tmp/led-ugreen.socket` exists, and then check whether `/sys/class/leds` contains corresponding LEDs. If both of them do not exist, then it will try to use the stateless method.
|
||||
|
||||
|
@@ -70,7 +70,8 @@ void show_help() {
|
||||
" LED_NAME: separated by white space, possible values are\n"
|
||||
" { power, netdev, disk[1-8], all }.\n"
|
||||
" -on / -off: turn on / off corresponding LEDs.\n"
|
||||
" -blink / -breath: set LED to the blink / breath mode. This \n"
|
||||
" -blink / -breath / -oneshot: \n"
|
||||
" set LED to the blink / breath / oneshot mode. This \n"
|
||||
" mode keeps the LED on for T_ON millseconds and then\n"
|
||||
" keeps it off for T_OFF millseconds. \n"
|
||||
" T_ON and T_OFF should belong to [0, 65535].\n"
|
||||
@@ -79,6 +80,8 @@ void show_help() {
|
||||
" -brightness: set the brightness of corresponding LEDs.\n"
|
||||
" BRIGHTNESS should belong to [0, 255].\n"
|
||||
" -status: display the status of corresponding LEDs.\n"
|
||||
" -shot: emit a blink cycle of corresponding LEDs.\n\n"
|
||||
"See https://github.com/miskcoo/ugreen_dx4600_leds_controller for more details.\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
@@ -8,9 +8,9 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
|
||||
#define UGREEN_MAX_LEDS 10
|
||||
#define WORKING_THREAD_INTERVAL 20
|
||||
|
||||
inline static std::chrono::milliseconds get_now_milliseconds() {
|
||||
|
||||
@@ -203,9 +203,16 @@ ugreen_daemon::ugreen_daemon(const char *sock_path) {
|
||||
// initialize the working thread
|
||||
exit_flag = false;
|
||||
working_thread = std::thread([this] {
|
||||
using namespace std::chrono;
|
||||
steady_clock clock;
|
||||
while (!exit_flag) {
|
||||
auto start_time = clock.now();
|
||||
apply_leds();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
auto end_time = clock.now();
|
||||
auto elapsed_time = duration_cast<milliseconds>(end_time - start_time).count();
|
||||
if (elapsed_time < WORKING_THREAD_INTERVAL) {
|
||||
std::this_thread::sleep_for(milliseconds(WORKING_THREAD_INTERVAL - elapsed_time));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
{ lsmod | grep ledtrig_netdev ; } || modprobe -v ledtrig_netdev
|
||||
{ lsmod | grep ledtrig_netdev > /dev/null ; } || modprobe -v ledtrig_netdev
|
||||
|
||||
sleep 2
|
||||
|
||||
led="netdev"
|
||||
|
||||
if [[ -f /sys/class/leds/$led ]]; then
|
||||
if [[ -f /sys/class/leds/$led/blink_type ]]; then
|
||||
echo netdev > /sys/class/leds/$led/trigger
|
||||
echo $1 > /sys/class/leds/$led/device_name
|
||||
echo 1 > /sys/class/leds/$led/link
|
||||
|
Reference in New Issue
Block a user