I know that an unsigned number can never be less than 0 and there is no need to test for it. But I want to avoid bogus frequencies for the tuner.
/* freqKHz is in KHz (duh) */
void videoinput_set_tuner_freq( videoinput_t *vidin, int freqKHz )
{
unsigned long frequency = freqKHz;
if( videoinput_has_tuner( vidin ) ) {
if( frequency < 0 ) {
/* Ignore bogus frequencies. */
return;
}
frequency *= 16;
vidin->tunerlow = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 1 : 0;
if( !vidin->tunerlow ) {
frequency /= 1000; /* switch to MHz */
}
...
}
Is it possible to make this check in another way (maybe with a limit)?
Come up with a better definition of a "bogus" frequency that a value that can't possibly exist.
The digital driver does not set the frequency if it has not changed since it was tuned. The analog tuner driver knows nothing about the frequency saved by the digital driver. When the frequency is set using the video4linux code, the hardware get changed but the digital driver's state does not get updated.
1 As you are converting
performing a sign check make sense of
2 A subsequent check for a reasonable bound, per you application, is also good practice. Of course the min check could be combine with the above.
3 Recommend a rounded conversion: