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#include "calculation_config_parser.h"
17
18#include <unistd.h>
19#include <json/json.h>
20
21#include "config_parser_base.h"
22#include "display_log.h"
23
24namespace OHOS {
25namespace DisplayPowerMgr {
26namespace {
27const std::string CONFIG_NAME = "brightness_curve_config";
28} // namespace
29
30using namespace OHOS::DisplayPowerMgr;
31
32bool CalculationConfigParser::ParseConfig(int displayId, CalculationConfig::Data& data)
33{
34    DISPLAY_HILOGI(FEAT_BRIGHTNESS, "[%{public}d] parse CalculationConfig start!", displayId);
35    const Json::Value root = ConfigParserBase::Get().LoadConfigRoot(displayId, CONFIG_NAME);
36    if (root.isNull()) {
37        return false;
38    }
39    if (root["defaultBrightness"].isNumeric()) {
40        data.defaultBrightness = root["defaultBrightness"].asFloat();
41    } else {
42        DISPLAY_HILOGW(FEAT_BRIGHTNESS, "[%{public}d] parse defaultBrightness error!", displayId);
43    }
44    ConfigParserBase::Get().ParsePointXy(root, "defaultPoints", data.defaultPoints);
45    DISPLAY_HILOGI(FEAT_BRIGHTNESS, "[%{public}d] parse CalculationConfig over!", displayId);
46    return true;
47}
48
49void CalculationConfigParser::PrintConfig(int displayId, const CalculationConfig::Data& data)
50{
51    std::string text = std::to_string(displayId);
52    text.append(" defaultBrightness: ");
53    text.append(std::to_string(data.defaultBrightness)).append(", ");
54    text.append(ConfigParserBase::Get().PointXyToString("defaultPoints", data.defaultPoints));
55    DISPLAY_HILOGI(FEAT_BRIGHTNESS, "%{public}s", text.c_str());
56}
57} // namespace DisplayPowerMgr
58} // namespace OHOS
59