Use IOCTL code to implement LCD backlight adjustment, and use ioctl code to implement LCD Backlight

Source: Internet
Author: User

Use IOCTL code to implement LCD backlight adjustment, and use ioctl code to implement LCD Backlight

Such Code cannot be found in China. Therefore, the following code is improved after the relevant code is referenced, and the implementation method uses IOCTL code to implement the LCD backlight adjustment function.

Suitable for tablets or laptops. It depends on BIOS support or not.

Compile the environment using the Dev-cpp tool.

#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <ddk/Ntddvdeo.h>typedef struct _DISPLAY_BRIGHTNESS {    UCHAR ucDisplayPolicy;    UCHAR ucACBrightness;    UCHAR ucDCBrightness;} DISPLAY_BRIGHTNESS, *PDISPLAY_BRIGHTNESS;#define IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS  CTL_CODE(FILE_DEVICE_VIDEO, 0x125, METHOD_BUFFERED, FILE_ANY_ACCESS)#define IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS CTL_CODE(FILE_DEVICE_VIDEO, 0x126, METHOD_BUFFERED, FILE_ANY_ACCESS)#define IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS CTL_CODE(FILE_DEVICE_VIDEO, 0x127, METHOD_BUFFERED, FILE_ANY_ACCESS)void help(void){fprintf(stderr, "(c) Tody, 2014\n");fprintf(stderr, "Usage: wbl.exe -b <level>\n");fprintf(stderr, "  Option:\n");fprintf(stderr, "     -b <level>\t brightness level need to be specified\n");fprintf(stderr, "\n  Error code:\n");fprintf(stderr, "     Pass: 0;  Fail: 1\n");exit(1);}int setBrightness(int level){HANDLE h ;DWORD nOutBufferSize = 256;BYTE SupportedBrightness[256];DWORD g_supportedLevelCount; DISPLAY_BRIGHTNESS DisplayBrightness;memset(SupportedBrightness, 0, sizeof(SupportedBrightness));/* use createfile function to open lcd.  * url from microsoft about IOCTL code.*  http://msdn.microsoft.com/en-us/library/windows/desktop/aa372703%28v=vs.85%29.aspx*/h = CreateFile("\\\\.\\LCD", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);if(h == INVALID_HANDLE_VALUE){printf("Open \\\\.\\LCD error");exit(1);}/* Query for display supported level */if(!DeviceIoControl(h, IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS, NULL, 0, SupportedBrightness, nOutBufferSize, &g_supportedLevelCount, NULL)){printf("IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS error - %d, - buffer: %d ", g_supportedLevelCount, nOutBufferSize);exit(1);}if (g_supportedLevelCount == 0)  /* 0 means not supported */{printf("\nLCD not support LEVEL COUNT", g_supportedLevelCount);exit(1);}DisplayBrightness.ucDisplayPolicy = 0;DisplayBrightness.ucACBrightness = level;DisplayBrightness.ucDCBrightness = level;/* Set display backlight level */nOutBufferSize = sizeof(DisplayBrightness);if(!DeviceIoControl(h, IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS, (DISPLAY_BRIGHTNESS *)&DisplayBrightness, nOutBufferSize, NULL, 0, &nOutBufferSize, NULL)){printf("IOCTL_VIDEO_SET_SUPPORTED_BRIGHTNESS error - %d, - buffer: %d ", g_supportedLevelCount, nOutBufferSize);exit(1);}Sleep(500); /* delay for some time while wmi event changed */nOutBufferSize = sizeof(DisplayBrightness);if(!DeviceIoControl(h, IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, NULL, 0, (DISPLAY_BRIGHTNESS *)&DisplayBrightness, nOutBufferSize, &nOutBufferSize, NULL)){printf("IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS error - %d, - buffer: %d ", g_supportedLevelCount, nOutBufferSize);exit(1);}printf("\nBrightness_AC: %d\nBrightness_DC: %d", DisplayBrightness.ucACBrightness, DisplayBrightness.ucDCBrightness);}int main(int argc, char *argv[]) {/* program with arguments support */if (argc == 3 && strcmp("-b", argv[1])==0){setBrightness(atoi(argv[2]));}else{help();}return 0;}



How to control the LCD12864 backlight, that is, how to use a single-chip microcomputer to adjust the brightness of the LCD12864 backlight, how to connect the hardware

The simplest is PWM. The backlight is controlled by a transistor, And the PWM inputs the baseline of the transistor.

How does XP Adjust the LCD backlight?

For a desktop, press the menu key on the monitor, find the brightness options, find the options to adjust the brightness, and then adjust the left and right arrows.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.