]> Chaos Git - corbenik/ctrulib.git/commitdiff
Allow toggling sleep mode.
authorSteven Smith <Steveice10@gmail.com>
Sun, 8 May 2016 19:45:18 +0000 (12:45 -0700)
committerSteven Smith <Steveice10@gmail.com>
Sun, 8 May 2016 19:45:18 +0000 (12:45 -0700)
libctru/include/3ds/services/apt.h
libctru/source/services/apt.c

index d73dd16ee21a27d9e9995b3a349df68300c01c09..ae961e8765fcd4f49ee47121a4317bfa3cacea23 100644 (file)
@@ -135,6 +135,18 @@ void aptWaitStatusEvent(void);
 /// Signals that the app is ready to sleep.
 void aptSignalReadyForSleep(void);
 
+/**
+ * @brief Gets whether to allow the system to enter sleep mode.
+ * @return Whether sleep mode is allowed.
+ */
+bool aptIsSleepAllowed();
+
+/**
+ * @brief Sets whether to allow the system to enter sleep mode.
+ * @param allowed Whether to allow sleep mode.
+ */
+void aptSetSleepAllowed(bool allowed);
+
 /**
  * @brief Gets the menu's app ID.
  * @return The menu's app ID.
index d3554cef4af9d2ee55c161eaabcedd965e965f5b..688c16e396912c54a71a232a267158e02204a290 100644 (file)
@@ -37,6 +37,7 @@ APT_AppStatus aptStatus = APP_NOTINITIALIZED;
 APT_AppStatus aptStatusBeforeSleep = APP_NOTINITIALIZED;
 u32 aptStatusPower;
 Handle aptSleepSync;
+static bool aptSleepAllowed = true;
 
 u32 aptParameters[0x1000/4]; //TEMP
 
@@ -336,14 +337,22 @@ static void __handle_notification(void) {
 
        case APTSIGNAL_PREPARESLEEP:
                // Reply to sleep-request.
-               aptStatusBeforeSleep = aptGetStatus();
-               aptSetStatus(APP_PREPARE_SLEEPMODE);
-               svcWaitSynchronization(aptSleepSync, U64_MAX);
-               svcClearEvent(aptSleepSync);
+               if(aptIsSleepAllowed())
+               {
+                       aptStatusBeforeSleep = aptGetStatus();
+                       aptSetStatus(APP_PREPARE_SLEEPMODE);
+                       svcWaitSynchronization(aptSleepSync, U64_MAX);
+                       svcClearEvent(aptSleepSync);
                
-               aptOpenSession();
-               APT_ReplySleepQuery(currentAppId, 0x1);
-               aptCloseSession();
+                       aptOpenSession();
+                       APT_ReplySleepQuery(currentAppId, 0x1);
+                       aptCloseSession();
+               } else
+               {
+                       aptOpenSession();
+                       APT_ReplySleepQuery(currentAppId, 0x0);
+                       aptCloseSession();
+               }
                break;
 
        case APTSIGNAL_ENTERSLEEP:
@@ -710,6 +719,16 @@ void aptSignalReadyForSleep(void)
        svcSignalEvent(aptSleepSync);
 }
 
+bool aptIsSleepAllowed()
+{
+       return aptSleepAllowed;
+}
+
+void aptSetSleepAllowed(bool allowed)
+{
+       aptSleepAllowed = allowed;
+}
+
 Result APT_GetLockHandle(u16 flags, Handle* lockHandle)
 {
        u32* cmdbuf=getThreadCommandBuffer();