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,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text(item.projectName), getCovidTestTypeImage(item)],
children: [Text(item.projectName ?? ""), getCovidTestTypeImage(item)],
),
);
}).toList(),

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

Loading…
Cancel
Save