-
Notifications
You must be signed in to change notification settings - Fork 814
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
base: flutter
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis 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 providersequenceDiagram
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
Class diagram for Wave Generator state managementclassDiagram
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
Class diagram for new ScienceLab waveform methodsclassDiagram
class ScienceLab {
+ setSI1(frequency, waveType)
+ setSI2(frequency, waveType)
+ setWaves(frequency, phase, frequency2)
+ sqrPWM(frequency, h0, p1, h1, p2, h2, p3, h3, pulse)
}
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/17005777364/artifacts/3779054720 |
5b2a328
to
2b7e90b
Compare
There was a problem hiding this 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>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@marcnause @CloudyPadmal This is now complete and ready to go in. |
Adds the functionality for the Wave Generator instrument.
Screenshots / Recordings
Screen_recording_20250815_234703.mp4
Screen_recording_20250815_235536.mp4
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: