Android Question Reduced Power Consumption with Sensor Co-Processor

PhilipK

Member
Licensed User
Hi

I have come across the following:

The power consumption of a Sony smartphone using its on-board sensors can be dramatically reduced: http://developer.sonymobile.com/201...e-new-sensor-co-processor-video-code-example/

Sony say there is a 10 x power saving. Normal running of a Sony phone (display off) with the sensors enabled is about 42mA. Using the sensor co-processor the consumption drops to around 3.9mA.

I'd like a piece of this!

How could this functionality be incorporated in B4A?

Here is the link to the developer site: http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_STEP_COUNTER

Thanks.
 

PhilipK

Member
Licensed User
Erel, great news, thanks.

I'd like to reduce the power consumption of my app which uses the accelerometers.

I've passed SensorType 19 but can't access any of the object's constants, methods etc.referred to in the developers guide. Please could you give a hint on how to implement this functionality, in code?

Your help is very much appreciated.
 

PhilipK

Member
Licensed User
The background: I have a service that handles the accelerometers. If collects values and posts the data into a public array. The data is processed in another service module (called DAS).

This is the current starting point:

B4X:
Sub Service_Create
   
    sensor.Initialize2(sensor.TYPE_ACCELEROMETER,0)

B4X:
Sub Sensor_SensorChanged (Values() As Float)
    DAS.DataArray(1,ArrayPoint)=Values(0)
    DAS.DataArray(2,ArrayPoint)=Values(1)
    DAS.DataArray(3,ArrayPoint)=Values(2)
    ArrayPoint=ArrayPoint+1
    If ArrayPoint>(DAS.ArraySize-1) Then ArrayPoint=0
End Sub
I think the following from the documentation is possibly the way to go but how?:

  1. Create a sensor manager instance.
  2. Register a listener for the STEP_COUNTER sensor type.
  3. Implement a SensorEvent callback function, onSensorChanged(), which serves the STEP_COUNTER sensor events.
  4. Make sure to handle the initial step-count value accordingly. As per definition the STEP_COUNTER will reset its value at system restart and increment it as long as there is a client application for it. This means that any application using it needs to track the start-offset itself, see variables mStepsSInceBoot and mLastReport in the java file for an example.
  5. Discard any OnPause() or other power management handling, this is not needed when having a built-in step counter. The sensor co-processor will be notified when the system goes up or down, and only send events when the system is up.
  6. During system down, the sensor co-processor will keep tracking steps and send an event as soon as the system is up. No action is needed in your app.
To support devices without the sensor co-processor, however, you will need to maintain a fallback solution of streaming raw accelerometer data instead of using the built-in step counter sensor type.
Having set SensorType to 19 it gives a single value which results in an index out of bounds error.

As you see, I'm completely lost!
 

PhilipK

Member
Licensed User
I'm missing something big here: How to pick up the X,Y,Z acceleration data, if only a single value is returned which MaFu says is a step count.

With the standard sensor.Initialize2(sensor.TYPE_ACCELEROMETER,0) you use 'Sub Sensor_SensorChanged (Values() As Float)' delivering an array with 3 axes of acceleration. The developer documentation refers to:

Implement a SensorEvent callback function, onSensorChanged()
In the low power mode, type 19, how do I access the acceleration data?
 

MaFu

Well-Known Member
Licensed User
In the low power mode, type 19, how do I access the acceleration data?
Mode 19 is only a step counter. If you need the full acceleration data you cannot use the low power mode (maybe in future but not yet).
 
Top