• Home
Name
Date
Size
#Lines
LOC

..--

figures/12-May-2024-

hal/12-May-2024-810617

hdi_impl/12-May-2024-291228

hdi_service/12-May-2024-479372

interfaces/12-May-2024-503194

test/12-May-2024-2,1341,407

BUILD.gnD12-May-2024890 2725

README.mdD12-May-20245.2 KiB12087

README_zh.mdD12-May-20245 KiB12993

bundle.jsonD12-May-20241.3 KiB5655

light.gniD12-May-2024181 65

README.md

1# Light
2
3## Introduction
4
5 The light driver model provides APIs for the upper-layer light hardware service layer to control lights, including obtaining the light type, setting the lighting mode and blinking effect, and turning on or off a light. This model implements functionalities such as cross-OS migration and differentiated configurations based on the Hardware Driver Foundation (HDF) to achieve the goal of "one-time development for cross-system deployment" of the light driver.
6
7**Figure 1** Light driver model
8
9![Light driver model](figures/light_driver_model.png)
10
11## Directory Structure
12
13The directory structure of the light module is as follows:
14
15```
16/drivers/peripheral/misc/light
17├── hal              # HAL code
18│   ├── include      # HAL header files
19│   └── src          # HAL code implementation
20├── interfaces       # Driver capability APIs provided for upper-layer services
21│   └── include      # APIs exposed externally
22└── test             # Test code
23    └── unittest     # Unit test code
24```
25
26## Usage
27
28### Available APIs
29
30The light driver model provides APIs to obtain information about all the lights in the system and dynamically set the blinking mode and duration. The light hardware service calls the **GetLightInfo** method to obtain basic information about the light and calls the **TurnOnLight** method to make the light blinking. The following table describes these APIs.
31
32**Table 1** Major APIs of the light module
33
34| API                                                      | Description                                                    |
35| ------------------------------------------------------------ | ------------------------------------------------------------ |
36| int32_t (*GetLightInfo)(struct LightInfo **lightInfo, uint32_t *count) | Obtains information about all lights in the system. **lightInfo** indicates the double pointer to the basic light information. **count** indicates the pointer to the number of lights.|
37| int32_t (*TurnOnLight)(uint32_t type, struct LightEffect *effect) | Turns on available lights in the list based on the specified light type. **type** indicates the light type, and **effect** indicates the pointer to the blinking effect.|
38| int32_t (*TurnOffLight)(uint32_t type)                       | Turns off available lights in the light list based on the specified light type. **type** indicates the light type.                                          |
39
40### How to Use
41
42The following provides the sample code for the small system.
43
44```c++
45#include "light_if.h"
46
47void LightSample(void)
48{
49	int32_t ret;
50    static struct LightInfo *g_lightInfo = nullptr;
51    static uint32_t g_count = 0;
52    const int32_t g_onTime = 500;
53    const int32_t g_offTime = 500;
54    const int32_t LIGHT_WAIT_TIME = 30;
55    const int32_t g_minLightType = LIGHT_TYPE_NONE;
56    const int32_t g_maxLightType = LIGHT_TYPE_BUTT;
57    struct LightEffect effect;
58
59	/* Create a LightInterface instance. */
60    struct LightInterface *g_lightDev = NewLightInterfaceInstance();
61    if (g_lightDev == NULL) {
62        return;
63    }
64	/* Obtain the list of lights supported by the device. */
65 	ret = g_lightDev->GetLightInfo(&g_lightInfo, &g_count);
66
67    /* Turn on the available lights of the specified color in the list and make it steady on. */
68    effect.lightBrightness = 0x80000000; // Brightness value. The most significant bit indicates the color. Bits16–31 for red, bits 8–15 for green, and bits 0–7 for blue. */
69    effect.flashEffect.flashMode = LIGHT_FLASH_NONE;
70
71    for (i = 0; i < g_count; ++i) {
72        ret = g_lightDev->TurnOnLight(g_lightInfo[i].lightType, &effect);
73        EXPECT_EQ(0, ret);
74
75        OsalSleep(LIGHT_WAIT_TIME);
76
77        ret = g_lightDev->TurnOffLight(g_lightInfo[i].lightType);
78        EXPECT_EQ(0, ret);
79    }
80    /* Turn on the available lights of the specified color in the list and make it blinking. */
81    effect.lightBrightness = 0x80000000;
82    effect.flashEffect.flashMode = LIGHT_FLASH_TIMED;
83    effect.flashEffect.onTime = g_onTime;    // Light on time in a blinking period, in ms
84    effect.flashEffect.offTime = g_offTime;    // Light off time in a blinking period, in ms
85
86    for (i = 0; i < g_count; ++i) {
87        ret = g_lightDev->TurnOnLight(g_lightInfo[i].lightType, &effect);
88        EXPECT_EQ(0, ret);
89
90        OsalSleep(LIGHT_WAIT_TIME);
91
92        ret = g_lightDev->TurnOffLight(g_lightInfo[i].lightType);
93        EXPECT_EQ(0, ret);
94    }
95
96    /* Turn off the light of the specified type in the light list. */
97    ret = g_lightDev->TurnOffLight(lightType);
98    EXPECT_EQ(0, ret);
99
100    /* Release the LightInterface instance. */
101    if (g_lightDev != nullptr) {
102        FreeLightInterfaceInstance();
103        g_lightDev = nullptr;
104    }
105}
106```
107
108## Repositories Involved
109
110[Drive Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md)
111
112[drivers_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
113
114[drivers_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
115
116[drivers_adapter_khdf_linuk](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
117[drivers_peripheral](https://gitee.com/openharmony/drivers_peripheral)
118
119[drivers_interface](https://gitee.com/openharmony/drivers_interface)
120

README_zh.md

1# light
2
3- [简介](##简介)
4- [目录](##目录)
5- [说明](##说明)
6  - [接口说明](###接口说明)
7  - [使用说明](###使用说明)
8
9- [相关仓](##相关仓)
10
11## 简介
12
13 Light驱动模型为上层Light硬件服务层提供稳定的灯控制能力接口,包括获取灯类型、配置点灯模式、配置灯闪烁效果、点灯、熄灯等。基于HDF( Hardware Device Interface )驱动框架开发的Light驱动模型,实现跨操作系统迁移,器件差异配置等功能。实现Light驱动“一次开发,多系统部署”的目标。
14
15**图 1**  Light驱动模型图
16
17![Light驱动模型图](figures/Light%E9%A9%B1%E5%8A%A8%E6%A8%A1%E5%9E%8B%E5%9B%BE.png)
18
19## 目录
20
21Light驱动下源代码目录结构如下所示:
22
23```
24/drivers/peripheral/misc/light
25├── hal              # light模块hal层代码
26│   ├── include      # light模块hal层内部头文件
27│   └── src          # light模块hal层代码的实现
28├── interfaces       # light模块对上层服务提供的驱动能力接口
29│   └── include      # light模块对外提供的接口定义
30└── test             # light模块测试代码
31    └── unittest     # light模块单元测试代码
32```
33
34## 说明
35
36### 接口说明
37
38Light驱动模型支持获取系统中所有灯的信息,动态配置闪烁模式和闪烁时间的能力。Light硬件服务调用GetLightInfo获取Light设备的基本信息;调用TurnOnLight接口启动配置的闪烁效果。开发能力如下表1:
39
40**表 1** Light的主要接口
41
42| 接口名                                                       | 功能描述                                                     |
43| ------------------------------------------------------------ | ------------------------------------------------------------ |
44| int32_t (*GetLightInfo)(struct LightInfo **lightInfo, uint32_t *count) | 获取系统中所有灯的信息,lightInfo表示灯设备的基本信息,count表示获取灯的个数。 |
45| int32_t (*TurnOnLight)(uint32_t lightId, struct LightEffect *effect) | 打开指定类型的灯,lightId表示灯类型,effect表示要设置的效果信息。 |
46| int32_t (*TurnOffLight)(uint32_t lightId)                    | 关闭指定类型的灯。                                           |
47
48### 使用说明
49
50代码示例,以小型系统为例。
51
52```c++
53#include "light_if.h"
54
55void LightSample(void)
56{
57	int32_t ret;
58    static struct LightInfo *g_lightInfo = nullptr;
59    static uint32_t g_count = 0;
60    const int32_t g_onTime = 500;
61    const int32_t g_offTime = 500;
62    const int32_t LIGHT_WAIT_TIME = 30;
63    const int32_t g_minLightId = LIGHT_ID_NONE;
64    const int32_t g_maxLightId = LIGHT_ID_BUTT;
65    struct LightEffect effect;
66
67	/* 创建Light接口实例 */
68    struct LightInterface *g_lightDev = NewLightInterfaceInstance();
69    if (g_lightDev == NULL) {
70        return;
71    }
72	/* 获取设备支持的Light列表 */
73 	ret = g_lightDev->GetLightInfo(&g_lightInfo, &g_count);
74
75    /* 按照指定的灯颜色,常亮模式打开灯列表中可用的灯 */
76    effect.lightBrightness = 0x00800000; // 亮度值,RGB最高位表示颜色:R:16-31位、G:8-15位、B:0-7位
77    effect.flashEffect.flashMode = LIGHT_FLASH_NONE;
78
79    for (i = 0; i < g_count; ++i) {
80        ret = g_lightDev->TurnOnLight(g_lightInfo[i].lightId, &effect);
81        EXPECT_EQ(0, ret);
82
83        OsalSleep(LIGHT_WAIT_TIME);
84
85        ret = g_lightDev->TurnOffLight(g_lightInfo[i].lightId);
86        EXPECT_EQ(0, ret);
87    }
88    /* 按照指定的灯颜色,闪烁模式打开灯列表中可用的灯 */
89    effect.lightBrightness = 0x00800000;
90    effect.flashEffect.flashMode = LIGHT_FLASH_TIMED;
91    effect.flashEffect.onTime = g_onTime;    // 一个闪烁周期内亮灯时长(ms)
92    effect.flashEffect.offTime = g_offTime;    // 一个闪烁周期内熄灯时长(ms)
93
94    for (i = 0; i < g_count; ++i) {
95        ret = g_lightDev->TurnOnLight(g_lightInfo[i].lightId, &effect);
96        EXPECT_EQ(0, ret);
97
98        OsalSleep(LIGHT_WAIT_TIME);
99
100        ret = g_lightDev->TurnOffLight(g_lightInfo[i].lightId);
101        EXPECT_EQ(0, ret);
102    }
103
104    /* 关闭灯列表中指定类型的灯 */
105    ret = g_lightDev->TurnOffLight(lightId);
106    EXPECT_EQ(0, ret);
107
108    /* 释放Light接口实例 */
109    if (g_lightDev != nullptr) {
110        FreeLightInterfaceInstance();
111        g_lightDev = nullptr;
112    }
113}
114```
115
116## 相关仓
117
118[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
119
120[drivers_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
121
122[drivers_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
123
124[drivers_adapter_khdf_linuk](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
125[drivers_peripheral](https://gitee.com/openharmony/drivers_peripheral)
126
127[drivers_interface](https://gitee.com/openharmony/drivers_interface)
128
129