#include "hal_interface_irled.h"
#include "hlog.h"

#define TAG "TAG_HAL_IRLED"

static IRCUT_MODE irled_mode = IRCUT_UNKNOWN;

extern void hal_irled_open(IRCUT_MODE mode);

static void *hal_irled_mode_set(void *param){
	kpacket *packet = (kpacket *)param;
	atomic_inc(packet);
	IRCUT_MODE new_mode = *((IRCUT_MODE*)packet->box->payload);
	hlogd("%s set_mode:%d", __func__, new_mode);
	if (irled_mode != new_mode){
		irled_mode = new_mode;
		hal_irled_open(new_mode == IRCUT_DAY ? 0 : 1);
	}else{
		hlogd("%s same as old no need to set new mode:%d", __func__, new_mode);
	}
	atomic_dec(packet);
	return 0;
}

uint32_t hal_irled_init(){
	hlogi("%s ok", __func__);
	hal_sub(EVENT_HAL_DAYNIGHT, hal_irled_mode_set, NULL);
	return 0;
}


uint32_t hal_irled_deinit(){
	hal_unsub(EVENT_HAL_DAYNIGHT, hal_irled_mode_set);
	return 0;
}

DECLARE_INIT(PRI_AFTER_DRIVER, hal_irled_init);
