Skip to content

feat: added functionality for Wave Generator #2826

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 2 commits into
base: flutter
Choose a base branch
from

Conversation

AsCress
Copy link
Collaborator

@AsCress AsCress commented Aug 10, 2025

Adds the functionality for the Wave Generator instrument.

Screenshots / Recordings

  1. Analog Waveforms:
Screen_recording_20250815_234703.mp4
  1. Digital Waveforms:
Screen_recording_20250815_235536.mp4
  1. Guide Screen:
Screen_recording_20250816_124758.mp4

Summary by Sourcery

Introduce state management for the Wave Generator instrument with enums for constants and data limits and a ChangeNotifier provider to track selected wave types.

New Features:

  • Define WaveConst enum listing wave types and parameters
  • Define WaveData enum encapsulating min/max values for frequency, phase, and duty cycle
  • Implement WaveGeneratorStateProvider to manage and initialize analog and digital wave selections

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

sourcery-ai bot commented Aug 10, 2025

Reviewer's Guide

This PR overhauls the Wave Generator feature by introducing a ChangeNotifier-based state provider with strongly typed enums for wave parameters, extending the ScienceLab communication layer with new waveform setup methods, and refactoring the UI to consume provider state and localized labels dynamically.

Sequence diagram for updating wave parameter via provider

sequenceDiagram
    actor User
    participant UI
    participant WaveGeneratorStateProvider
    participant ScienceLab
    User->>UI: Adjusts wave parameter (e.g., frequency)
    UI->>WaveGeneratorStateProvider: setValue(newValue)
    WaveGeneratorStateProvider->>ScienceLab: setWave() (calls appropriate waveform method)
    ScienceLab-->>WaveGeneratorStateProvider: Updates hardware
    WaveGeneratorStateProvider->>UI: Notifies listeners
    UI->>UI: Updates display
Loading

Class diagram for Wave Generator state management

classDiagram
    class WaveGeneratorStateProvider {
        - int sin
        - int triangular
        - int pwm
        - WaveConst? selectedAnalogWave
        - WaveConst? selectedDigitalWave
        - WaveConst? propSelected
        - WaveGeneratorConstants waveGeneratorConstants
        - List<List<FlSpot>> waveData
        - ScienceLab _scienceLab
        + setAnalogSelectedWave(WaveConst)
        + setDigitalSelectedWave(WaveConst)
        + setPropSelected(WaveConst)
        + setAnalogWaveType(int)
        + setValue(int)
        + setWave()
        + incrementValue()
        + decrementValue()
        + previewWave()
        + getSamplePoints(bool)
        + createPlots()
    }
    class WaveGeneratorConstants {
        + Map<WaveConst, Map<WaveConst, int>> wave
        + WaveConst modeSelected
        + Map<String, int> state
    }
    class WaveConst
    class WaveData {
        freqMin
        dutyMin
        phaseMin
        freqMax
        phaseMax
        dutyMax
        value
        getValue
    }
    WaveGeneratorStateProvider --> WaveGeneratorConstants
    WaveGeneratorConstants --> WaveConst
    WaveGeneratorConstants --> WaveData
    WaveGeneratorStateProvider --> ScienceLab
    WaveGeneratorStateProvider --> FlSpot
Loading

Class diagram for new ScienceLab waveform methods

classDiagram
    class ScienceLab {
        + setSI1(frequency, waveType)
        + setSI2(frequency, waveType)
        + setWaves(frequency, phase, frequency2)
        + sqrPWM(frequency, h0, p1, h1, p2, h2, p3, h3, pulse)
    }
Loading

File-Level Changes

Change Details Files
Introduce state management for wave generator with enums and ChangeNotifier provider
  • Add WaveConst and WaveData enums for wave types, parameters, and data limits
  • Implement WaveGeneratorStateProvider to track selections, preview data, and notify listeners
  • Define WaveGeneratorConstants to hold default wave settings
lib/providers/wave_generator_state_provider.dart
lib/others/wave_generator_constants.dart
Extend ScienceLab API with new waveform configuration methods
  • Add setSI1, setSI2 for analog sine/triangle output with prescaler logic
  • Implement setWaves to configure dual-wave frequency and phase
  • Introduce sqrPWM for complex PWM waveform generation
  • Fix typo in initialization loop for SI2 channel
lib/communication/science_lab.dart
Refactor UI widgets to integrate provider state and localization
  • Wrap screen in MultiProvider and use Consumer/Provider.of to drive widget state
  • Replace hard-coded labels and values with AppLocalizations and provider data
  • Add dynamic enable/disable logic for buttons and sliders based on selected prop
  • Update graph max/min values and use provider to generate plot data
  • Define new color constants for enabled/disabled button states
lib/view/wave_generator_screen.dart
lib/view/widgets/wave_generator_main_controls.dart
lib/view/widgets/analog_waveform_controls.dart
lib/view/widgets/digital_waveform_controls.dart
lib/view/widgets/wave_generator_graph.dart
lib/l10n/app_localizations.dart
lib/l10n/app_localizations_en.dart
lib/theme/colors.dart

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

github-actions bot commented Aug 10, 2025

@AsCress AsCress force-pushed the wavegen_func branch 2 times, most recently from 5b2a328 to 2b7e90b Compare August 15, 2025 18:39
@AsCress AsCress marked this pull request as ready for review August 15, 2025 18:39
Copy link
Contributor

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

  • There’s a lot of duplicated logic in science_lab’s new waveform methods (setSI1, setSI2, setWaves, sqrPWM) — extracting shared parts into helpers or a single configurable routine would reduce repetition.
  • The build functions in the waveform control widgets have grown very large with nested ternaries and inline logic — splitting out sub-widgets or helper methods would greatly improve readability.
  • Managing wave parameters via nested enum-keyed maps in WaveGeneratorStateProvider/WaveGeneratorConstants is hard to follow; consider modeling each wave’s settings with a dedicated class or data structure instead of deeply nested maps.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There’s a lot of duplicated logic in science_lab’s new waveform methods (setSI1, setSI2, setWaves, sqrPWM) — extracting shared parts into helpers or a single configurable routine would reduce repetition.
- The build functions in the waveform control widgets have grown very large with nested ternaries and inline logic — splitting out sub-widgets or helper methods would greatly improve readability.
- Managing wave parameters via nested enum-keyed maps in WaveGeneratorStateProvider/WaveGeneratorConstants is hard to follow; consider modeling each wave’s settings with a dedicated class or data structure instead of deeply nested maps.

## Individual Comments

### Comment 1
<location> `lib/view/widgets/wave_generator_graph.dart:36` </location>
<code_context>
     return Container(
       padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
       child: LineChart(
+        duration: const Duration(milliseconds: 10),
         LineChartData(
           backgroundColor: chartBackgroundColor,
</code_context>

<issue_to_address>
Very short chart animation duration may be imperceptible.

Consider increasing the animation duration or making it configurable to improve user experience.

Suggested implementation:

```
class WaveGeneratorGraph extends StatefulWidget {
  final Duration chartAnimationDuration;

  const WaveGeneratorGraph({
    Key? key,
    this.chartAnimationDuration = const Duration(milliseconds: 300),
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {

```

```
    return Container(
      padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
      child: LineChart(
        duration: chartAnimationDuration,
        LineChartData(
          backgroundColor: chartBackgroundColor,

```
</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.

@AsCress
Copy link
Collaborator Author

AsCress commented Aug 15, 2025

@marcnause @CloudyPadmal This is now complete and ready to go in.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant