main: Pass SensorDevice to sensor callbacks

Rather than SensorDriver. This would make it possible to differentiate
readings from 2 devices of the same type, eg. 2 accelerometers.
This commit is contained in:
Bastien Nocera
2021-01-19 11:11:29 +01:00
parent 16a206247a
commit e4eb952da2
12 changed files with 19 additions and 20 deletions

View File

@@ -46,7 +46,7 @@ typedef enum {
PROXIMITY_NEAR_TRUE = 1, PROXIMITY_NEAR_TRUE = 1,
} ProximityNear; } ProximityNear;
typedef struct SensorDriver SensorDriver; typedef struct SensorDevice SensorDevice;
typedef struct { typedef struct {
int accel_x; int accel_x;
@@ -68,13 +68,12 @@ typedef struct {
ProximityNear is_near; ProximityNear is_near;
} ProximityReadings; } ProximityReadings;
typedef void (*ReadingsUpdateFunc) (SensorDriver *driver, typedef void (*ReadingsUpdateFunc) (SensorDevice *sensor_device,
gpointer readings, gpointer readings,
gpointer user_data); gpointer user_data);
typedef struct SensorDevice SensorDevice;
struct SensorDriver { typedef struct {
const char *name; const char *name;
DriverType type; DriverType type;
@@ -83,10 +82,10 @@ struct SensorDriver {
void (*set_polling) (SensorDevice *device, void (*set_polling) (SensorDevice *device,
gboolean state); gboolean state);
void (*close) (SensorDevice *device); void (*close) (SensorDevice *device);
}; } SensorDriver;
struct SensorDevice { struct SensorDevice {
struct SensorDriver *drv; SensorDriver *drv;
gpointer priv; gpointer priv;
/* Callback function and data as pass to driver_open() */ /* Callback function and data as pass to driver_open() */

View File

@@ -50,7 +50,7 @@ compass_changed (gpointer user_data)
g_debug ("Changed heading to %f", heading); g_debug ("Changed heading to %f", heading);
readings.heading = heading; readings.heading = heading;
sensor_device->callback_func (&fake_compass, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View File

@@ -50,7 +50,7 @@ light_changed (gpointer user_data)
level += 1.0; level += 1.0;
readings.level = level; readings.level = level;
readings.uses_lux = TRUE; readings.uses_lux = TRUE;
sensor_device->callback_func (&fake_light, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View File

@@ -50,7 +50,7 @@ light_changed (gpointer user_data)
readings.level = level; readings.level = level;
readings.uses_lux = FALSE; readings.uses_lux = FALSE;
sensor_device->callback_func (&hwmon_light, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View File

@@ -73,7 +73,7 @@ process_scan (IIOSensorData data, SensorDevice *sensor_device)
readings.accel_y = tmp.y; readings.accel_y = tmp.y;
readings.accel_z = tmp.z; readings.accel_z = tmp.z;
copy_accel_scale (&readings.scale, scale); copy_accel_scale (&readings.scale, scale);
sensor_device->callback_func (&iio_buffer_accel, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return 1; return 1;
} }

View File

@@ -57,7 +57,7 @@ process_scan (IIOSensorData data, SensorDevice *sensor_device)
g_debug ("Heading read from IIO on '%s': %f (%d times %lf scale)", drv_data->name, readings.heading, raw_heading, scale); g_debug ("Heading read from IIO on '%s': %f (%d times %lf scale)", drv_data->name, readings.heading, raw_heading, scale);
//FIXME report errors //FIXME report errors
sensor_device->callback_func (&iio_buffer_compass, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return 1; return 1;
} }

View File

@@ -62,7 +62,7 @@ process_scan (IIOSensorData data, SensorDevice *sensor_device)
readings.uses_lux = TRUE; readings.uses_lux = TRUE;
//FIXME report errors //FIXME report errors
sensor_device->callback_func (&iio_buffer_light, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return 1; return 1;
} }

View File

@@ -56,7 +56,7 @@ poll_orientation (gpointer user_data)
readings.accel_y = tmp.y; readings.accel_y = tmp.y;
readings.accel_z = tmp.z; readings.accel_z = tmp.z;
sensor_device->callback_func (&iio_poll_accel, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View File

@@ -58,7 +58,7 @@ light_changed (gpointer user_data)
* will be Windows 8 compatible */ * will be Windows 8 compatible */
readings.uses_lux = TRUE; readings.uses_lux = TRUE;
sensor_device->callback_func (&iio_poll_light, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View File

@@ -46,7 +46,7 @@ poll_proximity (gpointer user_data)
g_debug ("Proximity read from IIO on '%s': %d/%f, near: %d", drv_data->name, prox, near_level, readings.is_near); g_debug ("Proximity read from IIO on '%s': %d/%f, near: %d", drv_data->name, prox, near_level, readings.is_near);
drv_data->last_level = prox; drv_data->last_level = prox;
sensor_device->callback_func (&iio_poll_proximity, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View File

@@ -157,7 +157,7 @@ accelerometer_changed (gpointer user_data)
readings.accel_y = tmp.y; readings.accel_y = tmp.y;
readings.accel_z = tmp.z; readings.accel_z = tmp.z;
sensor_device->callback_func (&input_accel, (gpointer) &readings, sensor_device->user_data); sensor_device->callback_func (sensor_device, (gpointer) &readings, sensor_device->user_data);
} }
static void static void

View File

@@ -661,7 +661,7 @@ setup_dbus (SensorData *data,
} }
static void static void
accel_changed_func (SensorDriver *driver, accel_changed_func (SensorDevice *sensor_device,
gpointer readings_data, gpointer readings_data,
gpointer user_data) gpointer user_data)
{ {
@@ -691,7 +691,7 @@ accel_changed_func (SensorDriver *driver,
} }
static void static void
light_changed_func (SensorDriver *driver, light_changed_func (SensorDevice *sensor_device,
gpointer readings_data, gpointer readings_data,
gpointer user_data) gpointer user_data)
{ {
@@ -718,7 +718,7 @@ light_changed_func (SensorDriver *driver,
} }
static void static void
compass_changed_func (SensorDriver *driver, compass_changed_func (SensorDevice *sensor_device,
gpointer readings_data, gpointer readings_data,
gpointer user_data) gpointer user_data)
{ {
@@ -742,7 +742,7 @@ compass_changed_func (SensorDriver *driver,
} }
static void static void
proximity_changed_func (SensorDriver *driver, proximity_changed_func (SensorDevice *sensor_device,
gpointer readings_data, gpointer readings_data,
gpointer user_data) gpointer user_data)
{ {