From 69c7ebb55fbd755beaf688631caaf787f77d1ad2 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 12 Mar 2016 13:49:26 -0800 Subject: [PATCH] Screen sleep control for iOS --- qgroundcontrol.pro | 11 ++++++++- src/MobileScreenMgr.cc | 36 ++++++++++++++++++++++++++++++ src/MobileScreenMgr.h | 36 ++++++++++++++++++++++++++++++ src/MobileScreenMgr.mm | 32 ++++++++++++++++++++++++++ src/Vehicle/MultiVehicleManager.cc | 21 +++++++++-------- 5 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 src/MobileScreenMgr.cc create mode 100644 src/MobileScreenMgr.h create mode 100644 src/MobileScreenMgr.mm diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 569526cdc..a25ad3bd7 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -109,7 +109,6 @@ iOSBuild { BUNDLE.files = $$files($$PWD/ios/AppIcon*.png) $$PWD/ios/QGCLaunchScreen.xib QMAKE_BUNDLE_DATA += BUNDLE LIBS += -framework AVFoundation - OBJECTIVE_SOURCES += src/audio/QGCAudioWorker_iOS.mm #-- Info.plist (need an "official" one for the App Store) ForAppStore { message(App Store Build) @@ -365,6 +364,16 @@ HEADERS += \ src/ViewWidgets/ViewWidgetController.h \ } +iOSBuild { + OBJECTIVE_SOURCES += \ + src/audio/QGCAudioWorker_iOS.mm \ + src/MobileScreenMgr.mm \ +} +androidBuild { + SOURCES += src/MobileScreenMgr.cc \ +} + + SOURCES += \ src/audio/QGCAudioWorker.cpp \ src/CmdLineOptParser.cc \ diff --git a/src/MobileScreenMgr.cc b/src/MobileScreenMgr.cc new file mode 100644 index 000000000..7f469e66e --- /dev/null +++ b/src/MobileScreenMgr.cc @@ -0,0 +1,36 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "MobileScreenMgr.h" + +#include +#include + +void MobileScreenMgr::setKeepScreenOn(bool keepScreenOn) +{ + if (keepScreenOn) { + QAndroidJniObject::callStaticMethod(kJniClassName, "keepScreenOn", "()V"); + } else { + QAndroidJniObject::callStaticMethod(kJniClassName, "restoreScreenOn", "()V"); + } +} diff --git a/src/MobileScreenMgr.h b/src/MobileScreenMgr.h new file mode 100644 index 000000000..3b019101d --- /dev/null +++ b/src/MobileScreenMgr.h @@ -0,0 +1,36 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef MobileScreenMgr_H +#define MobileScreenMgr_H + +#ifdef __mobile__ +class MobileScreenMgr { + +public: + /// Turns on/off screen sleep on mobile devices + static void setKeepScreenOn(bool keepScreenOn); +}; +#endif + +#endif diff --git a/src/MobileScreenMgr.mm b/src/MobileScreenMgr.mm new file mode 100644 index 000000000..50afcc961 --- /dev/null +++ b/src/MobileScreenMgr.mm @@ -0,0 +1,32 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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 + (at your option) any later version. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "MobileScreenMgr.h" + +#import +#import + +void MobileScreenMgr::setKeepScreenOn(bool keepScreenOn) +{ + [[UIApplication sharedApplication] setIdleTimerDisabled: (keepScreenOn ? YES : NO)]; +} diff --git a/src/Vehicle/MultiVehicleManager.cc b/src/Vehicle/MultiVehicleManager.cc index 14523ff40..ffff63370 100644 --- a/src/Vehicle/MultiVehicleManager.cc +++ b/src/Vehicle/MultiVehicleManager.cc @@ -30,13 +30,12 @@ #include "UAS.h" #include "QGCApplication.h" -#include - -#if defined __android__ -#include -#include +#ifdef __mobile__ +#include "MobileScreenMgr.h" #endif +#include + QGC_LOGGING_CATEGORY(MultiVehicleManagerLog, "MultiVehicleManagerLog") const char* MultiVehicleManager::_gcsHeartbeatEnabledKey = "gcsHeartbeatEnabled"; @@ -126,11 +125,11 @@ void MultiVehicleManager::_vehicleHeartbeatInfo(LinkInterface* link, int vehicle // Mark link as active link->setActive(true); -#if defined __android__ +#ifdef __mobile__ if(_vehicles.count() == 1) { - //-- Once a vehicle is connected, keep Android screen from going off + //-- Once a vehicle is connected, keep screen from going off qCDebug(MultiVehicleManagerLog) << "QAndroidJniObject::keepScreenOn"; - QAndroidJniObject::callStaticMethod(kJniClassName, "keepScreenOn", "()V"); + MobileScreenMgr::setKeepScreenOn(true); } #endif @@ -167,11 +166,11 @@ void MultiVehicleManager::_deleteVehiclePhase1(Vehicle* vehicle) emit parameterReadyVehicleAvailableChanged(false); emit vehicleRemoved(vehicle); -#if defined __android__ +#ifdef __mobile__ if(_vehicles.count() == 0) { - //-- Once no vehicles are connected, we no longer need to keep Android screen from going off + //-- Once no vehicles are connected, we no longer need to keep screen from going off qCDebug(MultiVehicleManagerLog) << "QAndroidJniObject::restoreScreenOn"; - QAndroidJniObject::callStaticMethod(kJniClassName, "restoreScreenOn", "()V"); + MobileScreenMgr::setKeepScreenOn(true); } #endif -- 2.22.0