1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci/** 17094332d3Sopenharmony_ci * @addtogroup Light 18094332d3Sopenharmony_ci * @{ 19094332d3Sopenharmony_ci * 20094332d3Sopenharmony_ci * @brief Provides APIs for the light service. 21094332d3Sopenharmony_ci * 22094332d3Sopenharmony_ci * The light module provides a unified interface for the light service to access the light driver. 23094332d3Sopenharmony_ci * After obtaining the driver object or proxy, the light service distinguishes light devices by id 24094332d3Sopenharmony_ci * and call related APIs to obtain light information, turn on or off a light, or set the blinking mode. 25094332d3Sopenharmony_ci * @since 3.1 26094332d3Sopenharmony_ci */ 27094332d3Sopenharmony_ci 28094332d3Sopenharmony_ci/** 29094332d3Sopenharmony_ci * @file Light_if.h 30094332d3Sopenharmony_ci * 31094332d3Sopenharmony_ci * @brief Declares common APIs of the light module. These APIs can be used to obtain the light id, 32094332d3Sopenharmony_ci * turn on or off a light, and set the light brightness and blinking mode. 33094332d3Sopenharmony_ci * @since 3.1 34094332d3Sopenharmony_ci */ 35094332d3Sopenharmony_ci 36094332d3Sopenharmony_ci#ifndef LIGHT_IF_H 37094332d3Sopenharmony_ci#define LIGHT_IF_H 38094332d3Sopenharmony_ci 39094332d3Sopenharmony_ci#include <stdint.h> 40094332d3Sopenharmony_ci#include "light_type.h" 41094332d3Sopenharmony_ci 42094332d3Sopenharmony_ci#ifdef __cplusplus 43094332d3Sopenharmony_ci#if __cplusplus 44094332d3Sopenharmony_ciextern "C" { 45094332d3Sopenharmony_ci#endif 46094332d3Sopenharmony_ci#endif /* __cplusplus */ 47094332d3Sopenharmony_ci 48094332d3Sopenharmony_ci/** 49094332d3Sopenharmony_ci * @brief Defines the basic operations that can be performed on lights. 50094332d3Sopenharmony_ci * 51094332d3Sopenharmony_ci * The operations include obtaining light information, turning on or off a light, 52094332d3Sopenharmony_ci * and setting the light brightness or blinking mode. 53094332d3Sopenharmony_ci */ 54094332d3Sopenharmony_ci 55094332d3Sopenharmony_cistruct LightInterface { 56094332d3Sopenharmony_ci /** 57094332d3Sopenharmony_ci * @brief Obtains information about all the lights in the system. 58094332d3Sopenharmony_ci * 59094332d3Sopenharmony_ci * @param lightInfo Indicates the double pointer to the light information. For details, see {@link LightInfo}. 60094332d3Sopenharmony_ci * @param count Indicates the pointer to the number of lights. 61094332d3Sopenharmony_ci * 62094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 63094332d3Sopenharmony_ci * @return Returns a negative value if the operation fails. 64094332d3Sopenharmony_ci * 65094332d3Sopenharmony_ci * @since 3.1 66094332d3Sopenharmony_ci */ 67094332d3Sopenharmony_ci int32_t (*GetLightInfo)(struct LightInfo **lightInfo, uint32_t *count); 68094332d3Sopenharmony_ci 69094332d3Sopenharmony_ci /** 70094332d3Sopenharmony_ci * @brief Turns on available lights in the list based on the specified light id. 71094332d3Sopenharmony_ci * 72094332d3Sopenharmony_ci * @param lightId Indicates the light id. For details, see {@link LightId}. 73094332d3Sopenharmony_ci * 74094332d3Sopenharmony_ci * @param effect Indicates the pointer to the lighting effect, if the lightbrightness field is 0, 75094332d3Sopenharmony_ci * light brightness according to the defaultBrightness configured by HCS. For details, see {@link LightEffect}. 76094332d3Sopenharmony_ci * 77094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 78094332d3Sopenharmony_ci * @return Returns <b>-1</b> if the light id is not supported. 79094332d3Sopenharmony_ci * @return Returns <b>-2</b> if the blinking setting is not supported. 80094332d3Sopenharmony_ci * @return Returns <b>-3</b> if the brightness setting is not supported. 81094332d3Sopenharmony_ci * 82094332d3Sopenharmony_ci * @since 3.1 83094332d3Sopenharmony_ci */ 84094332d3Sopenharmony_ci int32_t (*TurnOnLight)(uint32_t lightId, struct LightEffect *effect); 85094332d3Sopenharmony_ci 86094332d3Sopenharmony_ci /** 87094332d3Sopenharmony_ci * @brief Turn on multiple sub-lights contained in the corresponding light according to the specified light ID. 88094332d3Sopenharmony_ci * 89094332d3Sopenharmony_ci * @param lightId Indicates the light id. For details, see {@link HdfLightId}. 90094332d3Sopenharmony_ci * 91094332d3Sopenharmony_ci * @param colors Color and brightness corresponding to multiple lights, see {@link LightColor}. 92094332d3Sopenharmony_ci * 93094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 94094332d3Sopenharmony_ci * @return Returns negative value if the get failed. 95094332d3Sopenharmony_ci * 96094332d3Sopenharmony_ci * @since 3.2 97094332d3Sopenharmony_ci */ 98094332d3Sopenharmony_ci int32_t (*TurnOnMultiLights)(uint32_t lightId, const struct LightColor *colors, const uint32_t count); 99094332d3Sopenharmony_ci 100094332d3Sopenharmony_ci /** 101094332d3Sopenharmony_ci * @brief Turns off available lights in the list based on the specified light id. 102094332d3Sopenharmony_ci * 103094332d3Sopenharmony_ci * @param lightId Indicates the light id. For details, see {@link LightId}. 104094332d3Sopenharmony_ci * 105094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 106094332d3Sopenharmony_ci * @return Returns a negative value if the operation fails. 107094332d3Sopenharmony_ci * 108094332d3Sopenharmony_ci * @since 3.1 109094332d3Sopenharmony_ci */ 110094332d3Sopenharmony_ci int32_t (*TurnOffLight)(uint32_t lightId); 111094332d3Sopenharmony_ci}; 112094332d3Sopenharmony_ci 113094332d3Sopenharmony_ci/** 114094332d3Sopenharmony_ci * @brief Creates a <b>LightInterface</b> instance. 115094332d3Sopenharmony_ci * 116094332d3Sopenharmony_ci * The <b>LightInterface</b> instance created can be used to perform related light control operations. 117094332d3Sopenharmony_ci * 118094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation fails. 119094332d3Sopenharmony_ci * @return Returns a non-zero value if the operation is successful. 120094332d3Sopenharmony_ci * 121094332d3Sopenharmony_ci * @since 3.1 122094332d3Sopenharmony_ci */ 123094332d3Sopenharmony_ciconst struct LightInterface *NewLightInterfaceInstance(void); 124094332d3Sopenharmony_ci 125094332d3Sopenharmony_ci/** 126094332d3Sopenharmony_ci * @brief Releases the <b>LightInterface</b> instance and related resources. 127094332d3Sopenharmony_ci * 128094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 129094332d3Sopenharmony_ci * @return Returns a negative value if the operation fails. 130094332d3Sopenharmony_ci * 131094332d3Sopenharmony_ci * @since 3.1 132094332d3Sopenharmony_ci */ 133094332d3Sopenharmony_ciint32_t FreeLightInterfaceInstance(void); 134094332d3Sopenharmony_ci 135094332d3Sopenharmony_ci#ifdef __cplusplus 136094332d3Sopenharmony_ci#if __cplusplus 137094332d3Sopenharmony_ci} 138094332d3Sopenharmony_ci#endif 139094332d3Sopenharmony_ci#endif /* __cplusplus */ 140094332d3Sopenharmony_ci 141094332d3Sopenharmony_ci#endif /* LIGHT_IF_H */ 142094332d3Sopenharmony_ci/** @} */ 143