Skip to content
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: initialization of scienceLabCommon and In-Built MIC #2629

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

AsCress
Copy link
Collaborator

@AsCress AsCress commented Feb 11, 2025

Summary by Sourcery

Initialize the audio jack and ScienceLabCommon classes when the respective features are used, rather than at startup.

Bug Fixes:

  • Fix the initialization of the ScienceLabCommon and in-built microphone.

Enhancements:

  • Improve the efficiency of the oscilloscope by only initializing the audio jack when the in-built microphone is selected.

@AsCress AsCress requested a review from adityastic February 11, 2025 13:26
Copy link

sourcery-ai bot commented Feb 11, 2025

Reviewer's Guide by Sourcery

This pull request refactors and updates the initialization logic for the in-built MIC and scienceLabCommon components, along with some UI adjustments in the timebase trigger widget. The changes include moving from a nullable AudioJack to a late initialized instance with proper state checks, improving USB event handling, and streamlining widget build logic.

Sequence Diagram for USB Event Handling in BoardStateProvider

sequenceDiagram
    participant USB as UsbSerial Event Stream
    participant Board as BoardStateProvider
    participant Device as scienceLabCommon
    participant UI as User Interface

    Note right of Board: USB event listener waits for events
    USB->>Board: ACTION_USB_ATTACHED
    Board-->>Board: if (attemptToConnectPSLab())
    Board->>Device: openDevice()
    Board->>Board: setPSLabVersionIDs()

    USB->>Board: ACTION_USB_DETACHED
    Board->>Device: setConnected(false)
    Board-->>Board: update pslabIsConnected, pslabVersionID
    Board->>UI: notifyListeners()
Loading

Updated Class Diagram for AudioJack

classDiagram
    class AudioJack {
      +FlutterAudioCapture flutterAudioCapture
      -bool _isListening
      -List~double~ _audioBuffer
      +AudioJack()
      +Future<void> initialize()
      +Future<void> start()
      +Future<void> close()
      +List<double> read()
      +bool isListening()
    }

    AudioJack ..> FlutterAudioCapture : uses
Loading

File-Level Changes

Change Details Files
Refactored the timebase trigger widget UI implementation.
  • Removed the Consumer wrapper and directly accessed the provider.
  • Reorganized widget layout using Stack and Positioned for clarity.
  • Updated DropdownMenu and Slider widget configurations for consistency.
lib/view/widgets/timebase_trigger_widget.dart
Updated oscilloscope state provider to improve AudioJack initialization and usage.
  • Changed AudioJack to be late initialized rather than being nullable.
  • Modified the initialization logic to check if AudioJack is already listening before starting.
  • Ensured the AudioJack close method is called in disposal and when MIC is deselected.
  • Simplified audio reading by removing unnecessary null checks.
lib/providers/oscilloscope_state_provider.dart
Enhanced USB event handling in board state provider.
  • Modified the USB event listener to explicitly handle both attachment and detachment events.
  • Updated connection state and version properties upon USB detachment.
lib/providers/board_state_provider.dart
Refactored the AudioJack class to improve initialization and state management.
  • Renamed and refactored configure() to initialize() with Future return type.
  • Introduced an _isListening flag along with an isListening() method.
  • Updated the close() method to be asynchronous and update the listening flag appropriately.
lib/others/audio_jack.dart
Adjusted scienceLabCommon connectivity method to support dynamic connection states.
  • Modified setConnected() method to accept a boolean value, allowing explicit control over connection state.
lib/others/science_lab_common.dart

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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:

Overall Comments:

  • Consider extracting the large build method in _TimebaseTriggerState into smaller, more manageable widgets.
  • It looks like you're initializing _audioJack in OscilloscopeStateProvider's constructor now, which is good, but make sure it's properly disposed of in the dispose method to prevent memory leaks.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

lib/view/widgets/timebase_trigger_widget.dart Show resolved Hide resolved
lib/others/audio_jack.dart Show resolved Hide resolved
Copy link

@adityastic adityastic merged commit 5d8d1e4 into fossasia:flutter Feb 11, 2025
5 of 6 checks passed
@AsCress AsCress deleted the oscilloscope_functionality branch February 11, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants