After exiting suspend blink LED while in temporary suspend pending state

master
Miles Alan 4 years ago
parent bfdbe29c0b
commit f3275b7cd7
  1. 23
      programs/sxmo_screenlock.c

@ -39,6 +39,8 @@ void writefile(char *filepath, char *str);
// Variables // Variables
Display *dpy; Display *dpy;
enum State state = StateNoInput; enum State state = StateNoInput;
int suspendpendingsceenon = 0;
int suspendpendingtimeouts = 0;
KeySym lastkeysym = XK_Cancel; KeySym lastkeysym = XK_Cancel;
int lastkeyn = 0; int lastkeyn = 0;
char oldbrightness[10] = "200"; char oldbrightness[10] = "200";
@ -165,7 +167,7 @@ readinputloop(Display *dpy, int screen) {
fd_set fdset; fd_set fdset;
int xfd; int xfd;
int selectresult; int selectresult;
struct timeval xeventtimeout = {5, 0}; struct timeval xeventtimeout = {1, 0};
xfd = ConnectionNumber(dpy); xfd = ConnectionNumber(dpy);
for (;;) { for (;;) {
@ -194,10 +196,15 @@ readinputloop(Display *dpy, int screen) {
lastkeysym = XK_Cancel; lastkeysym = XK_Cancel;
switch (keysym) { switch (keysym) {
case XF86XK_AudioRaiseVolume: case XF86XK_AudioRaiseVolume:
suspendpendingsceenon = state == StateNoInput;
suspendpendingtimeouts = 0;
state = StateSuspend; state = StateSuspend;
break; break;
case XF86XK_AudioLowerVolume: case XF86XK_AudioLowerVolume:
state = (state == StateNoInput ? StateNoInputNoScreen : StateNoInput); if (state == StateNoInput) state = StateNoInputNoScreen;
else if (state == StateNoInputNoScreen) state = StateNoInput;
else if (state = StateSuspendPending && suspendpendingsceenon) state = StateNoInputNoScreen;
else state = StateNoInput;
break; break;
case XF86XK_PowerOff: case XF86XK_PowerOff:
state = StateDead; state = StateDead;
@ -206,7 +213,9 @@ readinputloop(Display *dpy, int screen) {
syncstate(); syncstate();
} }
} else if (state == StateSuspendPending) { } else if (state == StateSuspendPending) {
state = StateSuspend; suspendpendingtimeouts++;
// # E.g. after 4s kick back into suspend
if (suspendpendingtimeouts > 4) state = StateSuspend;
syncstate(); syncstate();
} }
@ -242,13 +251,19 @@ syncstate()
// Just woke up // Just woke up
updatestatusbar(); updatestatusbar();
state = StateSuspendPending; state = StateSuspendPending;
suspendpendingtimeouts = 0;
syncstate(); syncstate();
} else if (state == StateNoInput) { } else if (state == StateNoInput) {
setpineled(Blue); setpineled(Blue);
writefile(brightnessfile, oldbrightness); writefile(brightnessfile, oldbrightness);
} else if (state == StateNoInputNoScreen || state == StateSuspendPending) { } else if (state == StateNoInputNoScreen) {
setpineled(Purple); setpineled(Purple);
writefile(brightnessfile, "0"); writefile(brightnessfile, "0");
} else if (state == StateSuspendPending) {
writefile(brightnessfile, suspendpendingsceenon ? oldbrightness : "0");
setpineled(Off);
usleep(1000 * 100);
setpineled(suspendpendingsceenon ? Blue : Purple);
} else if (state == StateDead) { } else if (state == StateDead) {
writefile(brightnessfile, oldbrightness); writefile(brightnessfile, oldbrightness);
setpineled(Off); setpineled(Off);

Loading…
Cancel
Save