-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix more telemetry bugs, separate classes
- Loading branch information
paulo
authored and
paulo
committed
May 4, 2024
1 parent
c1054d4
commit 6c080c7
Showing
8 changed files
with
316 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
import '../../models/telemetry_state.dart'; | ||
import '../../models/timed_telemetry.dart'; | ||
import '../../repository/telemetry_repository.dart'; | ||
import '../radio_config/radio_config_service.dart'; | ||
import '../repository/telemetry_repository.dart'; | ||
import 'telemetry_receiver.dart'; | ||
|
||
part 'telemetry_latest_streamer.g.dart'; | ||
|
||
@Riverpod(keepAlive: true) | ||
class TelemetryLatestStreamer extends _$TelemetryLatestStreamer { | ||
late TelemetryRepository _telemetryRepository; | ||
late int _myNodeNum; | ||
late int _nodeNum; | ||
|
||
@override | ||
TelemetryState build({required int nodeNum}) { | ||
final sub = ref | ||
.watch(telemetryReceiverProvider) | ||
.addTelemetryListener(nodeNum: nodeNum, listener: _processTelemetry); | ||
_myNodeNum = ref | ||
.watch(radioConfigServiceProvider.select((value) => value.myNodeNum)); | ||
_telemetryRepository = ref.watch(telemetryRepositoryProvider); | ||
_nodeNum = nodeNum; | ||
ref.onDispose(sub.cancel); | ||
_loadFirstTelemetry(); | ||
return const TelemetryState(); | ||
} | ||
|
||
void _processTelemetry(TimedTelemetry timedTelemetry) { | ||
final telemetry = timedTelemetry.telemetry; | ||
final environmentMetrics = telemetry.environmentMetrics; | ||
if (environmentMetrics.hasTemperature()) { | ||
state = state.copyWith(temp: telemetry.environmentMetrics.temperature); | ||
} | ||
if (environmentMetrics.hasRelativeHumidity()) { | ||
state = state.copyWith( | ||
relativeHumidity: telemetry.environmentMetrics.relativeHumidity, | ||
); | ||
} | ||
if (environmentMetrics.hasBarometricPressure()) { | ||
state = state.copyWith( | ||
barometricPressure: telemetry.environmentMetrics.barometricPressure, | ||
); | ||
} | ||
if (environmentMetrics.hasGasResistance()) { | ||
state = state.copyWith( | ||
gasResistance: telemetry.environmentMetrics.gasResistance, | ||
); | ||
} | ||
} | ||
|
||
Future<void> _loadFirstTelemetry() async { | ||
final telemetry = await _telemetryRepository.getOne( | ||
index: 0, | ||
fromNode: _nodeNum, | ||
owner: _myNodeNum, | ||
); | ||
if (telemetry != null) { | ||
_processTelemetry(telemetry); | ||
} | ||
} | ||
} |
175 changes: 175 additions & 0 deletions
175
lib/providers/telemetry/telemetry_latest_streamer.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.