#ifndef USER_ELECT_H__
#define USER_ELECT_H__

#include <stdint.h>
#include <stdbool.h>
#include "define.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ELECT_COUNT											    5

#define ELECT_INTERVAL						                    10

#define ELECT_GPIO_RCC_ENABLE					                RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOD, ENABLE)

#define ELECT_01_OPEN_GPIO                                    	GPIOB
#define ELECT_01_OPEN_PIN                                     	GPIO_Pin_5
#define ELECT_01_OPEN_ON						                GPIO_WriteBit(ELECT_01_OPEN_GPIO, ELECT_01_OPEN_PIN, Bit_SET)
#define ELECT_01_OPEN_OFF						                GPIO_WriteBit(ELECT_01_OPEN_GPIO, ELECT_01_OPEN_PIN, Bit_RESET)

#define ELECT_01_CLOSE_GPIO                                   	GPIOB
#define ELECT_01_CLOSE_PIN                                    	GPIO_Pin_4
#define ELECT_01_CLOSE_ON						                GPIO_WriteBit(ELECT_01_CLOSE_GPIO, ELECT_01_CLOSE_PIN, Bit_SET)
#define ELECT_01_CLOSE_OFF						            	GPIO_WriteBit(ELECT_01_CLOSE_GPIO, ELECT_01_CLOSE_PIN, Bit_RESET)

#define ELECT_02_OPEN_GPIO                                    	GPIOB
#define ELECT_02_OPEN_PIN                                     	GPIO_Pin_3
#define ELECT_02_OPEN_ON						                GPIO_WriteBit(ELECT_02_OPEN_GPIO, ELECT_02_OPEN_PIN, Bit_SET)
#define ELECT_02_OPEN_OFF						                GPIO_WriteBit(ELECT_02_OPEN_GPIO, ELECT_02_OPEN_PIN, Bit_RESET)

#define ELECT_02_CLOSE_GPIO                                   	GPIOD
#define ELECT_02_CLOSE_PIN                                    	GPIO_Pin_2
#define ELECT_02_CLOSE_ON						                GPIO_WriteBit(ELECT_02_CLOSE_GPIO, ELECT_02_CLOSE_PIN, Bit_SET)
#define ELECT_02_CLOSE_OFF						            	GPIO_WriteBit(ELECT_02_CLOSE_GPIO, ELECT_02_CLOSE_PIN, Bit_RESET)

#define ELECT_03_OPEN_GPIO                                    	GPIOC
#define ELECT_03_OPEN_PIN                                     	GPIO_Pin_12
#define ELECT_03_OPEN_ON						                GPIO_WriteBit(ELECT_03_OPEN_GPIO, ELECT_03_OPEN_PIN, Bit_SET)
#define ELECT_03_OPEN_OFF						                GPIO_WriteBit(ELECT_03_OPEN_GPIO, ELECT_03_OPEN_PIN, Bit_RESET)

#define ELECT_03_CLOSE_GPIO                                   	GPIOC
#define ELECT_03_CLOSE_PIN                                    	GPIO_Pin_11
#define ELECT_03_CLOSE_ON						                GPIO_WriteBit(ELECT_03_CLOSE_GPIO, ELECT_03_CLOSE_PIN, Bit_SET)
#define ELECT_03_CLOSE_OFF						            	GPIO_WriteBit(ELECT_03_CLOSE_GPIO, ELECT_03_CLOSE_PIN, Bit_RESET)

#define ELECT_04_OPEN_GPIO                                    	GPIOA
#define ELECT_04_OPEN_PIN                                     	GPIO_Pin_15
#define ELECT_04_OPEN_ON						                GPIO_WriteBit(ELECT_04_OPEN_GPIO, ELECT_04_OPEN_PIN, Bit_SET)
#define ELECT_04_OPEN_OFF						                GPIO_WriteBit(ELECT_04_OPEN_GPIO, ELECT_04_OPEN_PIN, Bit_RESET)

#define ELECT_04_CLOSE_GPIO                                   	GPIOC
#define ELECT_04_CLOSE_PIN                                    	GPIO_Pin_10
#define ELECT_04_CLOSE_ON						                GPIO_WriteBit(ELECT_04_CLOSE_GPIO, ELECT_04_CLOSE_PIN, Bit_SET)
#define ELECT_04_CLOSE_OFF						            	GPIO_WriteBit(ELECT_04_CLOSE_GPIO, ELECT_04_CLOSE_PIN, Bit_RESET)

#define ELECT_05_OPEN_GPIO                                    	GPIOD
#define ELECT_05_OPEN_PIN                                     	GPIO_Pin_5
#define ELECT_05_OPEN_ON						                GPIO_WriteBit(ELECT_05_OPEN_GPIO, ELECT_05_OPEN_PIN, Bit_SET)
#define ELECT_05_OPEN_OFF						                GPIO_WriteBit(ELECT_05_OPEN_GPIO, ELECT_05_OPEN_PIN, Bit_RESET)

#define ELECT_05_CLOSE_GPIO                                   	GPIOD
#define ELECT_05_CLOSE_PIN                                    	GPIO_Pin_6
#define ELECT_05_CLOSE_ON						                GPIO_WriteBit(ELECT_05_CLOSE_GPIO, ELECT_05_CLOSE_PIN, Bit_SET)
#define ELECT_05_CLOSE_OFF						            	GPIO_WriteBit(ELECT_05_CLOSE_GPIO, ELECT_05_CLOSE_PIN, Bit_RESET)

typedef enum{
	ELECT_WORK_NULL,
	ELECT_WORK_START,
	ELECT_WORK_END,
}elect_work_type_e;

typedef void (*elect_work_stat_func)(bool stat, elect_work_type_e type);

typedef struct{
	const uint8_t idx;
	bool stat;
	elect_work_type_e type;
	uint32_t workTime;
	elect_work_stat_func func;
}elect_work_s;

typedef enum
{
    ELECT_QUEUE_TIME	= 0,
    ELECT_QUEUE_START	= 1,
	ELECTSW_QUEUE_TIME	= 2,
}ELECT_QUEUE_TYPE;

typedef void (*vUser_elect_upload_stat_func)(uint8_t idx, bool stat, bool finish);

void elect_task_init(void);
void elect_task_start(void);
void elect_start(uint8_t addr);
void set_elect_work_stat(uint8_t idx, bool stat);
void vUser_elect_set_upload_stat_func(vUser_elect_upload_stat_func func);

extern tmosTaskID elect_task_id;

#ifdef __cplusplus
}
#endif

#endif // LED_H__

/** @} */
