diff -urN gbm-0.30/gbm.c gbm-0.30.aoe/gbm.c --- gbm-0.30/gbm.c Thu Apr 26 17:23:00 2001 +++ gbm-0.30.aoe/gbm.c Mon May 28 00:52:39 2001 @@ -24,6 +24,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// fbinv code pasted from Ross Vandegrifts code (ross@willow.seitz.cominserted) +// found at http://poplar.seitz.com/~ross/agenda/ by Alexander Oelzant +// (aoe@mars.tuwien.ac.at) + #include #include #include @@ -40,16 +44,28 @@ extern int detach(int nochdir, int noclose); +void fbinv(int fd, unsigned char c); + #define DEBUG_GBM #define ON_SYNC "/etc/gbm/on_sync" // should the vr3 go into hibernation? int turn_off; +int pwr_pressed = 0; +int invert_or_backlight=0; // how long to hold the power button before toggling the backlight? int time_to_backlight = 2; // should the unit go to sleep when the pen is inserted? int hibernate_on_pen = 1; +void +swap (short *foo, short *bar) +{ + short temp = *foo; + *foo = *bar; + *bar = temp; +} + int echo(const char* s, const char* filename) { int fd; @@ -87,6 +103,27 @@ ioctl(fd, FBIOPUT_BACKLIGHT, c); } +void fbinv(int fd, unsigned char c) +{ + int invert; + int index; + unsigned short red [16], green [16], blue [16]; + struct fb_cmap cmap = { 0, 16, red, green, blue, NULL }; + +#ifdef DEBUG_GBM + printf("gbm: inverting: %.2x\n", c); +#endif + ioctl (fd, FBIOGETCMAP, &cmap); + + for (index = 0; index < 8; index ++) + { + swap (red + index, red + 15 - index); + swap (green + index, green + 15 - index); + swap (blue + index, blue + 15 - index); + } + ioctl (fd, FBIOPUTCMAP, &cmap); +} + int get_backlight(int fd) { int num; @@ -100,6 +137,7 @@ void alarm_handler(int data) { int fd; + switch (data) { case SIGALRM: fd = open("/dev/fb0", O_NONBLOCK); @@ -108,8 +146,16 @@ strerror(errno)); return; } + // invert first ... + if (!invert_or_backlight) { + fbinv(fd,'x'); + alarm(time_to_backlight); + invert_or_backlight=1; + } else { // toggle the backlight - set_backlight(fd, 1 - get_backlight(fd)); + set_backlight(fd, 1 - get_backlight(fd)); + invert_or_backlight=0; + } close(fd); // don't turn off, we handled the button press turn_off = 0; @@ -162,7 +208,9 @@ // If it turns out that we wanted to toggle the // backlight, then the alarm handler will set // this variable to 0 - turn_off = 1; + turn_off = 1; + pwr_pressed = 1; /* needed for stylus insert power off protection - aoe */ + invert_or_backlight=0; /* always invert first */; // Set an alarm to go off in the specified number // of seconds. If the button is still pressed // at that time, the state @@ -175,8 +223,9 @@ // If the alarm didn't happen, then this // variable will still be 1, so we should // go to sleep - if (turn_off == 1) + if (turn_off && pwr_pressed) do_sleep(); + pwr_pressed = 0; } break; @@ -188,9 +237,13 @@ case BTN_PEN: // This is the pen slot - if (hibernate_on_pen && (buff & BTN_PRESS)) + if (hibernate_on_pen && (buff & BTN_PRESS) && !pwr_pressed) // The pen has been inserted do_sleep(); + else { /* don't hibernate if power button is pressed */ + alarm(0); + turn_off = 0; + } break; case BTN_SYNC: