Indicator Control and Virtual Timer Library for Embedded Systems [嵌入式系统指示灯控制和虚拟定时器库]

Indicator Control and Virtual Timer Library for Embedded Systems

Version Record Table

DateAuthorVersionNote
2024.03.23Dog TaoV1.0Finish the first version of the article.
2024.03.29Dog TaoV1.1Write the Demo Code part to elaborate the usage of the library.

Introduction

The Indicator Control and Virtual Timer Library is a comprehensive software solution designed to address the nuanced needs of embedded systems in managing and controlling indicator devices, such as LEDs, buzzers, and other similar output peripherals. This library stands out due to its integration of virtual timer mechanisms, which facilitate precise control over the timing and behavior of these indicators without the need for dedicated hardware timers, thereby conserving valuable system resources.

Embedded systems, which are at the heart of countless modern devices from household appliances to industrial controllers, often require user feedback through indicators. The conventional approach involves direct control of these indicators via GPIO (General-Purpose Input/Output) pins and either hardware timers or CPU-bound delays for timing control. However, such methods can be resource-intensive, inflexible, and may not scale well with the complexity of modern applications.

The library introduces a layered architecture where the top layer provides straightforward APIs for defining and controlling indicators, abstracting the complexities involved in timing and state management. This approach allows developers to initiate behaviors like blinking, flashing in patterns, or maintaining steady states with minimal code, making the application layer clean and focused on business logic.

At its core, the virtual timer component serves as the backbone for timing operations, relying on a software-implemented scheduling mechanism to trigger indicator state changes. This design choice eliminates the need for multiple physical timers, a common limitation in microcontroller-based environments. The timers are managed efficiently through a singly-linked list, ensuring that each timer’s callback is invoked at the appropriate intervals, as specified by the application logic.

Furthermore, the library’s modular design encourages reuse and extensibility. Developers can easily extend the library to support additional indicator types or more complex behaviors as required by their specific applications. This flexibility is critical in the rapidly evolving landscape of embedded systems, where adaptability can significantly reduce development time and cost.

In summary, the Indicator Control and Virtual Timer Library represents a significant advancement in the development of user-friendly and resource-efficient embedded applications. By abstracting the intricacies of indicator management and virtual timing, it enables developers to focus on the unique value their applications bring, without being bogged down by lower-level details.

Framework Structure

The indicator library, comprising several source files (indicators.h, indicators.c, virtual_timer.h, virtual_timer.c, aw_slist.h, aw_slist.c, indicators_user.h, and indicators_user.c), provides a robust and flexible framework for controlling and managing indicator devices such as LEDs in embedded systems. The library’s architecture is designed to offer a range of functionalities, from simple on/off control to more complex behaviors like flashing at various speeds or patterns.

Core Components and Their Interactions

Indicator Management
  • Files: indicators.h and indicators.c
  • Functionality: Defines and implements the behavior of indicators, including initializing indicators, enabling/disabling them, setting their modes (e.g., off, on, fast flash, slow flash, count flash), and adjusting flash parameters like duration and count.
  • Structures: Uses Indicator_TypeDef to encapsulate all information necessary for an indicator’s operation, including a unique ID, pointers to functions for setting the indicator state, a software timer for timing control, and parameters for flash behavior.
Software Timer
  • Files: virtual_timer.h and virtual_timer.c
  • Functionality: Provides the timing mechanisms required by the indicators for operations like flashing. It allows for the initialization, registration, enabling/disabling, and configuration of software timers.
  • Structures: Utilizes SoftwareTimer_TypeDef for representing a timer, including its ID, count, expiration time, callback function, enable state, and repeat configuration.
  • Mechanism: Utilizes a singly-linked list (aw_slist) to manage active timers, invoking callbacks as timers expire.
Singly-Linked List
  • Files: aw_slist.h and aw_slist.c
  • Functionality: Implements a basic singly-linked list used by the software timer component to manage multiple timers efficiently. It supports operations like node creation, insertion, deletion, and traversal.
  • Structures: Defines SListNode as the fundamental element of the list, capable of storing arbitrary data along with the link to the next node.
User-Level Integration
  • Files: indicators_user.h and indicators_user.c
  • Functionality: Demonstrates how to utilize the indicator library in application code, defining specific indicators (e.g., LEDs, buzzers), their pins, and common operations like turning an indicator on/off or setting it to flash at predefined speeds.
  • Patterns: Provides macros and functions for common indicator operations, simplifying the process of controlling indicators within the user’s application logic.

