Skip to content

Commit

Permalink
iio: Add AccelerometerRaw support for direct access of sensor values
Browse files Browse the repository at this point in the history
Fixes: hadess#21
  • Loading branch information
janbrummer committed Oct 15, 2017
1 parent 393c113 commit 80e7415
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/iio-sensor-proxy.c
Expand Up @@ -45,6 +45,9 @@ typedef struct {

/* Accelerometer */
OrientationUp previous_orientation;
int previous_accel_x;
int previous_accel_y;
int previous_accel_z;

/* Light */
gdouble previous_level;
Expand Down Expand Up @@ -164,11 +167,13 @@ typedef enum {
PROP_HAS_AMBIENT_LIGHT = 1 << 2,
PROP_LIGHT_LEVEL = 1 << 3,
PROP_HAS_COMPASS = 1 << 4,
PROP_COMPASS_HEADING = 1 << 5
PROP_COMPASS_HEADING = 1 << 5,
PROP_ACCELEROMETER_RAW = 1 << 6,
} PropertiesMask;

#define PROP_ALL (PROP_HAS_ACCELEROMETER | \
PROP_ACCELEROMETER_ORIENTATION | \
PROP_ACCELEROMETER_RAW | \
PROP_HAS_AMBIENT_LIGHT | \
PROP_LIGHT_LEVEL)
#define PROP_ALL_COMPASS (PROP_HAS_COMPASS | \
Expand Down Expand Up @@ -208,6 +213,10 @@ send_dbus_event (SensorData *data,
g_variant_builder_add (&props_builder, "{sv}", "AccelerometerOrientation",
g_variant_new_string (orientation_to_string (data->previous_orientation)));
}
if (mask & PROP_ACCELEROMETER_RAW) {
g_variant_builder_add (&props_builder, "{sv}", "AccelerometerRaw",
g_variant_new ("(iiix)", data->previous_accel_x, data->previous_accel_y, data->previous_accel_z, g_get_real_time()));
}

if (mask & PROP_HAS_AMBIENT_LIGHT) {
gboolean has_als;
Expand Down Expand Up @@ -626,10 +635,22 @@ accel_changed_func (SensorDriver *driver,

tmp = data->previous_orientation;
data->previous_orientation = orientation;

send_dbus_event (data, PROP_ACCELEROMETER_ORIENTATION);
g_debug ("Emitted orientation changed: from %s to %s",
orientation_to_string (tmp),
orientation_to_string (data->previous_orientation));

data->previous_accel_x = readings->accel_x;
data->previous_accel_y = readings->accel_y;
data->previous_accel_z = readings->accel_z;
send_dbus_event (data, PROP_ACCELEROMETER_RAW);
} else if (data->previous_accel_x != readings->accel_x || data->previous_accel_y != readings->accel_y || data->previous_accel_z != readings->accel_z) {
data->previous_accel_x = readings->accel_x;
data->previous_accel_y = readings->accel_y;
data->previous_accel_z = readings->accel_z;

send_dbus_event (data, PROP_ACCELEROMETER_RAW);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/monitor-sensor.c
Expand Up @@ -37,6 +37,16 @@ properties_changed (GDBusProxy *proxy,
g_print (" Accelerometer orientation changed: %s\n", g_variant_get_string (v, NULL));
g_variant_unref (v);
}
if (g_variant_dict_contains (&dict, "AccelerometerRaw")) {
gint x, y, z;
gint64 time;

v = g_dbus_proxy_get_cached_property (iio_proxy, "AccelerometerRaw");

g_variant_get (v, "(iiix)", &x, &y, &z, &time);
g_print (" Accelerometer raw changed: x=%d/y=%d/z=%d time=%ld\n", x, y, z, time);
g_variant_unref (v);
}
if (g_variant_dict_contains (&dict, "HasAmbientLight")) {
v = g_dbus_proxy_get_cached_property (iio_proxy, "HasAmbientLight");
if (g_variant_get_boolean (v))
Expand Down

0 comments on commit 80e7415

Please sign in to comment.