自动背光设置
设置自动背光时间,可以让系统在停止操作一定时间后自动关闭屏幕背光,当恢复操作后自动打开屏幕背光,设置方法如下:
打开控制面板->电源,选择“方案”页,选择“电源使用方案”为“交流电源”,选择“将状态切换为用户空闲”选项的时间,这个时间即自动关闭背光的时间。
手动控制背光开关
有时客户希望在自己应用程序中能够自由控制背光的开关,那么可以参考我们例程进行如下调用。
#include
#include "winioctl.h"
#include "pm.h"
#define FILE_DEVICE_POWER FILE_DEVICE_ACPI
#define IOCTL_POWER_SET CTL_CODE(FILE_DEVICE_POWER, 0x402, METHOD_BUFFERED, FILE_ANY_ACCESS)
HANDLE hBLK;
CEDEVICE_POWER_STATE power;
DWORD dwReturn;
//操作背光前需要先打开背光驱动
hBLK = CreateFile(L"BKL1:", // name of device
GENERIC_READ|GENERIC_WRITE, // desired access
FILE_SHARE_READ|FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (ignored)
OPEN_EXISTING, // creation disposition
FILE_FLAG_RANDOM_ACCESS, // flags/attributes
NULL); // template file (ignored)
//获得屏幕背光状态
BOOL success;
success = DeviceIoControl(hBLK,
IOCTL_POWER_GET,
NULL,
0,
&power,
sizeof(CEDEVICE_POWER_STATE),
NULL,
NULL);
//关闭屏幕背光,恢复操作(鼠标移动,按键等)屏幕背光不会打开
power = D4;
success = DeviceIoControl(hBLK,
IOCTL_POWER_SET,
NULL,
0,
&power,
sizeof(CEDEVICE_POWER_STATE),
&dwReturn,
NULL);
//关闭屏幕背光,恢复操作(鼠标移动,按键等)屏幕背光自动打开
power = D1;
success = DeviceIoControl(hBLK,
IOCTL_POWER_SET,
NULL,
0,
&power,
sizeof(CEDEVICE_POWER_STATE),
&dwReturn,
NULL);
//打开屏幕背光
power = D0;
success = DeviceIoControl(hBLK,
IOCTL_POWER_SET,
NULL,
0,
&power,
sizeof(CEDEVICE_POWER_STATE),
&dwReturn,
NULL);
//关闭背光驱动
if (hBLK != NULL)
{
CloseHandle(hBLK);
}
操作时需要先打开背光驱动,操作完成后需关闭背光驱动,D0为开,D4为关。
控制屏幕背光亮度
ESM335X WEC7除了控制屏幕开关,还可以调节屏幕亮度,操作代码如下:
#define IOCTL_BKL_GET_SETTINGS CTL_CODE(FILE_DEVICE_BACKLIGHT, 0x102, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_BKL_SET_SETTINGS CTL_CODE(FILE_DEVICE_BACKLIGHT, 0x103, METHOD_BUFFERED, FILE_ANY_ACCESS)
BKL_SETTINGS_INFO bklInfo;
//操作背光前需要先打开背光驱动
hBLK = CreateFile(L"BKL1:", // name of device
GENERIC_READ|GENERIC_WRITE, // desired access
FILE_SHARE_READ|FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (ignored)
OPEN_EXISTING, // creation disposition
FILE_FLAG_RANDOM_ACCESS, // flags/attributes
NULL);
//先调用IOCTL_BKL_GET_SETTINGS获得当前BKL_SETTINGS_INFO
success = DeviceIoControl(hBLK,
IOCTL_BKL_GET_SETTINGS,
NULL,
0,
&bklInfo,
sizeof(BKL_SETTINGS_INFO),
&dwReturn,
NULL);
//通过修改BKL_SETTINGS_INFO的dwBrightness_ExPower,让屏幕从亮变暗
for(int i=0xff; i>=0; )
{
bklInfo.dwBrightness_ExPower = i;
success = DeviceIoControl(hBLK,
IOCTL_BKL_SET_SETTINGS,
&bklInfo,
sizeof(BKL_SETTINGS_INFO),
NULL,
0,
&dwReturn,
NULL);
Sleep(100);
i -= 5;
}
//通过修改BKL_SETTINGS_INFO的dwBrightness_ExPower,让屏幕从暗变亮
for(int i=0; i<=0xff; )
{
bklInfo.dwBrightness_ExPower = i;
success = DeviceIoControl(hBLK,
IOCTL_BKL_SET_SETTINGS,
&bklInfo,
sizeof(BKL_SETTINGS_INFO),
NULL,
0,
&dwReturn,
NULL);
Sleep(100);
i+= 5;
}
if (hBLK != NULL)
{
CloseHandle(hBLK);
}
操作时需要先打开背光驱动,需要先调用IOCTL_BKL_GET_SETTINGS获得背光参数,然后调用IOCTL_BKL_SET_SETTINGS设置亮度范围。亮度范围为0到255,0表示最暗,255表示最亮。
其它屏幕背光参数控制说明
使用远程注册表工具打开ESM335X WEC7注册表,找到背光驱动信息处。
这里的PwmFreq值为屏幕背光频率值,默认为400Hz,用户可以根据自身选购屏参数性能自由调节该频率值。
本文提及的例程均可联系英创工程师获得。