Peripheral Control

Last Updated on : 2023-08-09 09:25:02download

Lighting effects, audio prompts, and buttons are the common peripheral features of an IP camera (IPC).

  • Indicator and speaker: intuitively indicate the working states of the IPC with different light and sound effects.
  • Button: allows the user to reset the IPC and update firmware from a flash drive.

Feature description

Generic logic for IPC indicators

Device state Peripheral behavior
The device is starting (normal power on). Solid red light.
The device is ready for pairing. Fast-blinking red light.
The device has received the pairing information and starts connecting to the router. Slow-blinking green light. (If this step fails, the lights blink slowly between red and green.)
The device has successfully connected to the router and is now registering. Fast-blinking green light. (If this step fails, the lights blink fast between red and green.)
The device is online. Solid green light.
The device is faulty. Solid red light.
The device is performing an OTA firmware update. Slow-blinking amber light (red and green lights blink simultaneously).

Definition of fast blinking and slow blinking:

  • Fast blinking: on for 250 ms and off for 250 ms.
  • Slow blinking: on for 1,500 ms and off for 1,500 ms.

Generic logic for IPC audio prompts

Device state Peripheral behavior
The device is ready for pairing. Tone 1
The device receives the pairing information. Tone 2
The device is reset successfully. Tone 2 (emitted after files are erased but before a restart)
The device has been successfully updated. Tone 2 (emitted after flash is erased but before a restart)
  • Tone 1: located at resource/audio/beepA.pcm in the product directory.
  • Tone 2: located at resource/audio/beepB.pcm in the product directory.

Generic logic for IPC buttons

Device state Peripheral behavior
Device reset Press and hold the reset button for three seconds.

Development guide

Components

  • app_sys_led
  • app_sys_panel

Data structure

LED behaviors

typedef enum
{
    TY_LED_RED_ON,                     ///< Solid red light.
    TY_LED_RED_OFF,                    ///< Red light off.
    TY_LED_BLUE_ON,                    ///< Solid blue light.
    TY_LED_BLUE_OFF,                   ///< Blue light off.
    TY_LED_GREEN_ON,                   ///< Solid green light.
    TY_LED_GREEN_OFF = 5,              ///< Green light off.
    TY_LED_YELLOW_ON,                  ///< Solid amber light.
    TY_LED_YELLOW_OFF,                 ///< Amber light off.
    TY_LED_RGB_ON,                     ///< Solid RGB white light.
    TY_LED_RGB_OFF,                    ///< RGB white light off.
    TY_IRLED_ON = 10,                  ///< Solid infrared light.
    TY_IRLED_OFF,                      ///< Infrared light off.
    TY_LED_RED_BLINK_FAST,             ///< Fast-blinking red light.
    TY_LED_RED_BLINK_SLOW,             ///< Slow-blinking red light.
    TY_LED_BLUE_BLINK_FAST,            ///< Fast-blinking blue light.
    TY_LED_BLUE_BLINK_SLOW = 15,       ///< Slow-blinking blue light.
    TY_LED_GREEN_BLINK_FAST,           ///< Fast-blinking green light.
    TY_LED_GREEN_BLINK_SLOW,           ///< Slow-blinking green light.
    TY_LED_YELLOW_BLINK_FAST,          ///< Fast-blinking amber light.
    TY_LED_YELLOW_BLINK_SLOW,          ///< Slow-blinking amber light.
    TY_LED_RING_BLINK = 20,            ///< Alternate orbit blinking.
    TY_WHITELED_ON,                    ///< Solid white fill light.
    TY_WHITELED_OFF,                   ///< White fill light off.
    TY_LED_WHITE_BLINK_FAST,           ///< Fast-blinking white light.
    TY_LED_WHITE_BLINK_SLOW,           ///< Slow-blinking white light.
    TY_LED_RG_BLINK_FAST = 25,         ///< Lights blink fast between red and green.
    TY_LED_RG_BLINK_SLOW,              ///< Lights blink slowly between red and green.
    TY_LED_RB_BLINK_FAST,              ///< Lights blink fast between red and blue.
    TY_LED_RB_BLINK_SLOW,              ///< Lights blink slowly between red and blue.
    TY_LED_RING_ON,                    ///< Solid alternate orbit lighting.
    TY_LED_RING_OFF = 30,              ///< Alternate orbit lighting off.
    TY_LED_RING_BLINK_FAST,            ///< Fast alternate orbit blinking.
    TY_LED_RING_BLINK_SLOW,            ///< Slow alternate orbit blinking.
    TY_LED_RING_BLINK_BREATH_START,    ///< Orbit breathing light starts.
    TY_LED_RING_BLINK_BREATH_STOP,     ///< Orbit breathing light stops.
    TY_LED_RING_BLINK_ROLL,            ///< Orbit marquee light.
    TY_LED_RING_BLINK_BREATH_ONCE,     ///< Breathing light runs once.
    TY_LED_RING_BLINK_BREATH_TWICE,    ///< Breathing light runs twice.
    TY_FILL_LIGHT_ON,                  ///< White fill light on.
    TY_FILL_LIGHT_OFF,                 ///< White fill light off.
    TY_LED_STATUS_NULL,                ///< No lighting effect.
    TY_LED_STATUS_MAX,
} TY_SYS_LED_STATUS;

