From 1c27f92284c7d4aff8511a0e43be4f498b49b669 Mon Sep 17 00:00:00 2001 From: Samruddhi Rahegaonkar Date: Wed, 18 Dec 2024 13:36:06 +0530 Subject: [PATCH 1/7] Fix: Display all implemented sensors in SensorActivity #2584 --- app/build.gradle.kts | 5 ++-- .../io/pslab/activity/SensorActivity.java | 23 ++++++++++--------- build.gradle.kts | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 78d0828e7..97a0f2c0d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -83,7 +83,6 @@ dependencies { implementation("com.github.mirrajabi:search-dialog:1.2.4") implementation(files("../libs/croller-release.aar")) implementation("com.github.BeppiMenozzi:Knob:1.9.0") - implementation("com.github.warkiz:IndicatorSeekBar:v2.1.1") implementation("com.github.Vatican-Cameos:CarouselPicker:1.2") implementation("com.github.anastr:speedviewlib:1.6.1") implementation("com.github.GoodieBag:ProtractorView:v1.2") @@ -118,5 +117,7 @@ dependencies { // OSS license plugin implementation("com.google.android.gms:play-services-oss-licenses:17.1.0") + implementation ("com.github.warkiz:IndicatorSeekBar:2.1.1") -} + +} \ No newline at end of file diff --git a/app/src/main/java/io/pslab/activity/SensorActivity.java b/app/src/main/java/io/pslab/activity/SensorActivity.java index 5e9021968..9be8333b6 100644 --- a/app/src/main/java/io/pslab/activity/SensorActivity.java +++ b/app/src/main/java/io/pslab/activity/SensorActivity.java @@ -74,17 +74,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } i2c = scienceLab.i2c; - sensorAddr.put(0x48, "ADS1115"); - sensorAddr.put(0x77, "BMP180"); - sensorAddr.put(0x5A, "MLX90614"); - sensorAddr.put(0x1E, "HMC5883L"); - sensorAddr.put(0x68, "MPU6050"); - sensorAddr.put(0x40, "SHT21"); - sensorAddr.put(0x39, "TSL2561"); - sensorAddr.put(0x69, "MPU925x"); - sensorAddr.put(0x29, "VL53L0X"); - sensorAddr.put(0x5A, "CCS811"); - sensorAddr.put(0x39, "APDS9960"); + sensorAddr.put(0x48, "ADS1115"); // Unique address for ADS1115 + sensorAddr.put(0x77, "BMP180"); // Unique address for BMP180 + sensorAddr.put(0x5A, "MLX90614"); // Unique address for MLX90614 + sensorAddr.put(0x1E, "HMC5883L"); // Unique address for HMC5883L + sensorAddr.put(0x68, "MPU6050"); // Unique address for MPU6050 + sensorAddr.put(0x40, "SHT21"); // Unique address for SHT21 + sensorAddr.put(0x39, "TSL2561"); // Unique address for TSL2561 + sensorAddr.put(0x69, "MPU925x"); // Unique address for MPU925x + sensorAddr.put(0x29, "VL53L0X"); // Unique address for VL53L0X + sensorAddr.put(0x3A, "CCS811"); // New unique address for CCS811 + sensorAddr.put(0x3B, "APDS9960"); // New unique address for APDS9960 + adapter = new ArrayAdapter<>(getApplication(), R.layout.sensor_list_item, R.id.tv_sensor_list_item, dataName); diff --git a/build.gradle.kts b/build.gradle.kts index d40e359b1..749d74de2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,5 +11,5 @@ buildscript { } plugins { - id("com.android.application") version "8.7.3" apply false -} + id("com.android.application") version "8.5.1" apply false +} \ No newline at end of file From 4ff8ce3a6be4752c46f71e6246bc5806fc16b604 Mon Sep 17 00:00:00 2001 From: Samruddhi Rahegaonkar Date: Wed, 25 Dec 2024 10:46:56 +0530 Subject: [PATCH 2/7] fix: Display all implemented sensors in SensorActivity --- .../io/pslab/activity/SensorActivity.java | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/SensorActivity.java b/app/src/main/java/io/pslab/activity/SensorActivity.java index 9be8333b6..d9e3765d4 100644 --- a/app/src/main/java/io/pslab/activity/SensorActivity.java +++ b/app/src/main/java/io/pslab/activity/SensorActivity.java @@ -40,16 +40,11 @@ import io.pslab.sensors.SensorTSL2561; import io.pslab.sensors.SensorVL53L0X; -/** - * Created by asitava on 18/6/17. - */ - public class SensorActivity extends GuideActivity { private I2C i2c; private ScienceLab scienceLab; - private final Map sensorAddr = new LinkedHashMap<>(); - private final List dataAddress = new ArrayList<>(); + private final Map> sensorAddr = new LinkedHashMap<>(); private final List dataName = new ArrayList<>(); private ArrayAdapter adapter; private ListView lvSensor; @@ -74,18 +69,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } i2c = scienceLab.i2c; - sensorAddr.put(0x48, "ADS1115"); // Unique address for ADS1115 - sensorAddr.put(0x77, "BMP180"); // Unique address for BMP180 - sensorAddr.put(0x5A, "MLX90614"); // Unique address for MLX90614 - sensorAddr.put(0x1E, "HMC5883L"); // Unique address for HMC5883L - sensorAddr.put(0x68, "MPU6050"); // Unique address for MPU6050 - sensorAddr.put(0x40, "SHT21"); // Unique address for SHT21 - sensorAddr.put(0x39, "TSL2561"); // Unique address for TSL2561 - sensorAddr.put(0x69, "MPU925x"); // Unique address for MPU925x - sensorAddr.put(0x29, "VL53L0X"); // Unique address for VL53L0X - sensorAddr.put(0x3A, "CCS811"); // New unique address for CCS811 - sensorAddr.put(0x3B, "APDS9960"); // New unique address for APDS9960 + // Initialize the sensor map + addSensorToMap(0x48, "ADS1115"); + addSensorToMap(0x77, "BMP180"); + addSensorToMap(0x5A, "MLX90614"); + addSensorToMap(0x5A, "CCS811"); // Duplicate address + addSensorToMap(0x1E, "HMC5883L"); + addSensorToMap(0x68, "MPU6050"); + addSensorToMap(0x40, "SHT21"); + addSensorToMap(0x39, "TSL2561"); + addSensorToMap(0x39, "APDS9960"); // Duplicate address + addSensorToMap(0x69, "MPU925x"); + addSensorToMap(0x29, "VL53L0X"); adapter = new ArrayAdapter<>(getApplication(), R.layout.sensor_list_item, R.id.tv_sensor_list_item, dataName); @@ -100,6 +96,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { tvSensorScan.setText(getResources().getString(R.string.scanning)); new PopulateSensors().execute(); }); + lvSensor.setOnItemClickListener((parent, view, position, id) -> { String itemValue = (String) lvSensor.getItemAtPosition(position); Intent intent; @@ -155,17 +152,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { }); } + private void addSensorToMap(int address, String sensorName) { + // Add the sensor to the map, creating a new list if necessary + sensorAddr.computeIfAbsent(address, k -> new ArrayList<>()).add(sensorName); + } + private class PopulateSensors extends AsyncTask { - private List data; + private List detectedAddresses; @Override protected Void doInBackground(Void... voids) { - data = new ArrayList<>(); + detectedAddresses = new ArrayList<>(); dataName.clear(); - dataAddress.clear(); + if (scienceLab.isConnected()) { try { - data = i2c.scan(null); + detectedAddresses = i2c.scan(null); } catch (IOException | NullPointerException e) { e.printStackTrace(); } @@ -177,31 +179,29 @@ protected Void doInBackground(Void... voids) { protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - StringBuilder tvData = new StringBuilder(); - if (data != null) { - for (Integer myInt : data) { - if (myInt != null && sensorAddr.get(myInt) != null) { - dataAddress.add(String.valueOf(myInt)); + if (scienceLab.isConnected() && detectedAddresses != null) { + for (Integer address : detectedAddresses) { + if (sensorAddr.containsKey(address)) { + dataName.addAll(sensorAddr.get(address)); } } - - for (final String s : dataAddress) { - tvData.append(s).append(":").append(sensorAddr.get(Integer.parseInt(s))).append("\n"); - } - - } else { - tvData.append(getResources().getString(R.string.sensor_not_connected)); } - for (int key : sensorAddr.keySet()) { - dataName.add(sensorAddr.get(key)); + // Add all sensors, even if not detected + for (List sensors : sensorAddr.values()) { + for (String sensor : sensors) { + if (!dataName.contains(sensor)) { + dataName.add(sensor); + } + } } if (scienceLab.isConnected()) { - tvSensorScan.setText(tvData); + tvSensorScan.setText(getString(R.string.not_connected)); } else { tvSensorScan.setText(getString(R.string.not_connected)); } + adapter.notifyDataSetChanged(); buttonSensorAutoScan.setClickable(true); } From 584f6c9adf7cbbe8da445dda4a194a069f237c20 Mon Sep 17 00:00:00 2001 From: Samruddhi Rahegaonkar Date: Wed, 25 Dec 2024 10:46:56 +0530 Subject: [PATCH 3/7] Fixed display All Sensors --- .../io/pslab/activity/SensorActivity.java | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/SensorActivity.java b/app/src/main/java/io/pslab/activity/SensorActivity.java index 9be8333b6..d9e3765d4 100644 --- a/app/src/main/java/io/pslab/activity/SensorActivity.java +++ b/app/src/main/java/io/pslab/activity/SensorActivity.java @@ -40,16 +40,11 @@ import io.pslab.sensors.SensorTSL2561; import io.pslab.sensors.SensorVL53L0X; -/** - * Created by asitava on 18/6/17. - */ - public class SensorActivity extends GuideActivity { private I2C i2c; private ScienceLab scienceLab; - private final Map sensorAddr = new LinkedHashMap<>(); - private final List dataAddress = new ArrayList<>(); + private final Map> sensorAddr = new LinkedHashMap<>(); private final List dataName = new ArrayList<>(); private ArrayAdapter adapter; private ListView lvSensor; @@ -74,18 +69,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } i2c = scienceLab.i2c; - sensorAddr.put(0x48, "ADS1115"); // Unique address for ADS1115 - sensorAddr.put(0x77, "BMP180"); // Unique address for BMP180 - sensorAddr.put(0x5A, "MLX90614"); // Unique address for MLX90614 - sensorAddr.put(0x1E, "HMC5883L"); // Unique address for HMC5883L - sensorAddr.put(0x68, "MPU6050"); // Unique address for MPU6050 - sensorAddr.put(0x40, "SHT21"); // Unique address for SHT21 - sensorAddr.put(0x39, "TSL2561"); // Unique address for TSL2561 - sensorAddr.put(0x69, "MPU925x"); // Unique address for MPU925x - sensorAddr.put(0x29, "VL53L0X"); // Unique address for VL53L0X - sensorAddr.put(0x3A, "CCS811"); // New unique address for CCS811 - sensorAddr.put(0x3B, "APDS9960"); // New unique address for APDS9960 + // Initialize the sensor map + addSensorToMap(0x48, "ADS1115"); + addSensorToMap(0x77, "BMP180"); + addSensorToMap(0x5A, "MLX90614"); + addSensorToMap(0x5A, "CCS811"); // Duplicate address + addSensorToMap(0x1E, "HMC5883L"); + addSensorToMap(0x68, "MPU6050"); + addSensorToMap(0x40, "SHT21"); + addSensorToMap(0x39, "TSL2561"); + addSensorToMap(0x39, "APDS9960"); // Duplicate address + addSensorToMap(0x69, "MPU925x"); + addSensorToMap(0x29, "VL53L0X"); adapter = new ArrayAdapter<>(getApplication(), R.layout.sensor_list_item, R.id.tv_sensor_list_item, dataName); @@ -100,6 +96,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { tvSensorScan.setText(getResources().getString(R.string.scanning)); new PopulateSensors().execute(); }); + lvSensor.setOnItemClickListener((parent, view, position, id) -> { String itemValue = (String) lvSensor.getItemAtPosition(position); Intent intent; @@ -155,17 +152,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { }); } + private void addSensorToMap(int address, String sensorName) { + // Add the sensor to the map, creating a new list if necessary + sensorAddr.computeIfAbsent(address, k -> new ArrayList<>()).add(sensorName); + } + private class PopulateSensors extends AsyncTask { - private List data; + private List detectedAddresses; @Override protected Void doInBackground(Void... voids) { - data = new ArrayList<>(); + detectedAddresses = new ArrayList<>(); dataName.clear(); - dataAddress.clear(); + if (scienceLab.isConnected()) { try { - data = i2c.scan(null); + detectedAddresses = i2c.scan(null); } catch (IOException | NullPointerException e) { e.printStackTrace(); } @@ -177,31 +179,29 @@ protected Void doInBackground(Void... voids) { protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - StringBuilder tvData = new StringBuilder(); - if (data != null) { - for (Integer myInt : data) { - if (myInt != null && sensorAddr.get(myInt) != null) { - dataAddress.add(String.valueOf(myInt)); + if (scienceLab.isConnected() && detectedAddresses != null) { + for (Integer address : detectedAddresses) { + if (sensorAddr.containsKey(address)) { + dataName.addAll(sensorAddr.get(address)); } } - - for (final String s : dataAddress) { - tvData.append(s).append(":").append(sensorAddr.get(Integer.parseInt(s))).append("\n"); - } - - } else { - tvData.append(getResources().getString(R.string.sensor_not_connected)); } - for (int key : sensorAddr.keySet()) { - dataName.add(sensorAddr.get(key)); + // Add all sensors, even if not detected + for (List sensors : sensorAddr.values()) { + for (String sensor : sensors) { + if (!dataName.contains(sensor)) { + dataName.add(sensor); + } + } } if (scienceLab.isConnected()) { - tvSensorScan.setText(tvData); + tvSensorScan.setText(getString(R.string.not_connected)); } else { tvSensorScan.setText(getString(R.string.not_connected)); } + adapter.notifyDataSetChanged(); buttonSensorAutoScan.setClickable(true); } From d1a92ae7bdaeee1be3db8a6d59d352c9eb334fc3 Mon Sep 17 00:00:00 2001 From: Samruddhi Rahegaonkar Date: Fri, 27 Dec 2024 21:04:39 +0530 Subject: [PATCH 4/7] Update SensorActivity.java Fix #2597 Alphabetical-order-sensor --- app/src/main/java/io/pslab/activity/SensorActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/pslab/activity/SensorActivity.java b/app/src/main/java/io/pslab/activity/SensorActivity.java index d9e3765d4..47cdae795 100644 --- a/app/src/main/java/io/pslab/activity/SensorActivity.java +++ b/app/src/main/java/io/pslab/activity/SensorActivity.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -195,6 +196,7 @@ protected void onPostExecute(Void aVoid) { } } } + Collections.sort(dataName); if (scienceLab.isConnected()) { tvSensorScan.setText(getString(R.string.not_connected)); From 3a0e685c60ebe8cbe8a786b26664d05bab71e617 Mon Sep 17 00:00:00 2001 From: Samruddhi Rahegaonkar Date: Fri, 10 Jan 2025 18:56:27 +0530 Subject: [PATCH 5/7] Fix:Alphabetical_order_sensor --- .../io/pslab/activity/SensorActivity.java | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/SensorActivity.java b/app/src/main/java/io/pslab/activity/SensorActivity.java index 47cdae795..bef0c4ea4 100644 --- a/app/src/main/java/io/pslab/activity/SensorActivity.java +++ b/app/src/main/java/io/pslab/activity/SensorActivity.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -41,11 +40,16 @@ import io.pslab.sensors.SensorTSL2561; import io.pslab.sensors.SensorVL53L0X; +/** + * Created by asitava on 18/6/17. + */ + public class SensorActivity extends GuideActivity { private I2C i2c; private ScienceLab scienceLab; private final Map> sensorAddr = new LinkedHashMap<>(); + private final List dataAddress = new ArrayList<>(); private final List dataName = new ArrayList<>(); private ArrayAdapter adapter; private ListView lvSensor; @@ -71,18 +75,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { i2c = scienceLab.i2c; - // Initialize the sensor map - addSensorToMap(0x48, "ADS1115"); - addSensorToMap(0x77, "BMP180"); - addSensorToMap(0x5A, "MLX90614"); - addSensorToMap(0x5A, "CCS811"); // Duplicate address - addSensorToMap(0x1E, "HMC5883L"); - addSensorToMap(0x68, "MPU6050"); - addSensorToMap(0x40, "SHT21"); - addSensorToMap(0x39, "TSL2561"); - addSensorToMap(0x39, "APDS9960"); // Duplicate address - addSensorToMap(0x69, "MPU925x"); - addSensorToMap(0x29, "VL53L0X"); + // Populate sensor addresses with multiple sensors mapped to the same address + sensorAddr.put(0x48, List.of("ADS1115")); + sensorAddr.put(0x77, List.of("BMP180")); + sensorAddr.put(0x5A, List.of("MLX90614", "CCS811")); + sensorAddr.put(0x1E, List.of("HMC5883L")); + sensorAddr.put(0x68, List.of("MPU6050")); + sensorAddr.put(0x40, List.of("SHT21")); + sensorAddr.put(0x39, List.of("TSL2561", "APDS9960")); + sensorAddr.put(0x69, List.of("MPU925x")); + sensorAddr.put(0x29, List.of("VL53L0X")); adapter = new ArrayAdapter<>(getApplication(), R.layout.sensor_list_item, R.id.tv_sensor_list_item, dataName); @@ -153,26 +155,24 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { }); } - private void addSensorToMap(int address, String sensorName) { - // Add the sensor to the map, creating a new list if necessary - sensorAddr.computeIfAbsent(address, k -> new ArrayList<>()).add(sensorName); - } - private class PopulateSensors extends AsyncTask { - private List detectedAddresses; + private List detectedSensors; @Override protected Void doInBackground(Void... voids) { - detectedAddresses = new ArrayList<>(); + detectedSensors = new ArrayList<>(); + dataAddress.clear(); dataName.clear(); if (scienceLab.isConnected()) { try { - detectedAddresses = i2c.scan(null); + // Perform I2C scan to detect connected sensors + detectedSensors = i2c.scan(null); } catch (IOException | NullPointerException e) { e.printStackTrace(); } } + return null; } @@ -180,30 +180,36 @@ protected Void doInBackground(Void... voids) { protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - if (scienceLab.isConnected() && detectedAddresses != null) { - for (Integer address : detectedAddresses) { - if (sensorAddr.containsKey(address)) { + StringBuilder scanResults = new StringBuilder(); + + // Populate the list with detected sensors + if (detectedSensors != null && scienceLab.isConnected()) { + for (Integer address : detectedSensors) { + if (address != null && sensorAddr.containsKey(address)) { + dataAddress.add(String.valueOf(address)); dataName.addAll(sensorAddr.get(address)); } } + + // Build scan results for detected sensors + for (final String address : dataAddress) { + scanResults.append(address).append(": ").append(sensorAddr.get(Integer.parseInt(address))).append("\n"); + } + tvSensorScan.setText(scanResults); } - // Add all sensors, even if not detected + // Ensure the full list of sensors is displayed, even if not connected for (List sensors : sensorAddr.values()) { - for (String sensor : sensors) { - if (!dataName.contains(sensor)) { - dataName.add(sensor); - } + if (!dataName.containsAll(sensors)) { + dataName.addAll(sensors); } } - Collections.sort(dataName); - if (scienceLab.isConnected()) { - tvSensorScan.setText(getString(R.string.not_connected)); - } else { + // Update scan message if no sensors were detected + if (detectedSensors == null || detectedSensors.isEmpty()) { tvSensorScan.setText(getString(R.string.not_connected)); } - + dataName.sort(String::compareTo); adapter.notifyDataSetChanged(); buttonSensorAutoScan.setClickable(true); } From ec28bb5f5be347c9c1e688b34da029f5f249327a Mon Sep 17 00:00:00 2001 From: Samruddhi Rahegaonkar Date: Sat, 11 Jan 2025 08:45:33 +0530 Subject: [PATCH 6/7] Fix : Rollback_changes --- app/build.gradle.kts | 2 -- build.gradle.kts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 05d5f7068..60cdb014b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -118,7 +118,5 @@ dependencies { // OSS license plugin implementation("com.google.android.gms:play-services-oss-licenses:17.1.0") - implementation ("com.github.warkiz:IndicatorSeekBar:2.1.1") - } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 749d74de2..d8cddfeef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,5 +11,5 @@ buildscript { } plugins { - id("com.android.application") version "8.5.1" apply false + id("com.android.application") version "8.7.3" apply false } \ No newline at end of file From acf6e20b0cbfd44b8696b73dee71e26fa19cbd90 Mon Sep 17 00:00:00 2001 From: Anashuman Singh Date: Sat, 11 Jan 2025 12:35:58 +0530 Subject: [PATCH 7/7] fix: general improvements --- app/build.gradle.kts | 2 +- build.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 60cdb014b..40cc38e09 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -119,4 +119,4 @@ dependencies { // OSS license plugin implementation("com.google.android.gms:play-services-oss-licenses:17.1.0") -} \ No newline at end of file +} diff --git a/build.gradle.kts b/build.gradle.kts index d8cddfeef..d40e359b1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,4 +12,4 @@ buildscript { plugins { id("com.android.application") version "8.7.3" apply false -} \ No newline at end of file +}