Skip to content

Commit

Permalink
Fix up errno when mismatched/not connected for ADI round 3
Browse files Browse the repository at this point in the history
  • Loading branch information
edjubuh committed Mar 10, 2019
1 parent 9b2e651 commit afcbc32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 49 deletions.
63 changes: 23 additions & 40 deletions include/pros/adi.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ int32_t adi_analog_calibrate(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an analog input
* EADDRINUSE - The port is configured as something other than an analog input
* EADDRINUSE - The port is not configured as an analog input
*
* \param port
* The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be
Expand All @@ -280,8 +279,7 @@ int32_t adi_analog_read(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an analog input
* EADDRINUSE - The port is configured as something other than an analog input
* EADDRINUSE - The port is not configured as an analog input
*
* \param port
* The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be
Expand All @@ -308,8 +306,7 @@ int32_t adi_analog_read_calibrated(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an analog input
* EADDRINUSE - The port is configured as something other than an analog input
* EADDRINUSE - The port is not configured as an analog input
*
* \param port
* The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be
Expand All @@ -331,8 +328,7 @@ int32_t adi_analog_read_calibrated_HR(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a digital input
* EADDRINUSE - The port is configured as something other than a digital input
* EADDRINUSE - The port is not configured as a digital input
*
* \param port
* The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')
Expand All @@ -355,8 +351,7 @@ int32_t adi_digital_read(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a digital input
* EADDRINUSE - The port is configured as something other than a digital input
* EADDRINUSE - The port is not configured as a digital input
*
* \param port
* The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')
Expand All @@ -374,8 +369,7 @@ int32_t adi_digital_get_new_press(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a digital output
* EADDRINUSE - The port is configured as something other than a digital output
* EADDRINUSE - The port is not configured as a digital output
*
* \param port
* The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')
Expand Down Expand Up @@ -411,8 +405,7 @@ int32_t adi_pin_mode(uint8_t port, uint8_t mode);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an motor
* EADDRINUSE - The port is configured as something other than a motor
* EADDRINUSE - The port is not configured as an motor
*
* \param port
* The ADI port to set (from 1-8, 'a'-'h', 'A'-'H')
Expand All @@ -431,8 +424,7 @@ int32_t adi_motor_set(uint8_t port, int8_t speed);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an motor
* EADDRINUSE - The port is configured as something other than a motor
* EADDRINUSE - The port is not configured as an motor
*
* \param port
* The ADI port to get (from 1-8, 'a'-'h', 'A'-'H')
Expand All @@ -447,8 +439,7 @@ int32_t adi_motor_get(uint8_t port);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an motor
* EADDRINUSE - The port is configured as something other than a motor
* EADDRINUSE - The port is not configured as an motor
*
* \param port
* The ADI port to set (from 1-8, 'a'-'h', 'A'-'H')
Expand All @@ -474,8 +465,8 @@ typedef int32_t adi_encoder_t;
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an encoder
* EADDRINUSE - The port is configured as something other than an encoder
* EADDRINUSE - The port is not configured as an encoder
*
* \param enc
* The adi_encoder_t object from adi_encoder_init() to read
Expand All @@ -491,8 +482,8 @@ int32_t adi_encoder_get(adi_encoder_t enc);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an encoder
* EADDRINUSE - The port is configured as something other than an encoder
* EADDRINUSE - The port is not configured as an encoder
*
* \param port_top
* The "top" wire from the encoder sensor with the removable cover side
Expand All @@ -516,8 +507,8 @@ adi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, const bool
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an encoder
* EADDRINUSE - The port is configured as something other than an encoder
* EADDRINUSE - The port is not configured as an encoder
*
* \param enc
* The adi_encoder_t object from adi_encoder_init() to reset
Expand All @@ -533,8 +524,7 @@ int32_t adi_encoder_reset(adi_encoder_t enc);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an encoder
* EADDRINUSE - The port is configured as something other than an encoder
* EADDRINUSE - The port is not configured as an encoder
*
* \param enc
* The adi_encoder_t object from adi_encoder_init() to stop
Expand Down Expand Up @@ -562,8 +552,7 @@ typedef int32_t adi_ultrasonic_t;
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an ultrasonic
* EADDRINUSE - The port is configured as something other than an ultrasonic
* EADDRINUSE - The port is not configured as an ultrasonic
*
* \param ult
* The adi_ultrasonic_t object from adi_ultrasonic_init() to read
Expand All @@ -579,8 +568,7 @@ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an ultrasonic
* EADDRINUSE - The port is configured as something other than an ultrasonic
* EADDRINUSE - The port is not configured as an ultrasonic
*
* \param port_ping
* The port connected to the orange OUTPUT cable. This should be in the
Expand All @@ -600,8 +588,7 @@ adi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as an ultrasonic
* EADDRINUSE - The port is configured as something other than an ultrasonic
* EADDRINUSE - The port is not configured as an ultrasonic
*
* \param ult
* The adi_ultrasonic_t object from adi_ultrasonic_init() to stop
Expand Down Expand Up @@ -630,8 +617,7 @@ typedef int32_t adi_gyro_t;
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a gyro
* EADDRINUSE - The port is configured as something other than a gyro
* EADDRINUSE - The port is not configured as a gyro
*
* \param gyro
* The adi_gyro_t object for which the angle will be returned
Expand All @@ -651,8 +637,7 @@ double adi_gyro_get(adi_gyro_t gyro);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a gyro
* EADDRINUSE - The port is configured as something other than a gyro
* EADDRINUSE - The port is not configured as a gyro
*
* \param port
* The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')
Expand All @@ -671,8 +656,7 @@ adi_gyro_t adi_gyro_init(uint8_t port, double multiplier);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a gyro
* EADDRINUSE - The port is configured as something other than a gyro
* EADDRINUSE - The port is not configured as a gyro
*
* \param gyro
* The adi_gyro_t object for which the angle will be returned
Expand All @@ -688,8 +672,7 @@ int32_t adi_gyro_reset(adi_gyro_t gyro);
* This function uses the following values of errno when an error state is
* reached:
* ENXIO - The given value is not within the range of ADI Ports
* ENODEV - The port is not configured as a gyro
* EADDRINUSE - The port is configured as something other than a gyro
* EADDRINUSE - The port is not configured as a gyro
*
* \param gyro
* The adi_gyro_t object to be shut down
Expand Down
10 changes: 1 addition & 9 deletions src/devices/vdml_adi.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,13 @@ static void set_gyro_tare(uint8_t port, double tare) {

#define validate_type(port, type) \
adi_port_config_e_t config = _adi_port_get_config(port); \
if (config == E_ADI_TYPE_UNDEFINED) { \
errno = ENODEV; \
return PROS_ERR; \
} \
if (config != type) { \
errno = EADDRINUSE; \
return PROS_ERR; \
}

#define validate_type_f(port, type) \
adi_port_config_e_t config = _adi_port_get_config(port); \
if (config == E_ADI_TYPE_UNDEFINED) { \
errno = ENODEV; \
return PROS_ERR_F; \
} \
if (config != type) { \
errno = EADDRINUSE; \
return PROS_ERR_F; \
Expand Down Expand Up @@ -170,7 +162,7 @@ static void set_gyro_tare(uint8_t port, double tare) {

static inline int32_t _adi_port_set_config(uint8_t port, adi_port_config_e_t type) {
claim_port(INTERNAL_ADI_PORT, E_DEVICE_ADI);
vexDeviceAdiPortConfigSet(device->device_info, port, type);
vexDeviceAdiPortConfigSet(device->device_info, port, (V5_AdiPortConfiguration)type);
return_port(INTERNAL_ADI_PORT, 1);
}

Expand Down

0 comments on commit afcbc32

Please sign in to comment.