Despite how much my C has improve lately, I don't know what the problem is here. The math all works, and I've debugged that the code is actually being hit.
Short story: In the code below, after I set the value of the struct below, the values all still read 0
Short story: In the code below, after I set the value of the struct below, the values all still read 0
Code:
struct channelConfig {
int Min;
int Max;
int Zero;
int Safe;
float NegativeFactor;
float PositiveFactor;
float ZeroTime;
};
static struct channelConfig configuration[PPM_Channels_Used];
uint8_t subframeMillis = 2;
//Times are 1024 * the percentage of the pulse would be high for the value minus 1. (0-1023)
//Values should be based on actual servo needs.
//Test values current being used below are [0-8],256,512,768,512
void ConfigurePPMChannel(uint8_t channel, int minTime, int zeroTime,
int maxTime, int safeValue) {
if (channel >= PPM_Channels_Used || minTime == 0 || maxTime == 0
|| zeroTime == 0 || maxTime < zeroTime || zeroTime < minTime
|| minTime > 1023 || maxTime > 1023 || zeroTime > 1023
|| safeValue > 1023)
//Invalid values. (This isn't hit, which is good)
return;
configuration[channel].Min = minTime;
configuration[channel].Max = maxTime;
configuration[channel].Zero = zeroTime;
configuration[channel].Safe = safeValue;
configuration[channel].NegativeFactor = (.25f * subframeMillis * (zeroTime - minTime))
/(-512.0f);
configuration[channel].PositiveFactor = (.25f * subframeMillis * (maxTime - zeroTime))
/ (512.0f);
configuration[channel].ZeroTime = zeroTime / 512.0f;
if (configuration[channel].NegativeFactor > -1 || configuration[channel].PositiveFactor < 1)
Serial.println("Configuration Failure."); //This is always hit, but shouldn't be.
}