From 3d637a9abb3fa37b7f0b6a14f10da3d295cafac7 Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Mon, 27 Sep 2021 17:40:40 +0800 Subject: [PATCH] charger: process hall_sensor event to show charging animation Bug: 191831427 Test: charging animation can show in display correctly Signed-off-by: Jack Wu Change-Id: Id99a7401f53f647790e179e995dad9841f8284bb --- healthd/healthd_mode_charger.cpp | 47 +++++++++++++++++++ .../charger/healthd_mode_charger.h | 9 ++++ 2 files changed, 56 insertions(+) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 821206f06..012e33ba1 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -348,6 +348,14 @@ void Charger::UpdateScreenState(int64_t now) { disp_time = batt_anim_.frames[batt_anim_.cur_frame].disp_time; + /* turn off all screen */ + if (screen_switch_ == SCREEN_SWITCH_ENABLE) { + healthd_draw_->blank_screen(true, 0 /* drm */); + healthd_draw_->blank_screen(true, 1 /* drm */); + screen_blanked_ = true; + screen_switch_ = SCREEN_SWITCH_DISABLE; + } + if (screen_blanked_) { healthd_draw_->blank_screen(false, static_cast(drm_)); screen_blanked_ = false; @@ -452,7 +460,26 @@ int Charger::SetKeyCallback(int code, int value) { return 0; } +int Charger::SetSwCallback(int code, int value) { + if (code > SW_MAX) return -1; + if (code == SW_LID) { + if ((screen_switch_ == SCREEN_SWITCH_DEFAULT) || ((value != 0) && (drm_ == DRM_INNER)) || + ((value == 0) && (drm_ == DRM_OUTER))) { + screen_switch_ = SCREEN_SWITCH_ENABLE; + drm_ = (value != 0) ? DRM_OUTER : DRM_INNER; + keys_[code].pending = true; + } + } + + return 0; +} + void Charger::UpdateInputState(input_event* ev) { + if (ev->type == EV_SW && ev->code == SW_LID) { + SetSwCallback(ev->code, ev->value); + return; + } + if (ev->type != EV_KEY) return; SetKeyCallback(ev->code, ev->value); } @@ -511,10 +538,26 @@ void Charger::ProcessKey(int code, int64_t now) { key->pending = false; } +void Charger::ProcessHallSensor(int code) { + key_state* key = &keys_[code]; + + if (code == SW_LID) { + if (key->pending) { + reset_animation(&batt_anim_); + kick_animation(&batt_anim_); + RequestDisableSuspend(); + } + } + + key->pending = false; +} + void Charger::HandleInputState(int64_t now) { ProcessKey(KEY_POWER, now); if (next_key_check_ != -1 && now > next_key_check_) next_key_check_ = -1; + + ProcessHallSensor(SW_LID); } void Charger::HandlePowerSupplyState(int64_t now) { @@ -744,9 +787,13 @@ void Charger::OnInit(struct healthd_config* config) { } } drm_ = DRM_INNER; + screen_switch_ = SCREEN_SWITCH_DEFAULT; ev_sync_key_state(std::bind(&Charger::SetKeyCallback, this, std::placeholders::_1, std::placeholders::_2)); + (void)ev_sync_sw_state( + std::bind(&Charger::SetSwCallback, this, std::placeholders::_1, std::placeholders::_2)); + next_screen_transition_ = -1; next_key_check_ = -1; next_pwr_check_ = -1; diff --git a/healthd/include_charger/charger/healthd_mode_charger.h b/healthd/include_charger/charger/healthd_mode_charger.h index 698719f78..28e1fb531 100644 --- a/healthd/include_charger/charger/healthd_mode_charger.h +++ b/healthd/include_charger/charger/healthd_mode_charger.h @@ -49,6 +49,12 @@ enum DirectRenderManager { DRM_OUTER, }; +enum SrceenSwitch { + SCREEN_SWITCH_DEFAULT, + SCREEN_SWITCH_DISABLE, + SCREEN_SWITCH_ENABLE, +}; + // Configuration interface for charger. This includes: // - HalHealthLoop APIs that interests charger. // - configuration values that used to be provided by sysprops @@ -90,9 +96,11 @@ class Charger { void InitDefaultAnimationFrames(); void UpdateScreenState(int64_t now); int SetKeyCallback(int code, int value); + int SetSwCallback(int code, int value); void UpdateInputState(input_event* ev); void SetNextKeyCheck(key_state* key, int64_t timeout); void ProcessKey(int code, int64_t now); + void ProcessHallSensor(int code); void HandleInputState(int64_t now); void HandlePowerSupplyState(int64_t now); int InputCallback(int fd, unsigned int epevents); @@ -108,6 +116,7 @@ class Charger { int64_t wait_batt_level_timestamp_ = 0; DirectRenderManager drm_; + SrceenSwitch screen_switch_; key_state keys_[KEY_MAX + 1] = {};