1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SCREEN_BRIGHTNESS_TASK 17 #define SCREEN_BRIGHTNESS_TASK 18 19 #include <map> 20 #include <mutex> 21 22 #include "nocopyable.h" 23 #include "timer.h" 24 25 #include "finite_state_machine.h" 26 #include "iscreen_brightness_task.h" 27 28 namespace OHOS { 29 namespace UserIam { 30 namespace FaceAuth { 31 class ScreenBrightnessTask : public IScreenBrightnessTask, 32 public std::enable_shared_from_this<ScreenBrightnessTask>, 33 public NoCopyable { 34 public: 35 ScreenBrightnessTask(); 36 ~ScreenBrightnessTask() override; 37 38 void Start() override; 39 void Stop() override; 40 void SetAmbientLight(float lux) override; 41 void RegisterDestructCallback(DestructCallback callback) override; 42 43 void OnStartDelayTimeout(); 44 void OnIncreaseBrightness(); 45 46 private: 47 enum State : uint32_t { 48 S_INIT = 0, 49 S_WAIT_AMBIENT_LIGHT_INFO_AND_START_DELAY = 1, 50 S_WAIT_AMBIENT_LIGHT_INFO = 2, 51 S_WAIT_START_DELAY = 3, 52 S_INCREASING_BRIGHTNESS = 4, 53 S_END = 5 54 }; 55 enum Event : uint32_t { 56 E_START = 0, 57 E_START_DELAY_EXPIRED = 1, 58 E_RECEIVE_AMBIENT_LIGHT_INFO = 2, 59 E_INCREASE_BRIGHTNESS = 3, 60 E_STOP = 4, 61 }; 62 63 std::shared_ptr<FiniteStateMachine> MakeFiniteStateMachine(); 64 void StartProcess(); 65 void BeginIncreaseBrightness(); 66 void DoIncreaseBrightness(); 67 void EndProcess(); 68 69 std::shared_ptr<FiniteStateMachine> machine_; 70 Utils::Timer timer_; 71 uint32_t currTimerId_; 72 float currentAmbientLightLux_; 73 std::mutex currentAmbientLightLuxMutex_; 74 uint32_t currentBrightness_; 75 uint32_t increaseBrightnessIndex_; 76 uint32_t increaseBrightnessInterval_; 77 uint32_t increaseBrightnessMax_; 78 DestructCallback destructCallback_; 79 }; 80 } // namespace FaceAuth 81 } // namespace UserIam 82 } // namespace OHOS 83 84 #endif // SCREEN_BRIGHTNESS_TASK