1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CHARGER_THREAD_H 17 #define CHARGER_THREAD_H 18 19 #include <thread> 20 21 #include <linux/input.h> 22 #include "input_type.h" 23 #include "battery_thread.h" 24 #include "battery_vibrate.h" 25 #include "battery_backlight.h" 26 #include "battery_led.h" 27 #include "animation_label.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace Battery { 32 namespace V1_1 { 33 class ChargerThread : public BatteryThread { 34 public: 35 friend class BatteryThreadTest; 36 private: 37 void Init(); 38 static void UpdateAnimation(const int32_t& capacity); 39 void Run(void* service) override; 40 void UpdateBatteryInfo(void* arg) override; 41 void HandleChargingState(); 42 void HandleScreenState(); 43 void HandleTemperature(const int32_t& temperature); 44 void HandleCapacity(const int32_t& capacity); 45 void HandleStates() override; 46 int32_t UpdateWaitInterval() override; 47 void CycleMatters() override; 48 static void AnimationInit(); 49 static void LoadImages(AnimationLabel* animationLabel); 50 void SetKeyWait(struct KeyState& key, int64_t timeout); 51 static void SetKeyState(int32_t code, int32_t value, int64_t now); 52 static void InitInput(); 53 static void EventPkgCallback(const InputEventPackage** pkgs, uint32_t count, uint32_t devIndex); 54 void HandlePowerKeyState(); 55 void HandlePowerKey(int32_t keycode, int64_t now); 56 static void HandleInputEvent(const struct input_event* iev); 57 std::unique_ptr<PowerSupplyProvider> provider_ = nullptr; 58 std::unique_ptr<BatteryVibrate> vibrate_ = nullptr; 59 std::unique_ptr<BatteryBacklight> backlight_ = nullptr; 60 std::unique_ptr<BatteryLed> led_ = nullptr; 61 62 static const int32_t INVALID = -1; 63 int64_t pluginWait_ = INVALID; 64 int64_t keyWait_ = INVALID; 65 int64_t backlightWait_ = INVALID; 66 int32_t capacity_ = INVALID; 67 int32_t chargeState_ = PowerSupplyProvider::BatteryChargeState::CHARGE_STATE_RESERVED; 68 bool started_ = false; 69 }; 70 } // namespace V1_1 71 } // namespace Battery 72 } // namespace HDI 73 } // namespace OHOS 74 #endif 75