Implementation Principles

  • Modularity: The library is structured into distinct components (indicator control, software timer, linked list management), enhancing readability, maintainability, and reusability.
  • Abstraction: Details of timer management and linked list operations are abstracted away from the user, who interacts with simple and high-level functions for controlling indicators.
  • Flexibility: The library supports various indicator behaviors and is easily extendable to accommodate new types of indicators or additional functionalities.
  • Resource Efficiency: The use of software timers and a singly-linked list minimizes hardware resource requirements, making the library suitable for resource-constrained embedded systems.
  • Scalability: The design allows for easy scaling, capable of managing multiple indicators and timers without significant modifications to the core library.

In summary, the indicator library is a well-designed framework that abstracts the complexities of indicator control and timing management, providing a user-friendly interface for embedded system developers to control indicators with minimal resource usage and high flexibility.

Source Code

Library Code

  • Header file indicators.h
#pragma once
#include "virtual_timer.h"

// Definition of function pointer types for operations related to indicator status change.
typedef void (*Indicator_Operate)(void);
typedef SoftwareTimer_TimeoutCB Indicator_TimerCB;

// Enumeration for defining different working modes of an indicator.
typedef enum
{
    Indicator_Mode_Off = 0,    // The indicator is always off.
    Indicator_Mode_FastFlash,  // The indicator flashes quickly.
    Indicator_Mode_SlowFlash,  // The indicator flashes slowly.
    Indicator_Mode_CountFlash, // The indicator flashes a specified number of times.
    Indicator_Mode_On,         // The indicator is always on.
} Indicator_WorkMod;

// Structure definition for an indicator, encapsulating its properties and control mechanisms.
typedef struct
{
    uint16_t id;                     // Unique identifier for the indicator.
    SoftwareTimer_TypeDef TimerReverse; // Software timer for managing indicator timing.
    Indicator_Operate SetOff_P;      // Function pointer to turn the indicator off.
    Indicator_Operate SetOn_P;       // Function pointer to turn the indicator on.
    Indicator_TimerCB SetReverse_P;  // Callback function for timer events.
    Indicator_WorkMod WorkMode;      // Current working mode of the indicator.
    uint32_t FlashCount;             // Number of flashes for the CountFlash mode.
    uint32_t FlashSlowDelay;         // Delay between flashes in SlowFlash mode.
    uint32_t FlashFastDelay;         // Delay between flashes in FastFlash mode.
    uint32_t FlashRepeatDelay;       // Delay between flash sequences in CountFlash mode.
} Indicator_TypeDef;

/**
 * @brief Initializes the indicator with default settings and registers its associated timer.
 *
 * This function initializes the software timer for the indicator with a default interval and
 * registers the timer to enable its functionality. It sets up the timer callback function and
 * the repeat mode to ensure the indicator can function according to its designated mode.
 *
 * @param indicator_P Pointer to an Indicator_TypeDef structure that holds all data for the indicator.
 */
void Indicator_Init(Indicator_TypeDef* indicator_P);

/**
 * @brief Enables the indicator based on its currently configured mode.
 *
 * Depending on the configured work mode of the indicator, this function sets up the software timer
 * with appropriate intervals and repeat configurations. For flashing modes, it enables the timer with
 * specified intervals. For constant ON or OFF modes, it directly sets the indicator state without using a timer.
 *
 * @param indicator_P Pointer to an Indicator_TypeDef structure that holds all data for the indicator.
 */
void Indicator_Enable(Indicator_TypeDef* indicator_P);

/**
 * @brief Disables the indicator by stopping its timer and turning off the indicator light.
 *
 * This function stops the software timer associated with the indicator and sets the indicator to
 * its OFF state to ensure it does not consume power or remain active when not required.
 *
 * @param indicator_P Pointer to an Indicator_TypeDef structure that holds all data for the indicator.
 */
void Indicator_Disable(Indicator_TypeDef* indicator_P);

/**
 * @brief Sets the operating mode of the indicator and applies the new mode by temporarily disabling the indicator.
 *
 * The function first disables the indicator to reset its state and then sets the new working mode
 * as specified by the caller. This ensures a clean transition between modes, especially when switching
 * between different flashing patterns or between ON/OFF states.
 *
 * @param indicator_P Pointer to an Indicator_TypeDef structure that holds all data for the indicator.
 * @param workMode The desired working mode to set for the indicator, as defined by the Indicator_WorkMod enumeration.
 */
