File: brightThread.cpp

package info (click to toggle)
ukui-settings-daemon 4.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,324 kB
  • sloc: cpp: 39,120; ansic: 3,240; xml: 1,570; sh: 88; makefile: 4
file content (133 lines) | stat: -rw-r--r-- 3,660 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2023 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "brightThread.h"
#include <QByteArray>
#include <QDebug>
#include <QMutexLocker>
#include <QDBusInterface>
#include <QApplication>

#include "usd_global_define.h"
#include "QGSettings/qgsettings.h"

extern "C"{
#include <math.h>
#include <unistd.h>
#include "clib-syslog.h"
}

//空闲模式不进行亮度处理

BrightThread::BrightThread(QObject *parent):
    m_stop(false)
{
    bool ret = false;
    m_powerSettings = new QGSettings(POWER_MANAGER_SCHEMA);

    if (nullptr == m_powerSettings) {
        USD_LOG(LOG_DEBUG,"can't find %s", POWER_MANAGER_SCHEMA);
    }

    m_brightnessSettings = new QGSettings(AUTO_BRIGHTNESS_SCHEMA);
    if (nullptr == m_brightnessSettings) {
        return;
    }

    m_delayms = m_brightnessSettings->get(DELAYMS_KEY).toInt(&ret);

    if (false == ret) {
        USD_LOG(LOG_DEBUG,"can't find delayms");
        m_delayms = 30;
    }

    USD_LOG_SHOW_PARAM1(m_delayms);
}

//待电源管理优化内部处理。
//需要电源管理重新建立一个设置背光的接口,包含目标亮度与设置时间,以及设置完毕的signal与实时亮度的dbus,signal。usd调用接口传递设置间隔和目标亮度给电源管理,有电源管理进行线性处理,
//其他组件要想同步线性曲线,就监控实时亮度的dbus上的signal。
void BrightThread::run(){
    int currentBrightnessValue;

    if (nullptr == m_powerSettings) {
        return;
    }

    if (false == m_powerSettings->keys().contains(BRIGHTNESS_AC_KEY)) {
        return;
    }

    currentBrightnessValue = m_powerSettings->get(BRIGHTNESS_AC_KEY).toInt();
    USD_LOG(LOG_DEBUG,"start set brightness");

    m_stop = false;
    while(currentBrightnessValue != m_destBrightness) {

        if (m_stop) {
            USD_LOG(LOG_DEBUG,"start set brightness interrupt.");
            return;
        }

        if (currentBrightnessValue>m_destBrightness){
            currentBrightnessValue--;
        } else {
            currentBrightnessValue++;
        }

        m_powerSettings->set(BRIGHTNESS_AC_KEY, currentBrightnessValue);
        m_powerSettings->apply();
        msleep(m_delayms);//30 ms效果较好。
    }
    USD_LOG(LOG_DEBUG,"set brightness over");
}

void BrightThread::stopImmediately(){
    m_stop = true;
}


void BrightThread::setBrightness(int brightness)
{
    m_destBrightness = brightness;
//    USD_LOG(LOG_DEBUG,brightness);
    USD_LOG_SHOW_PARAM1(brightness);
}

int BrightThread::getRealTimeBrightness()
{
    if (false == m_powerSettings->keys().contains(BRIGHTNESS_AC_KEY)) {
       return -1;
    }

    return m_powerSettings->get(BRIGHTNESS_AC_KEY).toInt();
}

BrightThread::~BrightThread()
{
    if (m_powerSettings) {
        delete m_powerSettings;
        m_powerSettings = nullptr;
    }

    if (m_brightnessSettings) {
        delete m_brightnessSettings;
        m_brightnessSettings = nullptr;
    }
}