• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

frameworks/12-May-2024-1,211872

interfaces/kits/12-May-2024-324104

services/12-May-2024-1,048798

test/12-May-2024-261170

.clang-formatD12-May-20241.3 KiB3836

BUILD.gnD12-May-2024767 2219

LICENSED12-May-202410.1 KiB177150

OAT.xmlD12-May-2024982 2610

README.mdD12-May-20246.5 KiB12797

README_zh.mdD12-May-20246.3 KiB12597

batterymgr.gniD12-May-20241.4 KiB4534

bundle.jsonD12-May-20241.4 KiB6463

config.gniD12-May-2024639 1715

README.md

1# Lite Battery Manager<a name="EN-US_TOPIC_0000001174637973"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section19472752217)
5-   [Usage](#section146636391856)
6    -   [Available APIs](#section481251394)
7    -   [Usage Guidelines](#section12620311012)
8
9-   [Repositories Involved](#section63151229062)
10
11## Introduction<a name="section11660541593"></a>
12
13The lite battery manager provides the following functionalities:
14
151.  Obtaining battery information
162.  Obtaining the battery charging status and the battery state of charge \(SoC\)
173.  Monitoring the battery state of health \(SoH\)
184.  Controlling the battery charging indicator
19
20**Figure  1**  Lite battery manager architecture<a name="fig106301571239"></a>
21
22
23![](figures/en-us_image_0000001176131699.png)
24
25## Directory Structure<a name="section19472752217"></a>
26
27```
28base/powermgr/battery_lite
29├── figures           # Architecture figures
30├── frameworks        # Frameworks
31│   ├── js            # Built_in interface
32│   └── native        # Native code
33├── interfaces        # APIs
34│   └── kits          # External APIs
35├── services          # Services
36│   ├── include       # Header files
37│   └── src           # Source files
38└── test              # Interface test
39```
40
41## Usage<a name="section146636391856"></a>
42
43### Available APIs<a name="section481251394"></a>
44
45The following table lists the JavaScript APIs provided by the lite battery manager.
46
47<a name="table45171237103112"></a>
48
49<table><thead align="left"><tr id="row12572123793117"><th class="cellrowborder" valign="top" width="38.71%" id="mcps1.1.3.1.1"><p id="p19572937163116"><a name="p19572937163116"></a><a name="p19572937163116"></a><strong id="b1783175664017"><a name="b1783175664017"></a><a name="b1783175664017"></a>API</strong></p>
50</th>
51<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.3.1.2"><p id="p157213711313"><a name="p157213711313"></a><a name="p157213711313"></a><strong id="b62896374115"><a name="b62896374115"></a><a name="b62896374115"></a>Description</strong></p>
52</th>
53</tr>
54</thead>
55<tbody><tr id="row14574143723119"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p169098161437"><a name="p169098161437"></a><a name="p169098161437"></a>int32_t GetBatSoc()</p>
56</td>
57<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p105741337153115"><a name="p105741337153115"></a><a name="p105741337153115"></a>Obtains the battery SoC.</p>
58</td>
59</tr>
60<tr id="row19195203919318"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p46911925104319"><a name="p46911925104319"></a><a name="p46911925104319"></a>BatteryChargeState GetChargingStatus()</p>
61</td>
62<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p1619618397312"><a name="p1619618397312"></a><a name="p1619618397312"></a>Obtains the current battery charging status.</p>
63</td>
64</tr>
65<tr id="row9397121153216"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p1339731103216"><a name="p1339731103216"></a><a name="p1339731103216"></a>BatteryHealthState GetHealthStatus()</p>
66</td>
67<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p113972183214"><a name="p113972183214"></a><a name="p113972183214"></a>Obtains the battery SoH.</p>
68</td>
69</tr>
70<tr id="row1721311920324"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p321412915320"><a name="p321412915320"></a><a name="p321412915320"></a>BatteryPluggedType GetPluggedType()</p>
71</td>
72<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p32141298323"><a name="p32141298323"></a><a name="p32141298323"></a>Obtains the charger type.</p>
73</td>
74</tr>
75<tr id="row269082112447"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p16690202119449"><a name="p16690202119449"></a><a name="p16690202119449"></a>int32_t GetBatVoltage()</p>
76</td>
77<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p1869014214445"><a name="p1869014214445"></a><a name="p1869014214445"></a>Obtains the battery voltage.</p>
78</td>
79</tr>
80<tr id="row3654173318447"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p11654173374412"><a name="p11654173374412"></a><a name="p11654173374412"></a>bool IsBatPresent()</p>
81</td>
82<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p13654123354416"><a name="p13654123354416"></a><a name="p13654123354416"></a>Checks whether the battery is present.</p>
83</td>
84</tr>
85<tr id="row12187141584413"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p718841504418"><a name="p718841504418"></a><a name="p718841504418"></a>char* GetBatTechnology()</p>
86</td>
87<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p181881615194414"><a name="p181881615194414"></a><a name="p181881615194414"></a>Obtains the battery model.</p>
88</td>
89</tr>
90<tr id="row18381310134520"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p18838610114516"><a name="p18838610114516"></a><a name="p18838610114516"></a>int32_t GetBatTemperature()</p>
91</td>
92<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p13838121064515"><a name="p13838121064515"></a><a name="p13838121064515"></a>Obtains the battery temperature.</p>
93</td>
94</tr>
95</tbody>
96</table>
97
98
99### Usage Guidelines<a name="section12620311012"></a>
100
101The lite battery manager provides APIs for obtaining the battery SoC, battery charging status, and battery SoH.
102
103The sample code is as follows:
104
105```
106int32_t capacity = GetBatSoc();
107BatteryChargeState chargState = GetChargingStatus();
108```
109
110## Repositories Involved<a name="section63151229062"></a>
111
112[Power management subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/power-management.md)
113
114[powermgr_power_manager](https://gitee.com/openharmony/powermgr_power_manager)
115
116[powermgr_display_manager](https://gitee.com/openharmony/powermgr_display_manager)
117
118[powermgr_battery_manager](https://gitee.com/openharmony/powermgr_battery_manager)
119
120[powermgr_thermal_manager](https://gitee.com/openharmony/powermgr_thermal_manager)
121
122[powermgr_battery_statistics](https://gitee.com/openharmony/powermgr_battery_statistics)
123
124**powermgr_battery_lite**
125
126[powermgr_powermgr_lite](https://gitee.com/openharmony/powermgr_powermgr_lite)
127

README_zh.md

1# 轻量级电池管理组件<a name="ZH-CN_TOPIC_0000001174637973"></a>
2
3-   [简介](#section11660541593)
4-   [目录](#section19472752217)
5-   [说明](#section146636391856)
6    -   [接口说明](#section481251394)
7    -   [使用说明](#section12620311012)
8
9-   [相关仓](#section63151229062)
10
11## 简介<a name="section11660541593"></a>
12
13电池服务组件提供如下功能:
14
151.  电池信息查询。
162.  充放电状态查询。
173.  电池健康状态监测。
184.  充电指示灯控制。
19
20**图 1**  轻量级电池管理组件架构图<a name="fig106301571239"></a>
21
22
23![](figures/en-us_image_0000001176131699.png)
24
25## 目录<a name="section19472752217"></a>
26
27```
28base/powermgr/battery_lite
29├── figures           # 架构图
30├── frameworks        # Framework层
31│   ├── js            # 内置接口
32│   └── native        # naive层
33├── interfaces        # 接口层
34│   └── kits          # 外部接口层
35├── services          # 服务层
36│   ├── include       # 服务层头文件
37│   └── src           # 服务层源文件
38└── test              # 测试用例
39```
40
41## 说明<a name="section146636391856"></a>
42
43### 接口说明<a name="section481251394"></a>
44
45轻量电池管理组件对外提供的接口,如下表:
46
47<a name="table45171237103112"></a>
48<table><thead align="left"><tr id="row12572123793117"><th class="cellrowborder" valign="top" width="38.71%" id="mcps1.1.3.1.1"><p id="p19572937163116"><a name="p19572937163116"></a><a name="p19572937163116"></a><strong id="b18552135014316"><a name="b18552135014316"></a><a name="b18552135014316"></a>接口名</strong></p>
49</th>
50<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.3.1.2"><p id="p157213711313"><a name="p157213711313"></a><a name="p157213711313"></a><strong id="b193891558123118"><a name="b193891558123118"></a><a name="b193891558123118"></a>描述</strong></p>
51</th>
52</tr>
53</thead>
54<tbody><tr id="row14574143723119"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p169098161437"><a name="p169098161437"></a><a name="p169098161437"></a>int32_t GetBatSoc()</p>
55</td>
56<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p105741337153115"><a name="p105741337153115"></a><a name="p105741337153115"></a>获取电池剩余电量(SOC)。</p>
57</td>
58</tr>
59<tr id="row19195203919318"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p46911925104319"><a name="p46911925104319"></a><a name="p46911925104319"></a>BatteryChargeState GetChargingStatus()</p>
60</td>
61<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p1619618397312"><a name="p1619618397312"></a><a name="p1619618397312"></a>获取当前充电状态。</p>
62</td>
63</tr>
64<tr id="row9397121153216"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p1339731103216"><a name="p1339731103216"></a><a name="p1339731103216"></a>BatteryHealthState GetHealthStatus()</p>
65</td>
66<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p113972183214"><a name="p113972183214"></a><a name="p113972183214"></a>获取电池健康状态。</p>
67</td>
68</tr>
69<tr id="row1721311920324"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p321412915320"><a name="p321412915320"></a><a name="p321412915320"></a>BatteryPluggedType GetPluggedType()</p>
70</td>
71<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p32141298323"><a name="p32141298323"></a><a name="p32141298323"></a>获取当前连接的充电器类型。</p>
72</td>
73</tr>
74<tr id="row269082112447"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p16690202119449"><a name="p16690202119449"></a><a name="p16690202119449"></a>int32_t GetBatVoltage()</p>
75</td>
76<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p1869014214445"><a name="p1869014214445"></a><a name="p1869014214445"></a>获取电池电压。</p>
77</td>
78</tr>
79<tr id="row3654173318447"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p11654173374412"><a name="p11654173374412"></a><a name="p11654173374412"></a>bool IsBatPresent()</p>
80</td>
81<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p13654123354416"><a name="p13654123354416"></a><a name="p13654123354416"></a>检查电池是否在位。</p>
82</td>
83</tr>
84<tr id="row12187141584413"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p718841504418"><a name="p718841504418"></a><a name="p718841504418"></a>char* GetBatTechnology()</p>
85</td>
86<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p181881615194414"><a name="p181881615194414"></a><a name="p181881615194414"></a>获取电池类型。</p>
87</td>
88</tr>
89<tr id="row18381310134520"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p18838610114516"><a name="p18838610114516"></a><a name="p18838610114516"></a>int32_t GetBatTemperature()</p>
90</td>
91<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p13838121064515"><a name="p13838121064515"></a><a name="p13838121064515"></a>获取电池温度。</p>
92</td>
93</tr>
94</tbody>
95</table>
96
97### 使用说明<a name="section12620311012"></a>
98
99电池管理组件提供了获取电池剩余电量、充电状态、电池健康状态等接口。
100
101代码示例如下:
102
103```
104int32_t capacity = GetBatSoc();
105BatteryChargeState chargState = GetChargingStatus();
106```
107
108## 相关仓<a name="section63151229062"></a>
109
110[电源管理子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E7%94%B5%E6%BA%90%E7%AE%A1%E7%90%86%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
111
112[powermgr_power_manager](https://gitee.com/openharmony/powermgr_power_manager)
113
114[powermgr_display_manager](https://gitee.com/openharmony/powermgr_display_manager)
115
116[powermgr_battery_manager](https://gitee.com/openharmony/powermgr_battery_manager)
117
118[powermgr_thermal_manager](https://gitee.com/openharmony/powermgr_thermal_manager)
119
120[powermgr_battery_statistics](https://gitee.com/openharmony/powermgr_battery_statistics)
121
122**powermgr_battery_lite**
123
124[powermgr_powermgr_lite](https://gitee.com/openharmony/powermgr_powermgr_lite)
125