r4581 - developers/raster/ompower
raster at docs.openmoko.org
raster at docs.openmoko.org
Tue Aug 5 08:08:48 CEST 2008
Author: raster
Date: 2008-08-05 08:08:47 +0200 (Tue, 05 Aug 2008)
New Revision: 4581
Modified:
developers/raster/ompower/power.c
Log:
fix brightness/bl power setting.
Modified: developers/raster/ompower/power.c
===================================================================
--- developers/raster/ompower/power.c 2008-08-04 16:46:22 UTC (rev 4580)
+++ developers/raster/ompower/power.c 2008-08-05 06:08:47 UTC (rev 4581)
@@ -1,5 +1,37 @@
#include "main.h"
+static void
+file_write(const char *file, int val)
+{
+ char buf[80];
+ int fd;
+
+ snprintf(buf, sizeof(buf), "%i\n", val);
+ fd = open(file, O_RDWR);
+ if (fd < 0) return;
+ write(fd, buf, strlen(buf));
+ close(fd);
+}
+
+static int
+file_read(const char *file)
+{
+ char buf[80];
+ int fd, len;
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0) return -1;
+ len = read(fd, buf, sizeof(buf) - 1);
+ if (len <= 0)
+ {
+ close(fd);
+ return -1;
+ }
+ buf[len] = 0;
+ close(fd);
+ return atoi(buf);
+}
+
void
screen_off(void)
{
@@ -10,7 +42,7 @@
// putenv("DISPLAY=:0");
// hack - force activate screensaver
// system("xset s activate");
- fd = open("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/backlight/pcf50633-bl", O_RDWR);
+ fd = open("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/backlight/pcf50633-bl/bl_power", O_RDWR);
if (fd >= 0)
{
write(fd, string, sizeof(string));
@@ -25,7 +57,7 @@
int fd;
const char *string = "0\n";
- fd = open("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/backlight/pcf50633-bl", O_RDWR);
+ fd = open("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/backlight/pcf50633-bl/bl_power", O_RDWR);
if (fd >= 0)
{
write(fd, string, sizeof(string));
@@ -36,18 +68,37 @@
system("xset s reset");
}
+int
+brightness_get(void)
+{
+ return file_read("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/backlight/pcf50633-bl/brightness");
+}
+
void
+brightness_set(int val)
+{
+ file_write("/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/backlight/pcf50633-bl/brightness", val);
+}
+
+void
cpu_suspend(void)
{
int manual_resume = 0;
+ int prev_brightness;
+
+ prev_brightness = brightness_get();
+ screen_off();
- screen_off();
+ sleep(1);
system("apm -s");
// we resumed - find out why
manual_resume = 1;
if (manual_resume)
- screen_on();
+ {
+ screen_on();
+ brightness_set(prev_brightness);
+ }
}
More information about the commitlog
mailing list