/******************************************************************************
* File Name		:	LED.c
* Date				: 2021/05/26
* Description	:	
******************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "LED_Display.h"
#include "NTC_Main.h"
#include "sonix_user.h"


/*_____ D E C L A R A T I O N S ____________________________________________*/
bit f_ClockDisplayStart = 0;
xdata uint8_t bLEDMartxi1_ScanCNT =0;
xdata uint8_t	b_aryLEDMatrix[3] = {0};
xdata uint8_t r_lcd_buf[5]= {0};		
code	uint8_t r_table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};	
LEDTypeDef Mix;							
/*_____ D E F I N I T I O N S ______________________________________________*/

/*_____ M A C R O S ________________________________________________________*/

/*_____ F U N C T I O N S __________________________________________________*/

/*****************************************************************************
* Function		: MixLED
* Description	: MixLED
* Input			: None
* Output		: None
* Return		: None
* Note			: None
*****************************************************************************/
void LEDMatrixDriver(void)
{	
	MATRIXLED1_IO_INPUT_SCHMITT_OFF;
	switch(bLEDMartxi1_ScanCNT)
	{
		case 0 :	LED_1_ON;LED_2_ON;LED_3_ON;LED_10_ON;LED_11_ON;LED_12_ON;LED_13_ON;	break;
		case 1 :	LED_4_ON;LED_5_ON;LED_6_ON;LED_7_ON;LED_8_ON;LED_9_ON;LED_21_ON;	break;
		case 2 :	LED_14_ON;LED_15_ON;LED_16_ON;LED_17_ON;LED_18_ON;LED_19_ON;LED_20_ON;	break;		
		case 3 :	LED_DISPLAY1_SEG1_A_ON; \
							LED_DISPLAY1_SEG1_B_ON; \
							LED_DISPLAY1_SEG1_C_ON; \
							LED_DISPLAY1_SEG1_D_ON; \
							LED_DISPLAY1_SEG1_E_ON; \
							LED_DISPLAY1_SEG1_F_ON; \
							LED_DISPLAY1_SEG1_G_ON; \
							LED_DISPLAY1_SEG1_DP_ON; break;				

		case 4 :	LED_DISPLAY1_SEG2_A_ON; \
							LED_DISPLAY1_SEG2_B_ON; \
							LED_DISPLAY1_SEG2_C_ON; \
							LED_DISPLAY1_SEG2_D_ON; \
							LED_DISPLAY1_SEG2_E_ON; \
							LED_DISPLAY1_SEG2_F_ON; \
							LED_DISPLAY1_SEG2_G_ON; \
							LED_DISPLAY1_SEG2_DP_ON; break;			

		case 5 :	LED_DISPLAY1_SEG3_A_ON; \
							LED_DISPLAY1_SEG3_B_ON; \
							LED_DISPLAY1_SEG3_C_ON; \
							LED_DISPLAY1_SEG3_D_ON; \
							LED_DISPLAY1_SEG3_E_ON; \
							LED_DISPLAY1_SEG3_F_ON; \
							LED_DISPLAY1_SEG3_G_ON; \
							LED_DISPLAY1_SEG3_DP_ON; break;			
							
		case 6 :	LED_DISPLAY1_SEG4_A_ON; \
							LED_DISPLAY1_SEG4_B_ON; \
							LED_DISPLAY1_SEG4_C_ON; \
							LED_DISPLAY1_SEG4_D_ON; \
							LED_DISPLAY1_SEG4_E_ON; \
							LED_DISPLAY1_SEG4_F_ON; \
							LED_DISPLAY1_SEG4_G_ON; \
							LED_DISPLAY1_SEG4_DP_ON; break;										
		//**  LED 1-8							
//		case 0 :	LED_1_ON	;	break;
//		case 1 :	LED_2_ON	; break;
//		case 2 :	LED_3_ON	;	break;
//		case 3 :	LED_4_ON	;	break;
//		case 4 :	LED_5_ON	; break;
//		case 5 :	LED_6_ON	;	break;		
//		case 6 :	LED_7_ON	;	break;
//		case 7 :	LED_8_ON	;	break;
//		//**  LED 9-16
//		case 8 :	LED_9_ON	;	break;
//		case 9 :	LED_10_ON	;	break;
//		case 10:	LED_11_ON	;	break;
//		case 11:	LED_12_ON	;	break;		
//		case 12:	LED_13_ON	;	break;
//		case 13:	LED_14_ON	;	break;		
//		case 14:	LED_15_ON	;	break;
//		case 15:	LED_16_ON	;	break;		
//		//**  LED 17-21		
//		case 16:	LED_17_ON	;	break;
//		case 17:	LED_18_ON	;	break;			
//		case 18 :	LED_19_ON	;	break;
//		case 19 :	LED_20_ON	;	break;
//		case 20 :	LED_21_ON	;	break;

		default:	bLEDMartxi1_ScanCNT =0; break;
	}

	bLEDMartxi1_ScanCNT++;
	if(bLEDMartxi1_ScanCNT>6)
	{
		bLEDMartxi1_ScanCNT=0;
	}
}

/*****************************************************************************
* Function		: Dis_on_off
* Description	: Dis_on_off
* Input			: None
* Output		: None
* Return		: None
* Note			: None
*****************************************************************************/
void Dis_on_off(bit flag)
{
	if(flag)
	{
		r_lcd_buf[0] = 0;
		r_lcd_buf[1] = 0;		
		r_lcd_buf[2] = 0x3F;
		r_lcd_buf[3] = A|B|C|E|F;
		r_lcd_buf[4] = 0;
	}
	else
	{
		r_lcd_buf[0] = 0;
		r_lcd_buf[1] = 0;		
		r_lcd_buf[2] = 0x3F;
		r_lcd_buf[3] = A|G|E|F;
		r_lcd_buf[4] = A|G|E|F;
	}	
}

/*****************************************************************************
* Function		: led_ctr
* Description	: led_ctr
* Input			: None
* Output		: None
* Return		: None
* Note			: None
*****************************************************************************/
void led_ctr(uint16_t dbLEDnumber ,bit on)
{
	TwoByte un_dbLEDIndex;
	un_dbLEDIndex.uniWord = dbLEDnumber;
	
	if(on)
	{
		b_aryLEDMatrix[un_dbLEDIndex.uniByte[0]] |= un_dbLEDIndex.uniByte[1];
		if(dbLEDnumber == 0xFFFF)
		{
			b_aryLEDMatrix[0] |= (led_4|led_5|led_6|led_7|led_8);
			b_aryLEDMatrix[1] |= (led_9|led_10|led_11|led_12|led_14|led_15|led_16);
			b_aryLEDMatrix[2] |= (led_17|led_18|led_19);			
		}
	}
	else
	{
		b_aryLEDMatrix[un_dbLEDIndex.uniByte[0]] &= ~un_dbLEDIndex.uniByte[1];
		if(dbLEDnumber == 0xFFFF)
		{
			b_aryLEDMatrix[0] = 0;
			b_aryLEDMatrix[1] = 0;
			b_aryLEDMatrix[2] = 0;			
		}		
	}			
	
}