.pr_agent_accepted_suggestions - iNavFlight/inav GitHub Wiki

                     PR 11085 (2025-10-27)                    
[general] Avoid premature type casting to float

✅ Avoid premature type casting to float

In osdGet3DSpeed, declare vert_speed and hor_speed as float to prevent loss of precision from premature casting before the Pythagorean calculation.

src/main/io/osd_common.c [202-207]

 int16_t osdGet3DSpeed(void)
 {
-    int16_t vert_speed = getEstimatedActualVelocity(Z);
-    int16_t hor_speed = gpsSol.groundSpeed;
+    float vert_speed = getEstimatedActualVelocity(Z);
+    float hor_speed = gpsSol.groundSpeed;
     return (int16_t)calc_length_pythagorean_2D(hor_speed, vert_speed);
 }

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a loss of precision by prematurely casting a float return value to int16_t before a calculation, and the proposed change improves the accuracy of the result.



                     PR 11064 (2025-10-12)                    
[possible issue] Use dot operator for struct

✅ Use dot operator for struct

Replace the incorrect pointer member access operator -> with the direct member access operator . when accessing fields of satelites[i], as it is a struct, not a pointer.

src/main/io/gps_ublox.c [748-751]

 for(int i =_buffer.svinfo.numSvs; i < UBLOX_MAX_SIGNALS; ++i) {
-    satelites[i]->gnssId = 0xFF;
-    satelites[i]->svId = 0xFF;
+    satelites[i].gnssId = 0xFF;
+    satelites[i].svId = 0xFF;
 }

Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a bug in the PR where the -> operator is used on a struct instance (satelites[i]) instead of a pointer, which would cause a compilation error.



                     PR 11045 (2025-09-28)                    
[possible issue] Update max enum values

✅ Update max enum values

Update CURRENT_SENSOR_MAX and VOLTAGE_SENSOR_MAX in their respective enums to CURRENT_SENSOR_SMARTPORT to correctly reflect the new maximum value.

src/main/sensors/battery_config_structs.h [28-45]

 typedef enum {
     CURRENT_SENSOR_NONE = 0,
     CURRENT_SENSOR_ADC,
     CURRENT_SENSOR_VIRTUAL,
     CURRENT_SENSOR_FAKE,
     CURRENT_SENSOR_ESC,
     CURRENT_SENSOR_SMARTPORT,
-    CURRENT_SENSOR_MAX = CURRENT_SENSOR_FAKE
+    CURRENT_SENSOR_MAX = CURRENT_SENSOR_SMARTPORT
 } currentSensor_e;
 
 typedef enum {
     VOLTAGE_SENSOR_NONE = 0,
     VOLTAGE_SENSOR_ADC,
     VOLTAGE_SENSOR_ESC,
     VOLTAGE_SENSOR_FAKE,
     VOLTAGE_SENSOR_SMARTPORT,
-    VOLTAGE_SENSOR_MAX = VOLTAGE_SENSOR_FAKE
+    VOLTAGE_SENSOR_MAX = VOLTAGE_SENSOR_SMARTPORT
 } voltageSensor_e;

Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a bug where the _MAX values in two enums were not updated after adding new members, which could lead to out-of-bounds memory access.



                     PR 10994 (2025-08-02)                    
[possible issue] Reset all magnetometer axes

✅ Reset all magnetometer axes

The Y-axis is not being reset to zero in case of failed read, which could leave stale data. All three axes should be reset to maintain consistency and prevent potential issues with outdated magnetometer readings.

src/main/drivers/compass/compass_qmc5883p.c [131-133]

 // set magData to zero for case of failed read
 mag->magADCRaw[X] = 0;
+mag->magADCRaw[Y] = 0;
 mag->magADCRaw[Z] = 0;

Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a bug where only the X and Z axes are cleared, potentially leaving stale data in the Y axis upon a failed read, which could lead to incorrect sensor fusion.



                     PR 10986 (2025-07-27)                    
[possible issue] Use static allocation for array

✅ Use static allocation for array

The array servoMixerSwitchHelper is allocated on the stack with a size that could be large (MAX_SERVO_RULES/2). This could cause stack overflow in embedded systems with limited stack space. Consider using static allocation or dynamic allocation instead.

src/main/flight/servos.c [211-227]

 //move the rate filter to new servo rules
 int maxMoveFilters = MAX_SERVO_RULES/2;
 int movefilterCount = 0;
