Android Question Reduced Power Consumption with Sensor Co-Processor

Discussion in 'Android Questions' started by PhilipK, Jun 15, 2015.

  1. PhilipK

    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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use the PhoneSensors library with this sensor. You need to pass 19 as the SensorType.
     
    Peter Simpson likes this.
  3. PhilipK

    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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Which method do you need to access?
     
  5. PhilipK

    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:

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

    Code:
    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-1Then ArrayPoint=0
    End Sub
    I think the following from the documentation is possibly the way to go but how?:

    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!
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Your code looks correct. It probably returns an array with a single value.
     
  7. MaFu

    MaFu Well-Known Member Licensed User

    Why do you expect more then one value?
    The accelerometer data are handled internally, the result value is only the number of steps.
     
  8. PhilipK

    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:

    In the low power mode, type 19, how do I access the acceleration data?
     
  9. MaFu

    MaFu Well-Known Member Licensed User

    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).
     
  10. PhilipK

    PhilipK Member Licensed User

    Attached Files:

Loading...