update logic uoutput data sensor
This commit is contained in:
parent
1bdc015476
commit
34ae69dae5
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import '../../widgets/thermal_heatmap.dart';
|
import '../../widgets/thermal_heatmap.dart'; // Pastikan widget ini sudah kamu buat
|
||||||
import '../../widgets/costum_header.dart';
|
import '../../widgets/costum_header.dart';
|
||||||
import '../notification/notification_screen.dart';
|
import '../notification/notification_screen.dart';
|
||||||
|
|
||||||
|
|
@ -28,8 +28,10 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_sensorRef = FirebaseDatabase.instance.ref('sensor');
|
_sensorRef = FirebaseDatabase.instance.ref('sensor');
|
||||||
_thermalRef = FirebaseDatabase.instance.ref('thermal/temperatures');
|
_thermalRef =
|
||||||
|
FirebaseDatabase.instance.ref('thermal_data'); // <- Sesuaikan di sini
|
||||||
|
|
||||||
|
// Listener untuk data sensor PIR, Ultrasonik, Pengusir
|
||||||
_sensorRef.onValue.listen((event) {
|
_sensorRef.onValue.listen((event) {
|
||||||
final data = event.snapshot.value;
|
final data = event.snapshot.value;
|
||||||
if (data != null && data is Map) {
|
if (data != null && data is Map) {
|
||||||
|
|
@ -45,31 +47,22 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listener untuk data thermal sensor
|
||||||
_thermalRef.onValue.listen((event) {
|
_thermalRef.onValue.listen((event) {
|
||||||
final data = event.snapshot.value;
|
final data = event.snapshot.value;
|
||||||
if (data != null) {
|
if (data != null && data is Map) {
|
||||||
List<double> temps = [];
|
final tempsData = data['temperatures'];
|
||||||
if (data is List) {
|
if (tempsData != null && tempsData is List) {
|
||||||
temps = data.map<double>((e) {
|
List<double> temps = tempsData.map<double>((e) {
|
||||||
if (e is num) return e.toDouble();
|
if (e is num) return e.toDouble();
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}).toList();
|
}).toList();
|
||||||
} else if (data is Map) {
|
|
||||||
temps = List<double>.filled(64, 0);
|
|
||||||
data.forEach((key, value) {
|
|
||||||
int idx = int.tryParse(key) ?? -1;
|
|
||||||
if (idx >= 0 && idx < 64) {
|
|
||||||
if (value is num) {
|
|
||||||
temps[idx] = value.toDouble();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temps.length == 64) {
|
if (temps.length == 64) {
|
||||||
setState(() {
|
setState(() {
|
||||||
thermalData = temps;
|
thermalData = temps;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -189,8 +182,8 @@ class SensorCard extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
elevation: 2, // shadow tipis
|
elevation: 2,
|
||||||
shadowColor: color.withOpacity(0.1), // lebih transparan
|
shadowColor: color.withOpacity(0.1),
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: isWide ? double.infinity : null,
|
width: isWide ? double.infinity : null,
|
||||||
|
|
|
||||||
|
|
@ -75,16 +75,24 @@ class _ThermalPainter extends CustomPainter {
|
||||||
// Garis putih di tengah dihilangkan (dihapus)
|
// Garis putih di tengah dihilangkan (dihapus)
|
||||||
}
|
}
|
||||||
|
|
||||||
Color _getColorForTemp(double t) {
|
Color _getColorForTemp(double t) {
|
||||||
double norm = ((t - 20) / 20).clamp(0.0, 1.0);
|
if (t <= 20) {
|
||||||
return HSVColor.lerp(
|
return Colors.blue;
|
||||||
HSVColor.fromColor(Colors.blue),
|
} else if (t <= 25) {
|
||||||
HSVColor.fromColor(Colors.red),
|
double ratio = (t - 20) / 5;
|
||||||
norm,
|
return Color.lerp(Colors.blue, Colors.green, ratio)!;
|
||||||
)!
|
} else if (t <= 28) {
|
||||||
.toColor();
|
double ratio = (t - 25) / 3;
|
||||||
|
return Color.lerp(Colors.green, Colors.yellow, ratio)!;
|
||||||
|
} else if (t < 30) {
|
||||||
|
double ratio = (t - 28) / 2;
|
||||||
|
return Color.lerp(Colors.yellow, Colors.red, ratio)!;
|
||||||
|
} else {
|
||||||
|
return Colors.red;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(covariant _ThermalPainter oldDelegate) {
|
bool shouldRepaint(covariant _ThermalPainter oldDelegate) {
|
||||||
if (oldDelegate.temps.length != temps.length) return true;
|
if (oldDelegate.temps.length != temps.length) return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue