diff --git a/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyScanResults.java b/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyScanResults.java deleted file mode 100644 index 88850e315e..0000000000 --- a/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyScanResults.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Created by geoff on 5/30/16. - * changed by Andy 10/20/18 - */ -public class FrequencyScanResults { - - public List trials = new ArrayList<>(); - public double bestFrequencyMHz = 0.0; - public long dateTime; - - - public void sort() { - Collections.sort(trials, (trial1, trial2) -> { - int res = trial1.averageRSSI.compareTo(trial2.averageRSSI); - - if (res == 0) { - return (int)(trial1.frequencyMHz - trial2.frequencyMHz); - } else - return res; - - }); - } - -} diff --git a/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyScanResults.kt b/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyScanResults.kt new file mode 100644 index 0000000000..6c61f4f47b --- /dev/null +++ b/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyScanResults.kt @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data + +class FrequencyScanResults { + + @JvmField var trials: MutableList = ArrayList() + @JvmField var bestFrequencyMHz = 0.0 + @JvmField var dateTime: Long = 0 + fun sort() { + trials.sortWith { trial1: FrequencyTrial, trial2: FrequencyTrial -> + val res = trial1.averageRSSI.compareTo(trial2.averageRSSI) + if (res == 0) (trial1.frequencyMHz - trial2.frequencyMHz).toInt() + else res + } + } +} diff --git a/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyTrial.java b/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyTrial.java deleted file mode 100644 index af7dce6a98..0000000000 --- a/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyTrial.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by geoff on 5/30/16. - * changed by Andy 10/20/18 - */ -public class FrequencyTrial { - - public int tries = 0; - public int successes = 0; - public Double averageRSSI = 0.0; - public double frequencyMHz = 0.0; - public List rssiList = new ArrayList<>(); - public double averageRSSI2; - - - public void calculateAverage() { - int sum = 0; - int count = 0; - for (Integer rssi : rssiList) { - sum += Math.abs(rssi); - count++; - } - - double avg = (sum / (count * 1.0d)); - - if (count != 0) - this.averageRSSI = avg * (-1); - else - this.averageRSSI = -99.0d; - } -} diff --git a/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyTrial.kt b/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyTrial.kt new file mode 100644 index 0000000000..7e2d1399bd --- /dev/null +++ b/pump/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/FrequencyTrial.kt @@ -0,0 +1,26 @@ +package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data + +import kotlin.math.abs + +class FrequencyTrial { + + @JvmField var tries = 0 + @JvmField var successes = 0 + @JvmField var averageRSSI = 0.0 + @JvmField var frequencyMHz = 0.0 + @JvmField var rssiList: List = ArrayList() + @JvmField var averageRSSI2 = 0.0 + fun calculateAverage() { + var sum = 0 + var count = 0 + for (rssi in rssiList) { + sum += abs(rssi) + count++ + } + averageRSSI = + if (count != 0) { + val avg = sum / (count * 1.0) + avg * -1 + } else -99.0 + } +}