|
27 | 27 | import org.altbeacon.beacon.MonitorNotifier; |
28 | 28 | import org.altbeacon.beacon.RangeNotifier; |
29 | 29 | import org.altbeacon.beacon.Region; |
| 30 | +import org.altbeacon.beacon.service.ArmaRssiFilter; |
| 31 | +import org.altbeacon.beacon.service.RunningAverageRssiFilter; |
30 | 32 |
|
31 | 33 | import java.util.Collection; |
32 | 34 | import java.util.HashMap; |
33 | 35 | import java.util.Map; |
34 | 36 |
|
35 | 37 | public class BeaconsAndroidModule extends ReactContextBaseJavaModule implements BeaconConsumer { |
36 | 38 | private static final String LOG_TAG = "BeaconsAndroidModule"; |
| 39 | + private static final int RUNNING_AVG_RSSI_FILTER = 0; |
| 40 | + private static final int ARMA_RSSI_FILTER = 1; |
37 | 41 | private ReactApplicationContext mReactContext; |
38 | 42 | private Context mApplicationContext; |
39 | 43 | private BeaconManager mBeaconManager; |
@@ -62,6 +66,8 @@ public Map<String, Object> getConstants() { |
62 | 66 | constants.put("NOT_SUPPORTED_BLE", BeaconTransmitter.NOT_SUPPORTED_BLE); |
63 | 67 | constants.put("NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS", BeaconTransmitter.NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS); |
64 | 68 | constants.put("NOT_SUPPORTED_CANNOT_GET_ADVERTISER", BeaconTransmitter.NOT_SUPPORTED_CANNOT_GET_ADVERTISER); |
| 69 | + constants.put("RUNNING_AVG_RSSI_FILTER",RUNNING_AVG_RSSI_FILTER); |
| 70 | + constants.put("ARMA_RSSI_FILTER",ARMA_RSSI_FILTER); |
65 | 71 | return constants; |
66 | 72 | } |
67 | 73 |
|
@@ -100,6 +106,27 @@ public void setForegroundBetweenScanPeriod(int period) { |
100 | 106 | mBeaconManager.setForegroundBetweenScanPeriod((long) period); |
101 | 107 | } |
102 | 108 |
|
| 109 | + @ReactMethod |
| 110 | + public void setRssiFilter(int filterType, double avgModifier) { |
| 111 | + String logMsg = "Could not set the rssi filter."; |
| 112 | + if (filterType==RUNNING_AVG_RSSI_FILTER){ |
| 113 | + logMsg="Setting filter RUNNING_AVG"; |
| 114 | + BeaconManager.setRssiFilterImplClass(RunningAverageRssiFilter.class); |
| 115 | + if (avgModifier>0){ |
| 116 | + RunningAverageRssiFilter.setSampleExpirationMilliseconds((long) avgModifier); |
| 117 | + logMsg+=" with custom avg modifier"; |
| 118 | + } |
| 119 | + } else if (filterType==ARMA_RSSI_FILTER){ |
| 120 | + logMsg="Setting filter ARMA"; |
| 121 | + BeaconManager.setRssiFilterImplClass(ArmaRssiFilter.class); |
| 122 | + if (avgModifier>0){ |
| 123 | + ArmaRssiFilter.setDEFAULT_ARMA_SPEED(avgModifier); |
| 124 | + logMsg+=" with custom avg modifier"; |
| 125 | + } |
| 126 | + } |
| 127 | + Log.d(LOG_TAG, logMsg); |
| 128 | + } |
| 129 | + |
103 | 130 | @ReactMethod |
104 | 131 | public void checkTransmissionSupported(Callback callback) { |
105 | 132 | int result = BeaconTransmitter.checkTransmissionSupported(mReactContext); |
|
0 commit comments