Android-driven learning-lighting system overall framework

Source: Internet
Author: User

The approximate flow of Android app access hardware can be divided into several steps:

As we said before, when adding new hardware, the Android system needs to add an interface Java file to access the hardware via JNI.

This Java is our own implementation, we can clearly know how to invoke it. But there are some other hardware like Android, such as screen, vibrator, sound card, LED, etc., because the hardware is not the same, so the driver is not the same, then how can we let other people's app on our system will also be able to run normally? Here's what you need to be aware of:

Some of the necessary jni has been added to the Android system, and when we want to add some common devices, we need to use the JNI files in the system, write the HAL files to adapt to the JNI files, so that other people's apps can operate the hardware properly.

Let's analyze the lighting system below.

The lighting system consists of the following four files

App: Battery light app, notification light app, backlight app
JNI:com_android_server_lights_LightsService.cpp
HAL: We implement it ourselves and implement a LIGHTS.C
Drive: leds_nanopi3.c (JNI needs what is here to give it what, here we achieve flashing and brightness)

The main functions of the lighting system:

    1. The hardware belongs to the same (including color and flicker):
      Battery Light: Color changes when battery power changes
      Notification light: Notification flashes, such as missed calls or text messages

    2. Adjust LCD Brightness:
      Backlight Light

The JNI file for the lighting system is com_android_server_lights_lightsservice.cpp

It contains:

The steps in JNI are:

    1. We need to get the hw_module_t structure inside, so our HAL needs to implement this structure
    2. The Get_device in JNI will call Module->methods->open to return different light_device_t structures based on different names, with Set_light in the structure, which is the control function of different lights.
lights.h*********************#define light_id_backlight          "BACKLIGHT"#define light_id_keyboard "           KEYBOARD"#define light_id_buttons            "BUTTONS"#define light_id_ BATTERY "            BATTERY"#define light_id_notifications      "notifications"#define light_id_ ATTENTION          "ATTENTION"

Here we only implement Light_id_backlight (backlight), light_id_battery (battery), light_id_notifications (notification)

The steps in the HAL are:

Dividing the hardware LEDs into different logic lights
1. Implementing the HW_MODULE_T Structure
2. Implement the Open function, which returns a different light_device_t struct based on name
3. For different lights (backlight/battery/notification), the corresponding set_light function

struct light_device_t {    struct hw_device_t common;    int (*set_light)(struct light_device_t* dev,            struct light_state_t const* state);};

There are three set_light functions that need to be implemented

set_light_battery (struct light_device_t *dev, struct light_state_t const* state)set_light_notifications (struct light_device_t *dev, struct light_state_t const* state)set_light_backlight (struct light_device_t *dev, struct light_state_t const *state)

Operate the driver through these functions

drivers:
1. For RGB three LEDs, to achieve light off flashing three functions
2. For backlight, set PWM

Summary:
We only need to implement a HAL and a driver, HAL inside we only need to implement the hw_module_t structure and an open function, the open function according to the different name passed in to construct different light_device_t structure, and finally point to the different set_ The light function operates the driver, and the next chapter implements the code specifically.

Android-driven learning-lighting system overall framework

Related Article

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.