
#include "adc.h"
#include "../spi/gpio_spi.h"
#include "../spi/oled.h"
#include "../spi/oled_printf.h"

       
void Test_Adc_oled(void)
{
    float vol0, vol1;
    int t0, t1;
    char buf[100];
	int x, y, pressure,tmp = 0;
	int p_x=0,p_y=0;
	int mid,did;

	SPIInit();
    OLEDInit();
	OLEDPrint(0, 0, "www.100ask.com");
	
	SPIFlashInit(&mid,&did);
	printf("MID: 0x%x , DID : 0x%x\n\r",mid,did);
	oled_printf(2,0,"spiflash_Mid:%x",mid);
	oled_printf(4,0,"spiflash_Did:%x",did);	
	disp_rectangle(235,208,0xbfbfff);
	fb_print_string(210, 200, "return", 0xbfbfff);

	SPIFlashReadID();

	lmage_display(10,10);

    while (1)    // 串口无输入，则不断测试
    {
        vol0 = ((float)adc_read(0)*3.3)/1024.0;  // 计算电压值
        vol1 = ((float)adc_read(1)*3.3)/1024.0;  // 计算电压值
        t0   = (vol0 - (int)vol0) * 1000;   // 计算小数部分, 本代码中的printf无法打印浮点数
        t1   = (vol1 - (int)vol1) * 1000;   // 计算小数部分,  本代码中的printf无法打印浮点数
        printf("AIN0 = %d.%03dV    AIN1 = %d.%03dV\r", (int)vol0, t0, (int)vol1, t1);
        
		oled_printf(6, 0, "ADC: .   , .   ");
		oled_printf(6, 32, "%d",(int)vol0);
		oled_printf(6, 48, "%03d",t0);
		oled_printf(6, 80, "%d",(int)vol1);
		oled_printf(6, 96, "%03d",t1);


		ts_printf(100,150, 0xbfbfff,"ADC: .   , .  ");
		ts_printf(132,150, 0xbfbfff,"%d",(int)vol0);
		ts_printf(148,150,0xbfbfff,"%03d",t0);
		ts_printf(180,150,0xbfbfff,"%d",(int)vol1);
		ts_printf(196,150,0xbfbfff,"%03d",t1);

		if (ts_read(&x, &y, &pressure) == 0 && pressure)
		{
			if(tmp == 0 || juedui(p_x,p_y,x,y) == 0)
			{
				p_x = x;
				p_y = y;
			}
			tmp++;
		}
		else
		{
			if (175 <= p_x && p_x <= 295 && 181 <= p_y && p_y <= 235)
			{
				printf("return\n\r");
				Test_module_menu();
			}
			p_x=0,p_y=0;
			tmp = 0;
		}
    }
}

