temperature device implemented

dev_3.3_BLE
haroon amjad 3 years ago
parent 23ab0483e0
commit 336c0f17b6

@ -126,7 +126,7 @@ class _CovidDrivethruLocationState extends State<CovidDrivethruLocation> {
value: item, value: item,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text(item.projectName), getCovidTestTypeImage(item)], children: [Text(item.projectName ?? ""), getCovidTestTypeImage(item)],
), ),
); );
}).toList(), }).toList(),

@ -17,6 +17,15 @@ class _TemperatureHomePageState extends State<TemperatureHomePage> {
String connectionStatus = "disconnected"; String connectionStatus = "disconnected";
String currentTempInCelsius = "0.0"; String currentTempInCelsius = "0.0";
BluetoothDevice currentConnectedDevice;
@override
void dispose() {
super.dispose();
currentConnectedDevice.disconnect(timeout: 15);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppScaffold( return AppScaffold(
@ -52,7 +61,7 @@ class _TemperatureHomePageState extends State<TemperatureHomePage> {
SizedBox( SizedBox(
height: 50.0, height: 50.0,
), ),
Text("Current Temp: $currentTempInCelsius" + "\u2103"), Text("Current Temp: $currentTempInCelsius"),
], ],
), ),
); );
@ -91,6 +100,7 @@ class _TemperatureHomePageState extends State<TemperatureHomePage> {
// Note: you must always re-discover services after disconnection! // Note: you must always re-discover services after disconnection!
} }
if (state == BluetoothConnectionState.connected) { if (state == BluetoothConnectionState.connected) {
currentConnectedDevice = element.device;
List<BluetoothService> services = await element.device.discoverServices(); List<BluetoothService> services = await element.device.discoverServices();
services.forEach((service) { services.forEach((service) {
if (service.serviceUuid.toString().contains("1809")) { if (service.serviceUuid.toString().contains("1809")) {
@ -103,6 +113,8 @@ class _TemperatureHomePageState extends State<TemperatureHomePage> {
print(event); print(event);
setState(() { setState(() {
currentTempInCelsius = convertIntListToHex(event); currentTempInCelsius = convertIntListToHex(event);
String currentTempInFahrenheit = ((num.parse(currentTempInCelsius) * 1.8) + 32).toStringAsFixed(1);
currentTempInCelsius = currentTempInCelsius + "\u2103" + " / " + currentTempInFahrenheit + "\u2109";
}); });
}); });
await characteristic.setNotifyValue(true); await characteristic.setNotifyValue(true);

Loading…
Cancel
Save