From 9ca03646e5e98f24bd16910db3ebbd2916a4ee94 Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Wed, 30 Jan 2019 14:18:04 -0500 Subject: [PATCH 01/10] Better errno for registry validation failure, update vision sensor errnos Summary: - Changed port number validation to return ENXIO when outside the domain of port numbers - Changed port validation to return ENODEV when the requested device doesn't match the actual device - Vision Sensor read/get functions consistently use EAGAIN when the libv5rts tells us it couldn't get data - Remove docstrings for EACCES since it is practically impossible to get that errno (we wait for mutex indefinitely) Test Plan: TBD --- include/pros/adi.h | 118 ++++++++++--------------- include/pros/adi.hpp | 75 ++++++---------- include/pros/motors.h | 176 +++++++++++++++++++------------------- include/pros/motors.hpp | 113 +++++++++++------------- include/pros/vision.h | 72 ++++++++-------- include/pros/vision.hpp | 63 +++++++++----- include/vdml/vdml.h | 4 +- src/devices/vdml_adi.c | 4 +- src/devices/vdml_vision.c | 30 ++++--- 9 files changed, 310 insertions(+), 345 deletions(-) diff --git a/include/pros/adi.h b/include/pros/adi.h index b84b574d6..330ef90f7 100644 --- a/include/pros/adi.h +++ b/include/pros/adi.h @@ -122,8 +122,7 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which to return @@ -138,8 +137,7 @@ adi_port_config_e_t adi_port_get_config(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which the value @@ -154,8 +152,7 @@ int32_t adi_port_get_value(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -175,8 +172,7 @@ int32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which the value @@ -243,9 +239,7 @@ int32_t adi_port_set_value(uint8_t port, int32_t value); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an analog input. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports * * \param port * The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H') @@ -262,9 +256,8 @@ int32_t adi_analog_calibrate(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an analog input. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - 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 @@ -285,9 +278,8 @@ int32_t adi_analog_read(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an analog input. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - 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 @@ -313,9 +305,8 @@ int32_t adi_analog_read_calibrated(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an analog input. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - 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 @@ -336,9 +327,8 @@ int32_t adi_analog_read_calibrated_HR(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as a digital input. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as a digital input * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -360,9 +350,8 @@ int32_t adi_digital_read(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as a digital input. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as a digital input * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -379,9 +368,8 @@ int32_t adi_digital_get_new_press(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as a digital output. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as a digital output * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -399,8 +387,7 @@ int32_t adi_digital_write(uint8_t port, const bool value); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -417,9 +404,8 @@ 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: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Motor. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an motor * * \param port * The ADI port to set (from 1-8, 'a'-'h', 'A'-'H') @@ -437,9 +423,8 @@ 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: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Motor. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an motor * * \param port * The ADI port to get (from 1-8, 'a'-'h', 'A'-'H') @@ -453,9 +438,8 @@ int32_t adi_motor_get(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Motor. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an motor * * \param port * The ADI port to set (from 1-8, 'a'-'h', 'A'-'H') @@ -480,9 +464,8 @@ typedef int32_t adi_encoder_t; * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Encoder. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an encoder * * \param enc * The adi_encoder_t object from adi_encoder_init() to read @@ -497,9 +480,8 @@ int32_t adi_encoder_get(adi_encoder_t enc); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Encoder. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an encoder * * \param port_top * The "top" wire from the encoder sensor with the removable cover side @@ -522,9 +504,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: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Encoder. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an encoder * * \param enc * The adi_encoder_t object from adi_encoder_init() to reset @@ -539,9 +520,8 @@ int32_t adi_encoder_reset(adi_encoder_t enc); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Encoder. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an encoder * * \param enc * The adi_encoder_t object from adi_encoder_init() to stop @@ -568,9 +548,8 @@ typedef int32_t adi_ultrasonic_t; * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Ultrasonic. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an ultrasonic * * \param ult * The adi_ultrasonic_t object from adi_ultrasonic_init() to read @@ -585,9 +564,8 @@ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Ultrasonic. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an ultrasonic * * \param port_ping * The port connected to the orange OUTPUT cable. This should be in the @@ -606,9 +584,8 @@ 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: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Ultrasonic. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as an ultrasonic * * \param ult * The adi_ultrasonic_t object from adi_ultrasonic_init() to stop @@ -636,9 +613,8 @@ typedef int32_t adi_gyro_t; * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Gyro. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as a gyro * * \param gyro * The adi_gyro_t object for which the angle will be returned @@ -657,8 +633,8 @@ double adi_gyro_get(adi_gyro_t gyro); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - 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') @@ -676,9 +652,8 @@ 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: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Gyro. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as a gyro * * \param gyro * The adi_gyro_t object for which the angle will be returned @@ -693,9 +668,8 @@ int32_t adi_gyro_reset(adi_gyro_t gyro); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports, or the given - * port is not configured as an ADI Gyro. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports + * ENODEV - The port is not configured as a gyro * * \param gyro * The adi_gyro_t object to be shut down diff --git a/include/pros/adi.hpp b/include/pros/adi.hpp index a2d420e3a..516758caa 100644 --- a/include/pros/adi.hpp +++ b/include/pros/adi.hpp @@ -30,8 +30,7 @@ class ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -45,10 +44,6 @@ class ADIPort { /** * Gets the configuration for the given ADI port. * - * This function uses the following values of errno when an error state is - * reached: - * EACCES - Another resource is currently trying to access the ADI. - * * \return The ADI configuration for the given port */ std::int32_t get_config(void) const; @@ -56,10 +51,6 @@ class ADIPort { /** * Gets the value for the given ADI port. * - * This function uses the following values of errno when an error state is - * reached: - * EACCES - Another resource is currently trying to access the ADI. - * * \return The value stored for the given port */ std::int32_t get_value(void) const; @@ -67,10 +58,6 @@ class ADIPort { /** * Configures an ADI port to act as a given sensor type. * - * This function uses the following values of errno when an error state is - * reached: - * EACCES - Another resource is currently trying to access the ADI. - * * \param type * The configuration type for the port * @@ -85,10 +72,6 @@ class ADIPort { * This only works on ports configured as outputs, and the behavior will * change depending on the configuration of the port. * - * This function uses the following values of errno when an error state is - * reached: - * EACCES - Another resource is currently trying to access the ADI. - * * \param value * The value to set the ADI port to * @@ -109,8 +92,7 @@ class ADIAnalogIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -140,7 +122,7 @@ class ADIAnalogIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as an analog input * * \return The average sensor value computed by this function */ @@ -156,7 +138,7 @@ class ADIAnalogIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as an analog input * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 @@ -178,7 +160,7 @@ class ADIAnalogIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as an analog input * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 @@ -193,7 +175,7 @@ class ADIAnalogIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as an analog input * * \return The analog sensor value, where a value of 0 reflects an input * voltage of nearly 0 V and a value of 4095 reflects an input voltage of @@ -214,8 +196,7 @@ class ADIAnalogOut : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -232,7 +213,7 @@ class ADIAnalogOut : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as an analog output * * \param value * The value to set the ADI port to @@ -250,8 +231,7 @@ class ADIDigitalOut : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -268,7 +248,7 @@ class ADIDigitalOut : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a digital output * * \param value * The value to set the ADI port to @@ -286,8 +266,7 @@ class ADIDigitalIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -309,7 +288,7 @@ class ADIDigitalIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a digital input * * \return 1 if the button is pressed and had not been pressed the last time * this function was called, 0 otherwise. @@ -321,7 +300,7 @@ class ADIDigitalIn : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a digital input * * \return The value stored for the given port */ @@ -337,8 +316,7 @@ class ADIMotor : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure @@ -352,7 +330,7 @@ class ADIMotor : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. @@ -364,7 +342,7 @@ class ADIMotor : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a motor * * \param value * The new signed speed; -127 is full reverse and 127 is full forward, @@ -380,7 +358,7 @@ class ADIMotor : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a motor * * \return The last set speed of the motor on the given port */ @@ -394,8 +372,7 @@ class ADIEncoder : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port_top * The "top" wire from the encoder sensor with the removable cover side @@ -415,7 +392,7 @@ class ADIEncoder : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. @@ -429,7 +406,7 @@ class ADIEncoder : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a motor * * \return The signed and cumulative number of counts since the last start or * reset @@ -444,8 +421,7 @@ class ADIUltrasonic : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports. - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports. * * \param port_ping * The port connected to the orange OUTPUT cable. This should be in the @@ -465,7 +441,7 @@ class ADIUltrasonic : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as an ultrasonic * * \return The distance to the nearest object in m^-4 (10000 indicates 1 * meter), measured from the sensor's mounting points. @@ -488,8 +464,7 @@ class ADIGyro : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of ADI Ports - * EACCES - Another resource is currently trying to access the ADI. + * ENXIO - The given value is not within the range of ADI Ports * * \param port * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') @@ -511,7 +486,7 @@ class ADIGyro : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a gyro * * \return The gyro angle in degrees. */ @@ -522,7 +497,7 @@ class ADIGyro : private ADIPort { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the ADI. + * ENODEV - The port is not configured as a gyro * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. diff --git a/include/pros/motors.h b/include/pros/motors.h index e96caa174..2231a1ab0 100644 --- a/include/pros/motors.h +++ b/include/pros/motors.h @@ -43,8 +43,8 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -67,8 +67,8 @@ int32_t motor_move(uint8_t port, int32_t voltage); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -95,8 +95,8 @@ int32_t motor_move_absolute(uint8_t port, const double position, const int32_t v * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -121,8 +121,8 @@ int32_t motor_move_relative(uint8_t port, const double position, const int32_t v * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -140,8 +140,8 @@ int32_t motor_move_velocity(uint8_t port, const int32_t velocity); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -160,8 +160,8 @@ int32_t motor_move_voltage(uint8_t port, const int32_t voltage); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -179,8 +179,8 @@ int32_t motor_modify_profiled_velocity(uint8_t port, const int32_t velocity); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -195,8 +195,8 @@ double motor_get_target_position(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -217,8 +217,8 @@ int32_t motor_get_target_velocity(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -233,8 +233,8 @@ double motor_get_actual_velocity(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -249,8 +249,8 @@ int32_t motor_get_current_draw(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -269,8 +269,8 @@ int32_t motor_get_direction(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -285,8 +285,8 @@ double motor_get_efficiency(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -301,8 +301,8 @@ int32_t motor_is_over_current(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -382,8 +382,8 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -428,8 +428,8 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -443,8 +443,8 @@ uint32_t motor_get_flags(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -463,8 +463,8 @@ int32_t motor_get_raw_position(uint8_t port, uint32_t* const timestamp); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -479,8 +479,8 @@ double motor_get_position(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -495,8 +495,8 @@ double motor_get_power(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -511,8 +511,8 @@ double motor_get_temperature(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -527,8 +527,8 @@ double motor_get_torque(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -656,8 +656,8 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -674,8 +674,8 @@ int32_t motor_set_zero_position(uint8_t port, const double position); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -690,8 +690,8 @@ int32_t motor_tare_position(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -708,8 +708,8 @@ int32_t motor_set_brake_mode(uint8_t port, const motor_brake_mode_e_t mode); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -726,8 +726,8 @@ int32_t motor_set_current_limit(uint8_t port, const int32_t limit); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -744,8 +744,8 @@ int32_t motor_set_encoder_units(uint8_t port, const motor_encoder_units_e_t unit * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -766,8 +766,8 @@ int32_t motor_set_gearing(uint8_t port, const motor_gearset_e_t gearset); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param kf * The feedforward constant @@ -791,8 +791,8 @@ motor_pid_s_t motor_convert_pid(double kf, double kp, double ki, double kd); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param kf * The feedforward constant @@ -828,8 +828,8 @@ motor_pid_full_s_t motor_convert_pid_full(double kf, double kp, double ki, doubl * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -851,8 +851,8 @@ int32_t motor_set_pos_pid(uint8_t port, const motor_pid_s_t pid); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -875,8 +875,8 @@ int32_t motor_set_pos_pid_full(uint8_t port, const motor_pid_full_s_t pid); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -898,8 +898,8 @@ int32_t motor_set_vel_pid(uint8_t port, const motor_pid_s_t pid); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -918,8 +918,8 @@ int32_t motor_set_vel_pid_full(uint8_t port, const motor_pid_full_s_t pid); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -936,8 +936,8 @@ int32_t motor_set_reversed(uint8_t port, const bool reverse); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -954,8 +954,8 @@ int32_t motor_set_voltage_limit(uint8_t port, const int32_t limit); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -972,8 +972,8 @@ motor_brake_mode_e_t motor_get_brake_mode(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -988,8 +988,8 @@ int32_t motor_get_current_limit(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -1004,8 +1004,8 @@ motor_encoder_units_e_t motor_get_encoder_units(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -1022,8 +1022,8 @@ motor_gearset_e_t motor_get_gearing(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * Additionally, in an error state all values of the returned struct are set * to their negative maximum values. @@ -1043,8 +1043,8 @@ motor_pid_full_s_t motor_get_pos_pid(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * Additionally, in an error state all values of the returned struct are set * to their negative maximum values. @@ -1062,8 +1062,8 @@ motor_pid_full_s_t motor_get_vel_pid(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -1081,8 +1081,8 @@ int32_t motor_is_reversed(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 diff --git a/include/pros/motors.hpp b/include/pros/motors.hpp index 40dac7d03..0f19a8a59 100644 --- a/include/pros/motors.hpp +++ b/include/pros/motors.hpp @@ -31,7 +31,7 @@ class Motor { * This function uses the following values of errno when an error state is * reached: * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -67,7 +67,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param voltage * The new motor voltage from -127 to 127 @@ -86,7 +86,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param voltage * The new motor voltage from -127 to 127 @@ -108,7 +108,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param position * The absolute position to move to in the motor's encoder units @@ -133,7 +133,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param position * The relative position to move to in the motor's encoder units @@ -156,7 +156,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param velocity * The new motor velocity from -+-100, +-200, or +-600 depending on the @@ -172,7 +172,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -191,8 +191,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param velocity * The new motor velocity from +-100, +-200, or +-600 depending on the @@ -208,7 +207,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The target position in its encoder units or PROS_ERR_F if the * operation failed, setting errno. @@ -220,7 +219,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The commanded motor velocity from +-100, +-200, or +-600, or * PROS_ERR if the operation failed, setting errno. @@ -238,7 +237,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation * failed, setting errno. @@ -250,7 +249,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's current in mA or PROS_ERR if the operation failed, * setting errno. @@ -262,7 +261,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return 1 for moving in the positive direction, -1 for moving in the * negative direction, and PROS_ERR if the operation failed, setting errno. @@ -278,7 +277,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. @@ -290,7 +289,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return 1 if the motor's current limit is being exceeded and 0 if the * current limit is not exceeded, or PROS_ERR if the operation failed, setting @@ -301,6 +300,10 @@ class Motor { /** * Checks if the motor is stopped. * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * * \note Although this function forwards data from the motor, the motor * presently does not provide any value. This function returns PROS_ERR with * errno set to ENOSYS. @@ -313,6 +316,10 @@ class Motor { /** * Checks if the motor is at its zero position. * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * * \note Although this function forwards data from the motor, the motor * presently does not provide any value. This function returns PROS_ERR with * errno set to ENOSYS. @@ -330,7 +337,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -346,7 +353,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param port * The V5 port number from 1-21 @@ -360,7 +367,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param[in] timestamp * A pointer to a time in milliseconds for which the encoder count @@ -377,7 +384,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return 1 if the temperature limit is exceeded and 0 if the temperature is * below the limit, or PROS_ERR if the operation failed, setting errno. @@ -389,7 +396,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's absolute position in its encoder units or PROS_ERR_F * if the operation failed, setting errno. @@ -401,7 +408,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's power draw in Watts or PROS_ERR_F if the operation * failed, setting errno. @@ -413,7 +420,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the * operation failed, setting errno. @@ -425,7 +432,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, * setting errno. @@ -437,7 +444,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, * setting errno. @@ -458,7 +465,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param position * The new reference position in its encoder units @@ -473,7 +480,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. @@ -485,7 +492,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param mode * The motor_brake_mode_e_t to set for the motor @@ -500,7 +507,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param limit * The new current limit in mA @@ -515,7 +522,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param units * The new motor encoder units @@ -530,7 +537,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param gearset * The new motor gearset @@ -547,11 +554,6 @@ class Motor { * This function will convert the floating point values to the nearest 4.4 * value. * - * This function uses the following values of errno when an error state is - * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. - * * \param kf * The feedforward constant * \param kp @@ -572,11 +574,6 @@ class Motor { * This function will convert the floating point values to the nearest 4.4 * value. * - * This function uses the following values of errno when an error state is - * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. - * * \param kf * The feedforward constant * \param kp @@ -609,8 +606,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param pid * The new motor PID constants @@ -628,8 +624,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param pid * The new motor PID constants @@ -648,8 +643,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param pid * The new motor PID constants @@ -667,8 +661,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param pid * The new motor PID constants @@ -685,7 +678,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param reverse * True reverses the motor, false is default @@ -700,7 +693,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \param limit * The new voltage limit in Volts @@ -715,7 +708,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return One of motor_brake_mode_e_t, according to what was set for the * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. @@ -729,7 +722,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's current limit in mA or PROS_ERR if the operation failed, * setting errno. @@ -741,7 +734,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return One of motor_encoder_units_e_t according to what is set for the * motor or E_MOTOR_ENCODER_INVALID if the operation failed. @@ -753,7 +746,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return One of motor_gearset_e_t according to what is set for the motor, * or E_GEARSET_INVALID if the operation failed. @@ -767,8 +760,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * Additionally, in an error state all values of the returned struct are set * to their negative maximum values. @@ -785,8 +777,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * Additionally, in an error state all values of the returned struct are set * to their negative maximum values. @@ -801,7 +792,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return 1 if the motor has been reversed and 0 if the motor was not * reversed, or PROS_ERR if the operation failed, setting errno. @@ -816,7 +807,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a motor * * \return The motor's voltage limit in V or PROS_ERR if the operation failed, * setting errno. diff --git a/include/pros/vision.h b/include/pros/vision.h index ad58d0921..30257d7e6 100644 --- a/include/pros/vision.h +++ b/include/pros/vision.h @@ -121,8 +121,8 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -167,8 +167,8 @@ vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32 * * This function uses the following values of errno when an error state is * reached: - * EINVAL - Fewer than two signatures have been provided, or one of the - * signatures is out of its [1-7] range. + * EINVAL - Fewer than two signatures have been provided or one of the + * signatures is out of its [1-7] range (or 0 when omitted). * * \param port * The V5 port number from 1-21 @@ -193,8 +193,8 @@ vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. * EHOSTDOWN - Reading the vision sensor failed for an unknown reason. * @@ -214,10 +214,11 @@ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor + * EINVAL - sig_id is outside the range [1-8] * EDOM - size_id is greater than the number of available objects. - * EHOSTDOWN - Reading the vision sensor failed for an unknown reason. + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param port * The V5 port number from 1-21 @@ -237,9 +238,9 @@ vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. - * EAGAIN - Reading the Vision Sensor failed for an unknown reason. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param port * The V5 port number from 1-21 @@ -261,8 +262,8 @@ vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -277,8 +278,8 @@ int32_t vision_get_exposure(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -293,8 +294,8 @@ int32_t vision_get_object_count(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -318,9 +319,9 @@ int32_t vision_print_signature(const vision_signature_s_t sig); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21), or + * ENXIO - The given value is not within the range of V5 ports (1-21), or * fewer than object_count number of objects were found. - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. * * \param port @@ -347,9 +348,9 @@ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21), or + * ENXIO - The given value is not within the range of V5 ports (1-21), or * fewer than object_count number of objects were found. - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. * * \param port @@ -378,9 +379,9 @@ int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21), or + * ENXIO - The given value is not within the range of V5 ports (1-21), or * fewer than object_count number of objects were found. - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -437,8 +438,9 @@ int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_si * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor + * EINVAL - enable was not 0 or 1 * * \param port * The V5 port number from 1-21 @@ -457,8 +459,8 @@ int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -475,8 +477,8 @@ int32_t vision_set_exposure(uint8_t port, const uint8_t exposure); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -493,8 +495,8 @@ int32_t vision_set_led(uint8_t port, const int32_t rgb); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -515,8 +517,8 @@ int32_t vision_set_white_balance(uint8_t port, const int32_t rgb); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). - * EACCES - Another resource is currently trying to access the port. + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor * * \param port * The V5 port number from 1-21 @@ -533,7 +535,7 @@ int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point); * * This functions uses the following values of errno when an error state is * reached: - * EINVAL - The given port is not within the range of V5 ports (1-21) + * ENXIO - The given port is not within the range of V5 ports (1-21) * EACCESS - Anothe resources is currently trying to access the port * * \param port diff --git a/include/pros/vision.hpp b/include/pros/vision.hpp index 496508a50..079d2c21c 100644 --- a/include/pros/vision.hpp +++ b/include/pros/vision.hpp @@ -30,6 +30,11 @@ class Vision { /** * Create a Vision Sensor object on the given 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 V5 ports (1-21). + * ENODEV - The port cannot be configured as a vision sensor + * * \param port * The V5 port number from 1-21 * \param zero_point @@ -43,7 +48,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. @@ -86,8 +91,8 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - Fewer than two signatures have been provided, or one of the - * signatures is out of its [1-7] range. + * EINVAL - Fewer than two signatures have been provided or one of the + * signatures is out of its [1-7] range (or 0 when omitted). * * \param sig_id1 * The first signature id [1-7] to add to the color code @@ -111,9 +116,9 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. - * EHOSTDOWN - Reading the vision sensor failed for an unknown reason. + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param size_id * The object to read from a list roughly ordered by object size @@ -129,9 +134,10 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. - * EHOSTDOWN - Reading the vision sensor failed for an unknown reason. + * EINVAL - sig_id is outside the range [1-8] + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param size_id * The object to read from a list roughly ordered by object size @@ -150,7 +156,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EAGAIN - Reading the Vision Sensor failed for an unknown reason. * * \param size_id @@ -171,7 +177,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \return The current exposure parameter from [0,150], * PROS_ERR if an error occurred @@ -183,7 +189,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \return The number of objects detected on the specified vision sensor. * Returns PROS_ERR if the port was invalid or an error occurred. @@ -193,6 +199,10 @@ class Vision { /** * Gets the object detection signature with the given id number. * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a vision sensor + * * \param signature_id * The signature id to read * @@ -205,7 +215,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \return The current RGB white balance setting of the sensor */ @@ -216,8 +226,9 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param size_id * The object to read from a list roughly ordered by object size @@ -241,9 +252,10 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * EDOM - size_id is greater than the number of available objects. - * EHOSTDOWN - Reading the vision sensor failed for an unknown reason. + * EINVAL - sig_id is outside the range [1-8] + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param object_count * The number of objects to read @@ -270,8 +282,9 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - Fewer than object_count number of objects were found. - * EACCES - Another resource is currently trying to access the port. + * EDOM - size_id is greater than the number of available objects. + * ENODEV - The port cannot be configured as a vision sensor + * EAGAIN - Reading the vision sensor failed for an unknown reason. * * \param object_count * The number of objects to read @@ -307,7 +320,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \param enabled * Pass 0 to disable, 1 to enable @@ -324,7 +337,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \param percent * The new exposure setting from [0,150]. @@ -339,7 +352,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \param rgb * An RGB code to set the LED to @@ -355,6 +368,11 @@ class Vision { * NOTE: This saves the signature in volatile memory, and the signature will be * lost as soon as the sensor is powered down. * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a vision sensor + * EINVAL - sig_id is outside the range [1-8] + * * \param signature_id * The signature id to store into * \param[in] signature_ptr @@ -369,7 +387,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \param rgb * The new RGB white balance setting of the sensor @@ -388,7 +406,7 @@ class Vision { * * This function uses the following values of errno when an error state is * reached: - * EACCES - Another resource is currently trying to access the port. + * ENODEV - The port cannot be configured as a vision sensor * * \param zero_point * One of vision_zero_e_t to set the (0,0) coordinate for the FOV @@ -403,8 +421,7 @@ class Vision { * * This functions uses the following values of errno when an error state is * reached: - * EINVAL - The given port is not within the range of V5 ports (1-21) - * EACCESS - Anothe resources is currently trying to access the port + * ENODEV - The port cannot be configured as a vision sensor * * \param enable * Disable Wi-Fi on the Vision sensor if 0, enable otherwise (e.g. 1) diff --git a/include/vdml/vdml.h b/include/vdml/vdml.h index f3c37e3f8..4bf83c0a7 100644 --- a/include/vdml/vdml.h +++ b/include/vdml/vdml.h @@ -40,11 +40,11 @@ */ #define claim_port(port, device_type) \ if (!VALIDATE_PORT_NO(port)) { \ - errno = EINVAL; \ + errno = ENXIO; \ return PROS_ERR; \ } \ if (registry_validate_binding(port, device_type) != 0) { \ - errno = EINVAL; \ + errno = ENODEV; \ return PROS_ERR; \ } \ v5_smart_device_s_t* device = registry_get_device(port); \ diff --git a/src/devices/vdml_adi.c b/src/devices/vdml_adi.c index 2b36e8422..cd394a71f 100644 --- a/src/devices/vdml_adi.c +++ b/src/devices/vdml_adi.c @@ -133,13 +133,13 @@ static void set_gyro_tare(uint8_t port, double tare) { #define validate_motor(port) \ adi_port_config_e_t config = _adi_port_get_config(port); \ if (config != E_ADI_LEGACY_PWM && config != E_ADI_LEGACY_SERVO) { \ - errno = EINVAL; \ + errno = ENODEV; \ return PROS_ERR; \ } #define validate_twowire(port_top, port_bottom) \ if (abs(port_top - port_bottom) > 1) { \ - errno = EINVAL; \ + errno = ENXIO; \ return PROS_ERR; \ } \ int port; \ diff --git a/src/devices/vdml_vision.c b/src/devices/vdml_vision.c index c8f3ca220..ddf6bbd96 100644 --- a/src/devices/vdml_vision.c +++ b/src/devices/vdml_vision.c @@ -51,8 +51,7 @@ int32_t vision_get_object_count(uint8_t port) { vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id) { vision_object_s_t rtn; v5_smart_device_s_t* device; - int32_t err = claim_port_try(port - 1, E_DEVICE_VISION); - if (err == PROS_ERR) { + if (claim_port_try(port - 1, E_DEVICE_VISION) == PROS_ERR) { rtn.signature = VISION_OBJECT_ERR_SIG; return rtn; } @@ -64,7 +63,7 @@ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id) { } err = vexDeviceVisionObjectGet(device->device_info, size_id, (V5_DeviceVisionObject*)&rtn); if (err == 0) { - errno = EHOSTDOWN; + errno = EAGAIN; rtn.signature = VISION_OBJECT_ERR_SIG; goto leave; } @@ -82,9 +81,7 @@ vision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint8_t count = 0; int32_t object_count = 0; - int32_t err = claim_port_try(port - 1, E_DEVICE_VISION); - if (err == PROS_ERR) { - errno = EINVAL; + if (claim_port_try(port - 1, E_DEVICE_VISION) == PROS_ERR) { goto err_return; } @@ -99,7 +96,7 @@ vision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const vision_object_s_t check; err = vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)&check); if (err == PROS_ERR) { - errno = EHOSTDOWN; + errno = EAGAIN; rtn = check; goto err_return; } @@ -113,6 +110,7 @@ vision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const count++; } } + errno = EDOM; // we read through all the objects and none matched sig_id and size_id err_return: port_mutex_give(port - 1); @@ -151,6 +149,8 @@ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t for (uint32_t i = size_id; i < c; i++) { if (!vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + i))) { + errno = EAGAIN; + object_arr[i] = VISION_OBJECT_ERR_SIG; break; } _vision_transform_coords(port - 1, &object_arr[i]); @@ -176,15 +176,21 @@ int32_t _vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t uint8_t count = 0; for (uint8_t i = 0; i < c; i++) { - vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + i)); + if (!vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + count))) { + errno = EAGAIN; + object_arr[i] = VISION_OBJECT_ERR_SIG; + goto rtn; + } if (object_arr[i].signature == sig_id) { if (count > size_id) { _vision_transform_coords(port - 1, &object_arr[i]); } count++; } - if (count == object_count) break; + if (count == object_count) goto rtn; } + errno = EDOM; // read through all objects and couldn't find enough objects matching filter parameters +rtn: return_port(port - 1, count); } @@ -227,7 +233,7 @@ vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_ } int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t* const signature_ptr) { - if (signature_id > 8 || signature_id == 0) { + if (signature_id > 7 || signature_id == 0) { errno = EINVAL; return PROS_ERR; } @@ -334,11 +340,11 @@ int32_t vision_get_white_balance(uint8_t port) { int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point) { if (!VALIDATE_PORT_NO(port - 1)) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } if (registry_validate_binding(port - 1, E_DEVICE_VISION) != 0) { - errno = EINVAL; + errno = ENODEV; return PROS_ERR; } if (!port_mutex_take(port - 1)) { From 99dd577f89265043ddaf8e409a967e9e2aa7872b Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Tue, 26 Feb 2019 10:45:39 -0500 Subject: [PATCH 02/10] Update vdml_vision.c --- src/devices/vdml_vision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/vdml_vision.c b/src/devices/vdml_vision.c index ddf6bbd96..e18ca7bf5 100644 --- a/src/devices/vdml_vision.c +++ b/src/devices/vdml_vision.c @@ -61,7 +61,7 @@ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id) { rtn.signature = VISION_OBJECT_ERR_SIG; goto leave; } - err = vexDeviceVisionObjectGet(device->device_info, size_id, (V5_DeviceVisionObject*)&rtn); + int err = vexDeviceVisionObjectGet(device->device_info, size_id, (V5_DeviceVisionObject*)&rtn); if (err == 0) { errno = EAGAIN; rtn.signature = VISION_OBJECT_ERR_SIG; From e5700ed8bf91352d91663df404345bd8bd33bca3 Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Tue, 26 Feb 2019 11:11:58 -0500 Subject: [PATCH 03/10] Update vdml_vision.c --- src/devices/vdml_vision.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/devices/vdml_vision.c b/src/devices/vdml_vision.c index de81e4c88..408c262b8 100644 --- a/src/devices/vdml_vision.c +++ b/src/devices/vdml_vision.c @@ -61,8 +61,7 @@ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id) { rtn.signature = VISION_OBJECT_ERR_SIG; goto leave; } - int err = vexDeviceVisionObjectGet(device->device_info, size_id, (V5_DeviceVisionObject*)&rtn); - if (err == 0) { + if (vexDeviceVisionObjectGet(device->device_info, size_id, (V5_DeviceVisionObject*)&rtn) == 0) { errno = EAGAIN; rtn.signature = VISION_OBJECT_ERR_SIG; goto leave; From 6824927ecbe53abc4eefe3dd20f8bbc9ed2b7cc2 Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Tue, 26 Feb 2019 11:19:15 -0500 Subject: [PATCH 04/10] Update vdml_vision.c --- src/devices/vdml_vision.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/devices/vdml_vision.c b/src/devices/vdml_vision.c index 408c262b8..1c615a945 100644 --- a/src/devices/vdml_vision.c +++ b/src/devices/vdml_vision.c @@ -93,8 +93,7 @@ vision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const for (uint8_t i = 0; i <= object_count; i++) { vision_object_s_t check; - err = vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)&check); - if (err == PROS_ERR) { + if (vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)&check) == PROS_ERR) { errno = EAGAIN; rtn = check; goto err_return; From 01f2c7901ae8676f4fb0cb4a3fd5d21dfa93ee44 Mon Sep 17 00:00:00 2001 From: Alex Brooke Date: Sun, 10 Mar 2019 00:26:38 -0500 Subject: [PATCH 05/10] Apply suggestions from code review Co-Authored-By: edjubuh --- src/devices/vdml_vision.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/vdml_vision.c b/src/devices/vdml_vision.c index 1c615a945..5e2da0d36 100644 --- a/src/devices/vdml_vision.c +++ b/src/devices/vdml_vision.c @@ -148,7 +148,7 @@ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t for (uint32_t i = size_id; i < c; i++) { if (!vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + i))) { errno = EAGAIN; - object_arr[i] = VISION_OBJECT_ERR_SIG; + object_arr[i].signature = VISION_OBJECT_ERR_SIG; break; } _vision_transform_coords(port - 1, &object_arr[i]); @@ -176,7 +176,7 @@ int32_t _vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t for (uint8_t i = 0; i < c; i++) { if (!vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + count))) { errno = EAGAIN; - object_arr[i] = VISION_OBJECT_ERR_SIG; + object_arr[i].signature = VISION_OBJECT_ERR_SIG; goto rtn; } if (object_arr[i].signature == sig_id) { From 7b865af229cbd47a185aa428a2291fa7e3872c51 Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Sun, 10 Mar 2019 00:36:55 -0500 Subject: [PATCH 06/10] Fix whitespace --- include/vdml/vdml.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/vdml/vdml.h b/include/vdml/vdml.h index 4bf83c0a7..de3dd039d 100644 --- a/include/vdml/vdml.h +++ b/include/vdml/vdml.h @@ -39,19 +39,19 @@ * The v5_device_e_t that the port is configured as */ #define claim_port(port, device_type) \ - if (!VALIDATE_PORT_NO(port)) { \ - errno = ENXIO; \ - return PROS_ERR; \ - } \ - if (registry_validate_binding(port, device_type) != 0) { \ - errno = ENODEV; \ - return PROS_ERR; \ - } \ - v5_smart_device_s_t* device = registry_get_device(port); \ - if (!port_mutex_take(port)) { \ - errno = EACCES; \ - return PROS_ERR; \ - } + if (!VALIDATE_PORT_NO(port)) { \ + errno = ENXIO; \ + return PROS_ERR; \ + } \ + if (registry_validate_binding(port, device_type) != 0) { \ + errno = ENODEV; \ + return PROS_ERR; \ + } \ + v5_smart_device_s_t* device = registry_get_device(port); \ + if (!port_mutex_take(port)) { \ + errno = EACCES; \ + return PROS_ERR; \ + } /** * A function that executes claim_port for functions that do not return an @@ -84,8 +84,8 @@ int32_t claim_port_try(uint8_t port, v5_device_e_t type); * \return The rtn parameter */ #define return_port(port, rtn) \ - port_mutex_give(port); \ - return rtn; + port_mutex_give(port); \ + return rtn; /** * Bitmap to indicate if a port has had an error printed or not. From e4b2505a5cc9043c8150151a1b7a172b34a1f02b Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Sun, 10 Mar 2019 01:19:02 -0500 Subject: [PATCH 07/10] Fix up errno when mismatch/not connected --- include/pros/apix.h | 4 ++-- include/pros/motors.hpp | 2 +- include/vdml/registry.h | 10 +++++----- include/vdml/vdml.h | 11 +++++------ src/devices/registry.c | 18 ++++++++++-------- src/devices/vdml.c | 11 +++++------ src/devices/vdml_adi.c | 2 +- src/devices/vdml_vision.c | 3 ++- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/include/pros/apix.h b/include/pros/apix.h index ec2712e26..10a2d2371 100644 --- a/include/pros/apix.h +++ b/include/pros/apix.h @@ -382,7 +382,7 @@ typedef enum v5_device_e { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21), or a + * ENXIO - The given value is not within the range of V5 ports (1-21), or a * a different device than specified is plugged in. * EADDRINUSE - The port is already registered to another device. * @@ -402,7 +402,7 @@ int registry_bind_port(uint8_t port, v5_device_e_t device_type); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * * \param port * The port number to deregister diff --git a/include/pros/motors.hpp b/include/pros/motors.hpp index 0f19a8a59..d2dbc15a1 100644 --- a/include/pros/motors.hpp +++ b/include/pros/motors.hpp @@ -30,7 +30,7 @@ class Motor { * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a motor * * \param port diff --git a/include/vdml/registry.h b/include/vdml/registry.h index bc6aa72e1..2e32c24c1 100644 --- a/include/vdml/registry.h +++ b/include/vdml/registry.h @@ -40,7 +40,7 @@ void registry_update_types(); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * * \param port * The V5 port number from 1-21 @@ -55,7 +55,7 @@ v5_smart_device_s_t* registry_get_device(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * * \param port * The V5 port number from 0-32 @@ -70,7 +70,7 @@ v5_smart_device_s_t* registry_get_device_internal(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * * \param port * The V5 port number from 1-21 @@ -85,7 +85,7 @@ v5_device_e_t registry_get_bound_type(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * * \param port * The V5 port number from 1-21 @@ -105,7 +105,7 @@ v5_device_e_t registry_get_plugged_type(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * * \param port * The V5 port number from 1-21 diff --git a/include/vdml/vdml.h b/include/vdml/vdml.h index de3dd039d..80c6a46c4 100644 --- a/include/vdml/vdml.h +++ b/include/vdml/vdml.h @@ -44,7 +44,6 @@ return PROS_ERR; \ } \ if (registry_validate_binding(port, device_type) != 0) { \ - errno = ENODEV; \ return PROS_ERR; \ } \ v5_smart_device_s_t* device = registry_get_device(port); \ @@ -59,7 +58,7 @@ * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports (1-21). * EACCES - Another resource is currently trying to access the port. * * \param port @@ -138,7 +137,7 @@ void vdml_reset_port_error(); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (0-20). + * ENXIO - The given value is not within the range of V5 ports (0-20). * * \param port * The V5 port number to claim from 0-20 @@ -159,7 +158,7 @@ int port_mutex_take(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (0-20). + * ENXIO - The given value is not within the range of V5 ports (0-20). * * \param port * The V5 port number to free from 0-20 @@ -183,7 +182,7 @@ void port_mutex_give_all(); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (0-32). + * ENXIO - The given value is not within the range of V5 ports (0-32). * * \param port * The V5 port number from 0-32 @@ -201,7 +200,7 @@ int internal_port_mutex_take(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * EINVAL - The given value is not within the range of V5 ports (0-32). + * ENXIO - The given value is not within the range of V5 ports (0-32). * * \param port * The V5 port number from 0-32 diff --git a/src/devices/registry.c b/src/devices/registry.c index b274ecd16..e40772a36 100644 --- a/src/devices/registry.c +++ b/src/devices/registry.c @@ -46,7 +46,7 @@ void registry_update_types() { int registry_bind_port(uint8_t port, v5_device_e_t device_type) { if (!VALIDATE_PORT_NO(port)) { kprintf("[VDML][ERROR]Registration: Invalid port number %d\n", port + 1); - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } if (registry[port].device_type != E_DEVICE_NONE) { @@ -56,7 +56,7 @@ int registry_bind_port(uint8_t port, v5_device_e_t device_type) { } if ((v5_device_e_t)registry_types[port] != device_type && (v5_device_e_t)registry_types[port] != E_DEVICE_NONE) { kprintf("[VDML][ERROR]Registration: Device mismatch in port %d\n", port + 1); - errno = EINVAL; + errno = EADDRINUSE; return PROS_ERR; } kprintf("[VDML][INFO]Registering device in port %d\n", port + 1); @@ -70,7 +70,7 @@ int registry_bind_port(uint8_t port, v5_device_e_t device_type) { int registry_unbind_port(uint8_t port) { port--; if (!VALIDATE_PORT_NO(port)) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } registry[port].device_type = E_DEVICE_NONE; @@ -80,7 +80,7 @@ int registry_unbind_port(uint8_t port) { v5_smart_device_s_t* registry_get_device(uint8_t port) { if (!VALIDATE_PORT_NO(port)) { - errno = EINVAL; + errno = ENXIO; return NULL; } return ®istry[port]; @@ -88,7 +88,7 @@ v5_smart_device_s_t* registry_get_device(uint8_t port) { v5_smart_device_s_t* registry_get_device_internal(uint8_t port) { if (!VALIDATE_PORT_NO_INTERNAL(port)) { - errno = EINVAL; + errno = ENXIO; return NULL; } return ®istry[port]; @@ -96,7 +96,7 @@ v5_smart_device_s_t* registry_get_device_internal(uint8_t port) { v5_device_e_t registry_get_bound_type(uint8_t port) { if (!VALIDATE_PORT_NO(port)) { - errno = EINVAL; + errno = ENXIO; return E_DEVICE_UNDEFINED; } return registry[port].device_type; @@ -104,7 +104,7 @@ v5_device_e_t registry_get_bound_type(uint8_t port) { v5_device_e_t registry_get_plugged_type(uint8_t port) { if (!VALIDATE_PORT_NO(port)) { - errno = EINVAL; + errno = ENXIO; return -1; } return registry_types[port]; @@ -112,7 +112,7 @@ v5_device_e_t registry_get_plugged_type(uint8_t port) { int32_t registry_validate_binding(uint8_t port, v5_device_e_t expected_t) { if (!VALIDATE_PORT_NO(port)) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } @@ -137,6 +137,7 @@ int32_t registry_validate_binding(uint8_t port, v5_device_e_t expected_t) { kprintf("[VDML][WARNING] No device in port %d. Is it plugged in?\n", port + 1); vdml_set_port_error(port); } + errno = ENODEV; return 1; } else { // Warn about a mismatch @@ -144,6 +145,7 @@ int32_t registry_validate_binding(uint8_t port, v5_device_e_t expected_t) { kprintf("[VDML][WARNING] Device mistmatch in port %d.\n", port + 1); vdml_set_port_error(port); } + errno = EADDRINUSE; return 2; } } diff --git a/src/devices/vdml.c b/src/devices/vdml.c index de81f5cd0..8f0795013 100644 --- a/src/devices/vdml.c +++ b/src/devices/vdml.c @@ -31,11 +31,10 @@ extern void port_mutex_init(); int32_t claim_port_try(uint8_t port, v5_device_e_t type) { if (!VALIDATE_PORT_NO(port)) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } if (registry_validate_binding(port, type) != 0) { - errno = EINVAL; return PROS_ERR; } if (!port_mutex_take(port)) { @@ -77,7 +76,7 @@ void port_mutex_init() { int port_mutex_take(uint8_t port) { if (port >= V5_MAX_DEVICE_PORTS) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } return xTaskGetSchedulerState() != taskSCHEDULER_RUNNING || mutex_take(port_mutexes[port], TIMEOUT_MAX); @@ -85,7 +84,7 @@ int port_mutex_take(uint8_t port) { int internal_port_mutex_take(uint8_t port) { if (port >= V5_MAX_DEVICE_PORTS) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } return mutex_take(port_mutexes[port], TIMEOUT_MAX); @@ -99,7 +98,7 @@ static inline char* print_num(char* buff, int num) { int port_mutex_give(uint8_t port) { if (port >= V5_MAX_DEVICE_PORTS) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } return xTaskGetSchedulerState() != taskSCHEDULER_RUNNING || mutex_give(port_mutexes[port]); @@ -107,7 +106,7 @@ int port_mutex_give(uint8_t port) { int internal_port_mutex_give(uint8_t port) { if (port >= V5_MAX_DEVICE_PORTS) { - errno = EINVAL; + errno = ENXIO; return PROS_ERR; } return mutex_give(port_mutexes[port]); diff --git a/src/devices/vdml_adi.c b/src/devices/vdml_adi.c index 978559a3f..e52f374e2 100644 --- a/src/devices/vdml_adi.c +++ b/src/devices/vdml_adi.c @@ -114,7 +114,7 @@ static void set_gyro_tare(uint8_t port, double tare) { else \ port--; \ if (port > 7 || port < 0) { \ - errno = EINVAL; \ + errno = ENXIO; \ return PROS_ERR; \ } diff --git a/src/devices/vdml_vision.c b/src/devices/vdml_vision.c index 5e2da0d36..915f37b01 100644 --- a/src/devices/vdml_vision.c +++ b/src/devices/vdml_vision.c @@ -81,7 +81,7 @@ vision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const int32_t object_count = 0; if (claim_port_try(port - 1, E_DEVICE_VISION) == PROS_ERR) { - goto err_return; + goto err_return_no_mutex; } device = registry_get_device(port - 1); @@ -112,6 +112,7 @@ vision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const err_return: port_mutex_give(port - 1); +err_return_no_mutex: rtn.signature = VISION_OBJECT_ERR_SIG; return rtn; } From 64ed114943991718cf5c57718035ed61abb60bda Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Sun, 10 Mar 2019 01:24:20 -0500 Subject: [PATCH 08/10] Fix up errno when mismatch/not connected for ADI --- src/devices/vdml_adi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/devices/vdml_adi.c b/src/devices/vdml_adi.c index e52f374e2..22114d5c6 100644 --- a/src/devices/vdml_adi.c +++ b/src/devices/vdml_adi.c @@ -133,7 +133,7 @@ static void set_gyro_tare(uint8_t port, double tare) { #define validate_motor(port) \ adi_port_config_e_t config = _adi_port_get_config(port); \ if (config != E_ADI_LEGACY_PWM && config != E_ADI_LEGACY_SERVO) { \ - errno = ENODEV; \ + errno = EADDRINUSE; \ return PROS_ERR; \ } @@ -148,6 +148,7 @@ static void set_gyro_tare(uint8_t port, double tare) { else if (port_bottom < port_top) \ port = port_bottom; \ else \ + errno = EINVAL; \ return PROS_ERR; \ if (port % 2 == 1) { \ return PROS_ERR; \ From 9b2e651ff130b7e7aa391702d02e7793552f4de1 Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Sun, 10 Mar 2019 01:39:28 -0500 Subject: [PATCH 09/10] Fix up errno when mismatched/not connected for ADI round 2 --- include/pros/adi.h | 20 ++++++++++++++++++++ src/devices/vdml_adi.c | 14 ++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/pros/adi.h b/include/pros/adi.h index 330ef90f7..272226257 100644 --- a/include/pros/adi.h +++ b/include/pros/adi.h @@ -258,6 +258,7 @@ int32_t adi_analog_calibrate(uint8_t port); * 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 * * \param port * The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be @@ -280,6 +281,7 @@ int32_t adi_analog_read(uint8_t port); * 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 * * \param port * The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be @@ -307,6 +309,7 @@ int32_t adi_analog_read_calibrated(uint8_t port); * 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 * * \param port * The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be @@ -329,6 +332,7 @@ int32_t adi_analog_read_calibrated_HR(uint8_t port); * 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 * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -352,6 +356,7 @@ int32_t adi_digital_read(uint8_t port); * 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 * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -370,6 +375,7 @@ int32_t adi_digital_get_new_press(uint8_t port); * 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 * * \param port * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') @@ -406,6 +412,7 @@ int32_t adi_pin_mode(uint8_t port, uint8_t mode); * 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 * * \param port * The ADI port to set (from 1-8, 'a'-'h', 'A'-'H') @@ -425,6 +432,7 @@ int32_t adi_motor_set(uint8_t port, int8_t speed); * 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 * * \param port * The ADI port to get (from 1-8, 'a'-'h', 'A'-'H') @@ -440,6 +448,7 @@ int32_t adi_motor_get(uint8_t port); * 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 * * \param port * The ADI port to set (from 1-8, 'a'-'h', 'A'-'H') @@ -466,6 +475,7 @@ typedef int32_t adi_encoder_t; * 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 * * \param enc * The adi_encoder_t object from adi_encoder_init() to read @@ -482,6 +492,7 @@ int32_t adi_encoder_get(adi_encoder_t enc); * 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 * * \param port_top * The "top" wire from the encoder sensor with the removable cover side @@ -506,6 +517,7 @@ adi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, const bool * 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 * * \param enc * The adi_encoder_t object from adi_encoder_init() to reset @@ -522,6 +534,7 @@ int32_t adi_encoder_reset(adi_encoder_t enc); * 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 * * \param enc * The adi_encoder_t object from adi_encoder_init() to stop @@ -550,6 +563,7 @@ typedef int32_t adi_ultrasonic_t; * 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 * * \param ult * The adi_ultrasonic_t object from adi_ultrasonic_init() to read @@ -566,6 +580,7 @@ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult); * 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 * * \param port_ping * The port connected to the orange OUTPUT cable. This should be in the @@ -586,6 +601,7 @@ adi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo); * 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 * * \param ult * The adi_ultrasonic_t object from adi_ultrasonic_init() to stop @@ -615,6 +631,7 @@ typedef int32_t adi_gyro_t; * 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 * * \param gyro * The adi_gyro_t object for which the angle will be returned @@ -635,6 +652,7 @@ double adi_gyro_get(adi_gyro_t gyro); * 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 * * \param port * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') @@ -654,6 +672,7 @@ adi_gyro_t adi_gyro_init(uint8_t port, double multiplier); * 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 * * \param gyro * The adi_gyro_t object for which the angle will be returned @@ -670,6 +689,7 @@ int32_t adi_gyro_reset(adi_gyro_t gyro); * 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 * * \param gyro * The adi_gyro_t object to be shut down diff --git a/src/devices/vdml_adi.c b/src/devices/vdml_adi.c index 22114d5c6..29c966478 100644 --- a/src/devices/vdml_adi.c +++ b/src/devices/vdml_adi.c @@ -120,18 +120,32 @@ 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; \ } #define validate_motor(port) \ adi_port_config_e_t config = _adi_port_get_config(port); \ + if (config == E_ADI_TYPE_UNDEFINED) { \ + errno = ENODEV; \ + return PROS_ERR; \ + } \ if (config != E_ADI_LEGACY_PWM && config != E_ADI_LEGACY_SERVO) { \ errno = EADDRINUSE; \ return PROS_ERR; \ From afcbc3268437d7ec94288c6a6c7e18bbf8315d6a Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Sun, 10 Mar 2019 01:56:45 -0500 Subject: [PATCH 10/10] Fix up errno when mismatched/not connected for ADI round 3 --- include/pros/adi.h | 63 +++++++++++++++--------------------------- src/devices/vdml_adi.c | 10 +------ 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/include/pros/adi.h b/include/pros/adi.h index 272226257..9caac4fd0 100644 --- a/include/pros/adi.h +++ b/include/pros/adi.h @@ -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 @@ -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 @@ -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 @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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') @@ -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 @@ -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 diff --git a/src/devices/vdml_adi.c b/src/devices/vdml_adi.c index 29c966478..d24d02d33 100644 --- a/src/devices/vdml_adi.c +++ b/src/devices/vdml_adi.c @@ -120,10 +120,6 @@ 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; \ @@ -131,10 +127,6 @@ static void set_gyro_tare(uint8_t port, double tare) { #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; \ @@ -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); }