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

feat: initialized Oscilloscope Screen #2612

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

Conversation

AsCress
Copy link
Collaborator

@AsCress AsCress commented Jan 17, 2025

Slowly and steadily, we would get there 🥹.
This is currently a Work In Progress.
Initializes the Oscilloscope Screen in our flutter app.

Screenshots / Recordings

N/A

The layouts are done, functionality coming soon.

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.

@marcnause Would you like to test these layouts 😉 ?

Summary by Sourcery

Initialize the oscilloscope screen layouts.

New Features:

  • Added layouts for the oscilloscope screen in the Flutter app.

Tests:

  • Precached images for instrument icons and navigation header logo.

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

sourcery-ai bot commented Jan 17, 2025

Reviewer's Guide by Sourcery

This pull request initializes the Oscilloscope Screen in the Flutter app. It includes the basic layouts and integrates necessary providers for managing the board and oscilloscope states. The changes also involve updating dependencies and configuring USB device filters for Android.

Class diagram for the Oscilloscope Screen components

classDiagram
    class OscilloscopeScreen {
        +build()
        -setLandscapeOrientation()
    }
    class OscilloscopeStateProvider {
        -selectedIndex: int
        -yAxisScale: double
        -timebaseDivisions: int
        +timebaseSlider: double
        +isCH1Selected: bool
        +isCH2Selected: bool
        +isCH3Selected: bool
        +isMICSelected: bool
        +initialize()
        +setYAxisScale()
        +setTimebaseDivisions()
        +setTimebase()
        +createLineBarsData()
    }
    class ChannelParametersWidget {
        +build()
    }
    class TimebaseTriggerWidget {
        +build()
    }
    class DataAnalysisWidget {
        +build()
    }
    class XYPlotWidget {
        +build()
    }
    class OscilloscopeGraph {
        +build()
    }
    OscilloscopeScreen --> OscilloscopeStateProvider
    OscilloscopeScreen --> ChannelParametersWidget
    OscilloscopeScreen --> TimebaseTriggerWidget
    OscilloscopeScreen --> DataAnalysisWidget
    OscilloscopeScreen --> XYPlotWidget
    OscilloscopeScreen --> OscilloscopeGraph
Loading

Class diagram for the Communication components

classDiagram
    class ScienceLab {
        +connect()
        +isConnected()
        +getVersion()
        +captureTraces()
        +fetchTrace()
        +setGain()
        +loadEquation()
    }
    class PacketHandler {
        -buffer: Uint8List
        -connected: bool
        +getVersion()
        +sendByte()
        +sendInt()
        +getAcknowledgement()
        +getByte()
        +getInt()
    }
    class AnalogAcquisitionChannel {
        -resolution: int
        -timebase: double
        +length: int
        +bufferIndex: int
        +yAxis: List~double~
        +fixValue()
        +setParams()
        +regenerateXAxis()
    }
    class DigitalChannel {
        +channelName: String
        +channelNumber: int
        +length: int
        +loadData()
        +generateAxes()
    }
    ScienceLab --> PacketHandler
    ScienceLab --> AnalogAcquisitionChannel
    ScienceLab --> DigitalChannel
Loading

File-Level Changes

Change Details Files
Introduced the Oscilloscope Screen and its basic layout.
  • Created the OscilloscopeScreen widget with a basic structure.
  • Implemented the layout for the oscilloscope screen, including graph and control sections.
  • Added widgets for channel parameters, timebase trigger, data analysis, and XY plot settings.
  • Created OscilloscopeGraph widget to display the graph.
  • Created OscilloscopeScreenTabs widget for tabs.
lib/main.dart
lib/view/oscilloscope_screen.dart
lib/view/widgets/oscilloscope_graph.dart
lib/view/widgets/oscilloscope_screen_tabs.dart
lib/view/widgets/channel_parameters_widget.dart
lib/view/widgets/timebase_trigger_widget.dart
lib/view/widgets/data_analysis_widget.dart
lib/view/widgets/xyplot_widget.dart
Integrated provider for managing board and oscilloscope states.
  • Added BoardStateProvider and OscilloscopeStateProvider to manage application state.
  • Configured MultiProvider in main.dart to provide the state to the application.
  • Created locator.dart to setup get_it for dependency injection.
  • Initialized BoardStateProvider in main.dart.
lib/main.dart
lib/providers/board_state_provider.dart
lib/providers/oscilloscope_state_provider.dart
lib/providers/locator.dart
Updated dependencies and configurations.
  • Added dependencies for provider, usb_serial, get_it, flutter_audio_capture, data, permission_handler, and fl_chart.
  • Configured USB device filters in AndroidManifest.xml to recognize the PSLab device.
  • Added microphone permission to AndroidManifest.xml.
  • Added device_filter.xml to res/xml folder.
