Sailfish: prevent screen blanking

This commit is contained in:
Louis-Joseph Fournier 2015-12-29 21:32:57 +01:00
parent 73318f3551
commit 20ebc0c334
4 changed files with 31 additions and 3 deletions

View file

@ -1,4 +1,4 @@
QT += qml quick gui multimedia QT += qml quick gui multimedia dbus
TARGET = Tuner TARGET = Tuner
CONFIG += c++11 CONFIG += c++11

View file

@ -1,4 +1,4 @@
QT += qml quick gui multimedia QT += qml quick gui multimedia dbus
TARGET = harbour-sailtuner TARGET = harbour-sailtuner
CONFIG += c++11 sailfishapp sailfishapp_i18n CONFIG += c++11 sailfishapp sailfishapp_i18n

View file

@ -3,6 +3,8 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QUrl> #include <QUrl>
#include <QDBusConnection>
#include <QDBusInterface>
#include "Tuner.hpp" #include "Tuner.hpp"
@ -12,6 +14,21 @@ using namespace std;
static double a10[] = { 1 , -2.99214602, 2.98432286, -0.99217678 }; static double a10[] = { 1 , -2.99214602, 2.98432286, -0.99217678 };
static double b10[] = { 0.99608071, -2.98824212, 2.98824212, -0.99608071 }; static double b10[] = { 0.99608071, -2.98824212, 2.98824212, -0.99608071 };
// function to prevent screen blank
static void blank_prevent(bool prevent)
{
cerr << __func__ << endl;
QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system);
if (prevent) {
interface.call(QLatin1String("req_display_blanking_pause"));
} else {
interface.call(QLatin1String("req_display_cancel_blanking_pause"));
}
}
Tuner::Tuner() Tuner::Tuner()
{ {
running = false; running = false;
@ -53,6 +70,8 @@ Tuner::~Tuner()
void Tuner::Start() void Tuner::Start()
{ {
cerr << __func__ << endl; cerr << __func__ << endl;
nb_sample_running = 0;
blank_prevent(true);
high_filter->Clear(); high_filter->Clear();
cross->Clear(); cross->Clear();
recorder->record(); recorder->record();
@ -66,6 +85,7 @@ void Tuner::Stop()
running = false; running = false;
recorder->stop(); recorder->stop();
runningChanged(); runningChanged();
blank_prevent(false);
} }
void Tuner::ComputeFrame(int16_t v) void Tuner::ComputeFrame(int16_t v)
@ -83,6 +103,8 @@ void Tuner::AudioCb(const QAudioBuffer &buffer)
void Tuner::AudioAnalyse(const int16_t *ptr, int nb_frame) void Tuner::AudioAnalyse(const int16_t *ptr, int nb_frame)
{ {
nb_sample_running += nb_frame;
while (nb_frame--) ComputeFrame(*ptr++); while (nb_frame--) ComputeFrame(*ptr++);
if (freq != cross->Freq()) { if (freq != cross->Freq()) {
@ -98,6 +120,11 @@ void Tuner::AudioAnalyse(const int16_t *ptr, int nb_frame)
//std::cerr << note << " " << scale->NoteName(note) << std::endl; //std::cerr << note << " " << scale->NoteName(note) << std::endl;
} }
} }
if (nb_sample_running >= nbSamplePreventRunning && running) {
nb_sample_running = 0;
blank_prevent(true);
}
} }
bool Tuner::GetRunning() bool Tuner::GetRunning()

View file

@ -25,12 +25,13 @@ class Tuner : public QObject {
bool running; bool running;
double freq, deviation; double freq, deviation;
int note, octave; int note, octave, nb_sample_running;
static const int rate = 16000; static const int rate = 16000;
static const int defaultNbFrame = 1024; static const int defaultNbFrame = 1024;
static const int defaultFreqMin = 50; static const int defaultFreqMin = 50;
static const int defaultFreqMax = 2000; static const int defaultFreqMax = 2000;
static const int nbSamplePreventRunning = rate * 40; // 40 seconds
inline void ComputeFrame(int16_t v); inline void ComputeFrame(int16_t v);