[Si443x] Added tolerance to float comparison (#165)

This commit is contained in:
Jan Gromeš 2020-07-16 17:55:43 +02:00 committed by GitHub
parent 4e943b5437
commit a525c40e55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -386,63 +386,64 @@ int16_t Si443x::setRxBandwidth(float rxBw) {
filterSet = ((rxBw - 60.286)/10.7000 + 0.5); filterSet = ((rxBw - 60.286)/10.7000 + 0.5);
// this is the "Lord help thee who tread 'ere" section - no way to approximate this mess // this is the "Lord help thee who tread 'ere" section - no way to approximate this mess
} else if(rxBw == 142.8) { /// \todo float tolerance equality as macro?
} else if(abs(rxBw - 142.8) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 1; decRate = 1;
filterSet = 4; filterSet = 4;
} else if(rxBw == 167.8) { } else if(abs(rxBw - 167.8) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 1; decRate = 1;
filterSet = 5; filterSet = 5;
} else if(rxBw == 181.1) { } else if(abs(rxBw - 181.1) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 1; decRate = 1;
filterSet = 6; filterSet = 6;
} else if(rxBw == 191.5) { } else if(abs(rxBw - 191.5) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 15; filterSet = 15;
} else if(rxBw == 225.1) { } else if(abs(rxBw - 225.1) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 1; filterSet = 1;
} else if(rxBw == 248.8) { } else if(abs(rxBw - 248.8) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 2; filterSet = 2;
} else if(rxBw == 269.3) { } else if(abs(rxBw - 269.3) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 3; filterSet = 3;
} else if(rxBw == 284.8) { } else if(abs(rxBw - 284.8) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 4; filterSet = 4;
} else if(rxBw == 335.5) { } else if(abs(rxBw -335.5) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 8; filterSet = 8;
} else if(rxBw == 391.8) { } else if(abs(rxBw - 391.8) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 9; filterSet = 9;
} else if(rxBw == 420.2) { } else if(abs(rxBw - 420.2) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 10; filterSet = 10;
} else if(rxBw == 468.4) { } else if(abs(rxBw - 468.4) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 11; filterSet = 11;
} else if(rxBw == 518.8) { } else if(abs(rxBw - 518.8) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 12; filterSet = 12;
} else if(rxBw == 577.0) { } else if(abs(rxBw - 577.0) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 13; filterSet = 13;
} else if(rxBw == 620.7) { } else if(abs(rxBw - 620.7) <= 0.001) {
bypass = SI443X_BYPASS_DEC_BY_3_ON; bypass = SI443X_BYPASS_DEC_BY_3_ON;
decRate = 0; decRate = 0;
filterSet = 14; filterSet = 14;