-
Notifications
You must be signed in to change notification settings - Fork 815
docs: Added automatic scalling for graphs #2708
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
base: development
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -57,6 +57,14 @@ protected void onCreate(Bundle savedInstanceState) { | |
actionBar.setTitle(title); | ||
} | ||
|
||
Button myButton = findViewById(R.id.myButton); | ||
myButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Toast.makeText(CompassActivity.this, "Button clicked!", Toast.LENGTH_SHORT).show(); | ||
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. issue (bug_risk): Incorrect context in Toast call Use SettingsActivity.this or simply this as the context to avoid confusion and potential memory leaks. |
||
} | ||
}); | ||
|
||
Fragment fragment; | ||
switch (title) { | ||
case PSLabSensor.LUXMETER_CONFIGURATIONS: | ||
|
@@ -95,12 +103,29 @@ protected void onCreate(Bundle savedInstanceState) { | |
getSupportFragmentManager().beginTransaction().add(R.id.content, fragment).commit(); | ||
} | ||
} | ||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.activity_compass_help_menu, menu); | ||
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. issue: Menu resource seems misnamed The use of 'activity_compass_help_menu' in SettingsActivity suggests a copy-paste error. Please use a menu resource appropriate for settings. |
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (item.getItemId() == android.R.id.home) { | ||
finish(); | ||
} | ||
int id = item.getItemId(); | ||
|
||
if (id == android.R.id.home) { | ||
finish(); | ||
return true; | ||
} else if (id == R.id.compass_record_data) { | ||
|
||
Toast.makeText(this, "Recording current compass data...", Toast.LENGTH_SHORT).show(); | ||
return true; | ||
} else if (id == R.id.compass_help_icon) { | ||
|
||
Toast.makeText(this, "Opening compass help...", Toast.LENGTH_SHORT).show(); | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ public SensorList() { | |
sensorList.put(0x5A, new String[]{"MLX90614 PIR temperature"}); | ||
sensorList.put(0x1E, new String[]{"HMC5883L magnetometer", "LSM303 magnetometer"}); | ||
sensorList.put(0x77, new String[]{"BMP180/GY-68 altimeter", "MS5607", "MS5611"}); | ||
sensorList.put(0x68, new String[]{"MPU-6050/GY-521 accel+gyro+temp", "ITG3200", "DS1307", "DS3231"}); | ||
sensorList.put(0x69, new String[]{"MPU-6050/GY-521 accel+gyro+temp", "ITG3200", "DS1307", "DS3231"}); | ||
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. issue (bug_risk): Conflicting sensorList key 0x69 is assigned to two different sensor sets, causing one to overwrite the other. Please ensure each key is unique or combine the sensor sets as needed. |
||
sensorList.put(0x69, new String[]{"ITG3200"}); | ||
sensorList.put(0x76, new String[]{"MS5607", "MS5611"}); | ||
sensorList.put(0x6B, new String[]{"LSM9DSO gyro"}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,6 +417,9 @@ private void writeLogToFile(long timestamp, float readingX, float readingY, floa | |
accelerometerSensor.writeHeaderToFile = true; | ||
} | ||
} | ||
public LineChart getChart() { | ||
return chart; | ||
} | ||
|
||
private void visualizeData() { | ||
for (int i = 0; i < accelerometerViewFragments.size(); i++) { | ||
|
@@ -435,7 +438,16 @@ private void visualizeData() { | |
LineData data = new LineData(dataSet); | ||
|
||
fragment.setChartData(data); | ||
|
||
fragment.setYaxis(highLimit); | ||
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. issue (bug_risk): Fixed Y-axis conflicting with auto-scaling Remove setYaxis(highLimit) to allow auto-scaling to function as intended. |
||
// ✅ Auto-scaling Y-axis | ||
LineChart chart = fragment.getChart(); // Assuming you have this getter method | ||
chart.setAutoScaleMinMaxEnabled(true); | ||
chart.getAxisLeft().resetAxisMaximum(); | ||
chart.getAxisLeft().resetAxisMinimum(); | ||
|
||
chart.notifyDataSetChanged(); | ||
chart.invalidate(); | ||
} | ||
} | ||
Long currentTime = System.currentTimeMillis(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,8 +108,6 @@ private enum THERMOMETER_SENSOR {INBUILT_SENSOR, SHT21_SENSOR} | |
private ArrayList<Entry> entries; | ||
private ArrayList<ThermometerData> recordedThermoArray; | ||
private ThermometerData sensorData; | ||
private float currentMin = 125; | ||
private float currentMax = -40; | ||
private YAxis y; | ||
private Unbinder unbinder; | ||
private long previousTimeElapsed = (System.currentTimeMillis() - startTime) / updatePeriod; | ||
|
@@ -166,6 +164,13 @@ public void onResume() { | |
entries.clear(); | ||
mChart.clear(); | ||
mChart.invalidate(); | ||
// Auto-scaling: reset min/max if using MPAndroidChart | ||
mChart.getAxisLeft().resetAxisMinimum(); | ||
mChart.getAxisLeft().resetAxisMaximum(); | ||
mChart.getAxisRight().resetAxisMinimum(); | ||
mChart.getAxisRight().resetAxisMaximum(); | ||
initiateBaroSensor(sensorType); | ||
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. issue (bug_risk): Erroneous initialization of non-thermometer sensors Remove the initialization of Baro and Lux sensors from ThermometerDataFragment to ensure only the thermometer sensor is started. |
||
initiateLuxSensor(sensorType); | ||
initiateThermoSensor(sensorType); | ||
} else if (returningFromPause) { | ||
updateGraphs(); | ||
|
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.
issue (typo): Typo causing compile error
Remove the extra "rea" after finish() to fix the syntax error.