9 backlight example, Ktam3874/pitx software guide, Interface. the directory – Kontron KTAM3874-pITX User Manual
Page 84

KTD-S0057-I
Page 80 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
10.9 Backlight Example
An easy way to modify the backlight brightness value consists in use of the
sysfs
interface. The directory
/sys/class/backlight/ktam3874-lcd/
contains the following entries (please note - this directory appears
only if an LCD panel is enabled):
actual_brightness
Actual brightness value (read only)
brightness
Changeable brightness value
max_brightness
Maximal brightness value (read only)
bl_power
Changeable power state (on/off)
The program below gives an overview regarding the possible setting options.
/* Backlight test program
* Copyright (c) 2013 Kontron Technology A/S
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define MAX_BKL_VAL
255
#define MAX_BKL_POW
1
/* 0 = enable, 1 = disable */
#define WRITE_DELAY
20
#define POWER_DELAY
100
static const char *dev_pow = "/sys/class/backlight/ktam3874-lcd/bl_power";
static const char *dev_val = "/sys/class/backlight/ktam3874-lcd/brightness";
static const char *dev_act = "/sys/class/backlight/ktam3874-lcd/actual_brightness";
int write_bkl_val (int val)
{
int
fd;
char
str[8];
if ((val < 0) || (val > MAX_BKL_VAL))
return
-1;
fd = open (dev_val, O_WRONLY);
if (fd < 0)
return
-1;
sprintf (str, "%d", val);
if (write (fd, str, strlen (str)) != strlen (str))
{
close
(fd);
return
-1;
}
close
(fd);
return
0;
}