Mis wrote:This is high level of "C" coding : value = condition ? value_if_true : value_if_false; This is easy
If sevo[nr].middle have value less than RC_CHANS (e.g 0..11) this function return value from rc channel table indexed by servo[nr].middle. Example: If servo.middle have value of 5, then this function return value from rcData[5] that is eqievalent of AUX2 value. This is a part of conditional "(conf.servoConf[nr].middle < RC_CHANS)" statement before ":" if the condition is true.
In other case, if servo.middle is bigger than 12 (e.g 1500 or 1700) this function return directly the servo.middle value (1500 or 1700 in this case). This is a part of conditional "(conf.servoConf[nr].middle < RC_CHANS)" statement after ":" if the condition is false.
With this way you can assign predefined value for servo middle position, or assign any RC Channel for control servo middle position (setting value 0..11).
I know what C is.
I also know that servo[].middle is commented in the header to be "SERVO PWM VALUE, DEFAULT OF 1500".
So why the fuck it would EVER be an index into rcData[] array is absolutely fucking mindboggling.
This is not "high level of coding", this is high level of obfuscation and idiocy.
I"m not complaining about the ternary operator, I'm well aware of how it works.
I'm complaining about reusing a variable that's supposed to be a servo middle PWM value as an index into something else without absolutely any commenting or explanation or reason for why this is done.
Code: Select all
struct servo_conf_ { // this is a generic way to configure a servo, every multi type with a servo should use it
int16_t min; // minimum value, must be more than 1020 with the current implementation
int16_t max; // maximum value, must be less than 2000 with the current implementation
int16_t middle; [b]// default should be 1500[/b]
int8_t rate; // range [-100;+100] ; can be used to ajust a rate 0-100% and a direction
};