Sysctl Brightness

This forum discusses issues related to running FreeBSD on notebooks, laptops, and other mobile equipment.

Sysctl Brightness

Postby Draucia » 20 Apr 2012, 00:08

I'm trying to change my laptop brightness (Toshiba l505). Fn keys don't work, but I don't mind. [FILE]xbacklight[/FILE] doesn't work, and I can't seem to get [FILE]sysctl[/FILE] to work. I've loaded [FILE]acpi_video[/FILE], but whenever I do:

Code: Select all
sudo sysctl hw.acpi.video.<device>.active


it says unknown oid. I've tried [FILE]lcd[/FILE], [FILE]crt[/FILE], [FILE]tv[/FILE], [FILE]lcd0[/FILE], [FILE]crt0[/FILE], and [FILE]tv0[/FILE] as the [FILE]<device>[/FILE] and it always says unkown oid. I've also tried [FILE]acpi_toshiba[/FILE].

I've tried:

Code: Select all
sudo sysctl hw.acpi.toshiba.lcd_brightness=0


But it still says unknown oid. This max brightness is hurting my eyes. x(


Any help is appreciated.
Draucia
Junior Member
 
Posts: 23
Joined: 05 Sep 2011, 12:45

Postby aa » 20 Apr 2012, 04:13

Just type [file]sysctl hw.acpi[/file] to enumerate all recognized variables under [file]hw.acpi[/file]
aa
Junior Member
 
Posts: 47
Joined: 24 Mar 2012, 09:42

Postby DutchDaemon » 20 Apr 2012, 10:26

I found that my laptop (not a Toshiba) does respond to the brightness Fn keys when in the BIOS. Try that.
User avatar
DutchDaemon
Old Fart
 
Posts: 10463
Joined: 16 Nov 2008, 20:17
Location: The Netherlands

Postby Draucia » 20 Apr 2012, 19:45

aa wrote:Just type [file]sysctl hw.acpi[/file] to enumerate all recognized variables under [file]hw.acpi[/file]


When I do so, here is the output:

Code: Select all
 
hw.acpi.supported_sleep_state: S3 S4 S5
hw.acpi.power_button_state: S5
hw.acpi.sleep_button_state: S3
hw.acpi.lid_switch_state: NONE
hw.acpi.standby_state: NONE
hw.acpi.suspend_state: S3
hw.acpi.sleep_delay: 1
hw.acpi.s4bios: 0
hw.acpi.verbose: 0
hw.acpi.disable_on_reboot: 0
hw.acpi.handle_reboot: 1
hw.acpi.reset_video: 0
hw.acpi.cpu.cx_lowest: C1
hw.acpi.acline: 1
hw.acpi.battery.life: 100
hw.acpi.battery.time: -1
hw.acpi.battery.state: 0
hw.acpi.battery.units: 1
hw.acpi.battery.info_expire: 5
hw.acpi.thermal.min_runtime: 0
hw.acpi.thermal.polling_rate: 10
hw.acpi.thermal.user_override: 0
hw.acpi.thermal.tz0.temperature: 47.0C
hw.acpi.thermal.tz0.active: -1
hw.acpi.thermal.tz0.passive_cooling: 1
hw.acpi.thermal.tz0.thermal_flags: 0
hw.acpi.thermal.tz0._PSV: 104.0C
hw.acpi.thermal.tz0._HOT: -1
hw.acpi.thermal.tz0._CRT: 104.0C
hw.acpi.thermal.tz0._ACx: 70.0C -1 -1 -1 -1 -1 -1 -1 -1 -1
hw.acpi.thermal.tz0._TC1: 2
hw.acpi.thermal.tz0._TC2: 5
hw.acpi.thermal.tz0._TSP: 300


I don't understand. There is nothing related to brightness and anything related to hw.acpi.toshiba even though I did
Code: Select all
kldload acpi_toshiba
Am I doing something wrong?

DutchDaemon wrote:I found that my laptop (not a Toshiba) does respond to the brightness Fn keys when in the BIOS. Try that.


Tried it, doesn't work.
Draucia
Junior Member
 
Posts: 23
Joined: 05 Sep 2011, 12:45

Postby Draucia » 22 Apr 2012, 11:05

I still haven't been able to solve this issue. Is it just not possible on my laptop because [FILE]hw.acpi.video[/FILE] doesn't support it?
Draucia
Junior Member
 
Posts: 23
Joined: 05 Sep 2011, 12:45

Postby JonathanBSD » 23 Apr 2012, 19:15

I have the same laptop with the same problem, the only work around I found was installing the package [FILE]xbrightness[/FILE], download that, then in X type "[FILE]xbrightness 22000[/FILE]" - I find that number to be a good setting, of course you can adjust the number to whatever you want.

You can also then leave X and the brightness setting will remain until you next reboot.
JonathanBSD
Junior Member
 
Posts: 9
Joined: 16 Apr 2012, 17:09

Postby Draucia » 23 Apr 2012, 19:37

JonathanBSD wrote:I have the same laptop with the same problem, the only work around I found was installing
the package xbrightness, download that, then in X type "xbrightness 22000" - I find that number to be a good setting, of course you can adjust the number to whatever you want.

You can also then leave X and the brightness setting will remain until you next reboot.


Wow this works great. It can lower the brightness more than the keys could. Thanks a lot. :)
Draucia
Junior Member
 
