Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
47 request empty device works only once then need to reconnect to bro…
Browse files Browse the repository at this point in the history
…ker (#48)

* fix add empty device bpc

* Empty device can be add even if we quit the page and come back

---------

Co-authored-by: Damien Albisson <[email protected]>
  • Loading branch information
Darcraytore1 and Damien Albisson authored Jun 4, 2024
1 parent 1e56f61 commit 1719ef3
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 86 deletions.
50 changes: 30 additions & 20 deletions lib/after_setup_pages/device_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:convert';

// import '../widgets/interface_control/icw_bpc.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:panduza_sandbox_flutter/data/const.dart';
import 'package:panduza_sandbox_flutter/data/device_config.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';
// import 'package:mqtt_client/mqtt_server_client.dart';

// import 'userspace/ic_bpc.dart';
Expand Down Expand Up @@ -111,40 +113,48 @@ class _DevicePageState extends State<DevicePage> {
// final int columns = (width / 300.0).round();

return Scaffold(
appBar: AppBar(
title: Text('Device ${_config.name}'),
),
body: Column(children: [
appBar: getAppBar('Device ${_config.name}'),
body: Column(
children: [
const SizedBox(
height: 20,
),
TextField(
controller: _nameController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: 'Name',
labelStyle: TextStyle(
color: white
)
),
onChanged: (value) => {_config.name = value},
),
DropdownButton<String>(
items: _availableRefList!
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
value: _config.ref,
onChanged: (String? value) {
setState(() {
_config.ref = value!;
});
}),
items: _availableRefList!
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
value: _config.ref,
onChanged: (String? value) {
setState(() {
_config.ref = value!;
});
}
),
propertyWidget(),
ElevatedButton(
onPressed: () {
Navigator.pop(context, true);
},
child: const Text("Apply"),
)
]));
]
)
);
}
}
}
48 changes: 28 additions & 20 deletions lib/after_setup_pages/hunt_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HuntPage extends StatefulWidget {
PlatformConfig _platformConfig;

@override
_HuntPageState createState() => _HuntPageState();
State<HuntPage> createState() => _HuntPageState();
}

class _HuntPageState extends State<HuntPage> {
Expand Down Expand Up @@ -169,25 +169,33 @@ class _HuntPageState extends State<HuntPage> {

return Scaffold(
appBar: AppBar(
title: Row(children: [
Text('hunt'),
ElevatedButton(
onPressed: () {
widget._platformConfig.devices.insert(
0,
DeviceConfig(
ref: "Panduza.FakeBps", settings: {}, name: "empty"));
// print(widget._platformConfig.devices.length);
Navigator.pop(context, true);
},
// style: ElevatedButton.styleFrom(
// elevation: 0,
// backgroundColor: Colors.green, // Green background
// foregroundColor: Colors.white, // White foreground
// ),
child: const Text("Empty"),
),
])),
title: Row(
children: [
const Text('Hunt'),
ElevatedButton(
onPressed: () {
print(widget._platformConfig.devices);
widget._platformConfig.devices.insert(
0,
DeviceConfig(
ref: "panduza.fake_power_supply",
settings: {},
name: "empty"
)
);
// print(widget._platformConfig.devices.length);
Navigator.pop(context, true);
},
// style: ElevatedButton.styleFrom(
// elevation: 0,
// backgroundColor: Colors.green, // Green background
// foregroundColor: Colors.white, // White foreground
// ),
child: const Text("Empty"),
),
]
)
),
body: GridView.count(
primary: false,
padding: const EdgeInsets.all(20),
Expand Down
105 changes: 61 additions & 44 deletions lib/after_setup_pages/platform_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:convert';

// import '../widgets/interface_control/icw_bpc.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:panduza_sandbox_flutter/data/const.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';
// import 'package:mqtt_client/mqtt_server_client.dart';

// import 'userspace/ic_bpc.dart';
Expand Down Expand Up @@ -85,10 +87,12 @@ class _PlatformPageState extends State<PlatformPage> {
var jsonObject = json.decode(pt);

if (jsonObject.containsKey("devices")) {
Map<dynamic, dynamic> store = jsonObject["devices"]["store"];
setState(() {
_deviceStore = store;
});
if (jsonObject.containsKey("store")) {
Map<dynamic, dynamic> store = jsonObject["devices"]["store"];
setState(() {
_deviceStore = store;
});
}
}
}

Expand Down Expand Up @@ -133,20 +137,23 @@ class _PlatformPageState extends State<PlatformPage> {
List<Widget> items = [];
for (var device in _platformConfig.devices) {
// device.
items.add(ListTile(
title: Text(device.name),
subtitle: Text(device.ref),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
DevicePage(_deviceStore, _platformConfig, device)),
).then((value) {
setState(() {});
});
},
));
items.add(
ListTile(
textColor: white,
title: Text(device.name),
subtitle: Text(device.ref),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
DevicePage(_deviceStore, _platformConfig, device)),
).then((value) {
setState(() {});
});
},
)
);
}
return items;
}
Expand All @@ -158,45 +165,55 @@ class _PlatformPageState extends State<PlatformPage> {
super.initState();

// subscribe to info and atts ?
_platformConfig.devices = [];
Future.delayed(const Duration(milliseconds: 1), initializeMqttSubscription);
}

@override
Widget build(BuildContext context) {
print("!!!!!!!!!!! ${_platformConfig.devices.length}");

return Scaffold(
appBar: AppBar(
title: Text('Platform'),
),
appBar: getAppBar("Platform"),
body: Center(
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,

children: [
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HuntPage(
widget._interfaceConnection, _platformConfig)),
).then((value) {
// print(" !!!!!!!!!!! ^^^^ ");
setState(() {});
});
},
style: ElevatedButton.styleFrom(
elevation: 0,
// backgroundColor: Colors.green, // Green background
// foregroundColor: Colors.white, // White foreground
),
child: const Text("New Device"),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: sendConfigToPlatform,
style: ElevatedButton.styleFrom(elevation: 0),
child: const Text("Push Config"),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HuntPage(
widget._interfaceConnection,
_platformConfig
)
),
).then((value) {
// print(" !!!!!!!!!!! ^^^^ ");
setState(() {});
});
},
style: ElevatedButton.styleFrom(
elevation: 0,
// backgroundColor: Colors.green, // Green background
// foregroundColor: Colors.white, // White foreground
),
child: const Text("New Device"),
),
ElevatedButton(
onPressed: sendConfigToPlatform,
style: ElevatedButton.styleFrom(elevation: 0),
child: const Text("Push Config"),
),
],
),
// Text("!!! ${_platformConfig.devices.length}"),
SizedBox(
Expand Down
13 changes: 11 additions & 2 deletions lib/userspace_widgets/ic_bpc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:panduza_sandbox_flutter/data/const.dart';
import 'templates.dart';
import '../../data/interface_connection.dart';

Expand Down Expand Up @@ -246,7 +247,11 @@ class _IcBpcState extends State<IcBpc> {
// ],
// ),
Text(
'Voltage : ${double.parse(_voltageValueReq!.toStringAsFixed(2))}V'),
'Voltage : ${double.parse(_voltageValueReq!.toStringAsFixed(2))}V',
style: TextStyle(
color: black
),
),
Slider(
value: _voltageValueReq!,
onChanged: (value) {
Expand All @@ -258,7 +263,11 @@ class _IcBpcState extends State<IcBpc> {
// max: _attsEffective["voltage"]["max"],
),
Text(
'Current : ${double.parse(_currentValueReq!.toStringAsFixed(2))}V'),
'Current : ${double.parse(_currentValueReq!.toStringAsFixed(2))}V',
style: TextStyle(
color: black
),
),
Slider(
value: _currentValueReq!,
onChanged: (value) {
Expand Down

0 comments on commit 1719ef3

Please sign in to comment.