SlideShare a Scribd company logo
Introduction to
G-Sesnsor and
    E-Compass
           Jiahe Jou
            2, Dec., 2011
Outlines
● Introduction
  ○ Sensor System
● G-Sensor System
  ○ Java Application Layer
  ○ Java Framework Layer
  ○ JNI
  ○ Hardware Abstraction Layer
  ○ Linux Kernel
  ○ Setup G-Sensor Driver
● Conclusion
Introduction
           Sensor System
Sensor System
● Detect the environment to provide better
  user experience
  ○   Accelerometer
  ○   Magnetometer
  ○   Light Sensor
  ○   Temperature Meter
● Application
  ○ Game feature
  ○ Rotate screen
  ○ E-compass
Sensor System
● General architecture of sensor system
Sensor System
● API
  ○ Provide a interface to get system sensor manager
● Framework
  ○ Sensor manager service
  ○ Definitions of sensor, sensor event, event listener
● JNI
  ○ Link the framework layer and HAL
● HAL
  ○ The hardware foundation of Android
Sensor System
● In more detail
G-Sensor
System
          Java Application Layer
          Java Framework Layer
                             JNI
                            HAL
                    Linux Kernel
       Setup the G-Sensor driver
Java Application Layer
● Implement a sensor application
  ○ Get sensor manager
  ○ Get a specific sensor
  ○ Register sensor event listener

     ...

     mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

     mAccerlerometer = mSensorManager.getDefautSensor(
                                  Sensor.TYPE_ACCELEROMETER);

     mSensorManager.registerListener(this, mAccelerometer,
                                     SensorManager.SENSOR_DELAY_GAME);
     ...
