Use a single function for writing the device parameters.
This commit is contained in:
parent
8bfe481e58
commit
b7fcd5442c
@ -54,10 +54,7 @@ reefnet_sensusultra_device_read_user
|
||||
reefnet_sensusultra_device_sense
|
||||
reefnet_sensusultra_device_set_maxretries
|
||||
reefnet_sensusultra_device_set_timestamp
|
||||
reefnet_sensusultra_device_write_averaging
|
||||
reefnet_sensusultra_device_write_endcount
|
||||
reefnet_sensusultra_device_write_interval
|
||||
reefnet_sensusultra_device_write_threshold
|
||||
reefnet_sensusultra_device_write_parameter
|
||||
reefnet_sensusultra_device_write_user
|
||||
reefnet_sensusultra_extract_dives
|
||||
suunto_d9_device_open
|
||||
|
||||
@ -534,14 +534,41 @@ reefnet_sensusultra_device_write_user (device_t *abstract, const unsigned char *
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
reefnet_sensusultra_write_internal (device_t *abstract, unsigned int code, unsigned int value)
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_parameter (device_t *abstract, reefnet_sensusultra_parameter_t parameter, unsigned int value)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Set the instruction code and validate the new value.
|
||||
unsigned short code = 0;
|
||||
switch (parameter) {
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_INTERVAL:
|
||||
code = 0xB410;
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
break;
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_THRESHOLD:
|
||||
code = 0xB411;
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
break;
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_ENDCOUNT:
|
||||
code = 0xB412;
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
break;
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_AVERAGING:
|
||||
code = 0xB413;
|
||||
if (value != 1 && value != 2 && value != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
break;
|
||||
default:
|
||||
return DEVICE_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Send the instruction code to the device.
|
||||
device_status_t rc = reefnet_sensusultra_send_ushort (device, code);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
@ -556,46 +583,6 @@ reefnet_sensusultra_write_internal (device_t *abstract, unsigned int code, unsig
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_interval (device_t *abstract, unsigned int value)
|
||||
{
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
|
||||
return reefnet_sensusultra_write_internal (abstract, 0xB410, value);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_threshold (device_t *abstract, unsigned int value)
|
||||
{
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
|
||||
return reefnet_sensusultra_write_internal (abstract, 0xB411, value);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_endcount (device_t *abstract, unsigned int value)
|
||||
{
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
|
||||
return reefnet_sensusultra_write_internal (abstract, 0xB412, value);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_averaging (device_t *abstract, unsigned int value)
|
||||
{
|
||||
if (value != 1 && value != 2 && value != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
|
||||
return reefnet_sensusultra_write_internal (abstract, 0xB413, value);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_sense (device_t *abstract, unsigned char *data, unsigned int size)
|
||||
{
|
||||
|
||||
@ -36,6 +36,13 @@ extern "C" {
|
||||
#define REEFNET_SENSUSULTRA_HANDSHAKE_SIZE 24
|
||||
#define REEFNET_SENSUSULTRA_SENSE_SIZE 6
|
||||
|
||||
typedef enum reefnet_sensusultra_parameter_t {
|
||||
REEFNET_SENSUSULTRA_PARAMETER_INTERVAL,
|
||||
REEFNET_SENSUSULTRA_PARAMETER_THRESHOLD,
|
||||
REEFNET_SENSUSULTRA_PARAMETER_ENDCOUNT,
|
||||
REEFNET_SENSUSULTRA_PARAMETER_AVERAGING
|
||||
} reefnet_sensusultra_parameter_t;
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_open (device_t **device, const char* name);
|
||||
|
||||
@ -52,16 +59,7 @@ device_status_t
|
||||
reefnet_sensusultra_device_write_user (device_t *device, const unsigned char *data, unsigned int size);
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_interval (device_t *device, unsigned int value);
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_threshold (device_t *device, unsigned int value);
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_endcount (device_t *device, unsigned int value);
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_write_averaging (device_t *device, unsigned int value);
|
||||
reefnet_sensusultra_device_write_parameter (device_t *device, reefnet_sensusultra_parameter_t parameter, unsigned int value);
|
||||
|
||||
device_status_t
|
||||
reefnet_sensusultra_device_sense (device_t *device, unsigned char *data, unsigned int size);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user