#ifndef __USER_MISC_H__
#define __USER_MISC_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f4xx.h"

#define PORT_LED  (GPIOC)
#define LED1      (GPIO_Pin_4)
#define LED2      (GPIO_Pin_5)

#define PORT_HEAT (GPIOB)
#define PIN_HEAT  (GPIO_Pin_1)

#define GAS_ID_REF     0
#define GAS_ID_INVALID 0xFFFFFFFF

#define GAS_COMB_NULL 0
#define GAS_COMB_1_1  1
#define GAS_COMB_2_2  2
#define GAS_COMB_3_1  3
#define GAS_COMB_2_1  4

struct data_gas_info_s {
    uint32_t id[4];
    uint8_t ref[4];
    uint8_t comb;
};

#define LED_OFF       (0)
#define LED_ON        (1)
#define LED_BLINK_ON  (2)
#define LED_BLINK_OFF (3)

struct led_ctrl_s {
    uint8_t state_save;      /* saved state before blink */
    uint8_t state;           /* 0:off, 1:of, 2:blink_on, 3:blink_off */
    uint8_t on;              /* led on time when blink, unit:0.1s */
    uint8_t off;             /* led off time when blink, unit:0.1s */
    uint8_t times;           /* times of blink */
    uint8_t on_volatile;
    uint8_t off_volatile;
    uint8_t times_volatile;
};

extern struct led_ctrl_s led_ctrl[2];

extern struct data_gas_info_s data_gas_info;
extern uint32_t system_tick_cnt;

void led_init(uint16_t led);
void led_off(uint16_t led);
void led_on(uint16_t led);
void led_toggle(uint16_t led);

void led_det_temperature_init(void);
void led_det_temperature_loop(void);
void led_sig_loop(void);
void led_loop(void);

void heat_init(void);
void heat_on(void);
void heat_off(void);

void gas_id_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __USER_MISC_H__ */
