Beispiel #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();
}
/*!
 * This function is called whenever some change is detected around the battery
 * and its charger. This method will try to find out if the battery is actually
 * charging and if it is the method will calculate the charging animation speed.
 *
 * What we managed to find aboput the charging is:
 * 1) The battery is not charging (despite any other info returned) if the
 *    battery is full. See NB#172929 for further details.
 */
void
BatteryBusinessLogic::recalculateChargingInfo ()
{
    #ifdef HAVE_QMSYSTEM
    QmBattery::ChargingState chargingState;
    QmBattery::BatteryState  batteryState;
    QmBattery::ChargerType   chargerType;
    bool                     charging;
    bool                     couldBeCharging;
    int                      chargingRate;
   
    chargerType = m_battery->getChargerType ();
    chargingState = m_battery->getChargingState ();
    batteryState = m_battery->getBatteryState ();

    /*
     * Carefully calculating the charging rate, the animation rate of the
     * charging indicator.
     */
    couldBeCharging =
        chargingState == QmBattery::StateCharging &&
        // This is actually not necessary, but we even check it in the unit
        // test. Just to be sure.
        chargerType != QmBattery::None;

    charging = 
        batteryState != QmBattery::StateFull &&
        chargerType != QmBattery::None &&
        chargingState != QmBattery::StateNotCharging &&
        chargingState != QmBattery::StateChargingFailed;

    chargingRate = 0;
    if (charging) 
        chargingRate = chargerType == QmBattery::Wall ?
            animation_rate_charging_wall : animation_rate_charging_usb;

    SYS_DEBUG ("*** charging       = %s", SYS_BOOL(charging));
    SYS_DEBUG ("*** m_Charging     = %s", SYS_BOOL(m_Charging));
    SYS_DEBUG ("*** chargingRate   = %d", chargingRate);
    SYS_DEBUG ("*** m_ChargingRate = %d", m_ChargingRate);

    if (chargingRate == m_ChargingRate &&
            couldBeCharging == m_Charging) 
        return;

    /*
     * If the charging rate has been changed we need to notify the ui with a
     * signal.
     */
    m_Charging = couldBeCharging;
    SYS_DEBUG ("*** chargingRate %d -> %d", m_ChargingRate, chargingRate);
    m_ChargingRate = chargingRate;       
    SYS_DEBUG ("Emitting batteryCharging(%d)", m_ChargingRate);
    emit batteryCharging (m_ChargingRate);

    /*
     * Then we need to notify everyone about the bar value. 
     * FIXME: Why exactly do we need that?
     */
    SYS_DEBUG ("Emitting batteryBarValueReceived(%d)", batteryBarValue (-1));
    emit batteryBarValueReceived (batteryBarValue (-1));

    if(batteryState == QmBattery::StateFull)
    {
        emit batteryFull();
        return;
    }

    /*
     * And the remaining battery capacity has to be recalculated.
     */
    remainingCapacityRequired();
    #else
    /*
     * FIXME: To implement a variant that does not use QmSystem.
     */
    #endif
}
Beispiel #3
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;
        };
    };
}