Skip to content
/ LedLib Public

LED and RGB scene library | LED和RGB场景库

License

Notifications You must be signed in to change notification settings

syj0925/LedLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LedLib - LED and RGB Light Scene Library

查看中文版

LedLib is a repository for LED and RGB light scenes. Currently, it only contains rgb_scene.

1. Introduction to rgb_scene

rgb_scene supports both monochrome LED lights and RGB tri-color lights. By defining different LED scenes and running priorities, it can meet various indicator light needs.

1.1. Action

An Action is the smallest execution unit of rgb_scene. rgb_scene supports three types of Actions.

typedef struct
{
    uint16_t      rgb_mask;       /* RGB mask */
    uint16_t      cycle;          /* Action cycle count, 0xFFFF means forever */
    action_type_t type;           /* Action type */
    union
    {
        action_onoff_t onoff;     /* ON/OFF */
        action_blink_t blink;     /* Blink */
        action_fade_t  fade;      /* Fade */
    } sub;
} action_t;

1.1.1. on/off (Steady On/Steady Off)

typedef struct
{
    rgb_value_t value;            /* RGB value */
    uint16_t    lifetime;         /* Duration */
} action_onoff_t;

1.1.2. blink (Blinking)

typedef struct
{
    action_onoff_t action1;       /* First half of the blink action */
    action_onoff_t action2;       /* Second half of the blink action */
} action_blink_t;

1.1.3. fade (Fading)

typedef struct
{
    rgb_value_t start;            /* RGB value before fading */
    rgb_value_t end;              /* RGB value after fading */
    uint8_t     step;             /* Number of fade steps */
    uint16_t    interval;         /* Time interval */
} action_fade_t;

1.2. Scene

A Scene is composed of Actions. By combining different Actions, complex application scenarios can be implemented.

For example: A red light fades from 0% brightness to 100% brightness, stays for 400 milliseconds, then fades from 100% brightness back to 0%, stays for 1 second, and continues in this cycle.

const rgb_scene_t c_sys_pairing_fail = {
    .cycle = 5,
    .num = 4,

    .action[0] = {
        .cycle = 1,
        .type = ACTION_FADE,
        .sub.fade.start.r = 0,
        .sub.fade.start.g = 0,
        .sub.fade.start.b = 0,
        .sub.fade.end.r = 0xFF,
        .sub.fade.end.g = 0,
        .sub.fade.end.b = 0,
        .sub.fade.step = 100,
        .sub.fade.interval = 10*RGB_MSEC,
    },
    .action[1] = {
        .cycle = 1,
        .type = ACTION_ONOFF,
        .sub.onoff.value.r = 0xFF,
        .sub.onoff.value.g = 0,
        .sub.onoff.value.b = 0,
        .sub.onoff.lifetime = 400*RGB_MSEC,
    },
    .action[2] = {
        .cycle = 1,
        .type = ACTION_FADE,
        .sub.fade.start.r = 0xFF,
        .sub.fade.start.g = 0,
        .sub.fade.start.b = 0,
        .sub.fade.end.r = 0,
        .sub.fade.end.g = 0,
        .sub.fade.end.b = 0,
        .sub.fade.step = 100,
        .sub.fade.interval = 10*RGB_MSEC,
    },
    .action[3] = {
        .cycle = 1,
        .type = ACTION_ONOFF,
        .sub.onoff.value.r = 0,
        .sub.onoff.value.g = 0,
        .sub.onoff.value.b = 0,
        .sub.onoff.lifetime = 1*RGB_SEC,
    },
};

1.3. Priority

rgb_scene uses priority to regulate the execution order of scenes. Each scene must specify a priority, and multiple Scenes can share the same priority.

1.4. Demo Demonstration

Compilation and running environment: ubuntu 18

1.4.1. Make

  • cd /demo/linux
  • make

1.4.2. Running

  • ./build/rgb_scene_demo

demo

1.5. Application Instructions

  • For each independent LED, create a corresponding rgb_scene_obj_t object.
  • Each rgb_scene_obj_t object needs to define the corresponding enumeration -> priority and scene ID.
  • Based on the priority and scene ID, define the scene list rgb_scene_tab_t.
  • Mutually exclusive scenes are set to the same priority so that they will replace each other.
  • High-priority scenes preempt low-priority scenes. After a high-priority scene finishes, the low-priority scene will continue to run.
  • Design principle: For urgent and brief events, set them as high priority.

1.6. Porting Application

  • Copy the LedLib folder to your project’s source directory.
  • In the IDE or makefile, add the rgb_scene.c source file and include the rgb_scene.h header file path.
  • Define the scene table rgb_scene_tab_t.
  • Call RgbSceneObjCreate to create LED/RGB objects.
  • Periodically call RgbSceneTick.
  • Use RgbSceneStart to run a specified scene.

p.s. For details, refer to the demo.

About

LED and RGB scene library | LED和RGB场景库

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages