B4A Library PhoneSensorsExtra Library

Discussion in 'Additional libraries, classes and official updates' started by walterf25, Jul 24, 2014.

  1. walterf25

    walterf25 Well-Known Member Licensed User

    Hello all, i worked on an app for a client a while back and needed to retrieve a few extra information from the embedded sensors in the phones, I tried the PhoneSensors library that comes with B4A but did not provide me with the information i needed for this specific App. So I created my own, is very similar to the one that comes with B4A but with some extra stuff, hope someone finds it useful.

    METHODS:
    PhoneSensorsExtra
    Version:
    1
    • PhoneSensorsExtra
      Events:
      • sensorchanged (values() As Float)
      Fields:
      • TYPE_ACCELEROMETER As Int
      • TYPE_GRAVITY As Int
      • TYPE_GYROSCOPE As Int
      • TYPE_HUMIDTY As Int
      • TYPE_LIGHT As Int
      • TYPE_MAGNETIC_FIELD As Int
      • TYPE_MOTION As Int
      • TYPE_ORIENTATION As Int
      • TYPE_PRESSURE As Int
      • TYPE_PROXIMITY As Int
      • TYPE_STEP_COUNTER As Int
      • TYPE_STEP_DETECTOR As Int
      • TYPE_TEMPERATURE As Int
      Methods:
      • Initialize (SensorType As Int)
      • Initialize2 (SensorType As Int, SensorDelay As Int)
      • StartListening (EventName As String) As Boolean
      • getAllSensors As List
      • getMaximumRange (info4 As Float) As Float
      • getName (info1 As String) As String
      • getPower (info2 As Float) As Float
      • getResolution (info3 As Float) As Float
      • getVendor (info As String) As String
      • getVersion (info5 As Int) As Int
      Permissions:
      • android.permission.INTERNET

    I did not create an example apk for this since the library is very simple. Anyone should be able to use it by just looking at the methods.


    Enjoy!
     

    Attached Files:

    Last edited: Jul 24, 2014
  2. NJDude

    NJDude Expert Licensed User

    I wonder what "TYPE_HUMIDTY" does?, what I would really like is a HUMIDITY sensor, can you add that please? :D.

    Yes, I know. :p
     
  3. walterf25

    walterf25 Well-Known Member Licensed User

    In that case I would have to change all the TYPES, You might have to ask Erel to change his too then :)

    But I will do it just for you NJ!
     
  4. NJDude

    NJDude Expert Licensed User

    You are the best!!

    Also, the Event doesn't look right, maybe a copy-paste glitch?
     
  5. walterf25

    walterf25 Well-Known Member Licensed User

    Fixed it, is actually a glitch in the xml2bb thingy. LOL

    Good catch.
     
  6. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Hey Walter, thanks for this library.

    One question: Why the Internet permission ?
    • android.permission.INTERNET
     
  7. gazaduk

    gazaduk New Member Licensed User

    Hi Walter, Is there any way to stop listening once started?
     
  8. louisproy123

    louisproy123 Member Licensed User


    Thanks.... Do you have the cycle time of the whole loop? Louis
     
  9. walterf25

    walterf25 Well-Known Member Licensed User

    I'm not sure i understand your question!
     
  10. louisproy123

    louisproy123 Member Licensed User

    I mean the cycle time for reading the gyroscope / accelerometer / compass sensors and computing the Pitch / Roll / Yaw from these sensors ?
     
  11. Victor jung

    Victor jung Member Licensed User

    Whats the type of a sensor?
    Dim imu_sensor As PhoneSensorsExtra
    or
    Dim imu_sensor As PhoneSensors
    doesnt work:(
     
  12. jlperez

    jlperez Member Licensed User

    Yep Agree, I need to count steps and it's not possible with this lib or at least there's not such a simple way to use it.


    Walter could you give us just a little clue?

    Thanks a lot
    Jose Luis
     
  13. Tayfur

    Tayfur Well-Known Member Licensed User

    Why the "Internet permission" ?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Note that you can remove permissions with RemovePermission (in the manifest editor).
     
    Myr0n and lemonisdead like this.
  15. arge06

    arge06 Member Licensed User

    Hi dudes,

    I'm using step detection, when walking starts, after some steps it returns value=1, this is all right. Any way to stop listening the sensor or detect not walking state ?

    Thanks in advance.
     
  16. Kevin Hartin

    Kevin Hartin Member Licensed User

    listI am a total beginner on this app development thing, having put together a simple 1 screen app with some logic, calculations based on input and reading and writing to a database. However I really want to access Temperature, Humidity and Barometric Pressure sensors that I know are present in my S8+, but dont seem to be found by this library when I looped through the getAllSensors list. Of the 3 I want I could only find the following;

    {Sensor name="LPS22H Barometer Sensor", vendor="STMicroelectronics", version=1, type=6, maxRange=1260.0, resolution=2.4414062E-4, power=1.0, minDelay=100000}

    However I have no idea what code I need to write to read this sensor. Sorry, but I don't understand the concepts of methods, fields and events that is assumed in the original post.

    Any help on sample code would be much appreciated.

    Kev
     
  17. Kevin Hartin

    Kevin Hartin Member Licensed User

    When I run an app on my S8+ called Galaxy Sensors I get the following, which indicates the presence of working Barometric Pressure, Temperature and Humidity sensors;
    [​IMG]
    However when I parse all of the sensors using PhoneSensorsExtra library, I get the following, which has the Temperature and Humidity sensors missing;

    senlist.size 34
    {Sensor name="Rear Ambient Light", vendor="ADI", version=1, type=65577, maxRange=500000.0, resolution=1.0, power=1.0, minDelay=10000}
    {Sensor name="Rear Proximity detecting", vendor="ADI", version=1, type=65580, maxRange=3.0, resolution=1.0, power=1.0, minDelay=0}
    {Sensor name="HRMLED IR", vendor="ADI", version=1, type=65571, maxRange=500000.0, resolution=1.0, power=1.0, minDelay=10000}
    {Sensor name="HRMLED RED", vendor="ADI", version=1, type=65572, maxRange=500000.0, resolution=1.0, power=1.0, minDelay=10000}
    {Sensor name="ADPD143RI", vendor="ADI", version=1, type=65561, maxRange=500000.0, resolution=1.0, power=1.0, minDelay=10000}
    {Sensor name="LSM6DSL Acceleration Sensor", vendor="STM", version=1, type=1, maxRange=78.4532, resolution=0.0023942017, power=0.25, minDelay=2000}
    {Sensor name="LSM6DSL Gyroscope Sensor", vendor="STM", version=1, type=4, maxRange=17.453293, resolution=6.1086525E-4, power=6.1, minDelay=2000}
    {Sensor name="LSM6DSL Acceleration Sensor UnCalibrated", vendor="STM", version=1, type=35, maxRange=78.4532, resolution=0.0023942017, power=0.25, minDelay=2000}
    {Sensor name="LSM6DSL Gyroscope sensor UnCalibrated", vendor="STM", version=1, type=16, maxRange=17.453293, resolution=6.1086525E-4, power=6.1, minDelay=2000}
    {Sensor name="Interrupt Gyroscope Sensor", vendor="STM", version=1, type=65579, maxRange=17.453293, resolution=6.1086525E-4, power=0.061, minDelay=20000}
    {Sensor name="AK09916C Magnetic field Sensor", vendor="Asahi Kasei Microdevices", version=1, type=2, maxRange=2000.0, resolution=0.06, power=6.0, minDelay=10000}
    {Sensor name="AK09916C Magnetic Sensor UnCalibrated", vendor="Asahi Kasei Microdevices", version=1, type=14, maxRange=1200.0, resolution=0.06, power=6.0, minDelay=10000}
    {Sensor name="LPS22H Barometer Sensor", vendor="STMicroelectronics", version=1, type=6, maxRange=1260.0, resolution=2.4414062E-4, power=1.0, minDelay=100000}
    {Sensor name="TMD4906 Proximity Sensor", vendor="AMS, Inc.", version=1, type=8, maxRange=8.0, resolution=8.0, power=0.75, minDelay=0}
    {Sensor name="TMD4906 lux Sensor", vendor="AMS, Inc.", version=1, type=5, maxRange=60000.0, resolution=1.0, power=0.75, minDelay=200000}
    {Sensor name="TMD4906 RGB IR Sensor", vendor="AMS, Inc.", version=1, type=65578, maxRange=60000.0, resolution=1.0, power=0.75, minDelay=200000}
    {Sensor name="TMD4906 RGB Sensor", vendor="AMS, Inc.", version=1, type=65587, maxRange=60000.0, resolution=1.0, power=0.75, minDelay=200000}
    {Sensor name="Proximity Alert Sensor", vendor="Samsung Electronics", version=1, type=65582, maxRange=10.0, resolution=10.0, power=0.75, minDelay=0}
    {Sensor name="SAMSUNG Step Detector Sensor", vendor="Samsung Inc.", version=1, type=18, maxRange=1.0, resolution=1.0, power=0.3, minDelay=0}
    {Sensor name="SAMSUNG Step Counter Sensor", vendor="Samsung Inc.", version=1, type=19, maxRange=4.2949673E9, resolution=1.0, power=0.3, minDelay=0}
    {Sensor name="SAMSUNG Significant Motion Sensor", vendor="Samsung Inc.", version=2, type=17, maxRange=1.0, resolution=1.0, power=0.3, minDelay=-1}
    {Sensor name="Samsung Rotation Vector", vendor="Samsung Electronics", version=1, type=11, maxRange=1.0, resolution=5.9604645E-8, power=6.0, minDelay=10000}
    {Sensor name="Samsung Game Rotation Vector", vendor="Samsung Electronics", version=1, type=15, maxRange=1.0, resolution=5.9604645E-8, power=6.0, minDelay=10000}
    {Sensor name="SAMSUNG Tilt Detector", vendor="Samsung Inc.", version=1, type=22, maxRange=1.0, resolution=1.0, power=0.3, minDelay=0}
    {Sensor name="SAMSUNG Pick Up Gesture", vendor="Samsung Inc.", version=1, type=25, maxRange=1.0, resolution=1.0, power=0.3, minDelay=-1}
    {Sensor name="SContext", vendor="Samsung", version=1, type=65586, maxRange=1.0, resolution=0.0, power=0.001, minDelay=0}
    {Sensor name="SX9320 Grip Sensor", vendor="SEMTECH", version=512, type=65560, maxRange=5.0, resolution=5.0, power=0.75, minDelay=0}
    {Sensor name="Screen Orientation Sensor", vendor="Samsung Electronics", version=3, type=27, maxRange=255.0, resolution=255.0, power=0.0, minDelay=0}
    {Sensor name="HRM Sensor", vendor="Samsung Electronics", version=1, type=65562, maxRange=200.0, resolution=1.0, power=0.0, minDelay=0}
    {Sensor name="HeartRate Sensor", vendor="Samsung Electronics", version=1, type=21, maxRange=200.0, resolution=1.0, power=0.0, minDelay=1000000}
    {Sensor name="Motion Sensor", vendor="Samsung Electronics", version=1, type=65559, maxRange=200.0, resolution=0.0, power=0.0, minDelay=0}
    {Sensor name="Gravity Sensor", vendor="Samsung Electronics", version=3, type=9, maxRange=19.6133, resolution=5.9604645E-8, power=6.0, minDelay=10000}
    {Sensor name="Linear Acceleration Sensor", vendor="Samsung Electronics", version=3, type=10, maxRange=78.4532, resolution=0.0023942017, power=6.0, minDelay=10000}
    {Sensor name="Orientation Sensor", vendor="Samsung Electronics", version=1, type=3, maxRange=360.0, resolution=0.00390625, power=6.0, minDelay=10000}


    Any ideas how I can access these sensors?

    Thanks,
    Kev
     
  18. KY Leng

    KY Leng Member Licensed User

    without sample code, the library seem to be useless for some people like me...
    moreover, for magnetic field sensor, the output is in what unit ? Gauss or Tesla or ? and how to combine the Value(0), Value(1) and Value(2) to get the final reading ?
     
  19. DonManfred

    DonManfred Expert Licensed User

    walterf25 likes this.
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