nn::applet::CTR::SetSleepCanceledCallback Function
void SetSleepCanceledCallback(
AppletSleepCanceledCallback callback,
uptr arg = 0
);
| Name | Description | |
|---|---|---|
| in | callback | Callback. |
| in | arg | Callback arguments. |
Sets the sleep cancel callback.
This callback is called when the system is opened while the current applet manager is sending a sleep query to the applet or application.
The function is called when deferring a reply to a sleep query. If cancelling the transition to sleep mode, use nn::applet::CTR::ReplySleepQuery to return nn::applet::CTR::REPLY_REJECT.
Given the name of the callback function, it appears as if it always cancels the transition to sleep mode when called, but the applet manager will simply continue to wait for a reply to the sleep query if the callback does nothing.
This callback is intended for uses such as quickly detecting that the system has been opened and cancelling the transition to sleep mode when it might otherwise take a while to fully transition, with the screens remaining dark for several seconds if the user opens the system in the middle of the transition.
Example
bool isShellOpened;
nn::os::LightEvent awakeEvent;
// Sleep cancel callback
void mySleepCanceledCallback(uptr arg)
{
NN_UNUSED_VAR(arg);
if ( applet::IsActive() )
{
isShellOpened = true; // System opened
applet::ReplySleepQuery( applet::REPLY_REJECT );
}
}
// Sleep query callback
void mySleepQueryCallback(uptr arg)
{
NN_UNUSED_VAR(arg);
if ( applet::IsActive() )
{
isShellOpened = false;
awakeEvent.ClearSignal();
return applet::REPLY_LATER;
}
else
{
return applet::REPLY_ACCEPT;
}
}
// Wakeup callback
void myAwakeCallback(uptr arg)
{
NN_UNUSED_VAR(arg);
awakeEvent.Signal(); // Wake up
}
// Main
void nnMain()
{
awakeEvent.Initialize(false);
applet::SetSleepQueryCallback( mySleepQueryCallback, 0 );
applet::SetSleepCanceledCallback( mySleepCanceledCallback, 0 );
applet::SetAwakeCallback( myAwakeCallback, 0 );
applet::Enable();
while(1)
{
_exec();
_draw();
if ( applet::IsExpectedToReplySleepQuery() )
{
for(int i=0; i<N; n++) // Heavy processing before going to sleep. For instance, when saving N items of data.
{
_save( data[i] );
if ( isShellOpened ) // Interrupt since system is opened in the middle of all this
{
break;
}
}
// If system not opened, accept sleep query and wait to wake up
if ( ! isShellOpened )
{
applet::ReplySleepQuery( applet::REPLY_ACCEPT );
awakeEvent.Wait();
}
}
}
}
CONFIDENTIAL