I was wondering if someone much more clever than me could help me with the following code I am trying to convert into Flowcode.
Most of the blocks I can understand the logic behind (including the for loop as well), but what I am really struggling to understand is the following line:
if (missTargetCounter++ > 2)
How would one translate this into Flowcode?? I don't see any other part in the code where the missTargetCounter variable increments, so how can this be done inside the if statement? I am really lost with this one and fail to see the logic of this part especially. When does really this counter go over 2? I don't understand this, I am not a programmer per se
This code is part of an automatic ADCOffset adjustment program of a video chip and there is no documentation for this bit, except for this code, that it is supposed to auto adjust the offset of the input signal.
If anyone can help with this it would be very much appreciated! Thanks in advance.
Code: Select all
void calibrateAdcOffset()
{
uint16_t hitTargetCounter = 0;
uint16_t readout16 = 0;
uint8_t missTargetCounter = 0;
uint8_t readout = 0;
unsigned long startTimer = 0;
for (uint8_t i = 0; i < 3; i++) {
while ((millis() - startTimer) < 800) {
readout16 = TEST_ADC::read() & 0x7fff;
if (readout16 < 7) {
hitTargetCounter++;
missTargetCounter = 0;
}
else if (missTargetCounter++ > 2) {
if (i == 0) {
ADC_1::write(ADC_1::read() + 1); // incr. offset
readout = ADC_1::read();
}
else if (i == 1) {
ADC_2::write(ADC_2::read() + 1);
readout = ADC_2::read();
}
else if (i == 2) {
ADC_3::write(ADC_3::read() + 1);
readout = ADC_3::read();
}
if (readout >= 0x52) {
break;
}
delay(10);
hitTargetCounter = 0;
missTargetCounter = 0;
startTimer = millis(); // extend timer
}
if (hitTargetCounter > 1500) {
break;
}
}
if (i == 0) {
adc1 = ADC_1::read();
}
if (i == 1) {
adc2 = ADC_2::read();
}
if (i == 2) {
adc3 = ADC_3::read();
}
}
if (readout >= 0x52) {
adc1 = adc2 = adc3 = 0x40;
}
}