Java Application Layer
● Implement event listener
     ...
     // Called when the sensor accuracy changed
     public void onAccuracyChanged(int sensor, int accuracy){
            // You can leave this function empty
     }

     ...
     // Called when the sensor value changed
     public void onSensorChanged(SensorEvent event{
            ...
            Log.d(TAG, "onSensorChanged==> sensor: " + sensor +
                                  ", x: " + event.values[0] +
                                  ", y: " + event.values[1] +
                                  ", z: " + event.values[2]);
            …
     }
     ...
G-Sensor
System
          Java Application Layer
          Java Framework Layer
                             JNI
                            HAL
                    Linux Kernel
       Setup the G-Sensor driver
Java Framework Layer
● Sensor Manager
  ○ getDefautSensor(int type)
     ...
     public Sensor getDefaultSensor( int type){
           // just return the 1st sensor
           List<Sensor> l = getSensorList(type);
           return l.isEmpty() ? null : l.get(0);
     }
     …


  ○ registerListener(SensorEventListener listener,
    Sensor sensor, int rate)
     ...
     public boolean registerListener( (SensorEventListener listener, Sensor sensor, int rate){
              // Another function was return
              return registerListener(listener, sensor, rate, null);
     }
     …
Java Framework Layer
 ○ registerListener( (SensorEventListener listener,
    Sensor sensor, int rate, Handler handler)
    ■ Delegate a listener on a sensor
    ■ Lock the listening thread before sensor enabled
    ■ Enable the sensor
    ■ Unlock the listening thread
    ■ Start polling

    PS. Please refer to the Figure 7 in document
G-Sensor
System
          Java Application Layer
          Java Framework Layer
                             JNI
                            HAL
                    Linux Kernel
       Setup the G-Sensor driver
JNI
● Sensor Manager
  ○ Mapped to the sensor manager in framework layer
    ■ nativeClassInit()
  ○ Provide the native function interface, e.g.:
    ■ sensors_enable_sensor()
    ■ sensors_data_poll()

      PS. Please refer to the Figure 8 and Figure 9 in document
G-Sensor
System
          Java Application Layer
          Java Framework Layer
                             JNI
                            HAL
                    Linux Kernel
       Setup the G-Sensor driver
Hardware Abstraction Layer
● Located in /hardware/STSensors/*
● Built on SensorBase.cpp
  ○ openInput(const char* inpuName)
  ○ Open input device for a given name when
      construction

      P.S. Please refer to the Figure 10 in document
Hardware Abstraction Layer
● AccSensor
  ○ #define INPUT_SYSFS_PATH_ACC "/sys/class/i2c-
    adapter/i2c-4/4-0019/"
  ○ readEvents()
    ■ Get data from sensor event
    ■ Calibrate for real world

    P.S. Please refer to the Figure 12 in document
G-Sensor
System
          Java Application Layer
          Java Framework Layer
                             JNI
                            HAL
                    Linux Kernel
       Setup the G-Sensor driver
Linux Kernel
● User space communicate with kernel space
  by system call
● Hardware drivers
● i2c protocol used
Linux Kernel
● General architecture from user space to
  hardware
Linux Kernel
● i2c driver need implement four methods:
  ○ probe
    ■ Check the i2c functionality
    ■ Initialize the input status
    ■ Register the poll function
    ■ Create the sysfs interface
  ○ remove
    ■ Unregister the poll device
    ■ Shutdown the power
    ■ Remove sysfs interface
    ■ Free the memory
  ○ resume
  ○ suspend
     P.S. Please refer the Figure 16 and Figure 17 in document
Linux Kernel
● lsm303dlh_acc_report_values()
     static void lsm303dlh_acc_report_values(struct lsm303dlh_acc_data *acc, int *xyz)
     {
            struct input_dev *input = acc->input_poll_dev->input;

          input_report_abs(input, ABS_X, xyz[0]);
          input_report_abs(input, ABS_Y, xyz[1]);
          input_report_abs(input, ABS_Z, xyz[2]);
          input_sync(input);
     }


    P.S. Please refer to the Figure 18 and Figure 19 in document
G-Sensor
System
          Java Application Layer
          Java Framework Layer
                             JNI
                            HAL
                    Linux Kernel
       Setup the G-Sensor driver
Setup G-Sensor Driver
● Let Linux kernel load the driver
   ○ innocomm_oracle_deconfig
   ○ KConfig
   ○ Makefile
     P.S. Please refer to Figure 21 in document

● Setup regulator comsumer
   ○ board-oracle.c
     P.S. Please refer to Figure 22 in document

● Setup the i2c between oracle board and chip
   ○ board-oracle-i2c.c
     P.S. Please refer to Figure 23 in document
Conclusion
             Conclusion
Conclusion
● A top-down view:
  ○   Java application layer
  ○   Java framework layer
  ○   HAL
  ○   Linux kernel
● E-Compass system is as same as the G-
  Sensor system

More Related Content

PDF
Developing Rich Interfaces in JavaFX for Ultrabooks
PDF
A split screen-viable UI event system - Unite Copenhagen 2019
PPTX
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
DOCX
codings related to avr micro controller
PDF
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
PDF
02 - Basics of Qt
PDF
Preparation for mit ose lab4
ODP
Node js lecture
Developing Rich Interfaces in JavaFX for Ultrabooks
A split screen-viable UI event system - Unite Copenhagen 2019
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
codings related to avr micro controller
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
02 - Basics of Qt
Preparation for mit ose lab4
Node js lecture

What's hot (20)

PDF
Introduction to CUDA C: NVIDIA : Notes
ODP
YaST Debugging
PDF
Open CL For Speedup Workshop
PDF
Technical Deep Dive into the New Prefab System
PDF
DLL Design with Building Blocks
PDF
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
PPTX
PVS-Studio, a solution for resource intensive applications development
PDF
Converting Scene Data to DOTS – Unite Copenhagen 2019
ODP
Paractical Solutions for Multicore Programming
PPTX
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
PPTX
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
PDF
Меняем javascript с помощью javascript
PDF
Open gl basics
PPTX
ISCA Final Presentaiton - Compilations
PDF
Vulkan 1.1 Reference Guide
PDF
Дмитрий Вовк: Векторизация кода под мобильные платформы
PDF
The walking 0xDEAD
PPTX
Lec02 03 opencl_intro
PDF
Advanced cfg bypass on adobe flash player 18 defcon russia 23
PDF
OpenXR 1.0 Reference Guide
Introduction to CUDA C: NVIDIA : Notes
YaST Debugging
Open CL For Speedup Workshop
Technical Deep Dive into the New Prefab System
DLL Design with Building Blocks
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
PVS-Studio, a solution for resource intensive applications development
Converting Scene Data to DOTS – Unite Copenhagen 2019
Paractical Solutions for Multicore Programming
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
Меняем javascript с помощью javascript
Open gl basics
ISCA Final Presentaiton - Compilations
Vulkan 1.1 Reference Guide
Дмитрий Вовк: Векторизация кода под мобильные платформы
The walking 0xDEAD
Lec02 03 opencl_intro
Advanced cfg bypass on adobe flash player 18 defcon russia 23
OpenXR 1.0 Reference Guide
Ad

Viewers also liked (20)

PDF
Getting started with YUI3 and AlloyUI
PPTX
Accelerometer 1
DOCX
Android accelerometer sensor tutorial
PPTX
Android 1.8 sensor
PDF
From sensor data_to_android_and_back
ODP
Sensor-driven indoor localization with android #bcs2
PDF
Fusion_Class
PPTX
Android Training (Sensors)
PDF
Internet Week Yahoo! Academy: How Direct Can You Be?
PDF
пдд азербайджана
ODP
Gresco catalog
PPTX
The perng mha ngan box1
PPTX
Quotationsanddialogue 2014
PPTX
The perng mha ngan box
PDF
видеокамера сони
PDF
PPT
Wallander - Becka
PDF
Gallus2002 usermanual
PPTX
The perng mha ngan box
Getting started with YUI3 and AlloyUI
Accelerometer 1
Android accelerometer sensor tutorial
Android 1.8 sensor
From sensor data_to_android_and_back
Sensor-driven indoor localization with android #bcs2
Fusion_Class
Android Training (Sensors)
Internet Week Yahoo! Academy: How Direct Can You Be?
пдд азербайджана
Gresco catalog
The perng mha ngan box1
Quotationsanddialogue 2014
The perng mha ngan box
видеокамера сони
Wallander - Becka
Gallus2002 usermanual
The perng mha ngan box
Ad

Similar to Introduction to Android G-sensor (20)

PPT
Android Sensor System
ODP
Android sensors
PPTX
Using multitouch and sensors in Java
PPTX
Developing Rich Interfaces in JavaFX for Ultrabooks
PDF
SensorStudio deep dive (IDC 2016)
PDF
Sensors on android
PPTX
Intel galileo gen 2
PDF
Introducing the Sun SPOTs
PDF
Android Sensors
PPT
iwatchjr | Mobile Handset Sensors Coordinate System
PPT
Sensing Mobile Devices talk from QCon London 2013
PDF
Week12.pdf
DOC
FINISHED_CODE
PDF
Advanced sensors in Series 40 Java ME apps
PDF
Design and Implementation of Smart Car Driving
PPTX
sensors.pptx
PDF
From Arduino to LinnStrument
PDF
Android Things in action
PPTX
Sensors 9
PDF
IRJET- ARM 7 based Smart Accident Detection and Tracking System
Android Sensor System
Android sensors
Using multitouch and sensors in Java
Developing Rich Interfaces in JavaFX for Ultrabooks
SensorStudio deep dive (IDC 2016)
Sensors on android
Intel galileo gen 2
Introducing the Sun SPOTs
Android Sensors
iwatchjr | Mobile Handset Sensors Coordinate System
Sensing Mobile Devices talk from QCon London 2013
Week12.pdf
FINISHED_CODE
Advanced sensors in Series 40 Java ME apps
Design and Implementation of Smart Car Driving
sensors.pptx
From Arduino to LinnStrument
Android Things in action
Sensors 9
IRJET- ARM 7 based Smart Accident Detection and Tracking System

More from Johnson Chou (6)

PDF
JavaScript OOPs
PDF
Introduction to omap4 pad configuration
PDF
Introduction of unit test on android kernel
PDF
Introduction of omap4 booting sequence
PDF
Integrate gitolite with mantis
PDF
Algorithm Final Presentation
JavaScript OOPs
Introduction to omap4 pad configuration
Introduction of unit test on android kernel
Introduction of omap4 booting sequence
Integrate gitolite with mantis
Algorithm Final Presentation

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Modernizing your data center with Dell and AMD
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Chapter 3 Spatial Domain Image Processing.pdf
A Presentation on Artificial Intelligence
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Modernizing your data center with Dell and AMD
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I

Introduction to Android G-sensor

  • 1. Introduction to G-Sesnsor and E-Compass Jiahe Jou 2, Dec., 2011
  • 2. Outlines ● Introduction ○ Sensor System ● G-Sensor System ○ Java Application Layer ○ Java Framework Layer ○ JNI ○ Hardware Abstraction Layer ○ Linux Kernel ○ Setup G-Sensor Driver ● Conclusion
  • 3. Introduction Sensor System
  • 4. Sensor System ● Detect the environment to provide better user experience ○ Accelerometer ○ Magnetometer ○ Light Sensor ○ Temperature Meter ● Application ○ Game feature ○ Rotate screen ○ E-compass
  • 5. Sensor System ● General architecture of sensor system
  • 6. Sensor System ● API ○ Provide a interface to get system sensor manager ● Framework ○ Sensor manager service ○ Definitions of sensor, sensor event, event listener ● JNI ○ Link the framework layer and HAL ● HAL ○ The hardware foundation of Android
  • 7. Sensor System ● In more detail
  • 8. G-Sensor System Java Application Layer Java Framework Layer JNI HAL Linux Kernel Setup the G-Sensor driver
  • 9. Java Application Layer ● Implement a sensor application ○ Get sensor manager ○ Get a specific sensor ○ Register sensor event listener ... mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAccerlerometer = mSensorManager.getDefautSensor( Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); ...
  • 10. Java Application Layer ● Implement event listener ... // Called when the sensor accuracy changed public void onAccuracyChanged(int sensor, int accuracy){ // You can leave this function empty } ... // Called when the sensor value changed public void onSensorChanged(SensorEvent event{ ... Log.d(TAG, "onSensorChanged==> sensor: " + sensor + ", x: " + event.values[0] + ", y: " + event.values[1] + ", z: " + event.values[2]); … } ...
  • 11. G-Sensor System Java Application Layer Java Framework Layer JNI HAL Linux Kernel Setup the G-Sensor driver
  • 12. Java Framework Layer ● Sensor Manager ○ getDefautSensor(int type) ... public Sensor getDefaultSensor( int type){ // just return the 1st sensor List<Sensor> l = getSensorList(type); return l.isEmpty() ? null : l.get(0); } … ○ registerListener(SensorEventListener listener, Sensor sensor, int rate) ... public boolean registerListener( (SensorEventListener listener, Sensor sensor, int rate){ // Another function was return return registerListener(listener, sensor, rate, null); } …
  • 13. Java Framework Layer ○ registerListener( (SensorEventListener listener, Sensor sensor, int rate, Handler handler) ■ Delegate a listener on a sensor ■ Lock the listening thread before sensor enabled ■ Enable the sensor ■ Unlock the listening thread ■ Start polling PS. Please refer to the Figure 7 in document
  • 14. G-Sensor System Java Application Layer Java Framework Layer JNI HAL Linux Kernel Setup the G-Sensor driver
  • 15. JNI ● Sensor Manager ○ Mapped to the sensor manager in framework layer ■ nativeClassInit() ○ Provide the native function interface, e.g.: ■ sensors_enable_sensor() ■ sensors_data_poll() PS. Please refer to the Figure 8 and Figure 9 in document
  • 16. G-Sensor System Java Application Layer Java Framework Layer JNI HAL Linux Kernel Setup the G-Sensor driver
  • 17. Hardware Abstraction Layer ● Located in /hardware/STSensors/* ● Built on SensorBase.cpp ○ openInput(const char* inpuName) ○ Open input device for a given name when construction P.S. Please refer to the Figure 10 in document
  • 18. Hardware Abstraction Layer ● AccSensor ○ #define INPUT_SYSFS_PATH_ACC "/sys/class/i2c- adapter/i2c-4/4-0019/" ○ readEvents() ■ Get data from sensor event ■ Calibrate for real world P.S. Please refer to the Figure 12 in document
  • 19. G-Sensor System Java Application Layer Java Framework Layer JNI HAL Linux Kernel Setup the G-Sensor driver
  • 20. Linux Kernel ● User space communicate with kernel space by system call ● Hardware drivers ● i2c protocol used
  • 21. Linux Kernel ● General architecture from user space to hardware
  • 22. Linux Kernel ● i2c driver need implement four methods: ○ probe ■ Check the i2c functionality ■ Initialize the input status ■ Register the poll function ■ Create the sysfs interface ○ remove ■ Unregister the poll device ■ Shutdown the power ■ Remove sysfs interface ■ Free the memory ○ resume ○ suspend P.S. Please refer the Figure 16 and Figure 17 in document
  • 23. Linux Kernel ● lsm303dlh_acc_report_values() static void lsm303dlh_acc_report_values(struct lsm303dlh_acc_data *acc, int *xyz) { struct input_dev *input = acc->input_poll_dev->input; input_report_abs(input, ABS_X, xyz[0]); input_report_abs(input, ABS_Y, xyz[1]); input_report_abs(input, ABS_Z, xyz[2]); input_sync(input); } P.S. Please refer to the Figure 18 and Figure 19 in document
  • 24. G-Sensor System Java Application Layer Java Framework Layer JNI HAL Linux Kernel Setup the G-Sensor driver
  • 25. Setup G-Sensor Driver ● Let Linux kernel load the driver ○ innocomm_oracle_deconfig ○ KConfig ○ Makefile P.S. Please refer to Figure 21 in document ● Setup regulator comsumer ○ board-oracle.c P.S. Please refer to Figure 22 in document ● Setup the i2c between oracle board and chip ○ board-oracle-i2c.c P.S. Please refer to Figure 23 in document
  • 26. Conclusion Conclusion
  • 27. Conclusion ● A top-down view: ○ Java application layer ○ Java framework layer ○ HAL ○ Linux kernel ● E-Compass system is as same as the G- Sensor system