# Sysctl Brightness



## Draucia (Apr 20, 2012)

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


```
sudo sysctl hw.acpi.video.<device>.active
```

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

I've tried:


```
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.


----------



## aa (Apr 20, 2012)

Just type sysctl hw.acpi to enumerate all recognized variables under hw.acpi


----------



## DutchDaemon (Apr 20, 2012)

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


----------



## Draucia (Apr 20, 2012)

aa said:
			
		

> Just type sysctl hw.acpi to enumerate all recognized variables under hw.acpi



When I do so, here is the output:


```
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 
	
	



```
kldload acpi_toshiba
```
Am I doing something wrong?



			
				DutchDaemon said:
			
		

> 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 (Apr 22, 2012)

I still haven't been able to solve this issue. Is it just not possible on my laptop because hw.acpi.video doesn't support it?


----------



## JonathanBSD (Apr 23, 2012)

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.


----------



## Draucia (Apr 23, 2012)

JonathanBSD said:
			
		

> 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.


----------



## JonathanBSD (Apr 23, 2012)

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!


----------



## Draucia (Apr 23, 2012)

JonathanBSD said:
			
		

> 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!



RTL819 Wireless card? :O I have the Intel Wifi Link 5100AGN. 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.


----------



## Rul (Sep 5, 2012)

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


----------



## CanOfBees (Sep 6, 2012)

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!


----------



## Rul (Sep 6, 2012)

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


----------



## franck-porcher (Nov 3, 2012)

*Sysctl brightness all-in-one draft solution*

I was able to produce the following working solution :



> <Button push event>
> |
> v
> Captured by the system
> ...



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 sysctl 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 acpi_ibm and acpi_video. Check the available documentation to see which ones would be relevant for your particular hardware (generic acpi_<_oem_>)

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 /boot/loader.conf :


```
# ACPI for IBM ThinkPad
acpi_ibm_load="YES"
acpi_video_load="YES"
```

2)Second, configure the devd 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 :Notify=0x10 (resp. Notify=0x11).

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

/etc/devd.conf

```
# 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 /usr/local/bin/acpi_ibm_exec.sh *"0x10"* *ibm*

3) Third, provide the user-space software.

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

This "compilation" was inspired by acpi_ibm(4) and xbrightness(1) :

/usr/local/bin/acpi_ibm_exec.sh

```
#!/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
```

xgradbrightness.c

```
/*
 * 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);
}
```

Imakefile

```
DEPLIBS = $(DEPXXF86VMLIB) XawClientDepLibs
  SYS_LIBRARIES = MathLibrary
LOCAL_LIBRARIES = $(XXF86VMLIB) XawClientLibs
           SRCS = xgradbrightness.c 
           OBJS = xgradbrightness.o

ComplexProgramTarget(xgradbrightness)
```

*INSTALL*

```
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 (Nov 4, 2012)

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 ):


```
# Log into your CLI, then
[~user]$ xhost +
```

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

Cheers

--FP.


----------



## islamux (Jul 15, 2017)

```
[root@FreeBSD /]# xbrightness 22000
[root@FreeBSD /]# xbrightness 20000
[root@FreeBSD /]# xbrightness 2000
[root@FreeBSD /]# xbrightness 9000
[root@FreeBSD /]# xbrightness 33000 1.3
```

dosn't work for me i'm using virtualbox ,FreeBSD 11
i could change brightness in pc-psd -in hard not in virtualbox -by
`xbacklight -set <number>` but when i did it
`[root@FreeBSD /]# xbacklight -set 50
No outputs have backlight property`


----------



## darcsis (Sep 21, 2017)

LCD brightness works on my ThinkPad T430. The trick is you have to load the kernel module 'i915kms'. After you load the kernel module, brightness and sleep/wake will all work normally. And FYI, I am running 11-Release.


----------