Posts: 23
Joined: 05 Sep 2011, 12:45

Postby JonathanBSD » 23 Apr 2012, 21:53

No problem. Also, since we have the same laptop, I wonder did you manage to get your RTL819 wireless card working with NDIS? I haven't managed to do it and I'm stuck with wired for now!
JonathanBSD
Junior Member
 
Posts: 9
Joined: 16 Apr 2012, 17:09

Postby Draucia » 23 Apr 2012, 22:00

JonathanBSD wrote:No problem. Also, since we have the same laptop, I wonder did you manage to get your RTL819 wireless card working with dnis? I haven't managed to do it and i'm stuck with wired for now!


[FILE]RTL819 [/FILE]Wireless card? :O I have the [FILE]Intel Wifi Link 5100AGN[/FILE]. I didn't have to do anything special to get this it work. My whole laptop model is L505 - S6959. You might have a model that's slightly different.
Draucia
Junior Member
 
Posts: 23
Joined: 05 Sep 2011, 12:45

Postby Rul » 05 Sep 2012, 21:20

excuse me cuz i'm noob
im trying PCBSD for the first time, using 9.1RC1, have the same problem with brightness fn keys. I've followed this workarounds, and tried to install xbrightness, but don't know how. App cafe doesn't contain it, and /usr/ports/ doesn't exist in my 9.1RC1 installation,
Would somebody be kind and give me some cable?. Thanx
Rul
Junior Member
 
Posts: 2
Joined: 05 Sep 2012, 21:09

Postby CanOfBees » 05 Sep 2012, 23:12

Hi Rul,

1) First `su` to root
[CMD=""]su -[/CMD]
2) and then add the binary package for xbrightness:
[CMD=""]pkg_add -r xbrightness[/CMD]
3) After you've installed the package, run the command:
[CMD=""]xbrightness 9000[/CMD] or something. :)

Be careful what you install, though, as some ports/packages can interfere with the base system that PC-BSD uses. For more information about ports & packages, check out the FreeBSD handbook here: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports.html. Also, take a look at the PC-BSD handbook (here: http://wiki.pcbsd.org/index.php/PC-BSD_Users_Handbook) &, if you haven't, drop by the PC-BSD forums.

Cheers!
CanOfBees
Junior Member
 
Posts: 44
Joined: 02 Mar 2010, 18:08

Postby Rul » 05 Sep 2012, 23:38

SOLVED! (not exactly), 9.1RC1 Toshiba brightness Fn keys don't work, but..
sudo portsnap fetch
sudo portsnap extract
cd /usr/ports/x11/xbrightness
sudo make install clean
sudo xbrightness 33000 1.3
http://disjunkt.com/xbrightness/

Now i'm comfortable for rebuilding the whole code of this pretty OS, XDD
Rul
Junior Member
 
Posts: 2
Joined: 05 Sep 2012, 21:09

Sysctl brightness all-in-one draft solution

Postby franck-porcher » 03 Nov 2012, 08:01

I was able to produce the following working solution :

<Button push event>
|
v
Captured by the system
and forwarded as an ACPI "Notify"
event to the devd sub-system
|
v
devd daemon (using /etc/devd.conf)
is configured to respond to this
ACPI Notify event by triggering some
(custom) user-space software
|
v
(Custom) user-space software runs in turn to
handle the suitable action(s) needed
to take care of the low-level button pushed event


Though this solution now enables a perfect handling of my ThinkPad R61i brightness-up/brightness-down buttons, it will need to be tested and tuned against different hardware.

1)First, configure the system to bring all the necessary modules needed to have the [highlight]sysctl[/highlight] sub-system logically "maps" the available hardware as correctly as possible.

In my case, I'm using a Lenovo ThinkPad R61i. The modules to access apci video variables are [highlight]acpi_ibm[/highlight] and [highlight]acpi_video[/highlight]. Check the available documentation to see which ones would be relevant for your particular hardware (generic [highlight]acpi_<oem>[/highlight])

These modules need to be available and loaded. They could either be included in the built-in kernel, or be brought in at boot time thru via loader by adding the following lines in [file]/boot/loader.conf[/file] :

