Exemplo n.º 1
0
static void
cd_sensor_munki_sample_thread_cb (GSimpleAsyncResult *res,
				 GObject *object,
				 GCancellable *cancellable)
{
	g_autoptr(GError) error = NULL;
	CdSensor *sensor = CD_SENSOR (object);
//	CdSensorMunkiPrivate *priv = cd_sensor_munki_get_private (sensor);

	/* no hardware support */
	if (task->current_cap == CD_SENSOR_CAP_PROJECTOR) {
		g_set_error_literal (&error, CD_SENSOR_ERROR,
				     CD_SENSOR_ERROR_NO_SUPPORT,
				     "MUNKI cannot measure in projector mode");
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		goto out;
	}

	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_MEASURING);

	/* save result */
	task->sample = cd_color_xyz_new ();
	g_task_return_error (task, NULL);
out:
	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_IDLE);
}
Exemplo n.º 2
0
static void
cd_sensor_munki_get_ambient_thread_cb (GSimpleAsyncResult *res,
				      GObject *object,
				      GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (object);
	g_autoptr(GError) error = NULL;
//	CdSensorMunkiPrivate *priv = cd_sensor_munki_get_private (sensor);

	/* no hardware support */
	if (cd_sensor_get_mode (sensor) != CD_SENSOR_CAP_AMBIENT) {
		g_set_error_literal (&error, CD_SENSOR_ERROR,
				     CD_SENSOR_ERROR_NO_SUPPORT,
				     "Cannot measure ambient light in this mode (turn dial!)");
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		goto out;
	}

/*
 * ioctl(3, USBDEVFS_SUBMITURB or USBDEVFS_SUBMITURB32, {type=3, endpoint=129, status=0, flags=0, buffer_length=1096, actual_length=0, start_frame=0, number_of_packets=0, error_count=0, signr=0, usercontext=(nil), buffer=00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ) = 0
 * ioctl(3, USBDEVFS_CONTROL or USBDEVFS_CONTROL32, {requesttype=64, request=128, value=0, index=0, length=12, timeout=2000, data=00 00 01 00 b7 3e 00 00 02 00 00 00 ) = 12
 *
 * ioctl(3, USBDEVFS_SUBMITURB or USBDEVFS_SUBMITURB32, {type=3, endpoint=129, status=0, flags=0, buffer_length=548, actual_length=0, start_frame=0, number_of_packets=0, error_count=0, signr=0, usercontext=(nil), buffer=d0 a3 9d 00 d0 a3 9d 00 00 00 00 00 00 00 00 00 00 d0 86 40 bf c6 fa 21 a4 4b 61 40 0b 24 0c d6 7a 29 04 40 91 3a 0e c7 f9 28 04 40 c0 b1 55 bc 9b 28 04 40 b9 d3 41 53 86 6a 07 40 df 23 db 4d 0c e3 06 40 20 5c bf 4d b2 53 05 40 5f 28 38 74 26 44 07 40 e9 45 b7 e4 2f a5 08 40 bb a2 87 d7 8c db 07 40 34 90 30 b1 f3 a1 06 40 b0 8f fa 63 84 98 05 40 35 1f 09 07 97 47 04 40 53 ac 8a be ) = 0
 *
 * ioctl(3, USBDEVFS_REAPURBNDELAY or USBDEVFS_REAPURBNDELAY32, {type=3, endpoint=129, status=0, flags=0, buffer_length=548, actual_length=548, start_frame=0, number_of_packets=0, error_count=0, signr=0, usercontext=(nil), buffer=de 07 da 07 d6 07 d8 07 d6 07 16 08 29 0b 79 0d 22 12 f2 17 b4 1c 31 20 4b 22 e2 22 7b 22 a8 21 93 20 eb 1e 2d 1d fe 1b 1c 1b e5 19 69 19 c8 19 b5 19 8a 18 16 17 a4 15 86 14 ac 13 e8 12 22 12 20 12 bf 12 8e 13 d2 13 de 13 ea 13 fb 13 39 14 89 14 bd 14 ec 14 8b 15 78 16 69 17 99 18 ca 19 97 1a 14 1b 6f 1b b5 1b 7f 1c 98 1d 59 1e a9 1e af 1e 71 1e d2 1d db 1c c1 1b d4 1a 50 1a 46 1a }) = 0
 * write(1, " Result is XYZ: 126.685284 136.9"..., 91 Result is XYZ: 126.685284 136.946975 206.789116, D50 Lab: 112.817679 -7.615524 -49.589593
) = 91
* write(1, " Ambient = 430.2 Lux, CCT = 1115"..., 54 Ambient = 430.2 Lux, CCT = 11152K (Delta E 9.399372)
 */

	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_MEASURING);

	/* save result */
	g_task_return_error (task, NULL);
