zoukankan      html  css  js  c++  java
  • I.MX6 Android backlight modify by C demo

    /**************************************************************************
     *             I.MX6 Android backlight modify by C demo
     * 说明:
     *     因为一些特殊情况,需要添加一个这个简单的控制程序来控制android背光
     * 亮度,个人感觉是没有必要的,但是应要求还是加上。
     *
     *                                      2016-5-14 深圳 南山平山村 曾剑锋
     *************************************************************************/
    
    #include <stdio.h>  
    #include <stdlib.h>  
    #include <unistd.h>  
    #include <sys/types.h>  
    #include <sys/stat.h>  
    #include <fcntl.h>      
    #include <termios.h>    
    #include <string.h>
    #include <errno.h>  
    
    #define BACKLIGHT0_PATH "/sys/class/backlight/pwm-backlight.0/brightness"
    #define BACKLIGHT1_PATH "/sys/class/backlight/pwm-backlight.1/brightness"
    
    //#define BACKLIGHT0_PATH "brightness0"
    //#define BACKLIGHT1_PATH "brightness1"
    
    int help ( int argc );
    int isDigitalStr(char *str);
    int file_exists(char *filename);
    void writeStringToFile(char *filePath, char *string);
    
    int main(int argc, char **argv)  
    {  
        int bl0 = 0;
        int bl1 = 0;
        
        if ( help( argc ) != 0)
            return -1;
    
        if ( !isDigitalStr(argv[1]) ) {
            printf("Please give a numeric string.
    ");
            return -1;
        }   
    
        writeStringToFile(BACKLIGHT0_PATH, argv[1]);
        writeStringToFile(BACKLIGHT1_PATH, argv[1]);
    }
    
    void writeStringToFile(char *filePath, char *string) 
    {
        int fd = 0;
    
        if ( file_exists(filePath) ) {
    
            fd = open(filePath, O_RDWR);
    
            ftruncate(fd, 0);
            write(fd, string, strlen(string));
    
            close(fd);
    
        }
    }
    
    int isDigitalStr(char *str)
    {   
        int len = strlen(str);
        char *s = str;
        int i = 0;
     
        while( '0' <= *s && *s <= '9' && i < len){
            s++;
            i++;
        }
    
        if(i == len)
            return 1;
        else 
            return 0;       
    }
    
    int file_exists(char *filename) 
    { 
        if (access(filename, F_OK) == 0) {
            return 1;
        } else {
            printf("%s is not exist.
    ", filename);
            return 0;
        }
    }
    
    int help( int argc ) 
    {
        if ( argc != 2 ) {
            printf ( "USAGE:
    " );
            printf ( "    backlight <value>
    " );
            printf ( "    example:
    " );
            printf ( "        backlight 0
    " );
            return -1;
        }
    
        return 0;
    }
  • 相关阅读:
    Mapper映射文件没有提示的解决方案
    MyBatis简单使用
    js利用select标签生成简易计算功能
    输入数字,求各个位的值
    百度搜索页--不用浮动定位版
    画奥运五环
    border写一个直角三角形
    用diiv实现多个方块居中嵌套--padding
    用diiv实现多个方块居中嵌套--margin
    jq制作tab栏
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5492000.html
Copyright © 2011-2022 走看看