Code: Select all
# ACPI for IBM ThinkPad
acpi_ibm_load="YES"
acpi_video_load="YES"


2)Second, configure the [highlight]devd[/highlight] sub-system in order to properly capture the low-level events generated by pushing the brightness-up/brightness-down button.

For my R61i, the brightness-up (resp. brightnes-down) button is Fn-16 (resp. Fn-17) that are propagated to the devd sub-system as ACPI event :[highlight]Notify=0x10[/highlight] (resp. [highlight]Notify=0x11[/highlight]).

Devd configuration I use to respond to these events and trigger the user-space code [file]/usr/local/bin/acpi_ibm_exec.sh NOTIFY_EVENT OEM_NAME[/file], where OEM name is "ibm" in my case (depends one the [highlight]acpi_<oem>[/highlight] module loaded :

[file]/etc/devd.conf[/file]
Code: Select all
# ACPI Brightness up/down trap for IBM Thinkpad
notify 5 {
   match "system"          "ACPI";
   action "/usr/local/bin/acpi_generic_exec.sh $notify ibm";
};


Upon pressing the brightness-up button (Fn-16 -> 0x10 in hex) of my ThinkPad R61i, the typical call will be [file]/usr/local/bin/acpi_ibm_exec.sh "0x10" ibm[/file]

3) Third, provide the user-space software.

[file]/usr/local/bin/acpi_ibm_exec.sh[/file] is a (Bash) shell script which I put in [file]/usr/local/bin[/file] for convenience. This shell script in turn calls the binary [file]/usr/local/bin/xgradbrightness(1)[/file].

This "compilation" was inspired by [file]acpi_ibm(4)[/file] and [file]xbrightness(1)[/file] :

[file]/usr/local/bin/acpi_ibm_exec.sh[/file]
Code: Select all
#!/usr/local/bin/bash
#
# acpi_ibm_exec.sh
# Usage: $0 event oem_name
#
# Copyright (C) 2012 Franck Porcher,Ph.D. <franck.porcher@franckys.com>
export PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"

if [ -z "$1" -o -z "$2" ]
then
    echo "usage: $0 acpi_event oem_name"
    exit 1
fi

NOTIFY=$(echo $1)

case ${NOTIFY} in
    0x10) #(Fn-10) BRIGHTNESS UP
          possible_levels_asc=( $(  sysctl -n hw.acpi.video.lcd0.levels     \
                                  | while read -d ' ' x; do echo "$x"; done \
                                  | sort -nu
                               ))
          actual_level=$(sysctl -n hw.acpi.video.lcd0.brightness)
          i=0
          max_i=${#possible_levels_asc[@]}
          while (( i < max_i ))
          do
            if (( actual_level == ${possible_levels_asc[i]} ))
            then
                if (( i == (max_i - 1) ))
                then
                    xgradbrightness max
                else
                    actual_level=${possible_levels_asc[i + 1]}
                    if xgradbrightness $((65535 * actual_level / 100))
                    then
                        sysctl hw.acpi.video.lcd0.brightness=$actual_level
                    fi
                fi
                break
            else
                (( i++ ))
            fi
          done
          ;;

    0x11) #(Fn-11) BRIGHTNESS DOWN
          possible_levels_desc=( $(  sysctl -n hw.acpi.video.lcd0.levels     \
                                   | while read -d ' ' x; do echo "$x"; done \
                                   | sort -rnu
                                ))
          actual_level=$(sysctl -n hw.acpi.video.lcd0.brightness)
          i=0
          max_i=${#possible_levels_desc[@]}
          while (( i < max_i ))
          do
            if (( actual_level == ${possible_levels_desc[i]} ))
            then
                if (( i == (max_i - 1) ))
                then
                    xgradbrightness min
                else
                    actual_level=${possible_levels_desc[i + 1]}
                    if xgradbrightness $((65535 * actual_level / 100))
                    then
                        sysctl hw.acpi.video.lcd0.brightness=$actual_level
                    fi
                fi
                break
            else
                (( i++ ))
            fi
          done
          ;;

        *)
         ;;
esac


[file]xgradbrightness.c[/file]
Code: Select all
/*
 * LICENCE TYPE : BSD
 *
 * Copyright 2012 Franck Porcher, Ph.D <franck.porcher@franckys.com>
 * Inspired by x11/xbrightness (see x11/xbrightness/work/AUTHORS)
 */

#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/xf86vmode.h>
#include <math.h>

#define BRIGHTNESS_MAX      65535
#define BRIGHTNESS_MIN      0
#define BRIGHTNESS_DEFAULT  65535
#define STEPS_DEFAULT       5000
#define DISPLAY_DEFAULT     ":0"

