/*********************************************************************************************************************
* TC264 Opensourec Library TC264 Դ⣩һڹٷ SDK ӿڵĵԴ
* Copyright (c) 2022 SEEKFREE ɿƼ
*
* ļ TC264 Դһ
*
* TC264 Դ 
* Ըᷢ GPLGNU General Public License GNUͨù֤
*  GPL ĵ3棨 GPL3.0ѡģκκİ汾·/޸
*
* Դķϣܷãδκεı֤
* ûԻʺض;ı֤
* ϸμ GPL
*
* ӦյԴͬʱյһ GPL ĸ
* ûУ<https://www.gnu.org/licenses/>
*
* ע
* Դʹ GPL3.0 Դ֤Э Ϊİ汾
* Ӣİ libraries/doc ļµ GPL3_permission_statement.txt ļ
* ֤ libraries ļ ļµ LICENSE ļ
* ӭλʹò ޸ʱ뱣ɿƼİȨ
*
* ļ          zf_device_detector
* ˾          ɶɿƼ޹˾
* 汾Ϣ          鿴 libraries/doc ļ version ļ 汾˵
*           ADS v1.9.4
* ƽ̨          TC264D
*           https://seekfree.taobao.com/
*
* ޸ļ¼
*                               ע
* 2023-05-27       pudding           first version
********************************************************************************************************************/

#ifndef _zf_device_detector_h_
#define _zf_device_detector_h_

#include "zf_common_typedef.h"
#include "zf_common_debug.h"

// FIFOС
#define DETECTOR_BUFFER_SIZE             ( 0x40 )

// ʾͨ
#define DETECTOR_SET_OSCILLOSCOPE_COUNT  ( 0x08 )

// Եͨ
#define DETECTOR_SET_PARAMETR_COUNT      ( 0x08 )

// ͼ
#define DETECTOR_CAMERA_MAX_BOUNDARY     ( 0x08 )

// Ƭλ͵֡ͷ
#define DETECTOR_SEND_HEAD               ( 0xAA )

// ͷ
#define DETECTOR_CAMERA_FUNCTION         ( 0x02 ) 
#define DETECTOR_CAMERA_DOT_FUNCTION     ( 0x03 ) 
#define DETECTOR_CAMERA_OSCILLOSCOPE     ( 0x10 )

// λƬ͵֡ͷ
#define DETECTOR_RECEIVE_HEAD            ( 0x55 )

// 
#define DETECTOR_RECEIVE_SET_PARAMETER   ( 0x20 )


// ݷ豸ö
typedef enum
{
    DETECTOR_DEBUG_UART,                            // Դ    ʹõĴDEBUG_UART_INDEX궨ָ
    DETECTOR_WIRELESS_UART,                         // ת
    DETECTOR_CH9141,                                // 9141
    DETECTOR_WIFI_UART,                             // WIFIת
    DETECTOR_WIFI_SPI,                              // WIFI SPI
    DETECTOR_CUSTOM,                                // ԶͨѶʽ Ҫdetector_custom_write_byteʵݷ
}detector_transfer_type_enum;


// ͷö
typedef enum
{
    // ͷͺŶ
    DETECTOR_OV7725_BIN = 1,
    DETECTOR_MT9V03X,
    DETECTOR_SCC8660,
    
    // ͼͶ
    DETECTOR_BINARY = 1,
    DETECTOR_GRAY,
    DETECTOR_RGB565,
}detector_image_type_enum;

// ͷö
typedef enum
{
    // ͷͺŶ
    X_BOUNDARY,     // ͵ͼб߽ϢֻXҲֻкϢͼ߶ȵõ
    Y_BOUNDARY,     // ͵ͼб߽ϢֻYҲֻϢͼȵõͨ
    XY_BOUNDARY,    // ͵ͼб߽ϢXYָλãͿԷʾЧ
    NO_BOUNDARY,    // ͵ͼûбϢ
}detector_boundary_type_enum;

typedef struct
{
    uint8 head;                                     // ֡ͷ
    uint8 channel_num;                              // λΪ  λΪͨ
    uint8 check_sum;                                // У
    uint8 length;                                   // 
    float data[DETECTOR_SET_OSCILLOSCOPE_COUNT];    // ͨ
}detector_oscilloscope_struct;


typedef struct
{
    uint8 head;                                     // ֡ͷ
    uint8 function;                                 // 
    uint8 camera_type;                              // λʾ߽ λʾǷͼ  0x133ʾһͼ߽磨߽ͨ硢ߡұ߽磩1ʾûͼ
    uint8 length;                                   // ȣЭ鲿֣
    uint16 image_width;                             // ͼ
    uint16 image_height;                            // ͼ߶
}detector_camera_struct;


typedef struct
{
    uint8 head;                                     // ֡ͷ
    uint8 function;                                 // 
    uint8 dot_type;                                 //   BIT5116λ 08λ    BIT7-BIT60ֻX 1ֻY 2XY궼    BIT3-BIT0߽
    uint8 length;                                   // ȣЭ鲿֣
    uint16 dot_num;                                 // 
    uint8  valid_flag;                              // ͨʶ 
    uint8  reserve;                                 // 
}detector_camera_dot_struct;

typedef struct
{
    void *image_addr;                               // ͷַ
    uint16 width;                                   // ͼ
    uint16 height;                                  // ͼ߶
    detector_image_type_enum camera_type;           // ͷ
    void *boundary_x[DETECTOR_CAMERA_MAX_BOUNDARY]; // ַ߽
    void *boundary_y[DETECTOR_CAMERA_MAX_BOUNDARY]; // ַ߽
}detector_camera_buffer_struct;

typedef struct
{
    uint8 head;                                     // ֡ͷ
    uint8 function;                                 // 
    uint8 channel;                                  // ͨ
    uint8 check_sum;                                // У
    float data;                                     // 
}detector_parameter_struct;


extern detector_oscilloscope_struct                 detector_oscilloscope_data;                         // ʾ
extern float                                        detector_parameter[DETECTOR_SET_PARAMETR_COUNT];    // յĲ


void    detector_oscilloscope_send                  (detector_oscilloscope_struct *detector_oscilloscope);

void    detector_camera_information_config          (detector_image_type_enum camera_type, void *image_addr, uint16 width, uint16 height);
void    detector_camera_boundary_config             (detector_boundary_type_enum boundary_type, uint16 dot_num, void *dot_x1, void *dot_x2, void *dot_x3, void *dot_y1, void *dot_y2, void *dot_y3);
void    detector_camera_send                        (void);

void    detector_data_analysis                      (void);
void    detector_init                               (detector_transfer_type_enum transfer_type);



#endif

