PhantomSDR Support Forum

General Category => General Discussion => Topic started by: Phil - NY4Q on Dec 01, 2024, 03:32 PM

Title: Band Button
Post by: Phil - NY4Q on Dec 01, 2024, 03:32 PM
This code works for band buttons (after you create the button code of course).

Place it in frontend/src/App.svelte

let band;
 let newFrequency;
 let newMode;
 let currentBand = 80;

 function setBand(band,newFrequency,newMode) {
   currentBand = band;
   frequencyInputComponent.setFrequency(newFrequency * 1e3);
   handleFrequencyChange({ detail: newFrequency * 1e3 });
   SetMode(newMode);
}

Feed it with :
setBand(80,3750,"LSB")
Title: Re: Band Button
Post by: Phil - NY4Q on Dec 01, 2024, 03:36 PM
Next I want to set the waterfall zoom to the width of the chosen band. If you know how to do that, please post your code in this thread.
Title: Re: Band Button
Post by: Phil - NY4Q on Dec 01, 2024, 07:36 PM
Update : This change will set the waterfall to the band edges, but you'll need to figure out the numbers for your situation.

function setBand(band,newFrequency,newMode) {
   currentBand = band;
   frequencyInputComponent.setFrequency(newFrequency * 1e3);
   handleFrequencyChange({ detail: newFrequency * 1e3 });
   SetMode(newMode);

   let [l, m, r] = audio.getAudioRange();
   const [waterfallL, waterfallR] = waterfall.getWaterfallRange();
   const offset = ((m - waterfallL) / (waterfallR - waterfallL)) * waterfall.canvasWidth;
   m = Math.min(waterfall.waterfallMaxSize - 512, Math.max(512, m));
   l = Math.floor(m - 512);
   r = Math.ceil(m + 512);
   switch (band) {
     case 2200:
       l -= 100;
       r += 100;
       break;
     case 630:
       l -= 200;
       r += 200;
       break;
     case 160:
       l -= 10000;
       r += 10000;
       break;
     case 80:
       l -= 20000;
       r += 20000;
       break;
    }
   waterfall.setWaterfallRange(l, r);
   frequencyMarkerComponent.updateFrequencyMarkerPositions();
   updatePassband();
}
Title: Re: Band Button
Post by: hb3xdc on Dec 02, 2024, 09:04 AM
Thank you, I'll try to adopt this as soon as I find time, by "figure out the numbers" you mean the l and r distance form center frequency? still dont get this fully, and how have you coded the button section in HTML?
Title: Re: Band Button
Post by: Phil - NY4Q on Dec 02, 2024, 11:07 AM
I used the same button code you did with the Step Selection and just made the some basic changes. I'll post one here.

The full setBand function :
let band;
 let newFrequency;
 let newMode;
 let currentBand = 80; // Set to your startup band or the wrong band button will be highlighted.
 function setBand(band,newFrequency,newMode) {
   currentBand = band;
   frequencyInputComponent.setFrequency(newFrequency * 1e3);
   handleFrequencyChange({ detail: newFrequency * 1e3 });
   SetMode(newMode);

   let [l, m, r] = audio.getAudioRange();
   const [waterfallL, waterfallR] = waterfall.getWaterfallRange();
   const offset = ((m - waterfallL) / (waterfallR - waterfallL)) * waterfall.canvasWidth;
   m = Math.min(waterfall.waterfallMaxSize - 512, Math.max(512, m));
   l = Math.floor(m - 512);
   r = Math.ceil(m + 512);
   switch (band) {
     case 2200:
       l -= 100;
       r += 100;
       break;
     case 630:
       l -= 200;
       r += 200;
       break;
     case 160:
       l -= 15000;
       r += 15000;
       break;
     case 80:
       l -= 35000;
       r += 35000;
       break;
     case 60:
       l -= 6000;
       r += 6000;
       break;
     case 42:
       l -= 1000;
       r += 1000;
       break;
     case 40:
       l -= 35000;
       r += 35000;
       break;
     case 31:
       l -= 1000;
       r += 1000;
       break;
     case 30:
      l -= 3300;
      r += 3300;
      break;
     case 20:
      l -= 30000;
      r += 30000;
      break;
     case 17:
       l -= 7500;
       r += 7500;
       break;
     case 15:
       l -= 35000;
       r += 35000;
       break;
     case 12:
       l -= 9000;
       r += 9000;
       break;
     case 11:
       l -= 35000;
       r += 35000;
       break;
     case 10:
       l -= 20000;
       r += 20000;
       break;
    }
   waterfall.setWaterfallRange(l, r);
   frequencyMarkerComponent.updateFrequencyMarkerPositions();
   updatePassband();
}

The button code :
<button class="retro-button text-white font-bold h-10 text-base rounded-md flex items-center justify-center border border-gray-600 shadow-inner transition-all duration-200 ease-in-out {currentBand === 2200 ? 'bg-blue-600 pressed scale-95' : 'bg-gray-700 hover:bg-gray-600'}" on:click={() => setBand(2200,136,"USB")} title="2200 meters" >2200m
</button>

