Search
j0ke.net Open Build Service
>
Projects
>
GFS
>
powersave
> powersave-add-support_IBM_brightess_VistaBIOS.diff
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File powersave-add-support_IBM_brightess_VistaBIOS.diff of Package powersave
Index: daemon/brightness.h =================================================================== --- daemon/brightness.h (Revision 3114) +++ daemon/brightness.h (Arbeitskopie) @@ -83,6 +83,8 @@ }; class BrightnessIBM:public Brightness { + protected: + int brt_levels; public: void Init(); Index: daemon/brightness.cpp =================================================================== --- daemon/brightness.cpp (Revision 3114) +++ daemon/brightness.cpp (Arbeitskopie) @@ -39,6 +39,7 @@ #include <linux/pmu.h> #include "powerlib.h" +#include "powersave_hal.h" /* merge #include "config_pm.h" */ #include "brightness.h" @@ -264,13 +265,16 @@ void BrightnessIBM::Init() { last_percent = -1; + brt_levels = -1; iface = ACPI_IBM; + + brt_levels = GetLevels(); return; } int BrightnessIBM::Get() { - char value[18]; + char value[19]; int level; if ((fd = open(iface, O_RDONLY)) < 0) { @@ -279,12 +283,12 @@ goto out; } - if (read(fd, &value, 17) == -1) { + if (read(fd, &value, 18) == -1) { level = -1; goto out; } - sscanf(value, "level:%1d", &level); + sscanf(value, "level:%d\n", &level); out: close(fd); @@ -293,19 +297,24 @@ void BrightnessIBM::Set(int level) { - char value[8]; + char value[9]; + size_t to_write = 7; if ((fd = open(iface, O_RDWR)) < 0) { perror(iface); goto out; } - if (level > 7) - level = 7; + if (level > (brt_levels-1)) + level = brt_levels-1; else if (level < 0) level = 0; + + if (level > 9) + to_write = 8; + sprintf(value, "level %d", level); - if (write(fd, value, 7) < 0) { + if (write(fd, value, to_write) < 0) { pDebug(DBG_WARN, "Unable to write to IBM brightness interface"); } @@ -323,13 +332,42 @@ void BrightnessIBM::Med() { - Set(4); + Set(brt_levels/2); return; } int BrightnessIBM::GetLevels() { - return 8; + if (brt_levels != -1) { + return brt_levels; + } else { + if (!ps_hal_init()) { + return -1; + } + + char **ibm_panel_devs; + int levels = -1; + int num_devs; + + ibm_panel_devs = libhal_manager_find_device_string_match(ps_hal_context(), + "linux.acpi_path", + "/proc/acpi/ibm/brightness", + &num_devs, + ps_hal_dbus_error()); + + pDebug(DBG_INFO, "Found %d IBM panels devices", num_devs); + + if (num_devs == 0) { + libhal_free_string_array(ibm_panel_devs); + return -1; + } + + /* we can assume that there is only one such device for now */ + levels = ps_hal_get_property_int(ibm_panel_devs[0], "laptop_panel.num_levels"); + libhal_free_string_array(ibm_panel_devs); + + return levels; + } } /* Brightness (Sony object) */