void Indicator_SetMode(Indicator_TypeDef* indicator_P, Indicator_WorkMod workMode);

/**
 * @brief Sets the number of flashes for the CountFlash mode of the indicator.
 *
 * This function configures how many times the indicator will flash when it is set to the CountFlash mode.
 * The actual number of state changes (on to off, or off to on) will be twice the count value, as it includes
 * both turning the indicator on and off. This function disables the indicator before applying the new flash count
 * to prevent any ongoing flash sequence from being interrupted or behaving unexpectedly.
 *
 * @param indicator_P Pointer to an `Indicator_TypeDef` structure representing the indicator.
 * @param count The number of times the indicator should flash in CountFlash mode.
 */
void Indicator_SetFlashCount(Indicator_TypeDef* indicator_P, uint32_t count);

/**
 * @brief Sets the delay between flashes in SlowFlash mode for the indicator.
 *
 * In SlowFlash mode, this function sets the time interval between each flash of the indicator.
 * The delay is applied for both turning the indicator on and off, defining the slow flashing rhythm.
 * The indicator is disabled before changing the delay to ensure the new timing takes effect cleanly
 * without overlapping with any ongoing flashing behavior.
 *
 * @param indicator_P Pointer to an `Indicator_TypeDef` structure representing the indicator.
 * @param delayTicks The delay between flashes in SlowFlash mode, specified in timer ticks.
 */
void Indicator_SetFlashSlowDelay(Indicator_TypeDef *indicator_P, uint32_t delayTicks);

/**
 * @brief Sets the delay between flashes in FastFlash mode for the indicator.
 *
 * This function adjusts the time interval between consecutive flashes when the indicator is in FastFlash mode,
 * effectively setting the pace of the fast flashing. The delay is applied to both the on and off phases of each
 * flash. To ensure a consistent flashing pattern, the indicator is temporarily disabled when setting the new fast
 * flash delay.
 *
 * @param indicator_P Pointer to an `Indicator_TypeDef` structure representing the indicator.
 * @param delayTicks The delay between flashes in FastFlash mode, specified in timer ticks.
 */
void Indicator_SetFlashFastDelay(Indicator_TypeDef *indicator_P, uint32_t delayTicks);

/**
 * @brief Sets the delay between each flash sequence in CountFlash mode for the indicator.
 *
 * When the indicator is set to CountFlash mode, this function defines the delay between the end of one flash sequence
 * and the start of the next. This is particularly useful for creating patterns of flashes with pauses in between.
 * The indicator is disabled before changing this delay to prevent any interference with ongoing flash sequences,
 * ensuring that the new setting is applied cleanly.
 *
 * @param indicator_P Pointer to an `Indicator_TypeDef` structure representing the indicator.
 * @param delayTicks The delay between flash sequences in CountFlash mode, specified in timer ticks.
 */
void Indicator_SetFlashRepeatDelay(Indicator_TypeDef *indicator_P, uint32_t delayTicks);
  • Source file indicators.c
#include "indicators.h"

void Indicator_Init(Indicator_TypeDef *indicator_P)
{
    SoftwareTimer_Init(&indicator_P->TimerReverse, indicator_P->id, 1000, indicator_P->SetReverse_P, -1);
    SoftwareTimer_Register(&indicator_P->TimerReverse);
}

void Indicator_Enable(Indicator_TypeDef *indicator_P)
{
    switch (indicator_P->WorkMode)
    {
    case Indicator_Mode_Off:
        indicator_P->SetOff_P();
        break;
    case Indicator_Mode_FastFlash:
        SoftwareTimer_SetRepeatTimes(&indicator_P->TimerReverse, -1); // Repeat forever
        SoftwareTimer_SetInterval(&indicator_P->TimerReverse, indicator_P->FlashFastDelay);
        SoftwareTimer_Enable(&indicator_P->TimerReverse);
        break;
    case Indicator_Mode_SlowFlash:
        SoftwareTimer_SetRepeatTimes(&indicator_P->TimerReverse, -1); // Repeat forever
        SoftwareTimer_SetInterval(&indicator_P->TimerReverse, indicator_P->FlashSlowDelay);
        SoftwareTimer_Enable(&indicator_P->TimerReverse);
        break;
    case Indicator_Mode_CountFlash:
        SoftwareTimer_SetRepeatTimes(&indicator_P->TimerReverse, indicator_P->FlashCount); // Repeat Count
        SoftwareTimer_SetInterval(&indicator_P->TimerReverse, indicator_P->FlashRepeatDelay);
        SoftwareTimer_Enable(&indicator_P->TimerReverse);
        break;
    case Indicator_Mode_On:
        indicator_P->SetOn_P();
        break;
    default:
        break;
    }
}

void Indicator_Disable(Indicator_TypeDef *indicator_P)
{
    SoftwareTimer_Disable(&indicator_P->TimerReverse);
    indicator_P->SetOff_P();
}

void Indicator_SetMode(Indicator_TypeDef *indicator_P, Indicator_WorkMod workMode)
{
    Indicator_Disable(indicator_P);
    indicator_P->WorkMode = workMode;
}

void Indicator_SetFlashCount(Indicator_TypeDef *indicator_P, uint32_t count)
{
    Indicator_Disable(indicator_P);
    indicator_P->FlashCount = count*2;      // On and off
}

void Indicator_SetFlashSlowDelay(Indicator_TypeDef *indicator_P, uint32_t delayTicks)
{
    Indicator_Disable(indicator_P);
    indicator_P->FlashSlowDelay = delayTicks;
}

void Indicator_SetFlashFastDelay(Indicator_TypeDef *indicator_P, uint32_t delayTicks)
{
    Indicator_Disable(indicator_P);
    indicator_P->FlashFastDelay = delayTicks;
}

void Indicator_SetFlashRepeatDelay(Indicator_TypeDef *indicator_P, uint32_t delayTicks)
{
    Indicator_Disable(indicator_P);
    indicator_P->FlashRepeatDelay = delayTicks;
}

User Code

  • Header file indicators_user.h
/**
 * @file indicators_user.h
 * @brief Header file for user-level control of indicators using the Indicator Control and Virtual Timer Library.
 *
 * This file provides macros and declarations for controlling various indicators like LEDs and buzzers
 * with predefined behaviors such as on, off, slow blink, fast blink, and count-controlled flashing.
 * It leverages the underlying Indicator and Virtual Timer libraries to offer a high-level interface
 * for indicator control in embedded systems.
 */
#pragma once

#include "indicators.h"

// Predefined delays for different flashing modes in milliseconds.
#define FLASH_SLOWDELAY  500 /**< Delay for slow flashing mode. */
#define FLASH_FASTDELAY  200 /**< Delay for fast flashing mode. */
#define FLASH_COUNTDELAY  500 /**< Delay between flashes in count flash mode. */
#define TIMER_TICK_INTERVAL 100 /**< Interval at which the software timer ticks, in milliseconds. */

// Pin definitions for various indicators.
#define INDICATOR_BUZZER_NUM         PIN_IO1 /**< Pin number for the buzzer. */
#define INDICATOR_LED_NUM            PIN_IO2 /**< Pin number for a general LED. */
#define INDICATOR_LED_NET_NUM        PIN_IO3 /**< Pin number for a network status LED. */
#define INDICATOR_LED_FLASH_NUM      PIN_IO4 /**< Pin number for a camera flash LED. */

// Macros for controlling the buzzer with count-controlled slow and fast flashing.
#define INDICATOR_BUZZER_COUNTFLASH_SLOW(_COUNT_) Indicator_SetFlashRepeatDelay(&indicators[0], FLASH_SLOWDELAY/TIMER_TICK_INTERVAL); Indicator_SetFlashCount(&indicators[0], _COUNT_); Indicator_Enable(&indicators[0])
#define INDICATOR_BUZZER_COUNTFLASH_FAST(_COUNT_) Indicator_SetFlashRepeatDelay(&indicators[0], FLASH_FASTDELAY/TIMER_TICK_INTERVAL); Indicator_SetFlashCount(&indicators[0], _COUNT_); Indicator_Enable(&indicators[0])

// Macros for controlling a general LED with different modes: on, off, slow blink, fast blink, and count flash.
#define INDICATOR_LED_MAIN_ON()    Indicator_SetMode(&indicators[1], Indicator_Mode_On); Indicator_Enable(&indicators[1])
#define INDICATOR_LED_MAIN_SLOWBLINK()   Indicator_SetMode(&indicators[1], Indicator_Mode_SlowFlash); Indicator_Enable(&indicators[1])
#define INDICATOR_LED_MAIN_FASTBLINK()   Indicator_SetMode(&indicators[1], Indicator_Mode_FastFlash); Indicator_Enable(&indicators[1])
#define INDICATOR_LED_MAIN_COUNTFLASH(_COUNT_)   Indicator_SetMode(&indicators[1], Indicator_Mode_CountFlash); Indicator_SetFlashCount(&indicators[1], _COUNT_); Indicator_Enable(&indicators[1])
#define INDICATOR_LED_MAIN_OFF()   Indicator_Disable(&indicators[1])

// Macros for controlling the camera flash LED: on and off.
#define INDICATOR_LED_FLASH_ON()    Indicator_Enable(&indicators[3])
#define INDICATOR_LED_FLASH_OFF()   Indicator_Disable(&indicators[3])

// Macros for controlling a network status LED with different modes: on, off, slow blink, and fast blink.
#define INDICATOR_LED_NET_ON()    Indicator_SetMode(&indicators[2], Indicator_Mode_On); vTaskDelay(100); Indicator_Enable(&indicators[2])
#define INDICATOR_LED_NET_SLOWBLINK()   Indicator_SetMode(&indicators[2], Indicator_Mode_SlowFlash); vTaskDelay(100); Indicator_Enable(&indicators[2])
#define INDICATOR_LED_NET_FASTBLINK()   Indicator_SetMode(&indicators[2], Indicator_Mode_FastFlash); vTaskDelay(100); Indicator_Enable(&indicators[2])
#define INDICATOR_LED_NET_OFF()   Indicator_Disable(&indicators[2])

extern Indicator_TypeDef indicators[4]; /**< Array of indicator configurations. */

void Indicators_Init(); /**< Function to initialize all configured indicators. */
  • Source file indicators_user.c

/**
 * @file indicators_user.c
 * @brief Implementation file for user-level control of indicators using the Indicator Control and Virtual Timer Library.
 *
 * This file provides the implementation of functions and macros defined in indicators_user.h for controlling
 * various indicators like LEDs and buzzers in embedded systems. It includes initialization routines for indicators,
 * setting their modes, and the control logic for different indicator behaviors.
 */
#include "indicators_user.h"
#include "FreeRTOS.h"
#include "task.h"
#include "pca9557.h"

static void Indicator_1_SetOffHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_BUZZER_NUM, IO_LOW); /**< Turn off the buzzer. */
}

static void Indicator_1_SetOnHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_BUZZER_NUM, IO_HIGH); /**< Turn on the buzzer. */
}

/**
 * @brief Handler for toggling the state of the buzzer based on the timer.
 *
 * @param id The timer ID (unused in this handler, hence the void cast).
 */
static void Indicator_1_TimerHandler(uint16_t id)
{
    (void)id;
    bool pin_set = bsp_PcaGetIoStatus(INDICATOR_BUZZER_NUM) ? false : true; /**< Toggle the buzzer state. */
    bsp_PcaSetIoStatus(INDICATOR_BUZZER_NUM, pin_set);
}

static void Indicator_2_SetOffHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_LED_NUM, IO_LOW); /**< Turn off the general LED. */
}

static void Indicator_2_SetOnHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_LED_NUM, IO_HIGH); /**< Turn on the general LED. */
}

/**
 * @brief Handler for toggling the state of the general LED based on the timer.
 *
 * @param id The timer ID (unused in this handler, hence the void cast).
 */
static void Indicator_2_TimerHandler(uint16_t id)
{
    (void)id;
    bool pin_set = bsp_PcaGetIoStatus(INDICATOR_LED_NUM) ? false : true; /**< Toggle the general LED state. */
    bsp_PcaSetIoStatus(INDICATOR_LED_NUM, pin_set);
}

static void Indicator_3_SetOffHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_LED_NET_NUM, IO_LOW); /**< Turn off the network status LED. */
}

static void Indicator_3_SetOnHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_LED_NET_NUM, IO_HIGH); /**< Turn on the network status LED. */
}

/**
 * @brief Handler for toggling the state of the network status LED based on the timer.
 *
 * @param id The timer ID (unused in this handler, hence the void cast).
 */
static void Indicator_3_TimerHandler(uint16_t id)
{
    (void)id;
    bool pin_set = bsp_PcaGetIoStatus(INDICATOR_LED_NET_NUM) ? false : true; /**< Toggle the network status LED state. */
    bsp_PcaSetIoStatus(INDICATOR_LED_NET_NUM, pin_set);
}

static void Indicator_4_SetOffHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_LED_FLASH_NUM, IO_LOW); /**< Turn off the camera flash LED. */
}

static void Indicator_4_SetOnHandler()
{
    bsp_PcaSetIoStatus(INDICATOR_LED_FLASH_NUM, IO_HIGH); /**< Turn on the camera flash LED. */
}

