diff options
author | Richard Hughes <richard@hughsie.com> | 2016-10-05 22:03:45 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-10-06 09:46:03 +0100 |
commit | 9a706edfc9daef5ac42c46a010c25774cb352764 (patch) | |
tree | 28e6031e3d950a39bb0c63b86308163ef7dbb733 | |
parent | 3d8891426ec7a2a8d35f22b77e971487ee97518a (diff) | |
download | colord-9a706edfc9daef5ac42c46a010c25774cb352764.tar.gz |
colorhug: Add support for loading and saving the SRAM
-rw-r--r-- | lib/colorhug/ch-common.c | 6 | ||||
-rw-r--r-- | lib/colorhug/ch-common.h | 52 | ||||
-rw-r--r-- | lib/colorhug/ch-device.c | 124 | ||||
-rw-r--r-- | lib/colorhug/ch-device.h | 6 |
4 files changed, 188 insertions, 0 deletions
diff --git a/lib/colorhug/ch-common.c b/lib/colorhug/ch-common.c index 46c78ef..f18de69 100644 --- a/lib/colorhug/ch-common.c +++ b/lib/colorhug/ch-common.c @@ -372,6 +372,12 @@ ch_command_to_string (ChCmd cmd) case CH_CMD_SET_ILLUMINANTS: str = "set-illuminants"; break; + case CH_CMD_LOAD_SRAM: + str = "load-sram"; + break; + case CH_CMD_SAVE_SRAM: + str = "save-sram"; + break; default: str = "unknown-command"; break; diff --git a/lib/colorhug/ch-common.h b/lib/colorhug/ch-common.h index b94a333..a60b1da 100644 --- a/lib/colorhug/ch-common.h +++ b/lib/colorhug/ch-common.h @@ -1339,6 +1339,58 @@ G_BEGIN_DECLS #define CH_CMD_SELF_TEST 0x40 /** + * CH_CMD_LOAD_SRAM: + * + * Load the SRAM from the EEPROM. + * + * PROTOCOLv2: + * bRequest: [cmd] + * wValue: 0x00 + * wIndex: interface + * wLength: 0x00 + * Direction: DEVICE->HOST + * Data: [1:error][1:cmd] + * + * This command is available under these conditions: + * + * | Bootloader | Firmware + * ---------------+--------------+----------- + * ColorHug | × | × + * ColorHug2 | × | × + * ColorHug+ | × | ✓ + * ColorHugALS | × | × + * + * Since: 0.1.29 + **/ +#define CH_CMD_LOAD_SRAM 0x41 + +/** + * CH_CMD_SAVE_SRAM: + * + * Save the SRAM to the EEPROM. + * + * PROTOCOLv2: + * bRequest: [cmd] + * wValue: 0x00 + * wIndex: interface + * wLength: 0x00 + * Direction: DEVICE->HOST + * Data: [1:error][1:cmd] + * + * This command is available under these conditions: + * + * | Bootloader | Firmware + * ---------------+--------------+----------- + * ColorHug | × | × + * ColorHug2 | × | × + * ColorHug+ | × | ✓ + * ColorHugALS | × | × + * + * Since: 0.1.29 + **/ +#define CH_CMD_SAVE_SRAM 0x42 + +/** * CH_CMD_GET_ERROR: * * Gets any recorded error from the device. diff --git a/lib/colorhug/ch-device.c b/lib/colorhug/ch-device.c index c70d9d5..3aa1410 100644 --- a/lib/colorhug/ch-device.c +++ b/lib/colorhug/ch-device.c @@ -2431,3 +2431,127 @@ ch_device_get_spectrum (GUsbDevice *device, GCancellable *cancellable, GError ** /* return copy */ return cd_spectrum_dup (sp); } + +/** + * ch_device_get_spectrum: + * @device: A #GUsbDevice + * @cancellable: a #GCancellable, or %NULL + * @error: a #GError, or %NULL + * + * Gets the spectrum from the device. This queries the device multiple times + * until the spectrum has been populated. + * + * Returns: a #CdSpectrum, or %NULL for error + * + * Since: 1.3.1 + **/ +CdSpectrum * +ch_device_get_spectrum (GUsbDevice *device, GCancellable *cancellable, GError **error) +{ + return ch_device_get_spectrum_full (device, CH_SPECTRUM_KIND_RAW, + cancellable, error); +} + +/** + * ch_device_save_sram: + * @device: A #GUsbDevice + * @cancellable: a #GCancellable, or %NULL + * @error: a #GError, or %NULL + * + * Saves the entire SRAM space into the device EEPROM. + * + * Returns: %TRUE for success + * + * Since: 1.3.4 + **/ +gboolean +ch_device_save_sram (GUsbDevice *device, + GCancellable *cancellable, + GError **error) +{ + gboolean ret; + + if (ch_device_get_protocol_ver (device) != 2) { + g_set_error_literal (error, + CH_DEVICE_ERROR, + CH_ERROR_NOT_IMPLEMENTED, + "saving SRAM not supported"); + return FALSE; + } + + /* save SRAM */ + ret = g_usb_device_control_transfer (device, + G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE, + G_USB_DEVICE_REQUEST_TYPE_CLASS, + G_USB_DEVICE_RECIPIENT_INTERFACE, + CH_CMD_SAVE_SRAM, + 0, /* wValue */ + CH_USB_INTERFACE, /* idx */ + NULL, /* data */ + 0, /* length */ + NULL, /* actual_length */ + CH_DEVICE_USB_TIMEOUT, + cancellable, + error); + if (!ret) + return FALSE; + + /* check status */ + if (!ch_device_check_status (device, cancellable, error)) + return FALSE; + + /* success */ + return TRUE; +} + +/** + * ch_device_load_sram: + * @device: A #GUsbDevice + * @cancellable: a #GCancellable, or %NULL + * @error: a #GError, or %NULL + * + * Loads the entire SRAM from the device EEPROM. + * + * Returns: %TRUE for success + * + * Since: 1.3.4 + **/ +gboolean +ch_device_load_sram (GUsbDevice *device, + GCancellable *cancellable, + GError **error) +{ + gboolean ret; + + if (ch_device_get_protocol_ver (device) != 2) { + g_set_error_literal (error, + CH_DEVICE_ERROR, + CH_ERROR_NOT_IMPLEMENTED, + "saving SRAM not supported"); + return FALSE; + } + + /* save SRAM */ + ret = g_usb_device_control_transfer (device, + G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE, + G_USB_DEVICE_REQUEST_TYPE_CLASS, + G_USB_DEVICE_RECIPIENT_INTERFACE, + CH_CMD_LOAD_SRAM, + 0, /* wValue */ + CH_USB_INTERFACE, /* idx */ + NULL, /* data */ + 0, /* length */ + NULL, /* actual_length */ + CH_DEVICE_USB_TIMEOUT, + cancellable, + error); + if (!ret) + return FALSE; + + /* check status */ + if (!ch_device_check_status (device, cancellable, error)) + return FALSE; + + /* success */ + return TRUE; +} diff --git a/lib/colorhug/ch-device.h b/lib/colorhug/ch-device.h index 2dfeebc..2acabbb 100644 --- a/lib/colorhug/ch-device.h +++ b/lib/colorhug/ch-device.h @@ -176,6 +176,12 @@ CdColorXYZ *ch_device_take_reading_xyz (GUsbDevice *device, CdSpectrum *ch_device_get_spectrum (GUsbDevice *device, GCancellable *cancellable, GError **error); +gboolean ch_device_load_sram (GUsbDevice *device, + GCancellable *cancellable, + GError **error); +gboolean ch_device_save_sram (GUsbDevice *device, + GCancellable *cancellable, + GError **error); G_END_DECLS |