/*
 * Usage
 */
static void usage(char *arg) {
    fprintf (stderr, "%s builds a brightness ramp for X11.\n\n", arg);
    fprintf (stderr, "Usage:  %s [-h] [BRIGHTNESS] [STEP] [DISPLAY] \n", arg);
    fprintf (stderr, "Where :\n");
    fprintf (stderr, "    - BRIGHTNESS is the requested brightness. It can be a number from 0 to 65535, the word 'max' or the word 'min' (de
faults to max)\n");
    fprintf (stderr, "    - STEPS      is the number of steps (>= 1) to step-by-step progressively adjust the screen to the requested bright
ness (defaults to 5000)\n");
    fprintf (stderr, "    - DISPLAY    is the name of the X11 display to use (defaults to :0)\n\n");
    fprintf (stderr, "Copyright(C) Franck Porcher, Ph.D <franck.porcher@franckys.com>.\n");
    exit(0);
}

/*
 * Main
 */
int main(int argc, char *argv[]) {
    Display *dpy;
    int i,j;
    int screen, ramp_size;
    unsigned short *ramp;
    double level, delta_level;
    double brightness, delta_step;

    /**** Defaults ****/
    unsigned short brightness_requested = BRIGHTNESS_MAX;
    unsigned short steps = STEPS_DEFAULT;
    char *display = DISPLAY_DEFAULT;

    /**** Parameters ****/
    if (argc >= 2) {
        if (! strcmp(argv[1], "-h")) {
            usage(argv[0]);
        }

        if (! strcmp(argv[1], "max")) {
            brightness_requested = BRIGHTNESS_MAX;
        }
        else if (! strcmp(argv[1], "min")) {
            brightness_requested = BRIGHTNESS_MIN;
        }
        else {
            brightness_requested = atoi(argv[1]);
        }
    }

    if (argc >= 3) {
        steps = atoi(argv[2]);
    }

    if (argc >= 4) {
       display = argv[3];
    }

    /**** Setup ****/
    if ( (dpy = XOpenDisplay(display)) == NULL) {
        fprintf (stderr, "%s: unable to open default display '%s'.\n", argv[0], display);
        exit(1);
    }
    screen = DefaultScreen(dpy);

    /**** main portion ****/
    if (   XF86VidModeGetGammaRampSize(dpy, screen, &ramp_size )
        && (ramp = (unsigned short *) malloc(ramp_size * sizeof(unsigned short)))
        && XF86VidModeGetGammaRamp(dpy, screen, ramp_size, ramp, ramp, ramp)
    ) {
        /* "steps" steps by step progressive monitor's screen brightness adjustment.
         *  from "actual brightness", given by ramp[ramp_size-1],
         *  to   "requested brightness", given by 1st argument
         */

        brightness = (double)ramp[ramp_size-1];
        delta_step = ((double)brightness_requested - brightness)/steps;

        for (j=0; j<steps; j++) {
            brightness += delta_step;   /* progressive goal */

            delta_level = brightness/(ramp_size-1);
            level = 0.0;
            /* ramp[0] is always 0 whatever brightness,
             * so we start modifying ramp at index 1,
             * saving tiny fractions of precious time
             */
            for (i=1; i<ramp_size; i++) {
                level  += delta_level;
                ramp[i] = (unsigned short)level;
            }
            XF86VidModeSetGammaRamp(dpy, screen, ramp_size, ramp, ramp, ramp);
        }
    }
    XCloseDisplay(dpy);
    exit(0);
}


[file]Imakefile[/file]
Code: Select all
        DEPLIBS = $(DEPXXF86VMLIB) XawClientDepLibs
  SYS_LIBRARIES = MathLibrary
LOCAL_LIBRARIES = $(XXF86VMLIB) XawClientLibs
           SRCS = xgradbrightness.c
           OBJS = xgradbrightness.o

ComplexProgramTarget(xgradbrightness)


INSTALL
Code: Select all
xmkmf && make && make install


Wish you good success. Please report your mileage, your experience, and your suggestions.
This could become a tiny package on its own.

FP.
franck-porcher
Junior Member
 
Posts: 9
Joined: 21 Dec 2010, 14:45

Postby franck-porcher » 04 Nov 2012, 07:44

Forgot to mention that the script being called by sys daemons, you'll have to give them the right to access your X display, that is (though you will remember that when you push your brighten-up/down buttons and see nothing happening...�e ):

Code: Select all
# Log into your CLI, then
[~user]$ xhost +


There might be a better way, but I do not know it...

Cheers

--FP.
franck-porcher
Junior Member
 
Posts: 9
Joined: 21 Dec 2010, 14:45


Return to Mobile Computing

Who is online

Users browsing this forum: No registered users and 0 guests