overheat monitor with auto poweroff

- needs passwordless sudo on target machine or deploy to run as root
This commit is contained in:
Mikkeli Matlock
2026-01-25 19:53:43 +09:00
parent 22e9cd2c43
commit 15a805f7fe
9 changed files with 362 additions and 3 deletions

View File

@@ -2,6 +2,9 @@ import 'package:flutter/material.dart';
import 'screens/splash_screen.dart';
import 'screens/dashboard_screen.dart';
import 'screens/overheat_screen.dart';
import 'services/config_service.dart';
import 'services/overheat_monitor.dart';
/// Root widget that manages app state transitions
class AppRoot extends StatefulWidget {
@@ -13,6 +16,7 @@ class AppRoot extends StatefulWidget {
class _AppRootState extends State<AppRoot> {
bool _initialized = false;
bool _overheatTriggered = false;
String _initStatus = 'Starting...';
@override
@@ -21,7 +25,17 @@ class _AppRootState extends State<AppRoot> {
_runInitSequence();
}
@override
void dispose() {
OverheatMonitor.instance.stop();
super.dispose();
}
Future<void> _runInitSequence() async {
// Load config first
setState(() => _initStatus = 'Loading config...');
await ConfigService.instance.load();
// Simulate init checks - replace with real checks later
// (UART, GPS, sensors, etc.)
@@ -37,16 +51,31 @@ class _AppRootState extends State<AppRoot> {
setState(() => _initStatus = 'Ready');
await Future.delayed(const Duration(milliseconds: 300));
// Start overheat monitoring
OverheatMonitor.instance.start(
onOverheat: () {
setState(() => _overheatTriggered = true);
},
);
setState(() => _initialized = true);
}
@override
Widget build(BuildContext context) {
// Determine which screen to show (priority: overheat > splash > dashboard)
Widget child;
if (_overheatTriggered) {
child = const OverheatScreen(key: ValueKey('overheat'));
} else if (!_initialized) {
child = SplashScreen(key: const ValueKey('splash'), status: _initStatus);
} else {
child = const DashboardScreen(key: ValueKey('dashboard'));
}
return AnimatedSwitcher(
duration: const Duration(milliseconds: 500),
child: _initialized
? const DashboardScreen(key: ValueKey('dashboard'))
: SplashScreen(key: const ValueKey('splash'), status: _initStatus),
child: child,
);
}
}