Android Tri-Color Breathing light realization

Source: Internet
Author: User

Three-color (red-green-blue) breathing lamp, the main control calls, short-interest, not three different cases of the color of the breathing lamp display.

The specific implementation of the application layer (PHONE,MMS) to obtain the breathing lamp service, call the reserved interface, transmission frequency and color value;

1     Private voidRgbbreathledsswitchon () {2Ibreathledsservice ledsvc = IBreathLedsService.Stub.asInterface (Servicemanager.getservice ("Breath_leds")); Get a breathing light service3         intTime = 2;4         intReqtype = 0x80 |Time ; Frequency5         intLedtype = 1; Color value6         Try {7             if(featureoption.hexing_custom_breath_leds) {//Macro control Code8 ledsvc.setledsbrightness (Reqtype, ledtype);//Call setledsbrightness () interface9LOG.I ( This, "Breathleds switchon, Reqtype =" + Reqtype + ", Ledtype =" +ledtype);Ten}Else { OneLOG.I ( This, "not support breathleds."); A             } -}Catch(Exception e) { - e.printstacktrace (); the         } -}

On the service side, inherit the Ibreathledsservice.aidl service communication, implement the Setledsbrightness () interface, invoke the local method, and access the JNI;

1  Public classBreathledsserviceextendsIbreathledsservice.stub {2 3     // brightness level (level 32)4     Private Static Final int[] Brightness_level = {50, 1, 2, 4, 6, 10, 13, 18,622, 28, 33, 39, 46, 53, 61, 69,778, 86, 96, 106, 116, 126, 138, 149,8161, 173, 186, 199, 212, 226, 240, 255,9     };Ten  One      PublicBreathledsservice (Context context) { A init_native (); -     } -  the      Public voidturnonleds () { -Set_brightness_native (0x80); -     } -  +      Public voidturnoffleds () { -Set_brightness_native (0x00); +     } A  at      Public voidSetledsbrightness (intWhich,intLevel ) { -         //if ((Which > 12) | |  (which < 1)) return; -        -         //Level = level%; -         intdata = (which << 8) |Level ; - set_brightness_native (data); in     } -  to     Private native voidinit_native (); +     Private native voidSet_brightness_native (intdata); -}

Note: The Add service is required in Systemserver.java

1     Try {2         SLOG.I (TAG, "Breathleds Service"); 3         New  Breathledsservice (context)); Add Service4     catch  (Throwable e) {5         slog.e (TAG, " Failure starting breathleds Service ", e);     6     }

Implementation of module initialization, function mapping and registration of local methods in JNI, complete the process of the breathing lamp module;

1 #defineLog_tag "Breathledsservice"2 3#include"jni.h"4#include"JNIHelp.h"5#include"android_runtime/androidruntime.h"6 7#include 8#include 9 Ten namespaceAndroid { One  A     structbreath_leds_device_t* Leds_dev = NULL;// HAL device structure defined in Hw_breath_leds.h -      -     Static voidLeds_ctl_open (Const structhw_module_t* module,structbreath_leds_device_t**Dev) the     { -         // Call the Open function for a series of initialization work -Module->methods->open (module, breath_leds_hw_module_id, (structhw_device_t**) dev); -     } +      -     Static voidInit_leds (jnienv*env, Jobject thiz) +     { Abreath_leds_module_t* Leds_module =NULL; at          -         // finding the HAL module with the Hw_get_module function -         if(Hw_get_module (breath_leds_hw_module_id, (Consthw_module_t**) &leds_module) = =0) -         { -Leds_ctl_open (& (Leds_module->breath_module), &leds_dev);// Loading Leds_dev -         } in     } -      to     Static voidSet_brightness_leds (jnienv*env, Jobject thiz, jint level) +     { -Leds_dev->Set_breath_value (Leds_dev, level); the     } *      $     // defining JNI Function MappingsPanax Notoginseng     Static ConstJninativemethod method_tab[] = { -{"init_native","() V", (void*) Init_leds}, the{"set_brightness_native","(I) V", (void*) Set_brightness_leds}, +     }; A      the     intRegister_android_server_breathledsservice (JNIENV *env) +     { -         returnandroidruntime::registernativemethods (env, $                       "Com/android/server/breathledsservice", Method_tab, Nelem (Method_tab)); $     } -  -}/*namespace Android*/

Testimonials: Inspirational to the Android system frame layer struggle, continuous learning, continuous efforts; From now on, go deep into the vertical direction.

Android Tri-Color Breathing light realization

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.