From 20ebc0c334c33229b402513a202f26794f7ef3cc Mon Sep 17 00:00:00 2001 From: Louis-Joseph Fournier Date: Tue, 29 Dec 2015 21:32:57 +0100 Subject: [PATCH] Sailfish: prevent screen blanking --- Tuner.pro | 2 +- harbour-sailtuner.pro | 2 +- src/Tuner.cpp | 27 +++++++++++++++++++++++++++ src/Tuner.hpp | 3 ++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Tuner.pro b/Tuner.pro index c542b86..752f6ec 100644 --- a/Tuner.pro +++ b/Tuner.pro @@ -1,4 +1,4 @@ -QT += qml quick gui multimedia +QT += qml quick gui multimedia dbus TARGET = Tuner CONFIG += c++11 diff --git a/harbour-sailtuner.pro b/harbour-sailtuner.pro index dc9ce70..066ffe2 100644 --- a/harbour-sailtuner.pro +++ b/harbour-sailtuner.pro @@ -1,4 +1,4 @@ -QT += qml quick gui multimedia +QT += qml quick gui multimedia dbus TARGET = harbour-sailtuner CONFIG += c++11 sailfishapp sailfishapp_i18n diff --git a/src/Tuner.cpp b/src/Tuner.cpp index d043298..11bf8b6 100644 --- a/src/Tuner.cpp +++ b/src/Tuner.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include "Tuner.hpp" @@ -12,6 +14,21 @@ using namespace std; static double a10[] = { 1 , -2.99214602, 2.98432286, -0.99217678 }; 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() { running = false; @@ -53,6 +70,8 @@ Tuner::~Tuner() void Tuner::Start() { cerr << __func__ << endl; + nb_sample_running = 0; + blank_prevent(true); high_filter->Clear(); cross->Clear(); recorder->record(); @@ -66,6 +85,7 @@ void Tuner::Stop() running = false; recorder->stop(); runningChanged(); + blank_prevent(false); } 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) { + nb_sample_running += nb_frame; + while (nb_frame--) ComputeFrame(*ptr++); 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; } } + + if (nb_sample_running >= nbSamplePreventRunning && running) { + nb_sample_running = 0; + blank_prevent(true); + } } bool Tuner::GetRunning() diff --git a/src/Tuner.hpp b/src/Tuner.hpp index a1548fc..be6cdb4 100644 --- a/src/Tuner.hpp +++ b/src/Tuner.hpp @@ -25,12 +25,13 @@ class Tuner : public QObject { bool running; double freq, deviation; - int note, octave; + int note, octave, nb_sample_running; static const int rate = 16000; static const int defaultNbFrame = 1024; static const int defaultFreqMin = 50; static const int defaultFreqMax = 2000; + static const int nbSamplePreventRunning = rate * 40; // 40 seconds inline void ComputeFrame(int16_t v);