Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f10412c2 authored by Chunmei Cai's avatar Chunmei Cai Committed by Gerrit - the friendly Code Review server
Browse files

healthd: charger: Add board overrides in mode_charger

Add following overrides in mode_charger to improve the off-mode charging
user experience:
 1. Draw battery information on the animation, such as: capacity;
 2. Handle board specific battery status update;
 3. Handle board specific mode charger initialization;
 4. Turn on/off the backlight explicitely;
 5. Reduce the unplugged shutdown delay to 1 seccond;
 6. Do a period chorse and then heartbeat to reduce the animation boot
time.

Change-Id: Ic2b7ab6deeb52c4effe3b4af9b590950d5ee97f1
parent 6013e8d8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -357,6 +357,9 @@ int main(int argc, char **argv) {
        exit(2);
    }

    periodic_chores();
    healthd_mode_ops->heartbeat();

    healthd_mainloop();
    KLOG_ERROR("Main loop terminated, exiting\n");
    return 3;
+16 −0
Original line number Diff line number Diff line
@@ -121,4 +121,20 @@ void healthd_board_init(struct healthd_config *config);

int healthd_board_battery_update(struct android::BatteryProperties *props);

//This API is called to turn on/off the display backlight incase it can't be
//handle correcty in the display driver by calling gr_fg_blank();
void healthd_board_mode_charger_set_backlight(bool en);

//This API is called to update the battery/charging status by using the user
//noticeable method other then the animation, such as: LEDs
void healthd_board_mode_charger_battery_update(struct android::BatteryProperties *batt_prop);

//This API is used to handle some board specific charger mode initialization,
//such as: checking the charging is enabled or not.
void healthd_board_mode_charger_init(void);

//This API is called in the draw_battery() function to draw more infomation
//about the battery on the animation, such as the SoC (State of Charge).
void healthd_board_mode_charger_draw_battery(struct android::BatteryProperties *batt_prop);

#endif /* _HEALTHD_H_ */
+20 −0
Original line number Diff line number Diff line
@@ -27,3 +27,23 @@ int healthd_board_battery_update(struct android::BatteryProperties*)
    // return 0 to log periodic polled battery status to kernel log
    return 0;
}

void healthd_board_mode_charger_draw_battery(struct android::BatteryProperties*)
{

}

void healthd_board_mode_charger_battery_update(struct android::BatteryProperties*)
{

}

void healthd_board_mode_charger_set_backlight(bool)
{

}

void healthd_board_mode_charger_init()
{

}
+29 −11
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ char *locale;

#define BATTERY_UNKNOWN_TIME    (2 * MSEC_PER_SEC)
#define POWER_ON_KEY_TIME       (2 * MSEC_PER_SEC)
#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
#define UNPLUGGED_SHUTDOWN_TIME (1 * MSEC_PER_SEC)

#define BATTERY_FULL_THRESH     95

@@ -314,6 +314,7 @@ static void draw_battery(struct charger *charger)
             batt_anim->cur_frame, frame->min_capacity,
             frame->disp_time);
    }
    healthd_board_mode_charger_draw_battery(batt_prop);
}

static void redraw_screen(struct charger *charger)
@@ -367,6 +368,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
        gr_font_size(&char_width, &char_height);

#ifndef CHARGER_DISABLE_INIT_BLANK
        healthd_board_mode_charger_set_backlight(false);
        gr_fb_blank(true);
#endif
        minui_inited = true;
@@ -376,6 +378,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
    if (batt_anim->cur_cycle == batt_anim->num_cycles) {
        reset_animation(batt_anim);
        charger->next_screen_transition = -1;
        healthd_board_mode_charger_set_backlight(false);
        gr_fb_blank(true);
        LOGV("[%" PRId64 "] animation done\n", now);
        if (charger->charger_connected)
@@ -407,8 +410,10 @@ static void update_screen_state(struct charger *charger, int64_t now)
    }

    /* unblank the screen on first cycle */
    if (batt_anim->cur_cycle == 0)
    if (batt_anim->cur_cycle == 0) {
        gr_fb_blank(false);
        healthd_board_mode_charger_set_backlight(true);
    }

    /* draw the new frame (@ cur_frame) */
    redraw_screen(charger);
@@ -508,6 +513,7 @@ static void set_next_key_check(struct charger *charger,

static void process_key(struct charger *charger, int code, int64_t now)
{
    struct animation *batt_anim = charger->batt_anim;
    struct key_state *key = &charger->keys[code];

    if (code == KEY_POWER) {
@@ -534,17 +540,25 @@ static void process_key(struct charger *charger, int code, int64_t now)
                 * make sure we wake up at the right-ish time to check
                 */
                set_next_key_check(charger, key, POWER_ON_KEY_TIME);

               /* Turn on the display and kick animation on power-key press
                * rather than on key release
                */
                kick_animation(charger->batt_anim);
                request_suspend(false);
            }
        } else {
            /* if the power key got released, force screen state cycle */
            if (key->pending) {
                kick_animation(charger->batt_anim);
                /* If key is pressed when the animation is not running, kick
                 * the animation and quite suspend; If key is pressed when
                 * the animation is running, turn off the animation and request
                 * suspend.
                 */
                if (!batt_anim->run) {
                    kick_animation(batt_anim);
                    request_suspend(false);
                } else {
                    reset_animation(batt_anim);
                    charger->next_screen_transition = -1;
                    healthd_board_mode_charger_set_backlight(false);
                    gr_fb_blank(true);
                    if (charger->charger_connected)
                        request_suspend(true);
                }
            }
        }
    }
@@ -565,6 +579,8 @@ static void handle_power_supply_state(struct charger *charger, int64_t now)
    if (!charger->have_battery_state)
        return;

    healthd_board_mode_charger_battery_update(batt_prop);

    if (!charger->charger_connected) {

        /* Last cycle would have stopped at the extreme top of battery-icon
@@ -683,6 +699,8 @@ void healthd_mode_charger_init(struct healthd_config* config)

    LOGW("--------------- STARTING CHARGER MODE ---------------\n");

    healthd_board_mode_charger_init();

    ret = ev_init(input_callback, charger);
    if (!ret) {
        epollfd = ev_get_epollfd();