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