pubspec.yaml
android/app/src/main/AndroidManifest.xml
android/app/src/main/res/xml/device_filter.xml
Modified Instruments Screen to navigate to Oscilloscope Screen.
  • Added onTap to ApplicationsListItem to navigate to Oscilloscope Screen.
  • Modified InstrumentsScreen to navigate to Oscilloscope Screen.
lib/view/instruments_screen.dart
Refactored CommonScaffold to MainScaffold and CommonScaffold.
  • Created MainScaffold widget to include navigation drawer.
  • Created CommonScaffold widget to include back navigation.
  • Modified InstrumentsScreen to use MainScaffold.
lib/view/widgets/common_scaffold_widget.dart
lib/view/widgets/main_scaffold_widget.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

@AsCress AsCress force-pushed the flutter_oscilloscope branch 2 times, most recently from eab7d3a to 7917e13 Compare January 17, 2025 11:35
Copy link

github-actions bot commented Jan 17, 2025

@marcnause
Copy link
Contributor

Looks good on my device!

Screenshot_20250118-234215

@AsCress
Copy link
Collaborator Author

AsCress commented Jan 21, 2025

@marcnause This PR now sets up communication with the PSLab device, and basic initialisation of the board. You should be able to see the version string when you connect to the board 🥳.
You may test with the APK provided by the comment pipeline, it is now updated.

@AsCress AsCress force-pushed the flutter_oscilloscope branch from 7b72171 to 2a37948 Compare January 23, 2025 17:41
@marcnause
Copy link
Contributor

I tested with the latest version. I did not see any difference in the oscilloscope screen. Connecting the PSLab v5 and the PSLab v6 seems to work. With the v5 board I get a warning, for the v6 board I don't see the version. If I switch to the oscilloscope and back, the size of the navigation drawer changes on my device.

@AsCress AsCress force-pushed the flutter_oscilloscope branch 4 times, most recently from 00255a1 to 86b5191 Compare January 24, 2025 13:38
@marcnause
Copy link
Contributor

for the v6 board I don't see the version.

This was my fault. I still had the UART-hack FW running on my PSLab v6.

@AsCress AsCress force-pushed the flutter_oscilloscope branch 2 times, most recently from 721fac7 to 9ef1018 Compare January 26, 2025 17:18
@AsCress
Copy link
Collaborator Author

AsCress commented Jan 26, 2025

Just installed the legacy firmware on my v6 device. Everything works perfectly.

Screenshot_20250126_225747

All these observations are pointing towards a single thing: the USB Serial driver that we are using may not properly support the MCP2200 USB-UART (CDC-ACM driver) converter that the v5 uses, the same issue which we had in our native app.
Looks like I may have to write a custom USB Serial library tailored to the PSLab 😢.
Let's get to that on a later stage at this is something already done in the native app and just requires a port to flutter, and let's continue our testing with the v6 device.

@AsCress AsCress force-pushed the flutter_oscilloscope branch from 2ff3227 to b47cd9b Compare February 4, 2025 15:47
@AsCress AsCress marked this pull request as ready for review February 4, 2025 15:58
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 and found some issues that need to be addressed.

Blocking issues:

  • numBytesRead is never incremented in read() method (link)

Overall Comments:

  • Consider adding error handling and loading states for device communication operations to improve reliability and user experience
  • The signal processing algorithms would benefit from documentation explaining the mathematical approaches being used
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 1 other issue
  • 🟢 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/communication/packet_handler.dart Show resolved Hide resolved
lib/communication/communication_handler.dart Show resolved Hide resolved
@AsCress AsCress force-pushed the flutter_oscilloscope branch from b47cd9b to d98be69 Compare February 4, 2025 16:03
@AsCress
Copy link
Collaborator Author

AsCress commented Feb 4, 2025

@adityastic @marcnause This PR is now ready from my side for a final review.
Sorry for such a large PR. I'll try to keep the PRs short from now on.

What works

  1. The Oscilloscope with only the In-Built MIC feature.
  2. Range Selection for the Y-Axis.
  3. Time base selection for the X-Axis.

What doesn't work as of yet

  1. CH1, CH2, CH3 or the PSLab MIC.
  2. Triggering, Auto-Scale or Automated Measurements.
  3. Recording of Oscilloscope data.
  4. Any other feature which isn't listed in the above section.

These features would be added soon in upcoming PRs.

Demo of the Oscilloscope

Screen_recording_20250204_211716.mp4

@marcnause Can you please test the Oscilloscope and confirm if it works fine ? As usual, you can use the APK from the comment pipeline.

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.

2 participants