1e41f4b71Sopenharmony_ci# Battery Level and LED Color Mapping Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciOpenHarmony provides the battery level and LED color mapping by default. Some products, tablets for example, may use LED colors to display the battery level during charging. For example, green indicates a high battery level is high, yellow indicates a low battery level, and red indicates an extremely low battery level. The battery level and LED color mapping varies according to products. To address this issue, OpenHarmony provides the function of customizing the battery level and LED color mapping.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### Constraints
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci 
12e41f4b71Sopenharmony_ciThe configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_policy). In this development guide, `/vendor` is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## How to Develop
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### Setting Up the Environment
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**Hardware requirements:**
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciDevelopment board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**Environment requirements:**
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciFor details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci### Getting Started with Development
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ciThe following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate customization of the battery level and LED color mapping.
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci1. Create the `battery` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci2. Create a target folder by referring to the [default folder of battery level and LED color mapping configuration](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile), and install it in `//vendor/hihope/rk3568/battery`. The content is as follows:
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci    ```text
35e41f4b71Sopenharmony_ci    profile
36e41f4b71Sopenharmony_ci    ├── BUILD.gn
37e41f4b71Sopenharmony_ci    ├── battery_config.json
38e41f4b71Sopenharmony_ci    ```
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci3. Write the custom `battery_config.json` file by referring to the [battery_config.json](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json) file in the default folder of battery level and LED color mapping configuration. For example:
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci    ```json
43e41f4b71Sopenharmony_ci    {
44e41f4b71Sopenharmony_ci        "light": {
45e41f4b71Sopenharmony_ci            "low": {
46e41f4b71Sopenharmony_ci                "soc": [0, 20],
47e41f4b71Sopenharmony_ci                "rgb": [255, 192, 203]
48e41f4b71Sopenharmony_ci            },
49e41f4b71Sopenharmony_ci            "normal": {
50e41f4b71Sopenharmony_ci                "soc": [20, 95],
51e41f4b71Sopenharmony_ci                "rgb": [255, 0, 255]
52e41f4b71Sopenharmony_ci            },
53e41f4b71Sopenharmony_ci            "high": {
54e41f4b71Sopenharmony_ci                "soc": [95, 100],
55e41f4b71Sopenharmony_ci                "rgb": [0, 0, 255]
56e41f4b71Sopenharmony_ci            }
57e41f4b71Sopenharmony_ci        }
58e41f4b71Sopenharmony_ci    }
59e41f4b71Sopenharmony_ci    ```
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci    **Table 1** Description of battery levels
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci    | Battery Level| Description|
64e41f4b71Sopenharmony_ci    | -------- | -------- |
65e41f4b71Sopenharmony_ci    | low | Low battery level|
66e41f4b71Sopenharmony_ci    | normal | Normal battery level|
67e41f4b71Sopenharmony_ci    | high | High battery level|
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci    **Table 2** Configuration items for the battery level range and LED color
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci    | Configuration Item| Description|
72e41f4b71Sopenharmony_ci    | -------- | -------- |
73e41f4b71Sopenharmony_ci    | soc | Battery level range|
74e41f4b71Sopenharmony_ci    | rgb | LED RGB combination|
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci4. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/BUILD.gn) file in the default folder of battery level and LED color mapping configuration to pack the `battery_config.json` file to the `//vendor/etc/battery` directory. The configuration is as follows:
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci    ```shell
80e41f4b71Sopenharmony_ci    import("//build/ohos.gni")                # Reference build/ohos.gni.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("battery_config") {
83e41f4b71Sopenharmony_ci        source = "battery_config.json"
84e41f4b71Sopenharmony_ci        relative_install_dir = "battery"
85e41f4b71Sopenharmony_ci        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
86e41f4b71Sopenharmony_ci        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
87e41f4b71Sopenharmony_ci    }
88e41f4b71Sopenharmony_ci    ```
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci5. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build) in the `/vendor/hihope/rk3568` directory. For example:
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci    ```json
93e41f4b71Sopenharmony_ci    {
94e41f4b71Sopenharmony_ci    "parts": {
95e41f4b71Sopenharmony_ci        "product_rk3568": {
96e41f4b71Sopenharmony_ci        "module_list": [
97e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/default_app_config:default_app_config",
98e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/image_conf:custom_image_conf",
99e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
100e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
101e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/etc:product_etc_conf",
102e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config.
103e41f4b71Sopenharmony_ci        ]
104e41f4b71Sopenharmony_ci        }
105e41f4b71Sopenharmony_ci    },
106e41f4b71Sopenharmony_ci    "subsystem": "product_hihope"
107e41f4b71Sopenharmony_ci    }
108e41f4b71Sopenharmony_ci    ```
109e41f4b71Sopenharmony_ci    In the preceding code, //vendor/hihope/rk3568/battery/ is the folder path, profile is the folder name, and battery_config is the build target.
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci    ```shell
114e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
115e41f4b71Sopenharmony_ci    ```
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci### Debugging and Verification
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci1. After startup, run the following command to launch the shell command line:
122e41f4b71Sopenharmony_ci    ```
123e41f4b71Sopenharmony_ci    hdc shell
124e41f4b71Sopenharmony_ci    ```
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci2. Go to the custom battery level configuration directory. The path of DAYU200 is used as an example.
127e41f4b71Sopenharmony_ci    ```
128e41f4b71Sopenharmony_ci    cd /data/service/el0/battery/battery
129e41f4b71Sopenharmony_ci    ```
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci3. Modify the charging status, simulate reporting of the battery power change, and check whether the LED color is correct. The following uses the default battery level and LED color mapping configuration as an example.
132e41f4b71Sopenharmony_ci    
133e41f4b71Sopenharmony_ci    1. Modify the battery power.
134e41f4b71Sopenharmony_ci    ```
135e41f4b71Sopenharmony_ci    echo 5 > capacity
136e41f4b71Sopenharmony_ci    ```
137e41f4b71Sopenharmony_ci    2. Report the battery power change to trigger the LED mapping.
138e41f4b71Sopenharmony_ci    ```
139e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -r
140e41f4b71Sopenharmony_ci    ```
141e41f4b71Sopenharmony_ci    ![low_power_led](figures/low_power_led.jpg)
142e41f4b71Sopenharmony_ci    
143e41f4b71Sopenharmony_ci    3. Modify the battery power.
144e41f4b71Sopenharmony_ci    ```
145e41f4b71Sopenharmony_ci    echo 50 > capacity
146e41f4b71Sopenharmony_ci    ```
147e41f4b71Sopenharmony_ci    4. Report the battery power change to trigger the LED mapping.
148e41f4b71Sopenharmony_ci    ```
149e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -r
150e41f4b71Sopenharmony_ci    ```
151e41f4b71Sopenharmony_ci    ![normal_power_led](figures/normal_power_led.jpg)
152e41f4b71Sopenharmony_ci    
153e41f4b71Sopenharmony_ci    5. Modify the battery power.
154e41f4b71Sopenharmony_ci    ```
155e41f4b71Sopenharmony_ci    echo 100 > capacity
156e41f4b71Sopenharmony_ci    ```
157e41f4b71Sopenharmony_ci    6. Report the battery power change to trigger the LED mapping.
158e41f4b71Sopenharmony_ci    ```
159e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -r
160e41f4b71Sopenharmony_ci    ```
161e41f4b71Sopenharmony_ci    ![high_power_led](figures/high_power_led.jpg)
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci4. Customize the battery level and LED color mapping configuration. For example:
164e41f4b71Sopenharmony_ci    ```json
165e41f4b71Sopenharmony_ci    {
166e41f4b71Sopenharmony_ci        "light": {
167e41f4b71Sopenharmony_ci            "low": {
168e41f4b71Sopenharmony_ci                "soc": [0, 20],
169e41f4b71Sopenharmony_ci                "rgb": [255, 192, 203]
170e41f4b71Sopenharmony_ci            },
171e41f4b71Sopenharmony_ci            "normal": {
172e41f4b71Sopenharmony_ci                "soc": [20, 95],
173e41f4b71Sopenharmony_ci                "rgb": [255, 0, 255]
174e41f4b71Sopenharmony_ci            },
175e41f4b71Sopenharmony_ci            "high": {
176e41f4b71Sopenharmony_ci                "soc": [95, 100],
177e41f4b71Sopenharmony_ci                "rgb": [0, 0, 255]
178e41f4b71Sopenharmony_ci            }
179e41f4b71Sopenharmony_ci        }
180e41f4b71Sopenharmony_ci    }
181e41f4b71Sopenharmony_ci    ```
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci    1. Modify the battery power.
184e41f4b71Sopenharmony_ci    ```
185e41f4b71Sopenharmony_ci    echo 15 > capacity
186e41f4b71Sopenharmony_ci    ```
187e41f4b71Sopenharmony_ci    2. Report the battery power change to trigger the LED mapping.
188e41f4b71Sopenharmony_ci    ```
189e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -r
190e41f4b71Sopenharmony_ci    ```
191e41f4b71Sopenharmony_ci    ![low_power_led_alter](figures/normal_power_led_alter.jpg)
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci    3. Modify the battery power.
194e41f4b71Sopenharmony_ci    ```
195e41f4b71Sopenharmony_ci    echo 95 > capacity
196e41f4b71Sopenharmony_ci    ```
197e41f4b71Sopenharmony_ci    4. Report the battery power change to trigger the LED mapping.
198e41f4b71Sopenharmony_ci    ```
199e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -r
200e41f4b71Sopenharmony_ci    ```
201e41f4b71Sopenharmony_ci    ![normal_power_led_alter](figures/low_power_led_alter.jpg)
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci    5. Modify the battery power.
204e41f4b71Sopenharmony_ci    ```
205e41f4b71Sopenharmony_ci    echo 99 > capacity
206e41f4b71Sopenharmony_ci    ```
207e41f4b71Sopenharmony_ci    6. Report the battery power change to trigger the LED mapping.
208e41f4b71Sopenharmony_ci    ```
209e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -r
210e41f4b71Sopenharmony_ci    ```
211e41f4b71Sopenharmony_ci    ![high_power_led_alter](figures/high_power_led_alter.jpg)
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci## Reference
214e41f4b71Sopenharmony_ciDuring development, you can refer to the [default battery level and LED color mapping configuration](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json), as shown below:
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci 
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci```json 
219e41f4b71Sopenharmony_ci{
220e41f4b71Sopenharmony_ci    "light": {
221e41f4b71Sopenharmony_ci        "low": {
222e41f4b71Sopenharmony_ci            "soc": [0, 10],
223e41f4b71Sopenharmony_ci            "rgb": [255, 0, 0]
224e41f4b71Sopenharmony_ci        },
225e41f4b71Sopenharmony_ci        "normal": {
226e41f4b71Sopenharmony_ci            "soc": [10, 90],
227e41f4b71Sopenharmony_ci            "rgb": [255, 255, 0]
228e41f4b71Sopenharmony_ci        },
229e41f4b71Sopenharmony_ci        "high": {
230e41f4b71Sopenharmony_ci            "soc": [90, 100],
231e41f4b71Sopenharmony_ci            "rgb": [0, 255, 0]
232e41f4b71Sopenharmony_ci        }
233e41f4b71Sopenharmony_ci    }
234e41f4b71Sopenharmony_ci}
235e41f4b71Sopenharmony_ci``` 
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ciPacking path: /system/etc/battery
238