Files
ugreen_dx4600_leds_controller/cli/ugreen_leds.h
Yuhao Zhou 784925cdc5 add a kernel module.
Squashed commit of the following:

commit 48ad47c2cb990c7550325e798064cfab612c3e7e
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Fri Jun 7 01:51:01 2024 +0800

    update README.md

commit 576cc1e21d629e83ac589cd7f806698814da4858
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Fri Jun 7 01:23:31 2024 +0800

    update makefiles

commit 577e2fc326df4d8edc8c303a89bde89ceca90949
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Fri Jun 7 00:29:26 2024 +0800

    change the i2c device name

commit 303a05e1f4695dcc0bc117c412b0e668dd7bb2a5
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 22:46:18 2024 +0800

    add the status attribute

commit ca1a51522b9ad28b04dc12d6012994bc6dce022c
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 22:34:33 2024 +0800

    fix including filename

commit 4684bd1aaaa0de089537686d65caee4352df3bcf
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 22:18:11 2024 +0800

    add dkms.conf

commit 4925eec10259c5c626c9459a65a7abeb115c4050
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 19:35:37 2024 +0800

    Update the manual of the kernel module

commit e07f1570efab507221092d9f2d09d6b98e32f2eb
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 16:25:30 2024 +0800

    add a netdev monitoring script

commit 813884f0bd928424b3e5be9053a7cc9289ab2263
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 15:33:28 2024 +0800

    support blink and breath

commit 991db7c11521a2b7e2f841bf5916ff58003b951a
Merge: a4e540c c3e6324
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 13:35:16 2024 +0800

    Merge branch 'master' into kmod

commit a4e540cbbde41d6a8570881a85bbfebab9def1ad
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Thu Jun 6 13:20:28 2024 +0800

    add a script of monitoring diskio

commit 5b65173ec68d2a9ebc952d120935e0f533f6760f
Author: Yuhao Zhou <miskcoo@gmail.com>
Date:   Wed Jun 5 23:26:09 2024 +0800

    add a kernel driver of leds
2024-06-07 01:51:15 +08:00

66 lines
1.8 KiB
C++

#ifndef __UGREEN_LEDS_H__
#define __UGREEN_LEDS_H__
#include <array>
#include <optional>
#include "i2c.h"
#define UGREEN_LED_POWER ugreen_leds_t::led_type_t::power
#define UGREEN_LED_NETDEV ugreen_leds_t::led_type_t::netdev
#define UGREEN_LED_DISK1 ugreen_leds_t::led_type_t::disk1
#define UGREEN_LED_DISK2 ugreen_leds_t::led_type_t::disk2
#define UGREEN_LED_DISK3 ugreen_leds_t::led_type_t::disk3
#define UGREEN_LED_DISK4 ugreen_leds_t::led_type_t::disk4
#define UGREEN_LED_DISK5 ugreen_leds_t::led_type_t::disk5
#define UGREEN_LED_DISK6 ugreen_leds_t::led_type_t::disk6
#define UGREEN_LED_DISK7 ugreen_leds_t::led_type_t::disk7
#define UGREEN_LED_DISK8 ugreen_leds_t::led_type_t::disk8
// #define UGREEN_LED_I2C_DEV "/dev/i2c-1"
#define UGREEN_LED_I2C_ADDR 0x3a
class ugreen_leds_t {
i2c_device_t _i2c;
public:
enum class op_mode_t : uint8_t {
off = 0, on, blink, breath
};
enum class led_type_t : uint8_t {
power = 0, netdev, disk1, disk2, disk3, disk4, disk5, disk6, disk7, disk8
};
struct led_data_t {
bool is_available;
op_mode_t op_mode;
uint8_t brightness;
uint8_t color_r, color_g, color_b;
uint16_t t_on, t_off;
};
public:
int start();
led_data_t get_status(led_type_t id);
int set_onoff(led_type_t id, uint8_t status);
int set_rgb(led_type_t id, uint8_t r, uint8_t g, uint8_t b);
int set_brightness(led_type_t id, uint8_t brightness);
int set_blink(led_type_t id, uint16_t t_on, uint16_t t_off);
int set_breath(led_type_t id, uint16_t t_on, uint16_t t_off);
bool is_last_modification_successful();
private:
int _set_blink_or_breath(uint8_t command, led_type_t id, uint16_t t_on, uint16_t t_off);
int _change_status(led_type_t id, uint8_t command, std::array<std::optional<uint8_t>, 4> params);
};
#endif