B4A Library Sensor Extender Library

Discussion in 'Additional libraries, classes and official updates' started by MikieK, Dec 2, 2011.

  1. MikieK

    MikieK Member Licensed User

    I have created a library that offers access to many of Androids SensorManager "Helper" functions. (I'm only using API 8, so Ive missed out a few of the newer functions and a large chunk of gravity constants.)
    This library includes the facilities needed to get around the fact that TYPE_ORIENTATION is now depreciated.
    I've also added crude low pass and high pass filters (both easily done in B4a, but this keeps them in one place)

    I have implement Sensor.GetType() thanks to Erel, and added "_accuracychanged" event. I have included all of the PhoneSensors library in this library (mainly out of neccessity)

    I have also attached an example.
    Have a go and, let me know what you think.

    Attached Files:

    Last edited: Dec 4, 2011
    nemiroG1 likes this.
  2. MikieK

    MikieK Member Licensed User


    Version 0.01 Released
    • Entire PhoneSensors functionality
    • _accuracychanged event
    • getType()
    • fixed highpassfilter (I think)
    • changed other methods to be more in line with Android methodology
  3. stevel05

    stevel05 Expert Licensed User

    That's excellent, thank you. I've been working to use the orientation / accelerometer to control a game, I have just started to understand most of what it's all doing, the next step was to implement it and now you've already done that.

    It will be invaluable.
  4. latcc

    latcc Banned

    Great stuff.

    One thing. Users must rem the message box at the end of the code before running as this stops the program from exiting and you will need a task manager to kill this program.

    There doesn't seem to be any working code to display non-compass sensors. This would be useful.
    Last edited: Dec 27, 2011
  5. latcc

    latcc Banned

    I have noticed that once I run the compass code in my app (and then exit the app) on further starting of the app the compass is fixed at 001 degrees. Only rebooting my phone makes the compass work again.

    The code


    must NOT be placed here:

    if FIRSTTIME then
    end if

    Within the Activity_Create module or the compass will not work on second run.
    Last edited: Feb 11, 2012
  6. MikieK

    MikieK Member Licensed User

    Hi,I'm not sure what you mean, however, I have noticed that if you use this library or the phonesensors library, and stop the app with basic for android (ie. install an update when the app is running) the sensors are not released until you reboot the phone. It is a minor anoyance, that I have no idea how to fix, however, it should have little affect the final product.
  7. latcc

    latcc Banned

    To avoid sensor freeze afer a pause I found that the init code must NOT be placed within the IF FIRSTTIME THEN test of the Activity_Create code.

    Putting it in this test will freeze the compass sensor on program pause. I placed this initialization code outside this clause and it works fine now.

    So this is WRONG...

    if FIRSTTIME then
    end if

    The 'firsttime' test seems is not actioned after a program pause so the sensors are not reinitialized and don't work again (until you reboot). This is why the init code must be placed outside this test clause.
  8. BarrySumpter

    BarrySumpter Active Member Licensed User

    Is there some way I can use this as heading/bearing/direction?
  9. hmotiwala

    hmotiwala Member Licensed User

    Thanks for the very useful library.
    It seems that even after calling method "StopListening" the activity keeps receiving callback to SensorChanged() event. Shouldn't the callbacks stop? Does it mean once started it never stops listening ?
  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