LED initial parameters

typedef struct s_tycam_led
{
    int slow_blink_ms;                 ///< Slow blinking interval, in milliseconds.
    int fast_blink_ms;                 ///< Fast blinking interval, in milliseconds.
    int white_light_mode;              ///< Sound alarm for white light, by manual control.
    int white_light_pwm_highest;       ///< The maximum value of PWM for white light.
    int white_light_pwm_lowest;        ///< The minimum value of PWM for white light.
    char white_light_pwm_path[128];    ///< The path of the PWM file for white light.
} TY_LED_INIT_PARAM;

Pin direction

typedef enum {
    INPUT,     ///< Input mode.
    OUTPUT,    ///< Output mode.
}ty_gpio_mode;

Pin control mode

typedef enum {
    COMMON_MODE,    ///< Common mode.
    IOCTL_MODE,     ///< The ioctl mode.
}ty_gpio_ctrl_mode;

GPIO configurations

typedef struct s_tycam_gpio {
    int gpio_num;              ///< GPIO num
    ty_gpio_mode dir;          ///< GPIO direction. 0: input. 1: output.
    char default_val;          ///< Initial state of GPIO
    ty_gpio_ctrl_mode mode;    ///< Control mode of GPIO.
    char ioctl_path[64];       ///< The path of the node in ioctl mode.
} ty_sys_gpio;

Button initial parameters

typedef struct TY_KEY_INIT_PARAM_ {
    int long_press_ms;                      ///< Duration of pressing and holding the button, in milliseconds.
    int short_press_ms;                     ///< Duration of pressing the button, in milliseconds.
    TY_SYS_KEY_MSG_CB ty_sys_key_msg_cb;    ///< The reset button callback.
} TY_KEY_INIT_PARAM_S;

Button operations

typedef enum {
    TY_SYS_KEY_PRESS_TYPE_NO,           ///< The button is not responding.
    TY_SYS_KEY_PRESS_TYPE_UP,           ///< Release the button.
    TY_SYS_KEY_PRESS_TYPE_LONG = 500,   ///< Press and hold the button.
    TY_SYS_KEY_PRESS_TYPE_SHORT,        ///< Press the button.
    TY_SYS_KEY_TRIG_PRESS,              ///< Trigger the button.
    TY_SYS_KEY_SINGLE_CLICK,            ///< Single press.
    TY_SYS_KEY_DOUBLE_CLICK,            ///< Double press.
    TY_SYS_KEY_TRIPLE_CLICK,            ///< Triple press.
} TY_SYS_KEY_PRESS_TYPE;

API description

Initialize LED

This API initializes resources and creates threads to manage lighting effects.

/**
 * @brief Set the light Flash interval
 *
 * @param[in] led_param: Led initialization parameter
 *
 * @return int; 0: success, others: failed
 */
int ty_sys_led_init(TY_LED_INIT_PARAM *led_param);

Deinitialize LED

/**
 * @brief LED uninit
 *
 * @return int; 0: success, others: failed
 */
int ty_sys_led_deinit(void);

Control LED on/off

This API controls the LED indicator based on the user’s actions on the mobile app.

/**
 * @brief LED control switch
 *
 * @param[in] onoff: Turn the lights on or off
 *
 * @return void
 */
void ty_sys_led_switch(int onoff);

Set lighting effects

/**
 * @brief Lamp effect setting
 *
 * @param[in] status: Indicator status mode
 *
 * @return void
 */
void ty_sys_led_mode_set(TY_SYS_LED_STATUS status);

Initialize GPIO

/**
 * @brief init GPIO
 *
 * @param[in] p_gpio:GPIO configuration parameters
 *
 * @return int; 0: success, others: failed
 */
int ty_sys_gpio_init(ty_sys_gpio *p_gpio);

Set GPIO value

/**
 * @brief Set the value of GPIO
 *
 * @param[in] num: GPIO pin number
 * @param[in] value: Value to be set for GPIO
 *
 * @return int; 0: success, others: failed
 */
int ty_sys_panel_set_value(int num, int value);

Register button operations

Define the callbacks for button operations, including press and hold, press, and reset.

/**
 * @brief Key config param
 *
 * @param[in] key_param:
 *
 * @return int; 0: success, others: failed
 */
int ty_sys_key_press_init(TY_KEY_INIT_PARAM_S *key_param);

Things to note

For PCM audio format, the device supports:

  • 8,000 Hz sampling rate
  • 16-bit depth
  • Mono format

FAQs

How to troubleshoot if the LED fails to behave as expected?

Check the software to ensure that the GPIO and polarity are configured correctly.

How do I use a custom tone file?

Save your tone file in the directory apps/xxx/resource/audio.