From 1e7513d4f110d2eac625b6300dbbb8c086ab6c0c Mon Sep 17 00:00:00 2001 From: noam987 <50681033+noam987@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:31:41 -0400 Subject: [PATCH 1/4] Update issue templates (#596) --- .github/ISSUE_TEMPLATE/bug_report.md | 31 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 19 ++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..154fb51c1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "\U0001F41B[BUG] - " +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS, Windows, Linux] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..bdfd284b7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,19 @@ +--- +name: Feature request +about: Suggest an idea for the PROS kernel +title: "✨[FEATURE REQUEST]" +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**What is the behavior that isn't addressed by the existing API?** + +**OPTIONAL Describe any solutions you've considered** +A clear and concise description of any solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From dbb45996a1b029b86f50bbf81a5ca2de6a6fb496 Mon Sep 17 00:00:00 2001 From: Gracelu128 <112266075+Gracelu128@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:54:18 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9BFixed=20Imu::is=5Fcalibrating?= =?UTF-8?q?=20function=20for=20PROS=203=20#626=20(#628)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated Imu::is_calibrating function * Update main.cpp * Updated enum for imu_status_e Update to properly reflect what get_status returns * Added comments to imu.h Elaborating on imu_status_e value types * Reverted main.cpp --- include/pros/imu.h | 3 ++- src/devices/vdml_imu.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/pros/imu.h b/include/pros/imu.h index f5a1cdc3d..9b8aedf65 100644 --- a/include/pros/imu.h +++ b/include/pros/imu.h @@ -29,7 +29,8 @@ namespace c { #endif typedef enum imu_status_e { - E_IMU_STATUS_CALIBRATING = 0x01, + E_IMU_STATUS_READY = 0, // IMU is connected but not currently calibrating + E_IMU_STATUS_CALIBRATING = 19, // IMU is calibrating E_IMU_STATUS_ERROR = 0xFF, // NOTE: used for returning an error from the get_status function, not that the IMU is // necessarily in an error state } imu_status_e_t; diff --git a/src/devices/vdml_imu.cpp b/src/devices/vdml_imu.cpp index 948c1294f..f4eddf3f3 100644 --- a/src/devices/vdml_imu.cpp +++ b/src/devices/vdml_imu.cpp @@ -62,7 +62,7 @@ pros::c::imu_status_e_t Imu::get_status() const { } bool Imu::is_calibrating() const { - return get_status() & pros::c::E_IMU_STATUS_CALIBRATING; + return get_status() == pros::c::E_IMU_STATUS_CALIBRATING; } std::int32_t Imu::tare_heading() const { From 4aa077d81cb317967434f2611ce2513063a84944 Mon Sep 17 00:00:00 2001 From: phinc23 <60949293+phinc23@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:54:56 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20Add=20to=20GPS=20API=20(#630)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added GPS api. Initial commit tested. * Doxygenized and reverted * Delete version * Delete main * Revert "Delete main" * Revert "Delete version" * Fixed version # * Added newlines * Doxygen typo fixes * Fixed degree range doxy --- include/pros/gps.h | 85 ++++++++++++++++++++++++++++++++++++++++ include/pros/gps.hpp | 75 +++++++++++++++++++++++++++++++++++ src/devices/vdml_gps.c | 47 +++++++++++++++++++++- src/devices/vdml_gps.cpp | 20 ++++++++++ 4 files changed, 226 insertions(+), 1 deletion(-) diff --git a/include/pros/gps.h b/include/pros/gps.h index 1b2e7e7ba..917f69387 100644 --- a/include/pros/gps.h +++ b/include/pros/gps.h @@ -188,6 +188,91 @@ double gps_get_error(uint8_t port); */ gps_status_s_t gps_get_status(uint8_t port); +/** + * Gets the X position in meters of the robot relative to the starting position. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The X position in meters. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ +double gps_get_x_position(uint8_t port); + +/** + * Gets the Y position in meters of the robot relative to the starting position. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The Y position in meters. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ +double gps_get_y_position(uint8_t port); + +/** + * Gets the pitch of the GPS in degrees relative to the starting orientation. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The pitch in (-90,90] degree values. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ +double gps_get_pitch(uint8_t port); + +/** + * Gets the roll of the GPS in degrees relative to the starting orientation. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The roll in (-180,180] degree values. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ +double gps_get_roll(uint8_t port); + +/** + * Gets the yaw of the GPS in degrees relative to the starting orientation. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The yaw in (-180,180] degree values. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ +double gps_get_yaw(uint8_t port); + /** * Get the heading in [0,360) degree values. * diff --git a/include/pros/gps.hpp b/include/pros/gps.hpp index fce40c2a4..f25bd6087 100644 --- a/include/pros/gps.hpp +++ b/include/pros/gps.hpp @@ -173,6 +173,81 @@ class Gps { */ virtual pros::c::gps_status_s_t get_status() const; + /** + * Gets the X position in meters of the robot relative to the starting position. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * + * \return The X position in meters. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ + virtual double get_x_position() const; + + /** + * Gets the Y position in meters of the robot relative to the starting position. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * + * \return The Y position in meters. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ + virtual double get_y_position() const; + + /** + * Gets the pitch of the GPS in degrees relative to the starting orientation. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * + * \return The pitch in [0,360) degree values. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ + virtual double get_pitch() const; + + /** + * Gets the roll of the GPS in degrees relative to the starting orientation. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * + * \return The roll in [0,360) degree values. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ + virtual double get_roll() const; + + /** + * Gets the yaw of the GPS in degrees relative to the starting orientation. + * + * 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 GPS + * EAGAIN - The sensor is still calibrating + * + * + * \return The yaw in [0,360) degree values. If the operation failed, + * returns PROS_ERR_F and errno is set. + */ + virtual double get_yaw() const; + /** * Get the heading in [0,360) degree values. * diff --git a/src/devices/vdml_gps.c b/src/devices/vdml_gps.c index 93b155006..32d044deb 100644 --- a/src/devices/vdml_gps.c +++ b/src/devices/vdml_gps.c @@ -87,6 +87,51 @@ gps_status_s_t gps_get_status(uint8_t port) { return_port(port - 1, rtv); } +double gps_get_x_position(uint8_t port) { + claim_port_f(port - 1, E_DEVICE_GPS); + double rtv = PROS_ERR_F; + V5_DeviceGpsAttitude data; + vexDeviceGpsAttitudeGet(device->device_info, &data, false); + rtv = data.position_x; + return_port(port - 1, rtv); +} + +double gps_get_y_position(uint8_t port) { + claim_port_f(port - 1, E_DEVICE_GPS); + double rtv = PROS_ERR_F; + V5_DeviceGpsAttitude data; + vexDeviceGpsAttitudeGet(device->device_info, &data, false); + rtv = data.position_y; + return_port(port - 1, rtv); +} + +double gps_get_pitch(uint8_t port) { + claim_port_f(port - 1, E_DEVICE_GPS); + double rtv = PROS_ERR_F; + V5_DeviceGpsAttitude data; + vexDeviceGpsAttitudeGet(device->device_info, &data, false); + rtv = data.pitch; + return_port(port - 1, rtv); +} + +double gps_get_roll(uint8_t port) { + claim_port_f(port - 1, E_DEVICE_GPS); + double rtv = PROS_ERR_F; + V5_DeviceGpsAttitude data; + vexDeviceGpsAttitudeGet(device->device_info, &data, false); + rtv = data.roll; + return_port(port - 1, rtv); +} + +double gps_get_yaw(uint8_t port) { + claim_port_f(port - 1, E_DEVICE_GPS); + double rtv = PROS_ERR_F; + V5_DeviceGpsAttitude data; + vexDeviceGpsAttitudeGet(device->device_info, &data, false); + rtv = data.yaw; + return_port(port - 1, rtv); +} + double gps_get_heading(uint8_t port) { claim_port_f(port - 1, E_DEVICE_GPS); double rtv = vexDeviceGpsDegreesGet(device->device_info); @@ -101,7 +146,7 @@ double gps_get_heading_raw(uint8_t port) { double gps_get_rotation(uint8_t port) { claim_port_f(port - 1, E_DEVICE_GPS); - double rtv = vexDeviceGpsRotationGet(device->device_info); + double rtv = vexDeviceGpsHeadingGet(device->device_info); return_port(port - 1, rtv); } diff --git a/src/devices/vdml_gps.cpp b/src/devices/vdml_gps.cpp index bc0d4e85a..df3d3efdb 100644 --- a/src/devices/vdml_gps.cpp +++ b/src/devices/vdml_gps.cpp @@ -43,6 +43,26 @@ pros::c::gps_status_s_t Gps::get_status() const { return pros::c::gps_get_status(_port); } +double Gps::get_x_position() const { + return pros::c::gps_get_x_position(_port); +} + +double Gps::get_y_position() const { + return pros::c::gps_get_y_position(_port); +} + +double Gps::get_pitch() const { + return pros::c::gps_get_pitch(_port); +} + +double Gps::get_roll() const { + return pros::c::gps_get_roll(_port); +} + +double Gps::get_yaw() const { + return pros::c::gps_get_yaw(_port); +} + double Gps::get_heading() const { return pros::c::gps_get_heading(_port); } From eec7d25188e5076ca70a3e16f4cf4c57ce79836d Mon Sep 17 00:00:00 2001 From: Richard Li <61027374+R11G@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:02:51 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9BADI=20mutex=20fix=20for=20pros?= =?UTF-8?q?=203=20(#636)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ADI mutex fixes for pros 3 * Remove extra -1 that are covered by the init * fix typo * remove printf --------- Co-authored-by: noam987 --- src/devices/vdml_ext_adi.c | 80 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/src/devices/vdml_ext_adi.c b/src/devices/vdml_ext_adi.c index 76de6db93..51f291ca5 100644 --- a/src/devices/vdml_ext_adi.c +++ b/src/devices/vdml_ext_adi.c @@ -30,15 +30,17 @@ // Theoretical calibration time is 1024ms, but in practice this seemed to be the // actual time that it takes. #define GYRO_CALIBRATION_TIME 1300 -#define MAX_LED 64 //maximum number of LEDs supported in one port +#define MAX_LED 64 // maximum number of LEDs supported in one port // These 2 functions aren't in v5_api.h but should be... so we're going to directly expose them with an extern "C". #ifdef __cplusplus extern "C" { #endif - // private addressable LED API - int32_t vexDeviceAdiAddrLedSet( V5_DeviceT device, uint32_t port, uint32_t *pData, uint32_t nOffset, uint32_t nLength, uint32_t options ); - int32_t vexAdiAddrLedSet( uint32_t index, uint32_t port, uint32_t *pData, uint32_t nOffset, uint32_t nLength, uint32_t options ); +// private addressable LED API +int32_t vexDeviceAdiAddrLedSet(V5_DeviceT device, uint32_t port, uint32_t* pData, uint32_t nOffset, uint32_t nLength, + uint32_t options); +int32_t vexAdiAddrLedSet(uint32_t index, uint32_t port, uint32_t* pData, uint32_t nOffset, uint32_t nLength, + uint32_t options); #ifdef __cplusplus } #endif @@ -74,26 +76,26 @@ typedef union adi_data { return PROS_ERR; \ } -#define validate_type(device, adi_port, smart_port, type) \ - adi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \ - if (config != type) { \ - errno = EADDRINUSE; \ - printf("Error: validate_type\n"); \ - return_port(smart_port, PROS_ERR); \ +#define validate_type(device, adi_port, smart_port, type) \ + adi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \ + if (config != type) { \ + errno = EADDRINUSE; \ + printf("Error: validate_type\n"); \ + return_port(smart_port, PROS_ERR); \ } -#define validate_type_f(device, adi_port, smart_port, type) \ +#define validate_type_f(device, adi_port, smart_port, type) \ adi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \ - if (config != type) { \ - errno = EADDRINUSE; \ - return_port(smart_port, PROS_ERR_F); \ + if (config != type) { \ + errno = EADDRINUSE; \ + return_port(smart_port, PROS_ERR_F); \ } -#define validate_motor(device, adi_port, smart_port) \ +#define validate_motor(device, adi_port, smart_port) \ adi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \ - if (config != E_ADI_LEGACY_PWM && config != E_ADI_LEGACY_SERVO) { \ - errno = EADDRINUSE; \ - return_port(smart_port, PROS_ERR); \ + if (config != E_ADI_LEGACY_PWM && config != E_ADI_LEGACY_SERVO) { \ + errno = EADDRINUSE; \ + return_port(smart_port, PROS_ERR); \ } /* @@ -290,7 +292,7 @@ int32_t ext_adi_encoder_get(ext_adi_encoder_t enc) { get_ports(enc, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ENCODER); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_ENCODER); int32_t rtn; adi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port]; @@ -306,7 +308,7 @@ int32_t ext_adi_encoder_reset(ext_adi_encoder_t enc) { get_ports(enc, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ENCODER); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_ENCODER); vexDeviceAdiValueSet(device->device_info, adi_port, 0); return_port(smart_port, 1); @@ -317,7 +319,7 @@ int32_t ext_adi_encoder_shutdown(ext_adi_encoder_t enc) { get_ports(enc, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ENCODER); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_ENCODER); vexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_TYPE_UNDEFINED); return_port(smart_port, 1); @@ -342,7 +344,7 @@ int32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult) { get_ports(ult, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ULTRASONIC); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_ULTRASONIC); int32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port); return_port(smart_port, rtn); @@ -353,7 +355,7 @@ int32_t ext_adi_ultrasonic_shutdown(ext_adi_ultrasonic_t ult) { get_ports(ult, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ULTRASONIC); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_ULTRASONIC); vexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_TYPE_UNDEFINED); return_port(smart_port, 1); @@ -389,7 +391,7 @@ double ext_adi_gyro_get(ext_adi_gyro_t gyro) { get_ports(gyro, smart_port, adi_port); transform_adi_port(adi_port); claim_port_f(smart_port, E_DEVICE_ADI); - validate_type_f(device, adi_port, smart_port - 1, E_ADI_LEGACY_GYRO); + validate_type_f(device, adi_port, smart_port, E_ADI_LEGACY_GYRO); double rtv = (double)vexDeviceAdiValueGet(device->device_info, adi_port); adi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port]; @@ -403,7 +405,7 @@ int32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro) { get_ports(gyro, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_GYRO); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_GYRO); adi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port]; adi_data->gyro_data.tare_value = vexDeviceAdiValueGet(device->device_info, adi_port); @@ -415,7 +417,7 @@ int32_t ext_adi_gyro_shutdown(ext_adi_gyro_t gyro) { get_ports(gyro, smart_port, adi_port); transform_adi_port(adi_port); claim_port_i(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_GYRO); + validate_type(device, adi_port, smart_port, E_ADI_LEGACY_GYRO); vexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_TYPE_UNDEFINED); return_port(smart_port, 1); } @@ -437,7 +439,7 @@ double ext_adi_potentiometer_get_angle(ext_adi_potentiometer_t potentiometer) { get_ports(potentiometer, smart_port, adi_port); transform_adi_port(adi_port); claim_port_f(smart_port, E_DEVICE_ADI); - validate_type(device, adi_port, smart_port - 1, E_ADI_ANALOG_IN); + validate_type(device, adi_port, smart_port, E_ADI_ANALOG_IN); adi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port]; switch (adi_data->potentiometer_data.potentiometer_type) { case E_ADI_POT_EDR: @@ -456,7 +458,7 @@ double ext_adi_potentiometer_get_angle(ext_adi_potentiometer_t potentiometer) { ext_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port) { transform_adi_port(adi_port); claim_port_i(smart_port - 1, E_DEVICE_ADI); - vexDeviceAdiPortConfigSet(device->device_info, adi_port, (V5_AdiPortConfiguration)E_ADI_DIGITAL_OUT); + vexDeviceAdiPortConfigSet(device->device_info, adi_port, (V5_AdiPortConfiguration)E_ADI_DIGITAL_OUT); return_port(smart_port - 1, merge_adi_ports(smart_port - 1, adi_port + 1)); } @@ -468,35 +470,35 @@ int32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_len validate_type(device, adi_port, smart_port, E_ADI_DIGITAL_OUT); if (buffer_length > MAX_LED) { buffer_length = MAX_LED; - } - else if (buffer == NULL || buffer_length < 1) - { + } else if (buffer == NULL || buffer_length < 1) { errno = EINVAL; - return PROS_ERR; + return_port(smart_port, PROS_ERR); } uint32_t rtv = (uint32_t)vexDeviceAdiAddrLedSet(device->device_info, adi_port, buffer, 0, buffer_length, 0); - return_port(smart_port, rtv); + return_port(smart_port, rtv); } -int32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position) { +int32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, + uint32_t pixel_position) { uint8_t smart_port, adi_port; get_ports(led, smart_port, adi_port); - claim_port_i(smart_port, E_DEVICE_ADI); + claim_port_i(smart_port, E_DEVICE_ADI); transform_adi_port(adi_port); validate_type(device, adi_port, smart_port, E_ADI_DIGITAL_OUT); - if(buffer == NULL || pixel_position < 0 || buffer_length >= MAX_LED || buffer_length < 1 || pixel_position > buffer_length - 1) { + if (buffer == NULL || pixel_position < 0 || buffer_length >= MAX_LED || buffer_length < 1 || + pixel_position > buffer_length - 1) { errno = EINVAL; return_port(smart_port, PROS_ERR); } buffer[pixel_position] = color; uint32_t rtv = (uint32_t)vexDeviceAdiAddrLedSet(device->device_info, adi_port, buffer, 0, buffer_length, 0); - return_port(smart_port - 1, rtv); + return_port(smart_port, rtv); } int32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color) { - for(int i = 0; i < buffer_length; i++){ + for (int i = 0; i < buffer_length; i++) { buffer[i] = color; - } + } return ext_adi_led_set(led, buffer, buffer_length); }