altosui: Have single radio_to_frequency function
authorKeith Packard <keithp@keithp.com>
Tue, 9 Aug 2011 01:49:45 +0000 (18:49 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Aug 2011 01:50:55 +0000 (18:50 -0700)
This takes all three radio params (setting, cal, channel) and computes
the current frequency.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfig.java
altosui/AltosConvert.java

index d5d7d56..7312ea6 100644 (file)
@@ -320,8 +320,6 @@ public class AltosConfig implements ActionListener {
        }
 
        double frequency() {
-               System.out.printf("setting %d channel %d calibration %d\n",
-                                 radio_setting.get(), radio_channel.get(), radio_calibration.get());
                return AltosConvert.radio_to_frequency(radio_setting.get(),
                                                       radio_calibration.get(),
                                                       radio_channel.get());
index 6a9b699..c2ae9a5 100644 (file)
@@ -190,30 +190,24 @@ public class AltosConvert {
                return ignite / 32767 * 15.0;
        }
 
-       static double
-       radio_setting_to_frequency(int setting, int cal) {
+       static double radio_to_frequency(int setting, int cal, int channel) {
                double  f;
 
+               if (setting <= 0)
+                       setting = cal;
                f = 434.550 * setting / cal;
                /* Round to nearest 50KHz */
                f = Math.floor (20.0 * f + 0.5) / 20.0;
-               return f;
+               return f + channel * 0.100;
        }
 
-       static int
-       radio_frequency_to_setting(double frequency, int cal) {
+       static int radio_frequency_to_setting(double frequency, int cal) {
                double  set = frequency / 434.550 * cal;
 
                return (int) Math.floor (set + 0.5);
        }
 
-       static double
-       radio_channel_to_frequency(int channel) {
-               return 434.550 + channel * 0.100;
-       }
-
-       static int
-       radio_frequency_to_channel(double frequency) {
+       static int radio_frequency_to_channel(double frequency) {
                int     channel = (int) Math.floor ((frequency - 434.550) / 0.100 + 0.5);
 
                if (channel < 0)
@@ -222,4 +216,8 @@ public class AltosConvert {
                        channel = 9;
                return channel;
        }
+
+       static double radio_channel_to_frequency(int channel) {
+               return 434.550 + channel * 0.100;
+       }
 }