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:
@@ -46,7 +46,7 @@ typedef enum {
|
||||
PROXIMITY_NEAR_TRUE = 1,
|
||||
} ProximityNear;
|
||||
|
||||
typedef struct SensorDriver SensorDriver;
|
||||
typedef struct SensorDevice SensorDevice;
|
||||
|
||||
typedef struct {
|
||||
int accel_x;
|
||||
@@ -68,13 +68,12 @@ typedef struct {
|
||||
ProximityNear is_near;
|
||||
} ProximityReadings;
|
||||
|
||||
typedef void (*ReadingsUpdateFunc) (SensorDriver *driver,
|
||||
typedef void (*ReadingsUpdateFunc) (SensorDevice *sensor_device,
|
||||
gpointer readings,
|
||||
gpointer user_data);
|
||||
|
||||
typedef struct SensorDevice SensorDevice;
|
||||
|
||||
struct SensorDriver {
|
||||
typedef struct {
|
||||
const char *name;
|
||||
DriverType type;
|
||||
|
||||
@@ -83,10 +82,10 @@ struct SensorDriver {
|
||||
void (*set_polling) (SensorDevice *device,
|
||||
gboolean state);
|
||||
void (*close) (SensorDevice *device);
|
||||
};
|
||||
} SensorDriver;
|
||||
|
||||
struct SensorDevice {
|
||||
struct SensorDriver *drv;
|
||||
SensorDriver *drv;
|
||||
gpointer priv;
|
||||
|
||||
/* Callback function and data as pass to driver_open() */
|
||||
|
@@ -50,7 +50,7 @@ compass_changed (gpointer user_data)
|
||||
g_debug ("Changed heading to %f", 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;
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ light_changed (gpointer user_data)
|
||||
level += 1.0;
|
||||
readings.level = level;
|
||||
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;
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ light_changed (gpointer user_data)
|
||||
|
||||
readings.level = level;
|
||||
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;
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ process_scan (IIOSensorData data, SensorDevice *sensor_device)
|
||||
readings.accel_y = tmp.y;
|
||||
readings.accel_z = tmp.z;
|
||||
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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
//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;
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ process_scan (IIOSensorData data, SensorDevice *sensor_device)
|
||||
readings.uses_lux = TRUE;
|
||||
|
||||
//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;
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ poll_orientation (gpointer user_data)
|
||||
readings.accel_y = tmp.y;
|
||||
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;
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ light_changed (gpointer user_data)
|
||||
* will be Windows 8 compatible */
|
||||
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;
|
||||
}
|
||||
|
@@ -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);
|
||||
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;
|
||||
}
|
||||
|
@@ -157,7 +157,7 @@ accelerometer_changed (gpointer user_data)
|
||||
readings.accel_y = tmp.y;
|
||||
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
|
||||
|
@@ -661,7 +661,7 @@ setup_dbus (SensorData *data,
|
||||
}
|
||||
|
||||
static void
|
||||
accel_changed_func (SensorDriver *driver,
|
||||
accel_changed_func (SensorDevice *sensor_device,
|
||||
gpointer readings_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
@@ -691,7 +691,7 @@ accel_changed_func (SensorDriver *driver,
|
||||
}
|
||||
|
||||
static void
|
||||
light_changed_func (SensorDriver *driver,
|
||||
light_changed_func (SensorDevice *sensor_device,
|
||||
gpointer readings_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
@@ -718,7 +718,7 @@ light_changed_func (SensorDriver *driver,
|
||||
}
|
||||
|
||||
static void
|
||||
compass_changed_func (SensorDriver *driver,
|
||||
compass_changed_func (SensorDevice *sensor_device,
|
||||
gpointer readings_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
@@ -742,7 +742,7 @@ compass_changed_func (SensorDriver *driver,
|
||||
}
|
||||
|
||||
static void
|
||||
proximity_changed_func (SensorDriver *driver,
|
||||
proximity_changed_func (SensorDevice *sensor_device,
|
||||
gpointer readings_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
Reference in New Issue
Block a user