• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_config.h"
25 #include "battery_vibrate.h"
26 #include "battery_backlight.h"
27 #include "battery_led.h"
28 #include "animation_label.h"
29 
30 namespace OHOS {
31 namespace HDI {
32 namespace Battery {
33 namespace V1_0 {
34 class ChargerThread : public BatteryThread {
35 public:
36     friend class BatteryThreadTest;
37 private:
38     void Init();
39     static void UpdateAnimation(const int32_t& capacity);
40     void Run(void* service) override;
41     void UpdateBatteryInfo(void* arg, char* msg) override;
42     void UpdateBatteryInfo(void* arg) override;
43     void HandleChargingState();
44     void HandleScreenState();
45     void HandleTemperature(const int32_t& temperature);
46     void HandleCapacity(const int32_t& capacity);
47     void HandleStates() override;
48     int UpdateWaitInterval() override;
49     void CycleMatters() override;
50     void AnimationInit();
51     void LoadImgs(AnimationLabel* g_animationLabel);
52     static void SetKeyWait(struct KeyState& key, int64_t timeout);
53     static int SetKeyState(int code, int value, int64_t now);
54     int InputInit();
55     static void EventPkgCallback(const EventPackage** pkgs, const uint32_t count, uint32_t devIndex);
56     void HandlePowerKeyState();
57     void HandlePowerKey(int keycode, int64_t now);
58     static void HandleInputEvent(const struct input_event* iev);
59     std::unique_ptr<BatteryConfig> batteryConfig_ = nullptr;
60     std::unique_ptr<PowerSupplyProvider> provider_ = nullptr;
61     std::unique_ptr<BatteryVibrate> vibrate_ = nullptr;
62     std::unique_ptr<BatteryBacklight> backlight_ = nullptr;
63     std::unique_ptr<BatteryLed> led_ = nullptr;
64     int64_t pluginWait_ = -1;
65     static int64_t keyWait_;
66     static int64_t backlightWait_;
67     static int32_t capacity_;
68     int32_t chargeState_ = -1;
69     bool started_ = false;
70 };
71 
72 constexpr int START_X1 = 0;
73 constexpr int START_Y1 = 850;
74 constexpr int WIDTH1 = 480;
75 constexpr int HEIGHT1 = 30;
76 constexpr int START_X2 = 0;
77 constexpr int START_Y2 = 900;
78 constexpr int WIDTH2 = 480;
79 constexpr int HEIGHT2 = 30;
80 constexpr int START_X5 = 0;
81 constexpr int START_Y5 = 900;
82 constexpr int HEIGHT5 = 100;
83 constexpr int START_X_SCALE = 8;
84 constexpr int START_Y_SCALE = 8;
85 constexpr int WIDTH_SCALE1 = 3;
86 constexpr int WIDTH_SCALE2 = 4;
87 }  // namespace V1_0
88 }  // namespace Battery
89 }  // namespace HDI
90 }  // namespace OHOS
91 #endif
92