Android System Power Indicator Cubietruck

Source: Internet
Author: User

Please move first, the operation of the LED, we use the same battrey_leds.sh
http://forum.cubietech.com/forum.php?mod=viewthread&tid=3212&highlight=%E5%B5%8C%E5%85%A5%E5%BC%8F%E5% Ad%a6%e4%b9%a0
[Embedded learning]led subsystem and LED trigger

Refer to the following three blog posts

1. How system services are started

http://blog.csdn.net/windskier/article/details/6417657


2. Android Batteryservice

Http://www.cnblogs.com/armlinux/archive/2010/09/15/2396916.html


3. Android 2.3 Battery Management

http://blog.csdn.net/z642010820/article/details/7341469


Android below also calls the same battrey_leds.sh file
but Android's Uevent trigger event is already in the system's own battery service, and we just need to execute the script battrey_leds.sh in it.
as you can see, only after the JNI updates the current value, the SH is executed

===== to do a brief explanation ========

1. Android System Services

V2.0_a20\android\frameworks\base\services\java\com\android\server\systemserver.java

battery = new Batteryservice (context, lights);//Battery Service



2. Android Battery Service

V2.0_a20\android\frameworks\base\services\java\com\android\server\batteryservice.java

mpowersupplyobserver.startobserving ("subsystem=power_supply");//register uevent, monitor power_supply


Uevent and kernel socket communication, a dead loop, the kernel has an event escalation, trigger onuevent


Public
void Onuevent (Ueventobserver.uevent event) {
Synchronized (MLock) {
Updatelocked (); See 309L
}
}


Native_update (); Refresh power, invoke the function of the battery service JNI layer
Processvalueslocked ();//Publish a Power update broadcast



3. Android Battery Service JNI

V2.0_a20\android\frameworks\base\services\jni\com_android_server_batteryservice.cpp


This JNI shares variables with the Java layer

The power and other parameters are defined in the Java layer, defined in Batteryservice.java, and used here

android_server_batteryservice_update//Refresh power and other parameters

4. Android Uevent

V2.0_a20\android\\frameworks\base\core\java\android\os\ueventobserver.java


while (true)//A dead loop of the line thread, waiting for the kernel to escalate the event
Observer.onuevent (event);//CALLBACK The observer registers the Onuevent function, and finally calls the onuevent in Batteryservice.java



= = = Specific implementation steps = = =
1. In the JNI layer of the battery serviceadd script execution functions in Com_android_server_batteryservice.cpp

static int execmd (const char* cmd)


    if (!cmd)
   & nbsp    return-1;
                          
    INT ret = System (CMD);  
        if (Ret < 0) {
           &NB sp;    Aloge ("==========execmd error '%s '", cmd);         
  &NBSP;&NBS P    }
        
    return 0;
}

exposed tointerface of the Batteryservice.javanative_setbatleds

//Set battery light

static void Android_server_batteryservice_setbatleds () { 
    ALO GE ("==========android_server_batteryservice_setbatleds");  

        execmd ("sh/system/bin/battrey_leds.sh");  
}

//Add set battery light native_setbatleds
static Jninativemethod smethods[] = {
     /* name, Signa ture, Funcptr */
        {"Native_update", "() V", (void*) android_server_ Batteryservice_update},
    {"Native_shutdown", "() V", (void*) Android_server_batteryservice_ shutdownnotfrompms},        
    {"Native_setbatleds", "() V", (void*) android_server_batteryservice_setbatleds},           
};

2. In the battery serviceBatteryservice.javaThe JNI interface is declared in the

private native void Native_setbatleds ();

Called in updatelocked ().

private void updatelocked () {
if (!mupdatesstopped) {
Update the values of Maconline, et. All.
Native_update ();

JNI Layer Set Battery light
Native_setbatleds ();

Process the new values.
Processvalueslocked ();
}
}        


3. However, you need to be aware of file node permissions
in Android/device/softwinner/sugar-cubietruck/init.sun7i.rc

chown System System/sys/class/leds/xxx/brightness
Chown System System/sys/class/leds/xxx/trigger
CHOMD 0777/sys/class/leds/xxx/brightness
CHOMD 0777/sys/class/leds/xxx/trigger

XXX Replace the LED lights you want to operate

5. Put the battrey_leds.sh in
Android/out/target/product/sugar-cubietruck/system/bin
chmod +x

There is another way to copy the battrey_leds.sh file into the file system.
can refer to
android\device\softwinner\sugar-cubietruck\sugar_cubietruck.mk
android/device/softwinner/wing-common/productcommon.mk
the Product_copy_files field in the

=====================================================
finally on my Android compilation steps summary

---------------Install JDK--------------
$ wget dl.cubieboard.org/software/tools/android/jdk1.6.0_45.tar.gz
$ sudo vim ~/.BASHRC

ADD:
Java_home=/work/tools/jdk1.6.0_45
Export JRE_HOME=/WORK/TOOLS/JDK1.6.0_45/JRE
Export path= $JAVA _home/bin: $JRE _home/bin: $PATH

$ source ~/.BASHRC


---------------Install Tools--------------
$ sudo apt-get install git gnupg flex bison gperf build-essential \
Zip curl Libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 mingw32 tofrodos \
Python-markdown libxml2-utils xsltproc zlib1g-dev:i386 libgl1-mesa-glx:i386 Libgl1-mesa-dev

$ sudo apt-get install Xsltproc
$ sudo apt-get Install Bison
$ sudo apt-get install Flex
$ sudo apt-get install Gperf
$ sudo apt-get install g++
$ sudo apt-get install Gcc-multilib
$ sudo apt-get install Libxml2-utils


---------------Download Source code--------------
$ mkdir/home/box/work/android_build
$ wget Http://dl.cubieboard.org/softwar ... droid_source.tar.gz
$ TAR-ZXVF v2.0_a20_android_source.tar.gz


---------------Build Kernel--------------
$ CD lichee/linux-3.4
$ make clean
$ cp arch/arm/configs/cubietruck_config. config
$ CD.
$./build.sh-p sun7i_android





---------------Build Android--------------
$ CD. /android
$ source Build/envsetup.sh
$ lunch
$//note:select Sugar_cubietruck-eng//For a targeted look, the suffix eng indicates that the engineering machine Userdebug the development of the debugger user end user machine
$ extract-bsp//Its role is to copy the drivers generated in the kernel into the product copy kernel-generated module and *.image
$ make-j8//First time here is best not add J8, otherwise memory is not enough error, if wrong, try to use J2, J4 try
$ pack


Android System Power Indicator Cubietruck

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.