Skip to content

feat: ported barometer instrument #2743

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

Open
wants to merge 8 commits into
base: flutter
Choose a base branch
from

Conversation

Yugesh-Kumar-S
Copy link
Collaborator

@Yugesh-Kumar-S Yugesh-Kumar-S commented Jun 16, 2025

Fixes #2742

Changes

  • Ported the barometer instrument to flutter app.
  • Modified the InstrumentStat widget to change unit and font values.

Screenshots / Recordings

Simulated using virtual sensors

barometer.webm

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Port the barometer instrument into the Flutter app by adding a dedicated screen, provider, and widget components, updating navigation, and enhancing existing stat widgets for dynamic units.

New Features:

  • Add BarometerScreen for real-time barometer readings with pressure gauge, statistics, and altitude display
  • Implement BarometerStateProvider to manage barometer sensor streaming, error handling, and chart data generation
  • Create BarometerCard widget combining gauge, statistics, and altitude tile within the new barometer view

Enhancements:

  • Refactor InstrumentStats widget to accept dynamic units and font sizes instead of hardcoded 'Lx' labels
  • Update navigation mapping and routes in InstrumentsScreen and main.dart to include the new '/barometer' route
  • Define new constants for barometer titles, units, error messages, and altitude labels

Copy link

sourcery-ai bot commented Jun 16, 2025

Reviewer's Guide

Ports the barometer instrument end-to-end by adding a dedicated Flutter screen with gauge and chart UIs, integrating a BarometerStateProvider for live sensor streaming, refactoring existing stats widgets for dynamic unit and font support, and updating navigation routes and constants.

Class diagram for Instrumentstats and StatItem refactor

classDiagram
  class Instrumentstats {
    + double titleFontSize
    + double statFontSize
    + double maxValue
    + double minValue
    + double avgValue
    + String unit
    + Widget build(BuildContext context)
  }
  class StatItem {
    + String label
    + double value
    + double fontSize
    + Widget build(BuildContext context)
  }
  Instrumentstats --> StatItem : uses
Loading

File-Level Changes

Change Details Files
Ported barometer UI and navigation
  • Added BarometerScreen with CommonScaffold and chart section
  • Created BarometerCard widget to display gauge and altitude stats
  • Updated InstrumentsScreen cases for '/barometer' navigation
  • Registered '/barometer' route in main.dart
lib/view/barometer_screen.dart
lib/view/widgets/barometer_card.dart
lib/view/instruments_screen.dart
lib/main.dart
Introduced BarometerStateProvider for live data
  • Subscribed to barometerEventStream and initialized timer for time tracking
  • Buffered pressure and time data, computed min/max/avg and altitude
  • Generated FlSpot list for chart rendering
  • Handled sensor initialization and runtime errors with SnackBar callbacks
lib/providers/barometer_state_provider.dart
Refactored Instrumentstats and StatItem widgets
  • Replaced hardcoded 'Lx' labels with dynamic unit parameter
  • Passed fontSize into value TextStyle instead of local calculation
  • Allowed Instrumentstats to accept unit and configurable font sizes
lib/view/widgets/instruments_stats.dart
Added barometer-related constants
  • Defined barometerTitle, unit labels (atm, m), and altitudeLabel
  • Added sensor error and availability messages
lib/constants.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#2742 Maintain consistency with the existing PSLab Android app’s Barometer behavior and visual design.
#2742 Display real-time atmospheric pressure (in atm) along with calculated altitude (in meters) using a responsive gauge and chart.
#2742 Integrate continuous sensor data streaming with a dynamic UI that updates in real-time based on the latest sensor values.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Yugesh-Kumar-S - I've reviewed your changes - here's some feedback:

  • The hard-coded case 6, case 7, case 8 indices in InstrumentsScreen make navigation brittle—consider using named enums or a list of instrument routes instead of magic numbers.
  • The altitude-from-pressure formula is duplicated in both the provider and the chart widget; centralize that conversion in one place to avoid drift and maintenance overhead.
  • You’re firing a Timer every second and calling notifyListeners even if the pressure hasn’t changed—consider updating the chart only on new sensor events or throttling UI rebuilds to improve performance.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The hard-coded `case 6`, `case 7`, `case 8` indices in InstrumentsScreen make navigation brittle—consider using named enums or a list of instrument routes instead of magic numbers.
- The altitude-from-pressure formula is duplicated in both the provider and the chart widget; centralize that conversion in one place to avoid drift and maintenance overhead.
- You’re firing a Timer every second and calling notifyListeners even if the pressure hasn’t changed—consider updating the chart only on new sensor events or throttling UI rebuilds to improve performance.

## Individual Comments

### Comment 1
<location> `lib/view/barometer_screen.dart:132` </location>
<code_context>
+    );
+  }
+
+  Widget altitudeTitleWidgets(
+      double value, TitleMeta meta, double maxPressure) {
+    final screenWidth = MediaQuery.of(context).size.width;
</code_context>

<issue_to_address>
Remove unused 'maxPressure' parameter

Since 'maxPressure' is not used in the function, please remove it from the parameter list to simplify the code.

Suggested implementation:

```
  Widget altitudeTitleWidgets(
      double value, TitleMeta meta) {
    final screenWidth = MediaQuery.of(context).size.width;

```

You must also update all calls to `altitudeTitleWidgets` in this file to remove the third argument (`maxPressure`). For example, change:
```dart
altitudeTitleWidgets(value, meta, maxPressure)
```
to:
```dart
altitudeTitleWidgets(value, meta)
```
</issue_to_address>

### Comment 2
<location> `lib/providers/barometer_state_provider.dart:139` </location>
<code_context>
+      _dataCount > 0 ? _pressureSum / _dataCount : 0.0;
+
+  double getCurrentAltitude() => _pressureToAltitude(_currentPressure);
+  double getMinAltitude() =>
+      _pressureMin > 0 ? _pressureToAltitude(_pressureMax) : 0.0;
+  double getMaxAltitude() =>
+      _pressureMax > 0 ? _pressureToAltitude(_pressureMin) : 0.0;
</code_context>

<issue_to_address>
Incorrect guard condition in getMinAltitude

Consider checking _pressureMax > 0 or _dataCount > 0 instead, since _pressureMax is used in the calculation.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

github-actions bot commented Jun 16, 2025

@AsCress AsCress changed the title feat: ported barometer instrument. feat: ported barometer instrument Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Barometer sensor data visualization
1 participant