gui: Actions: Toggle backlight on power key

Create GUIAction to handle KEY_POWER with a screen backlight toggle.

Change-Id: Iad0a7923b4a776e0336722db74d6fc46cd0107a2
This commit is contained in:
Matt Mower
2016-01-20 18:12:47 -06:00
committed by Dees Troy
parent 874136434a
commit 9472ba1d39
13 changed files with 69 additions and 6 deletions
+7
View File
@@ -198,6 +198,7 @@ GUIAction::GUIAction(xml_node<>* node)
ADD_ACTION(mountsystemtoggle); ADD_ACTION(mountsystemtoggle);
ADD_ACTION(setlanguage); ADD_ACTION(setlanguage);
ADD_ACTION(checkforapp); ADD_ACTION(checkforapp);
ADD_ACTION(togglebacklight);
// remember actions that run in the caller thread // remember actions that run in the caller thread
for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it) for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it)
@@ -1865,6 +1866,12 @@ int GUIAction::setlanguage(std::string arg __unused)
return 0; return 0;
} }
int GUIAction::togglebacklight(std::string arg __unused)
{
blankTimer.toggleBlank();
return 0;
}
int GUIAction::setbootslot(std::string arg) int GUIAction::setbootslot(std::string arg)
{ {
operation_start("Set Boot Slot"); operation_start("Set Boot Slot");
+34
View File
@@ -116,3 +116,37 @@ void blanktimer::resetTimerAndUnblank(void) {
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);
#endif #endif
} }
void blanktimer::blank(void) {
/* 1) No need for timer handling since checkForTimeout() verifies
* state of screen before performing screen-off
* 2) Assume screen-off causes issues for devices that set
* TW_NO_SCREEN_TIMEOUT and do not blank screen here either
*/
#ifndef TW_NO_SCREEN_TIMEOUT
pthread_mutex_lock(&mutex);
if (state == kOn) {
orig_brightness = getBrightness();
state = kOff;
TWFunc::Set_Brightness("0");
TWFunc::check_and_run_script("/sbin/postscreenblank.sh", "blank");
}
#ifndef TW_NO_SCREEN_BLANK
if (state == kOff) {
gr_fb_blank(true);
state = kBlanked;
}
#endif
pthread_mutex_unlock(&mutex);
#endif
}
void blanktimer::toggleBlank(void) {
if (state == kOn) {
blank();
PageManager::ChangeOverlay("lock");
} else {
resetTimerAndUnblank();
}
}
+4
View File
@@ -37,11 +37,15 @@ public:
// call this when an input event is received or when an operation is finished // call this when an input event is received or when an operation is finished
void resetTimerAndUnblank(); void resetTimerAndUnblank();
// call this when power button is pressed
void toggleBlank(void);
bool isScreenOff(); bool isScreenOff();
private: private:
void setTimer(void); void setTimer(void);
string getBrightness(void); string getBrightness(void);
void blank(void);
pthread_mutex_t mutex; pthread_mutex_t mutex;
enum State { kOn = 0, kDim = 1, kOff = 2, kBlanked = 3 }; enum State { kOn = 0, kDim = 1, kOff = 2, kBlanked = 3 };
+3 -1
View File
@@ -205,7 +205,9 @@ bool InputHandler::processInput(int timeout_ms)
break; break;
} }
blankTimer.resetTimerAndUnblank(); if (ev.code != KEY_POWER && ev.code > KEY_RESERVED)
blankTimer.resetTimerAndUnblank();
return true; // we got an event, so there might be more in the queue return true; // we got an event, so there might be more in the queue
} }
+1
View File
@@ -363,6 +363,7 @@ protected:
int checkpartitionlifetimewrites(std::string arg); int checkpartitionlifetimewrites(std::string arg);
int mountsystemtoggle(std::string arg); int mountsystemtoggle(std::string arg);
int setlanguage(std::string arg); int setlanguage(std::string arg);
int togglebacklight(std::string arg);
int twcmd(std::string arg); int twcmd(std::string arg);
int setbootslot(std::string arg); int setbootslot(std::string arg);
int installapp(std::string arg); int installapp(std::string arg);
+5
View File
@@ -3517,6 +3517,11 @@
<text>{@swipe_to_unlock=Swipe to Unlock}</text> <text>{@swipe_to_unlock=Swipe to Unlock}</text>
<action function="overlay"/> <action function="overlay"/>
</slider> </slider>
<action>
<touch key="power"/>
<action function="togglebacklight"/>
</action>
</page> </page>
<page name="filemanagerlist"> <page name="filemanagerlist">
+5
View File
@@ -3779,6 +3779,11 @@
<text>{@swipe_to_unlock=Swipe to Unlock}</text> <text>{@swipe_to_unlock=Swipe to Unlock}</text>
<action function="overlay"/> <action function="overlay"/>
</slider> </slider>
<action>
<touch key="power"/>
<action function="togglebacklight"/>
</action>
</page> </page>
<page name="filemanagerlist"> <page name="filemanagerlist">
+5
View File
@@ -4424,6 +4424,11 @@
<text>{@swipe_unlock= Unlock}</text> <text>{@swipe_unlock= Unlock}</text>
<action function="overlay"/> <action function="overlay"/>
</slider> </slider>
<action>
<touch key="power"/>
<action function="togglebacklight"/>
</action>
</page> </page>
<page name="filemanagerlist"> <page name="filemanagerlist">
+1 -1
View File
@@ -432,7 +432,7 @@
<action> <action>
<touch key="power"/> <touch key="power"/>
<action function="overlay">lock</action> <action function="togglebacklight"/>
</action> </action>
<action> <action>
+1 -1
View File
@@ -432,7 +432,7 @@
<action> <action>
<touch key="power"/> <touch key="power"/>
<action function="overlay">lock</action> <action function="togglebacklight"/>
</action> </action>
<action> <action>
+1 -1
View File
@@ -336,7 +336,7 @@
<action> <action>
<touch key="power"/> <touch key="power"/>
<action function="overlay">lock</action> <action function="togglebacklight"/>
</action> </action>
<action> <action>
+1 -1
View File
@@ -336,7 +336,7 @@
<action> <action>
<touch key="power"/> <touch key="power"/>
<action function="overlay">lock</action> <action function="togglebacklight"/>
</action> </action>
<action> <action>
+1 -1
View File
@@ -258,7 +258,7 @@
<action> <action>
<touch key="power"/> <touch key="power"/>
<action function="overlay">lock</action> <action function="togglebacklight"/>
</action> </action>
<action> <action>