Skip to content

feat: added remaining Oscilloscope functionality #2750

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

Merged
merged 3 commits into from
Jun 28, 2025

Conversation

AsCress
Copy link
Collaborator

@AsCress AsCress commented Jun 22, 2025

Fixes #2745.
Adds the following remaining functionality to the Oscilloscope:

  • Auto Scale
  • Run Control
  • Automated Measurements

Screenshots/Recordings

Screen_recording_20250622_193304.mp4

@marcnause Would you like to test these additions ?

Summary by Sourcery

Add missing Oscilloscope features: automatic axis scaling, acquisition run control, and an overlay for automated channel measurements.

New Features:

  • Add AUTO button for automatic scaling of waveform axes
  • Add run/pause control button to start and stop data acquisition
  • Add toggle for an automated measurements overlay showing amplitude, peaks, frequency, and period per channel

Enhancements:

  • Compute and store per-channel measurements in the OscilloscopeStateProvider
  • Introduce OscilloscopeMeasurements model and MeasurementsList widget for displaying computed metrics
  • Refactor provider state to track running status and measurement toggle
  • Fix FFT analytics to use correct sublist slicing and amplitude list sizing

Documentation:

  • Add user-facing constants for labels: noSignal, AUTO, Automated Measurements

@AsCress AsCress self-assigned this Jun 22, 2025
@AsCress AsCress added Feature New addition to the existing app flutter labels Jun 22, 2025
Copy link

sourcery-ai bot commented Jun 22, 2025

Reviewer's Guide

Implements remaining Oscilloscope functionality—auto-scale, run/pause controls, recording UI, and automated measurements—by refactoring the screen UI for provider-driven state, extending the state provider with scaling and measurement logic, adding supporting models/widgets, and adjusting analytics FFT handling.

Entity relationship diagram for Oscilloscope channel measurements

erDiagram
    OSCILLOSCOPE_MEASUREMENTS {
      string channel
      double frequency
      double period
      double amplitude
      double positivePeak
      double negativePeak
    }
    OSCILLOSCOPE_MEASUREMENTS ||--o{ CHANNEL : has
    CHANNEL {
      string name
    }
Loading

Class diagram for Oscilloscope measurements and state management

classDiagram
    class OscilloscopeStateProvider {
      +bool isRunning
      +bool isMeasurementsChecked
      +List<List<FlSpot>> dataEntries
      +List<String> dataParamsChannels
      +bool autoScale()
      +notifyListeners()
      ...
    }
    class OscilloscopeMeasurements {
      +static Map<String, Map<ChannelMeasurements, double>> channel
    }
    class MeasurementsList {
      +List<String> dataParamsChannels
    }
    OscilloscopeStateProvider --> OscilloscopeMeasurements : updates
    MeasurementsList --> OscilloscopeMeasurements : reads
    OscilloscopeStateProvider --> MeasurementsList : provides dataParamsChannels
Loading

File-Level Changes

Change Details Files
Refactored OscilloscopeScreen UI to integrate auto-scale, run control, recording and automated measurements
  • Wrapped the screen in a Consumer to rebuild on provider changes
  • Replaced layout with a Stack to overlay MeasurementsList when enabled
  • Added AppBar actions: AUTO button, play/pause toggle, record and info icons
  • Introduced a PopupMenu to toggle automated measurements via checkbox
lib/view/oscilloscope_screen.dart
Extended OscilloscopeStateProvider with run control, auto-scaling and measurement computation
  • Exposed isRunning and isMeasurementsChecked flags and wired them to UI
  • Implemented autoScale() to recalc axes based on signal extrema and period
  • Added per-channel loops to compute frequency, period, amplitude and peaks
  • Populated OscilloscopeMeasurements and notified listeners on changes
lib/providers/oscilloscope_state_provider.dart
Added measurement model and list widget to display computed metrics
  • Created OscilloscopeMeasurements model with static channel map of metrics
  • Built MeasurementsList widget to format and show Vpp, peaks, frequency and period
lib/models/oscilloscope_measurements.dart
lib/view/widgets/measurements_list.dart
Fixed FFT array sizing in analytics to avoid cast errors
  • Replaced integer casts with .round() when subsetting frequency list
  • Used .round() for amplitude list initializations
lib/communication/analytics_class.dart
Updated constants with new UI labels
  • Added noSignal, autoScale and automatedMeasurements string constants
lib/constants.dart

Assessment against linked issues

Issue Objective Addressed Explanation

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 @AsCress - I've reviewed your changes - here's some feedback:

  • Consider refactoring the measurement/calculation logic into a shared helper or service rather than duplicating it in both _getData and autoScale to improve maintainability.
  • Avoid using setState to toggle provider fields (isRunning, isMeasurementsChecked)—instead update the provider and call notifyListeners so the UI rebuilds consistently through the ChangeNotifier.
  • The static OscilloscopeMeasurements.channel map introduces global mutable state; move measurement storage into the provider instance to prevent cross-component interference and improve testability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider refactoring the measurement/calculation logic into a shared helper or service rather than duplicating it in both `_getData` and `autoScale` to improve maintainability.
- Avoid using `setState` to toggle provider fields (`isRunning`, `isMeasurementsChecked`)—instead update the provider and call `notifyListeners` so the UI rebuilds consistently through the ChangeNotifier.
- The static `OscilloscopeMeasurements.channel` map introduces global mutable state; move measurement storage into the provider instance to prevent cross-component interference and improve testability.

## Individual Comments

### Comment 1
<location> `lib/providers/oscilloscope_state_provider.dart:614` </location>
<code_context>
   }

+  bool autoScale() {
+    double minY = double.maxFinite;
+    double maxY = double.minPositive;
+    double maxPeriod = -1 * double.minPositive;
+    double yRange;
</code_context>

<issue_to_address>
Initialization of maxY and maxPeriod may not handle negative values correctly.

minPositive only works for positive values. Use -double.maxFinite for initialization to handle negative data correctly.
</issue_to_address>

### Comment 2
<location> `lib/view/widgets/measurements_list.dart:18` </location>
<code_context>
+
+class _MeasurementsListState extends State<MeasurementsList> {
+  String formatFrequency(double? freq) {
+    return freq! >= 1000
+        ? '${(freq / 1000).toStringAsFixed(2)} kHz'
+        : '${freq.toStringAsFixed(2)} Hz';
+  }
+
</code_context>

<issue_to_address>
Potential null dereference in formatFrequency.

Handle cases where freq is null to prevent runtime exceptions from force-unwrapping.
</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 22, 2025

@marcnause marcnause added the Status: Review Required Requested reviews from peers and maintainers label Jun 22, 2025
@AsCress AsCress merged commit 6742a6f into fossasia:flutter Jun 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New addition to the existing app flutter Status: Review Required Requested reviews from peers and maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement remaining functionality in Oscilloscope
2 participants