Android Question Sensor MaxValue issue

peacemaker

Expert
Licensed User
I'm trying to use Acceleremeter and Orientation sensors. Together. By Erel sample, where all sensor types can be added, with shared Sub Sensor_SensorChanged (Values() As Float).

When i was debugging the code of accel only - all was OK as usual. But when i have added Orientation sensor also - values of the acceleromer sometimes are BIGGER than its Sensor.MaxValue !!!

And big values are only if to save them into a map (AccelData):
B4X:
Sub Sensor_SensorChanged (Values() As Float)
    Dim ps As PhoneSensors
    Dim sd As SensorData
    ps = Sender
    sd = SensorsMap.Get(ps) 'Get the associated SensorData obejct
    Dim stamp As Long = DateTime.Now
    If sd.Name.Contains("ACCELEROMETER") Then
        AccelMAX = ps.MaxValue
        AccelData.Put(stamp, Values)
        If AccelData.Size > 10 Then
            AccelData.Remove(AccelData.GetKeyAt(0))
        End If
    Else If sd.Name.Contains("ORIENTATION") Then    'MAGNETIC
        CompassData.Put(stamp, Values)
        'Log(sd.Name & " X=" & Values(0))
        If CompassData.Size > 10 Then
            CompassData.Remove(CompassData.GetKeyAt(0))
        End If
    End If

End Sub

And check later in Timer_Tick sub.

Anyone touched such issue ? Any help ? Exact calculations are not possible now... :-(
 
Last edited:

peacemaker

Expert
Licensed User
Code above is of the event. In a timer code I read the map items, that are sometimes are bigger than max. But if to check at the event - no exceeds at all.

Reading:
B4X:
Sub tim_Tick
tim.Enabled = False
Dim Values(3) As Float = AccelData.GetValueAt(AccelData.Size - 1)
    'Log(Values(0) & "_" & Values(1) & "_" & Values(2))
    Dim PrevValues(3) As Float = AccelData.GetValueAt(AccelData.Size - 2)
.....

But if to comment out all other AddSensor... excepting the accel - no such trouble at all.
Screenshot shows the data - latest utem of AccelData looks like data of Orientation sensor.
 

Attachments

  • TempDownload.png
    TempDownload.png
    479.4 KB · Views: 131
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Moreover, i found if to enable another sensor instead of Orientation, say Magnetic - its date (with big level up to 600) - is saved into AccelData sometimes!
Looks like name of the Sender in the event is incorrect...to detect the values...
 
Upvote 0

peacemaker

Expert
Licensed User
Tested on 3 devices: two with Android 4.0 and 4.2 have this trouble. One old LG of Android 2.3 - has no such trouble.
 
Upvote 0

peacemaker

Expert
Licensed User
So...trouble was bypassed by saving sensor result as new type variables (Type SensorRes (timestamp As Long, x As Float, y As Float, z As Float)) into the list, instead of map.
Seems, maps have some... strange behavior here
 
Upvote 0

peacemaker

Expert
Licensed User
Erel, code is above, again:

AccelData is a map, inited at activity creation.

B4X:
Sub Sensor_SensorChanged (Values() As Float)
    Dim ps As PhoneSensors
    Dim sd As SensorData
    ps = Sender
    sd = SensorsMap.Get(ps) 'Get the associated SensorData obejct
    Dim stamp As Long = DateTime.Now
    If sd.Name.Contains("ACCELEROMETER") Then
        AccelMAX = ps.MaxValue
        AccelData.Put(stamp, Values)
        If AccelData.Size > 10 Then
            AccelData.Remove(AccelData.GetKeyAt(0))
        End If
    Else If sd.Name.Contains("ORIENTATION") Then    'MAGNETIC
        CompassData.Put(stamp, Values)
        'Log(sd.Name & " X=" & Values(0))
        If CompassData.Size > 10 Then
            CompassData.Remove(CompassData.GetKeyAt(0))
        End If
    End If

End Sub
 
Upvote 0
Top