`monitor-sensor --accel` will show strings for orientation (e.g. "normal", "bottom/right/left-up"; but is there a way to get raw acceleration data? Is there a file (maybe under /sys/bus/iio/devices) that can be read from? What about the compass?
MediaTek SoC, and all IIO devices are ADCs (analog-to-digital converters). You can find it in the devicetree here: "/sys/firmware/devicetree/base/gyro/". When you want to get the raw data you can use a dbus channel like in this example :
import dbus
import time
bus = dbus.SystemBus()
sensor_service = bus.get_object('com.nokia.SensorService', '/SensorManager/gyroscopesensor')
gyro_interface = dbus.Interface(sensor_service, 'local.GyroscopeSensor')
props_interface = dbus.Interface(sensor_service, 'org.freedesktop.DBus.Properties')
gyro_interface.start(0)
print("Reading gyroscope data... (Press Ctrl+C to stop)")
try:
while True:
value = props_interface.Get('local.GyroscopeSensor', 'value')
timestamp, x, y, z = value
x_rounded = round(x)
y_rounded = round(y)
z_rounded = round(z)
print(f"Gyro - X: {x_rounded:8.2f}, Y: {y_rounded:8.2f}, Z: {z_rounded:8.2f} mdps", end='\r')
time.sleep(0.1)
except KeyboardInterrupt:
print("\nStopping...")
gyro_interface.stop(0)
The interface looks like this:
gdbus introspect --system --dest com.nokia.SensorService --object-path /SensorManager/gyroscopesensor
node /SensorManager/gyroscopesensor {
interface local.GyroscopeSensor {
methods:
isValid(out b arg_0);
errorString(out s arg_0);
description(out s arg_0);
id(out s arg_0);
interval(out u arg_0);
standbyOverride(out b arg_0);
bufferInterval(out u arg_0);
bufferSize(out u arg_0);
type(out s arg_0);
start(in i sessionId);
stop(in i sessionId);
setInterval(in i sessionId,
in i interval_ms);
setDataRate(in i sessionId,
in d dataRate_Hz);
@org.qtproject.QtDBus.QtTypeName.Out0("QList<DataRange>")
getAvailableIntervals(out a(ddd) arg_0);
setDefaultInterval(in i sessionId,
out b arg_0);
setStandbyOverride(in i sessionId,
in b value,
out b arg_0);
setDownsampling(in i sessionId,
in b value);
setBufferInterval(in i sessionId,
in u interval_ms);
setBufferSize(in i sessionId,
in u value);
@org.qtproject.QtDBus.QtTypeName.Out0("QList<std::pair<uint,uint>>")
getAvailableBufferIntervals(out a(uu) arg_0);
@org.qtproject.QtDBus.QtTypeName.Out0("QList<std::pair<uint,uint>>")
getAvailableBufferSizes(out a(uu) arg_0);
@org.qtproject.QtDBus.QtTypeName.Out0("QList<DataRange>")
getAvailableDataRanges(out a(ddd) arg_0);
@org.qtproject.QtDBus.QtTypeName.Out0("DataRange")
getCurrentDataRange(out (ddd) arg_0);
@org.qtproject.QtDBus.QtTypeName.In1("DataRange")
requestDataRange(in i sessionId,
in (ddd) range);
removeDataRangeRequest(in i sessionId);
setDataRangeIndex(in i sessionId,
in i rangeIndex,
out b arg_0);
hwBuffering(out b arg_0);
@org.qtproject.QtDBus.QtTypeName.Out0("XYZ")
value(out (tddd) arg_0);
signals:
propertyChanged(s name);
@org.qtproject.QtDBus.QtTypeName.Out0("XYZ")
dataAvailable((tddd) data);
properties:
readonly b isValid = true;
readonly s errorString = '';
readonly s description = 'x, y, and z axes angular velocity in mdps';
readonly s id = 'gyroscopesensor';
readonly u interval = 80;
readonly b standbyOverride = false;
readonly u bufferInterval = 0;
readonly u bufferSize = 0;
readonly s type = 'GyroscopeSensorChannel';
readonly i errorCodeInt = 0;
readonly b hwBuffering = false;
@org.qtproject.QtDBus.QtTypeName("XYZ")
readonly (tddd) value = (0, 0.0, 0.0, 0.0);
};
interface org.freedesktop.DBus.Properties {
methods:
Get(in s interface_name,
in s property_name,
out v value);
Set(in s interface_name,
in s property_name,
in v value);
@org.qtproject.QtDBus.QtTypeName.Out0("QVariantMap")
GetAll(in s interface_name,
out a{sv} values);
signals:
@org.qtproject.QtDBus.QtTypeName.Out1("QVariantMap")
PropertiesChanged(s interface_name,
a{sv} changed_properties,
as invalidated_properties);
properties:
};
interface org.freedesktop.DBus.Introspectable {
methods:
Introspect(out s xml_data);
signals:
properties:
};
interface org.freedesktop.DBus.Peer {
methods:
Ping();
GetMachineId(out s machine_uuid);
signals:
properties:
};
};