Android Question Sensor MaxValue issue

Discussion in 'Android Questions' started by peacemaker, Apr 23, 2015.

  1. peacemaker

    peacemaker Well-Known Member 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):
    Code:
    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: Apr 23, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the relevant code (the event sub at least)?
     
  3. peacemaker

    peacemaker Well-Known Member 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:
    Code:
    Sub tim_Tick
    tim.Enabled = 
    False
    Dim Values(3As Float = AccelData.GetValueAt(AccelData.Size - 1)
        
    'Log(Values(0) & "_" & Values(1) & "_" & Values(2))
        Dim PrevValues(3As 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.
     

    Attached Files:

    Last edited: Apr 23, 2015
  4. peacemaker

    peacemaker Well-Known Member 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...
     
  5. peacemaker

    peacemaker Well-Known Member 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.
     
  6. peacemaker

    peacemaker Well-Known Member 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
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Hard to say what was the problem without seeing the code that adds the data to the map.
     
  8. peacemaker

    peacemaker Well-Known Member Licensed User

    Erel, code is above, again:

    AccelData is a map, inited at activity creation.

    Code:
    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
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    The Values array can be reused by the native API. This means that you need to copy the values to your own array if you want to store them.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice