Exemplo n.º 1
0
static void batteryLevel(void)
{
    int dy = 0;
    int dx = 0;
    int32_t voltage = 0;
    float purcentage = 0;
    uint8_t color = 0x00;

    setExtFont("normal");
    dy = RESY - getFontHeight();
    dx = DoString(dx, dy, "Bat");

    if (batteryCharging()) {
        dx = DoString(dx, dy, "(+)");
    }
    dx = DoString(dx, dy, ":");

    voltage = batteryGetVoltage();
    purcentage = (voltage - (float)BAT_MIN) / ((float)BAT_MAX - BAT_MIN) * 100.0;

    if (purcentage >= 50) {
        color = RGB(0, 7, 0);
    }
    else if (purcentage >= 10) {
        color = RGB(7, 7, 0);
    }
    else {
        color = RGB(7, 0, 0);
    }
    setTextColor(GLOBAL(nickbg), color);
    dx = DoString(dx, dy, IntToStr(purcentage, 3, F_LONG));
    DoString(dx, dy, "%");
    resetColor();
}
Exemplo n.º 2
0
void ram(void){
    getInputWaitRelease();

    uint8_t old_state=-1;
    uint8_t charging_count=0;

    while(1){
        uint32_t mv = batteryGetVoltage();

        if (batteryCharging()) {
            if(!(charging_count % 50)){
                drawCommonThings(true);
                lcdPrintln("   Charging ...");

                if(charging_count>=50)  drawRectFill(16, 65, 22, 26, 0b11100000);
                if(charging_count>=100) drawRectFill(40, 65, 22, 26, 0b11110000);
                if(charging_count>=150) drawRectFill(64, 65, 22, 26, 0b10011100);
                if(charging_count>=200) drawRectFill(88, 65, 22, 26, 0b00011100);
                old_state = 0;
            }

            if(++charging_count > 250) charging_count=0;
            delayms(5);
        } else if (mv<3550 && old_state != 1){
            drawCommonThings(false);
            lcdPrintln("    Charge NOW!");
            drawRectFill(16, 65, 5, 26, 0b11100000);
            old_state = 1;
        }else if (mv<3650 && mv>=3550 && old_state != 2){
            drawCommonThings(false);
            lcdPrintln("    Charge soon");
            drawRectFill(16, 65, 22, 26, 0b11100000);
            old_state = 2;
        }else if (mv<4000 && mv>=3650 && old_state != 3){
            drawCommonThings(false);
            lcdPrintln("        OK");
            drawRectFill(16, 65, 22, 26, 0b11100000);
            drawRectFill(40, 65, 22, 26, 0b11110000);
            old_state = 3;
        }else if (mv<4120 && mv>=4000 && old_state != 4){
            drawCommonThings(false);
            lcdPrintln("       Good");
            drawRectFill(16, 65, 22, 26, 0b11100000);
            drawRectFill(40, 65, 22, 26, 0b11110000);
            drawRectFill(64, 65, 22, 26, 0b10011100);
            old_state = 4;
        }else if (mv>=4120 && old_state != 5) {
            drawCommonThings(false);
            lcdPrintln("       Full");
            drawRectFill(16, 65, 22, 26, 0b11100000);
            drawRectFill(40, 65, 22, 26, 0b11110000);
            drawRectFill(64, 65, 22, 26, 0b10011100);
            drawRectFill(88, 65, 22, 26, 0b00011100);
            old_state = 5;
        }

        // print voltage
        lcdSetCrsr(0, 100);
        uint8_t v = mv/1000;
        lcdPrint("      ");
        lcdPrint(IntToStr(v,2,0));
        lcdPrint(".");
        lcdPrint(IntToStr(mv%1000, 3, F_ZEROS | F_LONG));
        lcdPrintln("V");

        lcdDisplay();

        switch(getInput()){
            case BTN_LEFT:
                return;
            case BTN_ENTER:
                return;
        };
    };
}