diff --git a/include/libdivecomputer/hw_ostc3.h b/include/libdivecomputer/hw_ostc3.h index 021fd2f..267b7e3 100644 --- a/include/libdivecomputer/hw_ostc3.h +++ b/include/libdivecomputer/hw_ostc3.h @@ -49,6 +49,15 @@ hw_ostc3_device_display (dc_device_t *device, const char *text); dc_status_t hw_ostc3_device_customtext (dc_device_t *device, const char *text); +dc_status_t +hw_ostc3_device_config_read (dc_device_t *abstract, unsigned int config, unsigned char data[], unsigned int size); + +dc_status_t +hw_ostc3_device_config_write (dc_device_t *abstract, unsigned int config, const unsigned char data[], unsigned int size); + +dc_status_t +hw_ostc3_device_config_reset (dc_device_t *abstract); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index f9f1921..8373f96 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -42,6 +42,7 @@ #define SZ_CUSTOMTEXT 60 #define SZ_VERSION (SZ_CUSTOMTEXT + 4) #define SZ_MEMORY 0x200000 +#define SZ_CONFIG 4 #define RB_LOGBOOK_SIZE 256 #define RB_LOGBOOK_COUNT 256 @@ -53,6 +54,9 @@ #define DIVE 0x66 #define IDENTITY 0x69 #define DISPLAY 0x6E +#define READ 0x72 +#define WRITE 0x77 +#define RESET 0x78 #define INIT 0xBB #define EXIT 0xFF @@ -554,3 +558,64 @@ hw_ostc3_device_customtext (dc_device_t *abstract, const char *text) return DC_STATUS_SUCCESS; } + +dc_status_t +hw_ostc3_device_config_read (dc_device_t *abstract, unsigned int config, unsigned char data[], unsigned int size) +{ + hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract; + + if (!ISINSTANCE (abstract)) + return DC_STATUS_INVALIDARGS; + + if (size > SZ_CONFIG) { + ERROR (abstract->context, "Invalid parameter specified."); + return DC_STATUS_INVALIDARGS; + } + + // Send the command. + unsigned char command[1] = {config}; + dc_status_t rc = hw_ostc3_transfer (device, NULL, READ, command, sizeof (command), data, size); + if (rc != DC_STATUS_SUCCESS) + return rc; + + return DC_STATUS_SUCCESS; +} + +dc_status_t +hw_ostc3_device_config_write (dc_device_t *abstract, unsigned int config, const unsigned char data[], unsigned int size) +{ + hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract; + + if (!ISINSTANCE (abstract)) + return DC_STATUS_INVALIDARGS; + + if (size > SZ_CONFIG) { + ERROR (abstract->context, "Invalid parameter specified."); + return DC_STATUS_INVALIDARGS; + } + + // Send the command. + unsigned char command[SZ_CONFIG + 1] = {config}; + memcpy(command + 1, data, size); + dc_status_t rc = hw_ostc3_transfer (device, NULL, WRITE, command, size + 1, NULL, 0); + if (rc != DC_STATUS_SUCCESS) + return rc; + + return DC_STATUS_SUCCESS; +} + +dc_status_t +hw_ostc3_device_config_reset (dc_device_t *abstract) +{ + hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract; + + if (!ISINSTANCE (abstract)) + return DC_STATUS_INVALIDARGS; + + // Send the command. + dc_status_t rc = hw_ostc3_transfer (device, NULL, RESET, NULL, 0, NULL, 0); + if (rc != DC_STATUS_SUCCESS) + return rc; + + return DC_STATUS_SUCCESS; +} diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index 8b4e60c..14a96a8 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -154,6 +154,9 @@ hw_ostc3_device_version hw_ostc3_device_clock hw_ostc3_device_display hw_ostc3_device_customtext +hw_ostc3_device_config_read +hw_ostc3_device_config_write +hw_ostc3_device_config_reset zeagle_n2ition3_device_open atomics_cobalt_device_open atomics_cobalt_device_version