I plan to simplify that function and pass the span information via the function and eliminate that switch(band) mess.

73,
Phil


Title: Re: Band Button
Post by: Phil - NY4Q on Dec 02, 2024, 12:24 PM
And thinking about this from an ergonomics standpoint, it'd be much tidier to use a drop down menu like the one that switches the waterfall types than build a bunch of buttons.

I think I will move to that and eliminate the buttons at some point, but for now at least the mobile users are happier.
Title: Re: Band Button
Post by: Emmanuel SV1BTL on Dec 02, 2024, 08:36 PM
Very, very good job Phil!!!
Title: Re: Band Button
Post by: Emmanuel SV1BTL on Dec 02, 2024, 10:49 PM
Using your code Phil, I think I've made it... http://sv1btlham.no-ip.org:8900/ (http://sv1btlham.no-ip.org:8900/)
Title: Re: Band Button
Post by: hb3xdc on Dec 02, 2024, 10:56 PM
Thank you Phil for your great work!

Also implemented on:
http://websdr.hb3xdc.ch:8074/
http://sardinia-sdr.ddns.net:8073/
http://rigi.dyndns-remote.com:8074/
http://zugsdr.ddns.net:8074/
Title: Re: Band Button
Post by: Emmanuel SV1BTL on Dec 13, 2024, 10:23 AM
Quote from: Phil - NY4Q on Dec 02, 2024, 11:07 AMI used the same button code you did with the Step Selection and just made the some basic changes. I'll post one here.

The full setBand function :
let band;
 let newFrequency;
 let newMode;
 let currentBand = 80; // Set to your startup band or the wrong band button will be highlighted.
 function setBand(band,newFrequency,newMode) {
   currentBand = band;
   frequencyInputComponent.setFrequency(newFrequency * 1e3);
   handleFrequencyChange({ detail: newFrequency * 1e3 });
   SetMode(newMode);

   let [l, m, r] = audio.getAudioRange();
   const [waterfallL, waterfallR] = waterfall.getWaterfallRange();
   const offset = ((m - waterfallL) / (waterfallR - waterfallL)) * waterfall.canvasWidth;
   m = Math.min(waterfall.waterfallMaxSize - 512, Math.max(512, m));
   l = Math.floor(m - 512);
   r = Math.ceil(m + 512);
   switch (band) {
     case 2200:
       l -= 100;
       r += 100;
       break;
     case 630:
       l -= 200;
       r += 200;
       break;
     case 160:
       l -= 15000;
       r += 15000;
       break;
     case 80:
       l -= 35000;
       r += 35000;
       break;
     case 60:
       l -= 6000;
       r += 6000;
       break;
     case 42:
       l -= 1000;
       r += 1000;
       break;
     case 40:
       l -= 35000;
       r += 35000;
       break;
     case 31:
       l -= 1000;
       r += 1000;
       break;
     case 30:
      l -= 3300;
      r += 3300;
      break;
     case 20:
      l -= 30000;
      r += 30000;
      break;
     case 17:
       l -= 7500;
       r += 7500;
       break;
     case 15:
       l -= 35000;
       r += 35000;
       break;
     case 12:
       l -= 9000;
       r += 9000;
       break;
     case 11:
       l -= 35000;
       r += 35000;
       break;
     case 10:
       l -= 20000;
       r += 20000;
       break;
    }
   waterfall.setWaterfallRange(l, r);
   frequencyMarkerComponent.updateFrequencyMarkerPositions();
   updatePassband();
}

The button code :
<button class="retro-button text-white font-bold h-10 text-base rounded-md flex items-center justify-center border border-gray-600 shadow-inner transition-all duration-200 ease-in-out {currentBand === 2200 ? 'bg-blue-600 pressed scale-95' : 'bg-gray-700 hover:bg-gray-600'}" on:click={() => setBand(2200,136,"USB")} title="2200 meters" >2200m
</button>

I plan to simplify that function and pass the span information via the function and eliminate that switch(band) mess.

73,
Phil




Phill, can we include "waterfall controls" to the script? I think it will be a good choice to change automatically "min" and "max" waterfall controls for every band, when a band button is pressed, instead of manually set the sliders, and when "min Zoom" is pressed, to return to default.
Title: Re: Band Button
Post by: Phil - NY4Q on Dec 13, 2024, 03:03 PM
Quote from: Emmanuel SV1BTL on Dec 13, 2024, 10:23 AMPhill, can we include "waterfall controls" to the script? I think it will be a good choice to change automatically "min" and "max" waterfall controls for every band, when a band button is pressed, instead of manually set the sliders, and when "min Zoom" is pressed, to return to default.

That should be a fairly easy addition, but I'd like to wait on this to see what Stephen is going to do in the next few days. I believe he posted that he plans to work on some code this month.
Title: Re: Band Button
Post by: Bas ON5HB on Dec 13, 2024, 06:12 PM
Yes he did say that. End of this month.