Documentation

Documentation

Includes

stdint.h

#include <stdint.h>
#include 

tuya_cloud_types.h

#include "tuya_cloud_types.h"
#include "tuya_cloud_types.h"

tuya_pin.h

#include "tuya_pin.h"
#include "tuya_pin.h"

Macros

Marco __TUYA_KEY_H

#define __TUYA_KEY_H

      

Functions

Func reg_proc_key

OPERATE_RET reg_proc_key(IN CONST KEY_USER_DEF_S *key_ud);
/**
 * @brief Register a new KEY
 * 
 * @param[in] key_ud User defined key, see KEY_USER_DEF_S
 * 
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func key_init

OPERATE_RET key_init(IN CONST KEY_USER_DEF_S *p_tbl,IN CONST INT_T cnt,\
                        IN CONST INT_T timer_space);
/**
 * @brief Initialize KEY process service
 * 
 * @param[in] p_tbl User defined key tables, see KEY_USER_DEF_S
 * @param[in] cnt Count of key tables
 * @param[in] timer_space Key detect interval (unit ms). No more than 100,
 * if 0 then use default value(20ms)
 * 
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Vars

Consts

Types

Typedefs

Typedef PUSH_KEY_TYPE_E;

typedef enum {
   /** one shot */
   NORMAL_KEY = 0,
   /** continual shot */
   SEQ_KEY,
   /** long press */
   LONG_KEY,
}PUSH_KEY_TYPE_E;
/**
 * @brief Definition of KEY type
 */

Typedef KEY_LONG_PRESS_TP_E;

typedef enum {
   /** long press invalid */
   LP_INVALID = 0,
   /** long press once trigger */
   LP_ONCE_TRIG,
   /** long press more normal trigger */
   LP_MORE_NORMAL_TRIG,
   /** press key immedialtely trigger */
   FALLING_EDGE_TRIG,
   /** press key immedialtely trigger & LONG */
   FALLING_LONG_TRIG,
}KEY_LONG_PRESS_TP_E;
/**
 * Definitioin of long pross type
 */

Typedef VOID

typedef VOID(* KEY_CALLBACK)(tuya_pin_name_t port,PUSH_KEY_TYPE_E type,INT_T cnt);
/**
 * @brief Handler of KEY event
 * 
 * @param[in] port PIN ID that got the event
 * @param[in] type Press type, see PUSH_KEY_TYPE_E
 * @param[in] cnt Count of continual. 
 * 
 * @note (cnt >= 2) ==> SEQ_KEY,
 * time < long_key_time && (cnt == 1) ==> NORMAL_KEY,
 * time >= long_key_time && (cnt == 1) ==> LONG_KEY
 */

Typedef KEY_USER_DEF_S;

typedef struct {
   /** PIN ID */
   tuya_pin_name_t port;
   /** whether low level trigger */
   BOOL_T low_level_detect;
   /** long press type, see KEY_LONG_PRESS_TP_E */
   KEY_LONG_PRESS_TP_E lp_tp;
   /** unit: ms, lp_tp == LP_ONCE_TRIG then valid and must >= 1000ms */
   USHORT_T long_key_time;
   /** unit:ms , 0:disable default:400ms */
   USHORT_T seq_key_detect_time;
   /** handler of KEY event */
   KEY_CALLBACK call_back;
}KEY_USER_DEF_S;
/**
 * @brief Definition of user defined key
 */