Skip to content

sharpentheaxe/sendroid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sendroid

Description

The project has been created in purpose of making android devices useful in inventing field, it supports sensors that are supported by device.
It does fantastic work when fused with the cliserc module (my another one) which manages a simple client-server communication in Python 3.
Every example presented in this documentation shows only how to use the project, you have to embed this knowledge in your Kivy application.

Structure

Main package called sendroid contains single module sensor which defines the Sensor class used to create sensor readers.

Checking supported sensors

Use get_list static method of Sensor class to get list of all sensors supported by the current device:

from sendroid.sensor import Sensor

# Show all supported sensor names in readable format.
print('Supported sensors:\n', '\n'.join(Sensor.get_list()))
Reading sensor data

To read sensor (here accelerometer) data first check if it is supported using get_list static method which returns list of strings (sensor names). Note that names are always in lower case and may vary on other devices, for you I suggest printing the list first and finding the name of what you really need:

from sendroid.sensor import Sensor

supp = Sensor.get_list()
# Check if accelerometer sensor is supported.
if 'accelerometer' in supp:
    ...

Then if check succeed, create an instance of Sensor class which will target accelerometer sensor:

acc = Sensor(
    Sensor.JSensor.TYPE_ACCELEROMETER,  # Type of sensor.
    Sensor.JSensorManager.SENSOR_DELAY_NORMAL  # Type of delaying read operations.
    )

All possible sensor types are described there and types of delays there. JSensor and JSensorManager subclasses are java classes which contain constant values used above (reference to links). Enable the sensor using enable method. You should disable it with disable method when you are done:

acc.enable()

Sensor data is stored in member list called values and sensor accuracy level in accuracy member variable. values length depends on the sensor type for example here we want to read accelerometer sensor data; we know that it should return three values: x, y and z (the total acceleration) so values list will contain three elements which are these axes:

while True:
    # Show acceleration on three axes.
    print('Accelerometer data: {} {} {}'.format(*acc.values))
    print(f'Accuracy level: {acc.accuracy}')

acc.disable()  # Disable the sensor!

For more information about amount of items in values list per specific type of sensor read this, about possible accuracy levels this.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages