1 /* 2 * Copyright (c) 2023-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 LIGHT_LUX_MANAGER_H 17 #define LIGHT_LUX_MANAGER_H 18 19 #include <vector> 20 21 #include "config_parser.h" 22 #include "ilight_lux_manager.h" 23 #include "light_lux_buffer.h" 24 25 namespace OHOS { 26 namespace DisplayPowerMgr { 27 class LightLuxManager : public ILightLuxManager { 28 public: 29 LightLuxManager() = default; 30 ~LightLuxManager() override = default; 31 32 LightLuxManager(const LightLuxManager&) = delete; 33 LightLuxManager& operator=(const LightLuxManager&) = delete; 34 LightLuxManager(LightLuxManager&&) = delete; 35 LightLuxManager& operator=(LightLuxManager&&) = delete; 36 37 void InitParameters() override; 38 void SetSceneMode(BrightnessSceneMode mode) override; 39 float GetFilteredLux() const override; 40 float GetSmoothedLux() const override; 41 void ClearLuxData() override; 42 void UpdateSmoothedLux(float lux); 43 bool IsNeedUpdateBrightness(float lux) override; 44 45 float GetLux() const override; 46 void SetLux(const float lux) override; 47 bool GetIsFirstLux(); 48 49 private: 50 void UpdateLuxBuffer(int64_t timestamp, float lux); 51 bool IsUpdateLuxSuccess(int64_t timestamp); 52 float CalcSmoothLux() const; 53 int64_t GetNextBrightenTime(int64_t timestamp) const; 54 int64_t GetNextDarkenTime(int64_t timestamp) const; 55 void UpdateParam(float lux); 56 float CalcDelta(const std::vector<PointXy>& pointList) const; 57 float GetValidLux(float lux) const; 58 int GetDarkenResponseTime() const; 59 int GetBrightenResponseTime() const; 60 const LuxThresholdConfig::Mode& GetCurrentModeData() const; 61 std::vector<PointXy> GetBrightenLuxList(); 62 std::vector<PointXy> GetDarkenLuxList(); 63 int GetFilterNum(); 64 int GetNoFilterNum(); 65 void PrintCurrentLuxLog(int64_t timestamp); 66 67 LightLuxBuffer mLuxBuffer{}; 68 LightLuxBuffer mLuxBufferFilter{}; 69 float mLux{0.0f}; 70 float mFilteredLux{0.0f}; 71 bool mIsFirstLux{false}; 72 float mSmoothedButNotStabledLux{0.0f}; 73 float mBrightenDelta{120.0f}; 74 float mDarkenDelta{110.0f}; 75 int64_t mPrintLogTime{0}; 76 BrightnessFilterMode mCurrentFilter{static_cast<int>(BrightnessFilterMode::MEAN_FILTER)}; 77 BrightnessSceneMode mCurrentSceneMode{static_cast<int>(BrightnessSceneMode::MODE_DEFAULT)}; 78 Config mBrightnessConfigData{}; 79 }; 80 } // namespace BrightnessPowerMgr 81 } // namespace OHOS 82 #endif // LIGHT_LUX_MANAGER_H