-servoMixerSwitch_t servoMixerSwitchHelper[maxMoveFilters]; // helper to keep track of servoSpeedLimitFilter of servo rules
+static servoMixerSwitch_t servoMixerSwitchHelper[MAX_SERVO_RULES/2]; // helper to keep track of servoSpeedLimitFilter of servo rules
 memset(servoMixerSwitchHelper, 0, sizeof(servoMixerSwitchHelper));
 for (int i = 0; i < servoRuleCount; i++) {
     if(currentServoMixer[i].inputSource == INPUT_MIXER_SWITCH_HELPER || movefilterCount >= maxMoveFilters) {
         break;
     }
     if(currentServoMixer[i].speed != 0 && servoSpeedLimitFilter[i].state !=0) {
         servoMixerSwitchHelper[movefilterCount].targetChannel = currentServoMixer[i].targetChannel;
         servoMixerSwitchHelper[movefilterCount].speed = currentServoMixer[i].speed;
         servoMixerSwitchHelper[movefilterCount].rate = currentServoMixer[i].rate;
         servoMixerSwitchHelper[movefilterCount].speedLimitFilterState = servoSpeedLimitFilter[i].state;
         movefilterCount++;
     }
 }

Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a potential stack overflow risk by allocating a large array on the stack in an embedded environment and proposes using static allocation, which is a critical fix for system stability.



                     PR 10954 (2025-07-08)                    
[general] Remove duplicate macro definition

✅ Remove duplicate macro definition

The USE_OSD macro is defined twice in the file. This duplication is unnecessary and could lead to preprocessor warnings or confusion during compilation.

src/main/target/HUMMINGBIRD_FC305/target.h [81-161]

 #define USE_OSD
 #define USE_MAX7456
-MAX7456_SPI_BUS		    BUS_SPI3
+#define MAX7456_SPI_BUS		    BUS_SPI3
 #define MAX7456_CS_PIN          PC13
-...
-#define USE_OSD

Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies that the USE_OSD macro is defined twice (lines 81 and 161), and removing the redundant definition improves code quality.



                     PR 10895 (2025-05-28)                    
[possible issue] Use correct timer auto-detection macro

✅ Use correct timer auto-detection macro

In src/main/target/BOTWINGF722/target.c, replace TIM_USE_ANY with the correct TIM_USE_OUTPUT_AUTO macro for all motor and servo timer definitions to ensure proper timer allocation.

src/main/target/BOTWINGF722/target.c [19-25]

-// not able to fins any "TIM_USE_AUTO" DEFINED INSIDE THE typedef enum in timer.h file so used "   TIM_USE_ANY" INSTEAD .
-DEF_TIM(TIM3, CH1, PB4,  TIM_USE_ANY, 0, 0), // S1
-DEF_TIM(TIM3, CH2, PB5,  TIM_USE_ANY, 0, 0), // S2
-DEF_TIM(TIM3, CH3, PB0,  TIM_USE_ANY, 0, 0), // S3
-DEF_TIM(TIM3, CH4, PB1,  TIM_USE_ANY, 0, 0), // S4
-DEF_TIM(TIM2, CH1, PA15, TIM_USE_ANY, 0, 0),// Servo 1
-DEF_TIM(TIM2, CH2, PB3,  TIM_USE_ANY, 0, 0),// Servo 2
+DEF_TIM(TIM3, CH1, PB4,  TIM_USE_OUTPUT_AUTO, 0, 0), // S1
+DEF_TIM(TIM3, CH2, PB5,  TIM_USE_OUTPUT_AUTO, 0, 0), // S2
+DEF_TIM(TIM3, CH3, PB0,  TIM_USE_OUTPUT_AUTO, 0, 0), // S3
+DEF_TIM(TIM3, CH4, PB1,  TIM_USE_OUTPUT_AUTO, 0, 0), // S4
+DEF_TIM(TIM2, CH1, PA15, TIM_USE_OUTPUT_AUTO, 0, 0),// Servo 1
+DEF_TIM(TIM2, CH2, PB3,  TIM_USE_OUTPUT_AUTO, 0, 0),// Servo 2

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that TIM_USE_OUTPUT_AUTO should be used instead of TIM_USE_ANY, fixing a mistake the developer explicitly noted in a comment, which improves correctness.


[general] Configure second PINIO box as defined

✅ Configure second PINIO box as defined

Configure the second PINIO box (USER2) in src/main/target/BOTWINGF722/config.c to match the two PINIO pins defined in the corresponding target.h file.

src/main/target/BOTWINGF722/config.c [25]

 pinioBoxConfigMutable()->permanentId[0] = BOX_PERMANENT_ID_USER1;
+pinioBoxConfigMutable()->permanentId[1] = BOX_PERMANENT_ID_USER2;

Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that the configuration for the second PINIO pin, defined in the header, is missing, likely an oversight. Applying this change would enable the intended hardware feature.



⚠️ **GitHub.com Fallback** ⚠️