Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • 社区主页

    请问如何用命令行调整背光亮度?

    D1-H/D1s
    背光亮度调整
    2
    5
    156
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      ubuntu LV 6 last edited by

      请问如何用命令行调整背光亮度?

      《D1_Linux_LCD_开发指南.pdf》 没有找到相关说明

      1 Reply Last reply Reply Quote Share 0
      • W
        whycan晕哥 LV 8 last edited by

        可能只能用 ioctl 命令控制背光,但是我测试了一下,并没有什么作用,而且屏幕都黑了。

        https://blog.csdn.net/weixin_43772810/article/details/111617402

        #include <stdio.h> 
        #include <sys/types.h>
        #include <sys/stat.h>  
        #include <stdlib.h> 
        #include <unistd.h> 
        #include <fcntl.h>
        #include <sys/ioctl.h>
        
        //disp驱动部分命令(与背光相关,内核目录:/include/video/sunxi_display2.h)
        #define	DISP_LCD_SET_BRIGHTNESS  0x102
        #define DISP_LCD_GET_BRIGHTNESS  0x103
        #define	DISP_LCD_BACKLIGHT_ENABLE   0x104
        #define	DISP_LCD_BACKLIGHT_DISABLE  0x105
        
        #define BRIGHTNESS_MAX 255     //最大亮度
        
        int main(int argc, char *argv[])   
        { 
        	int fd;
        	unsigned long args[3]={0}; 
        	/*打开disp设备文件*/
        	fd = open("/dev/disp", O_RDWR, 0);
        	if(fd < 0)
        	{
        		printf("open /dev/disp failed.\n");
        		return -1;
        	}
        	/*打印旧的背光值*/
        	args[0] = 0;     //选择fb0(lcd0)
        	printf("the old lcd%d brightness is %d\n",\
        	args[0],ioctl(fd,DISP_LCD_GET_BRIGHTNESS,args));
        	
        	if(argc != 2)
        	{
        		printf("ERROR: the right format: ./app [brightness]\n");
        		return -1;
        	}
        	
        	int brightness = atoi(argv[1]);  
        	
        	if(brightness < 0 || brightness > BRIGHTNESS_MAX)
        	{
        		printf("ERROR: the range is 0 to %d\n",BRIGHTNESS_MAX);
        		return -1;
        	}
        	
        	/*参数数组填参*/
        	args[0] = 0; 			      
        	args[1] = brightness; 		//背光值(本人配置里最高为255)
        	args[2] = 0;     	      //暂时用不到的参数
        	ioctl(fd,DISP_LCD_SET_BRIGHTNESS,args);
        	printf("the new lcd%d brightness is %d\n",\
        	args[0],ioctl(fd,DISP_LCD_GET_BRIGHTNESS,args));
        	close(fd);
        	return 0;
        }
        
        1 Reply Last reply Reply Quote Share 0
        • W
          whycan晕哥 LV 8 last edited by

          问了一个大佬,给我的答复是:

          打开一个/dev/disp之后,获取文件描述符fb,不要关闭fb
          如果/dev/disp打开5个,关闭4次正常,如果再关闭一次,驱动会调用清图层操作。
          cat /sys/class/disp/disp/attr/sys为 空,说明没有一个图层

          然后我把 close(fd) 屏蔽起来,执行完发现仍然黑屏。

          1 Reply Last reply Reply Quote Share 0
          • W
            whycan晕哥 LV 8 last edited by whycan

            会不会是进程退出,自动 close 了文件句柄呢?

            然后继续测试了一下:

            d7890e07-b7bc-46e7-a7dc-9c27899d8fa9-image.png

            这样保持进程不退出,就可以调整背光亮度了。

            1 Reply Last reply Reply Quote Share 0
            • W
              whycan晕哥 LV 8 last edited by

              终于找到了, 可以用命令行调整背光亮度了:

              8208722513384b7d991b490bee98006.png

              mount -t debugfs none /sys/kernel/debug;
              cd /sys/kernel/debug/dispdbg;
              
              #背光0
              echo lcd0 > name; echo setbl > command; echo 0 > param; echo 1 > start
              
              #背光255
              echo lcd0 > name; echo setbl > command; echo 255 > param; echo 1 > start
              
              
              1 Reply Last reply Reply Quote Share 0
              • 1 / 1
              • First post
                Last post

              Copyright © 2021 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

              行为准则 | 用户协议 | 隐私权政策