This commit is contained in:
Sacha Weatherstone 2023-05-21 12:58:05 +10:00
parent 3856459fce
commit 045c5f7dd5

View file

@ -263,22 +263,21 @@ export const FrequencyCalculator = (): JSX.Element => {
useEffect(() => { useEffect(() => {
const selectedRegion = RegionData.get(region); const selectedRegion = RegionData.get(region);
const selectedModemPreset = modemPresets.get(modemPreset); const selectedModemPreset = modemPresets.get(modemPreset);
const calculatedNumChannels = Math.floor( setNumChannels(
Math.floor(
(selectedRegion.freq_end - selectedRegion.freq_start) / (selectedRegion.freq_end - selectedRegion.freq_start) /
(selectedRegion.spacing + selectedModemPreset.bw / 1000), (selectedRegion.spacing + selectedModemPreset.bw / 1000),
),
); );
setNumChannels(calculatedNumChannels);
let updatedChannel = channel; if (channel >= numChannels) {
if (updatedChannel >= calculatedNumChannels) { setChannel(numChannels - 1);
updatedChannel = calculatedNumChannels - 1;
} }
setChannel(updatedChannel);
setChannelFrequency( setChannelFrequency(
selectedRegion.freq_start + selectedRegion.freq_start +
selectedModemPreset.bw / 2000 + selectedModemPreset.bw / 2000 +
updatedChannel * (selectedModemPreset.bw / 1000), channel * (selectedModemPreset.bw / 1000),
); );
}, [modemPreset, region, channel]); }, [modemPreset, region, channel]);