예제 #1
0
void VBatQuant()
{
    /* Start ADC2 Software Conversion */

    /* Test EOC flag */
    while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);

    /* Get ADC2 converted data */
    int adcValue = ADC_GetConversionValue(ADC2);

    //Не задерживаем вывод на экран. Батарейка все равно медленно разряжается, поэтому показываем старое значение
    ADC_StartConversion(ADC2);

    const int Vup = 3080;//6.2 V
    const int Vdown = 2730;//5.5 V
    int value = 0;

    //Vup->6.5 Vdown->0
    value = adcValue-Vdown;
    if(value<0)
        value = 0;

    value = (value*65)/(10*(Vup-Vdown));

    //Draw battery
    byte x0 = 63, y0 = 0;
    LcdLine(x0, x0, y0+1, y0+7, PIXEL_ON );
    LcdLine(x0+1, x0+3, y0+1, y0+1, PIXEL_ON );
    LcdLine(x0+1, x0+3, y0+7, y0+7, PIXEL_ON );

    LcdLine(x0+3, x0+3, y0+1, y0+0, PIXEL_ON );
    LcdLine(x0+3, x0+3, y0+7, y0+8, PIXEL_ON );

    LcdLine(x0+3, x0+19, y0+0, y0+0, PIXEL_ON );
    LcdLine(x0+3, x0+19, y0+8, y0+8, PIXEL_ON );
    LcdLine(x0+20, x0+20, y0+0, y0+8, PIXEL_ON );

    if(value>5)
        LcdSingleBar( x0+2, y0+3+3, 3, 2, PIXEL_ON );

    for(byte i=0; i<5; i++)
    {
        if(value>4-i)
            LcdSingleBar( x0+5+i*3, y0+3+4, 5, 2, PIXEL_ON );
    }
}
예제 #2
0
void formatPrintX2(uint8_t y, char* aBuffer, float aValue, const char*const* aSuffix, uint8_t aSuffixCount, int8_t aSuffixMin)
{
	char* startBuffer = aBuffer;
	float mul = 1;
	int8_t iSuffix = 0;

	if(aValue<0)
	{
		LcdSingleBar  ( 0, y*8+2, 2, 5, PIXEL_ON);
		aValue = -aValue;
	}

	if(aValue>=1)
	{
		for(iSuffix = -aSuffixMin; iSuffix<(int8_t)aSuffixCount; iSuffix++)
		{
			float mul1 = mul*1000;
			if(aValue<mul1)
				goto FormatValue;
			mul = mul1; 
		}

		*aBuffer++ = 'i';
		*aBuffer++ = 'n';
		*aBuffer++ = 'f';
		iSuffix = -aSuffixMin;
		goto AddSufix;
	}else
	{
		for(iSuffix = -aSuffixMin; iSuffix>0; iSuffix--)
		{
			if(aValue>=mul)
				break;
			mul *= 1e-3f;
		}
	}


FormatValue:;
	aValue /= mul;

	{
		int value;

		if(aValue>=200)
		{
			value = (int)(aValue+0.5f);
			char c = (value/1000);
			if(c)
				*aBuffer++ = '0'+c;
			*aBuffer++ = '0'+((value/100)%10);
			*aBuffer++ = '0'+(char)((value/10)%10);
			*aBuffer++ = '0'+(char)(value%10);
		} else
		if(aValue>=20)
		{
			value = (int)(aValue*10+0.5f);
			char c = (value/1000);
			if(c)
				*aBuffer++ = '0'+c;
			*aBuffer++ = '0'+(value/100)%10;
			*aBuffer++ = '0'+(char)((value/10)%10);
			*aBuffer++ = '.';
			*aBuffer++ = '0'+(char)(value%10);
		} else
		if(aValue>=9)
		{
			value = (int)(aValue*100+0.5f);
			char c = (value/1000);
			if(c)
				*aBuffer++ = '0'+c;
			*aBuffer++ = '0'+(value/100)%10;
			*aBuffer++ = '.';
			*aBuffer++ = '0'+(char)((value/10)%10);
			*aBuffer++ = '0'+(char)(value%10);
		} else
		{
			value = (int)(aValue*1000+0.5f);
			char c = (value/1000);
			*aBuffer++ = '0'+c;
			*aBuffer++ = '.';
			*aBuffer++ = '0'+(value/100)%10;
			*aBuffer++ = '0'+(char)((value/10)%10);
			*aBuffer++ = '0'+(char)(value%10);
		}
	}

AddSufix:;
	*aBuffer = 0;
	LcdGotoXYFont(2, y+1);
	LcdStr(FONT_2X, startBuffer);

	LcdGotoXYFont(12, y+1);
	LcdStr(FONT_1X, aSuffix[iSuffix]);
}