/**
 * @brief Handler for toggling the state of the camera flash LED based on the timer.
 *
 * @param id The timer ID (unused in this handler, hence the void cast).
 */
static void Indicator_4_TimerHandler(uint16_t id)
{
    (void)id;
    bool pin_set = bsp_PcaGetIoStatus(INDICATOR_LED_FLASH_NUM) ? false : true; /**< Toggle the camera flash LED state. */
    bsp_PcaSetIoStatus(INDICATOR_LED_FLASH_NUM, pin_set);
}

/**
 * @brief Task that periodically calls the SoftwareTimer_Tick function to update the state of timers.
 *
 * @param arg Unused parameter, included for compatibility with FreeRTOS task signature.
 */
static void Indicators_Poll(void *arg)
{
    TickType_t ticks = xTaskGetTickCount();
    while (1)
    {
        SoftwareTimer_Tick(); /**< Update the state of all software timers. */
        vTaskDelayUntil(&ticks, TIMER_TICK_INTERVAL); /**< Wait for the next tick interval. */
    }
}

Indicator_TypeDef indicators[4] =
{
    // Initializer for the buzzer indicator
    {
        .id = 0,
        .SetOff_P = Indicator_1_SetOffHandler,
        .SetOn_P = Indicator_1_SetOnHandler,
        .SetReverse_P = Indicator_1_TimerHandler,
        .WorkMode = Indicator_Mode_CountFlash,
        .FlashCount = 5*2, /**< Flash count multiplied by 2 to account for on and off states. */
        .FlashSlowDelay = FLASH_SLOWDELAY/TIMER_TICK_INTERVAL,
        .FlashFastDelay = FLASH_FASTDELAY/TIMER_TICK_INTERVAL,
        .FlashRepeatDelay = FLASH_COUNTDELAY/TIMER_TICK_INTERVAL,
    },
    // Additional indicators are initialized similarly...
};

/**
 * @brief Initializes all indicators and starts the indicator polling task.
 */
void Indicators_Init()
{
    Indicator_Init(&indicators[0]); /**< Initialize buzzer indicator.
    Indicator_Init(&indicators[1]); /**< Initialize general LED indicator. */
    Indicator_Init(&indicators[2]); /**< Initialize network status LED indicator. */
    Indicator_Init(&indicators[3]); /**< Initialize camera flash LED indicator. */
    // Create a FreeRTOS task for polling indicator timers, ensuring they are updated at the defined intervals.
    xTaskCreate(
        Indicators_Poll,          // Task function.
        "Indicators_Poll",        // Name of the task (for debugging purposes).
        1024 * 2,                 // Stack size for the task.
        (void *)0,                // Task input parameter (not used in this case).
        10,                       // Priority of the task.
        NULL                      // Task handle (not used in this case).
    );
}

Demo Code

Once define and initialize the indicators with Indicator_TypeDef, the developer can operate the indicators using the functions of the library, when including the header file indicators_user.h. Combining functions through MACRO definitions would enable more concise coding, as demonstrated in the aforementioned indicators_user.h file:

  • Open main LED indicator: #define INDICATOR_LED_MAIN_ON() Indicator_SetMode(&indicators[1], Indicator_Mode_On); Indicator_Enable(&indicators[1])
  • Close main LED indicator: #define INDICATOR_LED_MAIN_OFF() Indicator_Disable(&indicators[1])
  • Set main LED blink slowly: #define INDICATOR_LED_MAIN_SLOWBLINK() Indicator_SetMode(&indicators[1], Indicator_Mode_SlowFlash); Indicator_Enable(&indicators[1])
  • Set main LED blink with a specific count: #define INDICATOR_LED_MAIN_COUNTFLASH(_COUNT_) Indicator_SetMode(&indicators[1], Indicator_Mode_CountFlash); Indicator_SetFlashCount(&indicators[1], _COUNT_); Indicator_Enable(&indicators[1])

E.g., if you want to flash led and buzzer in your board when timeout (as a reminding):

void One_min_timer_handler(void *p_context)
{
    int msg_id;
    
    // Operate the indicators
    INDICATOR_LED_MAIN_COUNTFLASH(5);
    INDICATOR_BUZZER_COUNTFLASH_SLOW(5);

    msg_id = Mqtt_SendMsg("CountDown-1 Stop.");
    ESP_LOGI(TAG, "CountDown-1 Stop, msg_id=%d", msg_id);
}
  • 18
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全能骑士涛锅锅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值