-
Notifications
You must be signed in to change notification settings - Fork 825
feat: Add support for sensor MLX90614 #3025
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 GuideAdds end-to-end support for the MLX90614 infrared temperature sensor, including an I2C driver, a provider with a polling loop, a dedicated UI screen, and wiring into navigation, dependency injection, and platform plugin registration. Sequence diagram for MLX90614Screen, provider, and sensor pollingsequenceDiagram
actor User
participant SensorsScreen
participant MLX90614Screen
participant MLX90614Provider
participant getIt
participant ScienceLab
participant I2C
participant MLX90614
User->>SensorsScreen: tap sensor MLX90614
SensorsScreen->>MLX90614Screen: Navigator.push
activate MLX90614Screen
MLX90614Screen->>MLX90614Screen: initState
MLX90614Screen->>MLX90614Screen: addPostFrameCallback
MLX90614Screen->>MLX90614Provider: Provider.of listen false
MLX90614Screen->>getIt: getIt<ScienceLab>()
getIt-->>MLX90614Screen: ScienceLab instance
MLX90614Screen->>ScienceLab: isConnected()
alt device connected
MLX90614Screen->>I2C: I2C(scienceLab.mPacketHandler)
MLX90614Screen->>MLX90614Provider: init(i2c)
MLX90614Provider->>MLX90614: MLX90614(i2c)
MLX90614Screen->>MLX90614Provider: startDataLog()
activate MLX90614Provider
loop while isWorking
MLX90614Provider->>MLX90614: getAmbientTemperature()
MLX90614->>I2C: readBulk(address, ambientTempReg, 2)
I2C-->>MLX90614: List<int> data
MLX90614-->>MLX90614Provider: double ambientTemp
MLX90614Provider->>MLX90614: getObjectTemperature()
MLX90614->>I2C: readBulk(address, objectTempReg, 2)
I2C-->>MLX90614: List<int> data
MLX90614-->>MLX90614Provider: double objectTemp
MLX90614Provider->>MLX90614Provider: notifyListeners()
MLX90614Provider-->>MLX90614Screen: updated temps via Consumer
MLX90614Provider->>MLX90614Provider: Future.delayed(1s)
end
else device not connected
MLX90614Screen-->>User: SnackBar Device not connected
end
User->>MLX90614Screen: navigate back
MLX90614Screen->>MLX90614Provider: stopDataLog()
deactivate MLX90614Provider
deactivate MLX90614Screen
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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 - I've found 1 issue, and left some high level feedback:
- Remove in-code review notes and commented-out references (e.g.,
// Keep ONLY MLX90614 for this PR,// REMOVED: ... <-- Causing error) fromSensorsScreenand related files to avoid leaving temporary review context and dead code in the main branch. - User-facing strings in
MLX90614Screen(AppBar title, card titles, units, SnackBar text) should be wired through the existing localization system (AppLocalizations) instead of hard-coded literals for consistency with the rest of the app.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Remove in-code review notes and commented-out references (e.g., `// Keep ONLY MLX90614 for this PR`, `// REMOVED: ... <-- Causing error`) from `SensorsScreen` and related files to avoid leaving temporary review context and dead code in the main branch.
- User-facing strings in `MLX90614Screen` (AppBar title, card titles, units, SnackBar text) should be wired through the existing localization system (`AppLocalizations`) instead of hard-coded literals for consistency with the rest of the app.
## Individual Comments
### Comment 1
<location> `lib/communication/sensors/mlx90614.dart:39-46` </location>
<code_context>
+ int msb = data[1];
+
+ // Combine the bytes: (MSB << 8) | LSB
+ int rawValue = (msb << 8) | lsb;
+
+ // Formula from datasheet:
+ // The sensor returns temperature in Kelvin * 50.
+ // Multiply by 0.02 to get Kelvin.
+ // Subtract 273.15 to convert Kelvin to Celsius.
+ double tempCelsius = (rawValue * 0.02) - 273.15;
+
+ return tempCelsius;
</code_context>
<issue_to_address>
**suggestion:** The raw temperature value might benefit from masking out status bits per the MLX90614 datasheet before applying the conversion.
Per the MLX90614 datasheet, only the lower 15 bits represent the temperature; the MSB may contain status/flags. Currently `rawValue` uses all 16 bits, so status bits could skew the reading. Consider masking off the MSB before scaling:
```dart
int rawValue = ((msb << 8) | lsb) & 0x7FFF; // mask out status bit
double tempCelsius = (rawValue * 0.02) - 273.15;
```
```suggestion
// Combine the bytes: (MSB << 8) | LSB and mask out status bit (only lower 15 bits are temperature)
int rawValue = ((msb << 8) | lsb) & 0x7FFF;
// Formula from datasheet:
// The sensor returns temperature in Kelvin * 50.
// Multiply by 0.02 to get Kelvin.
// Subtract 273.15 to convert Kelvin to Celsius.
double tempCelsius = (rawValue * 0.02) - 273.15;
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Build StatusBuild successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/20708890390/artifacts/5021970006. Screenshots |







-1_instruments_screen.png?raw=true)
-2_nav_drawer.png?raw=true)
-3_accelerometer.png?raw=true)
-4_power_source.png?raw=true)
-5_multimeter.png?raw=true)
-6_wave_generator.png?raw=true)
-7_oscilloscope.png?raw=true)
Summary
Implemented support for the MLX90614 Infrared Temperature Sensor.
Changes
MLX90614class for I2C communication.MLX90614Providerfor state management (includes error handling and safe loops).MLX90614Screento display Object and Ambient temperatures.locatorandmain.SensorsScreen.Fixes
Closes #2992
Summary by Sourcery
Add MLX90614 infrared temperature sensor support, including UI, provider wiring, and platform plugin registration updates.
New Features:
Bug Fixes:
Enhancements: