#ifndef __H2201_DISPATCHER_H__
#define __H2201_DISPATCHER_H__
#include "esp_event.h"
#include "esp_timer.h"

#define H2201_DISPATCHER_TAG "H2201_DISPATCHER"

// ESP_EVENT_DECLARE_BASE(TASK_EVENTS); // declaration of the task events family
//  enum
//  {
//      TASK_ITERATION_EVENT,
//      TASK_BUTTON_EVENT
//  };

/// void h2201_dispatcher_add_event(esp_event_base_t event_base, int32_t event_id, void *args);

enum
{
    ENCODER_UP = 0,
    ENCODER_DOWN = 1,
    BUTTON_PRESS = 2,
};

#define BT_APP_SIG_WORK_DISPATCH (0x01)

/**
 * @brief     handler for the dispatched work
 */
typedef void (*h2201_dispatcher_cb_t)(uint16_t event, void *param);

typedef struct
{
    uint16_t sig;             /*!< signal type */
    uint16_t event;           /*!< message event id */
    h2201_dispatcher_cb_t cb; /*!< context switch callback */
    void *param; /*!< parameter area needs to be last */
} h2201_dispatcher_msg_t;

/**
 * @brief     parameter deep-copy function to be customized
 */
typedef void (*h2201_dispatcher_copy_cb_t)(h2201_dispatcher_msg_t *msg, void *p_dest, void *p_src);

/**
 * @brief     work dispatcher for the application task
 */
bool h2201_dispatcher_work_dispatch(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len, h2201_dispatcher_copy_cb_t p_copy_cback);
void h2201_dispatcher_work_dispatch_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params); //, int param_len);
bool h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event);

void H2201_dispacther_init(void);

#endif /* __H2201_DISPATCHER_H__ */