Keep display freq within possible channels

This commit is contained in:
rcarteraz 2023-05-20 19:37:14 -07:00 committed by Sacha Weatherstone
parent a4234e9ae6
commit 3856459fce

View file

@ -263,16 +263,22 @@ 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);
setNumChannels( const calculatedNumChannels = Math.floor(
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 (updatedChannel >= calculatedNumChannels) {
updatedChannel = calculatedNumChannels - 1;
}
setChannel(updatedChannel);
setChannelFrequency( setChannelFrequency(
selectedRegion.freq_start + selectedRegion.freq_start +
selectedModemPreset.bw / 2000 + selectedModemPreset.bw / 2000 +
channel * (selectedModemPreset.bw / 1000), updatedChannel * (selectedModemPreset.bw / 1000),
); );
}, [modemPreset, region, channel]); }, [modemPreset, region, channel]);
@ -323,6 +329,7 @@ export const FrequencyCalculator = (): JSX.Element => {
))} ))}
</select> </select>
</div> </div>
<div className="flex gap-2"> <div className="flex gap-2">
<label className="font-semibold">Number of channels:</label> <label className="font-semibold">Number of channels:</label>
<input type="number" disabled value={numChannels} /> <input type="number" disabled value={numChannels} />