out:
	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_IDLE);
}
Exemplo n.º 3
0
static void
cd_sensor_dtp94_lock_thread_cb (GTask *task,
				gpointer source_object,
				gpointer task_data,
				GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (source_object);
	CdSensorDtp94Private *priv = cd_sensor_dtp94_get_private (sensor);
	g_autoptr(GError) error = NULL;
	g_autofree gchar *serial = NULL;

	/* try to find the USB device */
	priv->device = cd_sensor_open_usb_device (sensor,
						  0x01, /* config */
						  0x00, /* interface */
						  &error);
	if (priv->device == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		return;
	}

	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_STARTING);

	/* do startup sequence */
	if (!dtp94_device_setup (priv->device, &error)) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		return;
	}

	/* get serial */
	serial = dtp94_device_get_serial (priv->device, &error);
	if (serial == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_NO_DATA,
					 "%s", error->message);
		return;
	}
	cd_sensor_set_serial (sensor, serial);

	/* success */
	g_task_return_boolean (task, TRUE);
}
Exemplo n.º 4
0
static void
cd_sensor_dtp94_sample_thread_cb (GTask *task,
				  gpointer source_object,
				  gpointer task_data,
				  GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (source_object);
	CdSensorCap cap = GPOINTER_TO_UINT (task_data);
	CdSensorDtp94Private *priv = cd_sensor_dtp94_get_private (sensor);
	CdColorXYZ *sample;
	g_autoptr(GError) error = NULL;

	/* take a measurement from the sensor */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_MEASURING);
	sample = dtp94_device_take_sample (priv->device, cap, &error);
	if (sample == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_NO_DATA,
					 "%s", error->message);
		return;
	}
	g_task_return_pointer (task, sample, NULL);
}
Exemplo n.º 5
0
static void
cd_sensor_munki_lock_thread_cb (GSimpleAsyncResult *res,
			       GObject *object,
			       GCancellable *cancellable)
{
	CdSensor *sensor = CD_SENSOR (object);
	CdSensorMunkiPrivate *priv = cd_sensor_munki_get_private (sensor);
	gboolean ret = FALSE;
	g_autoptr(GError) error = NULL;
	gint retval;
	guint8 buffer[36];
	libusb_device_handle *handle;

	/* try to find the USB device */
	priv->device = cd_sensor_open_usb_device (sensor,
						  0x01, /* config */
						  0x00, /* interface */
						  &error);
	if (priv->device == NULL) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		goto out;
	}

	/* attach to the default mainloop */
	ret = cd_usb_attach_to_context (priv->usb, NULL, &error);
	if (!ret) {
		g_task_return_new_error (task, CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_NO_SUPPORT,
						 "failed to attach to mainloop: %s",
						 error->message);
		goto out;
	}

	/* get firmware parameters */
	handle = cd_usb_get_device_handle (priv->usb);
	retval = libusb_control_transfer (handle,
					  LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
					  MUNKI_REQUEST_FIRMWARE_PARAMS,
					  0, 0, buffer, 24, 2000);
	if (retval < 0) {
		g_task_return_new_error (task, CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_NO_SUPPORT,
						 "failed to get firmware parameters: %s",
						 libusb_strerror (retval));
		goto out;
	}
	priv->firmware_revision = g_strdup_printf ("%i.%i",
						   cd_buffer_read_uint32_le (buffer),
						   cd_buffer_read_uint32_le (buffer+4));
	priv->tick_duration = cd_buffer_read_uint32_le (buffer+8);
	priv->min_int = cd_buffer_read_uint32_le (buffer+0x0c);
	priv->eeprom_blocks = cd_buffer_read_uint32_le (buffer+0x10);
	priv->eeprom_blocksize = cd_buffer_read_uint32_le (buffer+0x14);

	/* get chip ID */
	retval = libusb_control_transfer (handle,
					  LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
					  MUNKI_REQUEST_CHIP_ID,
					  0, 0, buffer, 8, 2000);
	if (retval < 0) {
		g_task_return_new_error (task, CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_NO_SUPPORT,
						 "failed to get chip id parameters: %s",
						 libusb_strerror (retval));
		goto out;
	}
	priv->chip_id = g_strdup_printf ("%02x-%02x%02x%02x%02x%02x%02x%02x",
					 buffer[0], buffer[1], buffer[2], buffer[3],
					 buffer[4], buffer[5], buffer[6], buffer[7]);

	/* get version string */
	priv->version_string = g_new0 (gchar, 36);
	retval = libusb_control_transfer (handle,
					  LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
					  MUNKI_REQUEST_VERSION_STRING,
					  0, 0, (guint8*) priv->version_string, 36, 2000);
	if (retval < 0) {
		g_task_return_new_error (task, CD_SENSOR_ERROR,
						 CD_SENSOR_ERROR_NO_SUPPORT,
						 "failed to get version string: %s",
						 libusb_strerror (retval));
		goto out;
	}

	/* get serial number */
	ret = cd_sensor_munki_get_eeprom_data (sensor,
					       COLORMUNKI_EEPROM_OFFSET_SERIAL_NUMBER,
					       buffer, 10, &error);
	if (!ret) {
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		goto out;
	}
	cd_sensor_set_serial (sensor, (const gchar*) buffer);

	/* print details */
	g_debug ("Chip ID\t%s", priv->chip_id);
	g_debug ("Serial number\t%s", buffer);
	g_debug ("Version\t%s", priv->version_string);
	g_debug ("Firmware\tfirmware_revision=%s, tick_duration=%i, min_int=%i, eeprom_blocks=%i, eeprom_blocksize=%i",
		   priv->firmware_revision, priv->tick_duration, priv->min_int, priv->eeprom_blocks, priv->eeprom_blocksize);

	/* do unknown cool stuff */
	ret = cd_sensor_munki_random (sensor, &error);
	if (!ret) {
g_assert (error != NULL);
		g_task_return_new_error (task,
					 CD_SENSOR_ERROR,
					 CD_SENSOR_ERROR_INTERNAL,
					 "%s", error->message);
		goto out;
	}
out:
	/* set state */
	cd_sensor_set_state_in_idle (sensor, CD_SENSOR_STATE_IDLE);
}