-
Notifications
You must be signed in to change notification settings - Fork 807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Display all implemented sensors in SensorActivity #2584 #2589
base: development
Are you sure you want to change the base?
Changes from all commits
1c27f92
4ff8ce3
584f6c9
9321d17
929990e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some changes which arn't required. You can just rollback |
||
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") | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ public class SensorActivity extends GuideActivity { | |
|
||
private I2C i2c; | ||
private ScienceLab scienceLab; | ||
private final Map<Integer, String> sensorAddr = new LinkedHashMap<>(); | ||
private final Map<Integer, List<String>> sensorAddr = new LinkedHashMap<>(); | ||
private final List<String> dataAddress = new ArrayList<>(); | ||
private final List<String> dataName = new ArrayList<>(); | ||
private ArrayAdapter<String> adapter; | ||
|
@@ -74,17 +74,17 @@ 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"); | ||
|
||
// 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); | ||
|
||
|
@@ -99,6 +99,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; | ||
|
@@ -152,55 +153,69 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { | |
"Sensor Not Supported", null, null, Snackbar.LENGTH_SHORT); | ||
} | ||
}); | ||
|
||
// Populate the full list of sensors initially | ||
for (List<String> sensors : sensorAddr.values()) { | ||
dataName.addAll(sensors); | ||
} | ||
adapter.notifyDataSetChanged(); | ||
} | ||
|
||
private class PopulateSensors extends AsyncTask<Void, Void, Void> { | ||
private List<Integer> data; | ||
private List<Integer> detectedSensors; | ||
|
||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
data = new ArrayList<>(); | ||
dataName.clear(); | ||
detectedSensors = new ArrayList<>(); | ||
dataAddress.clear(); | ||
dataName.clear(); | ||
|
||
if (scienceLab.isConnected()) { | ||
try { | ||
data = i2c.scan(null); | ||
// Perform I2C scan to detect connected sensors | ||
detectedSensors = i2c.scan(null); | ||
} catch (IOException | NullPointerException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
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)); | ||
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)); | ||
} | ||
} | ||
|
||
for (final String s : dataAddress) { | ||
tvData.append(s).append(":").append(sensorAddr.get(Integer.parseInt(s))).append("\n"); | ||
// Build scan results for detected sensors | ||
for (final String address : dataAddress) { | ||
scanResults.append(address).append(": ").append(sensorAddr.get(Integer.parseInt(address))).append("\n"); | ||
} | ||
|
||
} else { | ||
tvData.append(getResources().getString(R.string.sensor_not_connected)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have to get this removed. |
||
tvSensorScan.setText(scanResults); | ||
} | ||
|
||
for (int key : sensorAddr.keySet()) { | ||
dataName.add(sensorAddr.get(key)); | ||
// Ensure the full list of sensors is displayed, even if not connected | ||
for (List<String> sensors : sensorAddr.values()) { | ||
if (!dataName.containsAll(sensors)) { | ||
dataName.addAll(sensors); | ||
} | ||
} | ||
|
||
if (scienceLab.isConnected()) { | ||
tvSensorScan.setText(tvData); | ||
} else { | ||
// Update scan message if no sensors were detected | ||
if (detectedSensors == null || detectedSensors.isEmpty()) { | ||
tvSensorScan.setText(getString(R.string.not_connected)); | ||
} | ||
|
||
adapter.notifyDataSetChanged(); | ||
buttonSensorAutoScan.setClickable(true); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ buildscript { | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rollback as discussed earlier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AsCress Sorry for late! please check the commit once. and suggest changes if needed. |
||
|
||
plugins { | ||
id("com.android.application") version "8.7.3" apply false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, some changes that arn't required. You can rollback these. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay @AsCress Thanks for Explaining me. I will do the needful ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AsCress Other than the SensorActivity the changes I have made because I was unable to run the application without making those changes. But after testing I will rollback it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AsCress to resolve this issue as you have said, I need to make changes in the method "PopulateSensors" to handle the cases where both having same addresses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samruddhi-Rahegaonkar The problem here is with the data structure that we are using to store the sensor addresses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AsCress Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samruddhi-Rahegaonkar Yep, that's one way. Go ahead and maybe try to implement whatever you find best in this PR. |
||
} | ||
id("com.android.application") version "8.5.1" apply false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rollback this whole file as discussed earlier.