Skip to content

Commit

Permalink
Auto point collection & UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaflik committed Aug 9, 2023
1 parent bb5eebe commit 632e50e
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 71 deletions.
67 changes: 51 additions & 16 deletions lib/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,9 @@ class Dashboard extends GetView<RobotStateController> {
@override
Widget build(BuildContext context) {
return n.Column([
const RobotStateWidget(),
n.Stack([
const MapWidget(centerOnRobot: false),
n.Column([
Card(
elevation: 3,
child: n.Column([
"Current State:".bodyLarge..m = 4,
Obx(() => controller.robotState.value.currentState.h4..m = 4)
])
..p = 16
..mainAxisAlignment = MainAxisAlignment.start
..crossAxisAlignment = CrossAxisAlignment.start
..fullWidth,
),
])
..p = 16
..expanded,
const RobotStateWidget(),
])
..expanded,
Material(elevation: 5, child: Obx(() => getButtonPanel(context, controller)))
Expand Down Expand Up @@ -69,6 +54,17 @@ class Dashboard extends GetView<RobotStateController> {
..expanded
..elevation = 2
..p = 16),
n.Button.elevatedIcon(
"Skip area".n, n.Icon(Icons.route))
..visible = controller
.hasAction("mower_logic:mowing/skip_area")
..onPressed = () {
remoteControl
.callAction("mower_logic:mowing/skip_area");
}
..style = n.ButtonStyle(backgroundColor: Colors.orangeAccent)
..elevation = 2
..p = 16,
n.Button.elevatedIcon("Stop".n, n.Icon(Icons.home))
..enable = controller.hasAction("mower_logic:mowing/abort_mowing")
..onPressed = () {
Expand Down Expand Up @@ -170,6 +166,45 @@ class Dashboard extends GetView<RobotStateController> {
..gap = 8
..px = 16
..py = 8,
n.Row([
controller.hasAction("mower_logic:area_recording/auto_point_collecting_disable")
? (n.Button.elevatedIcon(
"Disable auto collecting".n, n.Icon(Icons.route))
..visible = controller
.hasAction("mower_logic:area_recording/auto_point_collecting_disable")
..onPressed = () {
remoteControl
.callAction("mower_logic:area_recording/auto_point_collecting_disable");
}
..style = n.ButtonStyle(backgroundColor: Colors.orangeAccent)
..elevation = 2
..p = 16)
: (n.Button.elevatedIcon(
"Enable auto collecting".n, n.Icon(Icons.route))
..visible = controller
.hasAction("mower_logic:area_recording/auto_point_collecting_enable")
..onPressed = () {
remoteControl
.callAction("mower_logic:area_recording/auto_point_collecting_enable");
}
..elevation = 2
..p = 16),
n.Button.elevatedIcon(
"Add point".n, n.Icon(Icons.add_location))
..visible = controller
.hasAction("mower_logic:area_recording/collect_point")
..onPressed = () {
remoteControl
.callAction("mower_logic:area_recording/collect_point");
}
..style = n.ButtonStyle(backgroundColor: Colors.green)
..elevation = 2
..expanded
..p = 16,
])
..gap = 8
..px = 16
..py = 8,
])
..py = 8;
}
Expand Down
146 changes: 91 additions & 55 deletions lib/views/robot_state_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,123 @@ class RobotStateWidget extends GetView<RobotStateController> {
const RobotStateWidget({super.key});

IconData getGpsIcon(percent) {
if(percent > 0.75) {
if (percent > 0.75) {
return Icons.gps_fixed;
}
if(percent >= 0.25) {
if (percent >= 0.25) {
return Icons.gps_not_fixed;
}
return Icons.gps_off;
}

@override
Widget build(BuildContext context) {
return Material(
elevation: 5,
child: Obx(() =>n.Row([
RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black87),
children: [
const TextSpan(text: "MQTT: "),
WidgetSpan(
child:
Icon(controller.robotState.value.isConnected ? Icons.link : Icons.link_off, color: Colors.black54),
alignment: PlaceholderAlignment.middle),
])),
/*RichText(
text: const TextSpan(
style: TextStyle(color: Colors.black87),
children: [
TextSpan(text: "WiFi: "),
WidgetSpan(
child:
Icon(Icons.network_wifi_3_bar, color: Colors.black54),
alignment: PlaceholderAlignment.middle),
])),*/
RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black87),
children: [
const TextSpan(text: "GPS: "),
WidgetSpan(
child: Obx(() => Icon(getGpsIcon(controller.robotState.value.gpsPercent), color: Colors.black54)),
alignment: PlaceholderAlignment.middle),
])),
RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black87),
children: [
const TextSpan(text: "Battery: "),
WidgetSpan(
child: Icon(getBatteryIcon(controller.robotState.value.batteryPercent, controller.robotState.value.isCharging), color: Colors.black54),
alignment: PlaceholderAlignment.middle),
]))
])
..mainAxisAlignment = MainAxisAlignment.end
..m = 16
..gap = 8));
var stateCol = n.Column([
Card(
elevation: 3,
child: n.Column([
Obx(() => controller.robotState.value.currentState.h5..m = 4)
])
..p = 16),
])
..p = 16
..expanded
..mainAxisAlignment = MainAxisAlignment.start
..crossAxisAlignment = CrossAxisAlignment.start;

var iconsCol = n.Column([
Obx(() => n.Row([
RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black87),
children: [
const TextSpan(text: "MQTT: "),
WidgetSpan(
child: Icon(
controller.robotState.value.isConnected
? Icons.link
: Icons.link_off,
color: Colors.black54),
alignment: PlaceholderAlignment.middle),
])),
// RichText(
// text: const TextSpan(
// style: TextStyle(color: Colors.black87),
// children: [
// TextSpan(text: "WiFi: "),
// WidgetSpan(
// child:
// Icon(Icons.network_wifi_3_bar, color: Colors.black54),
// alignment: PlaceholderAlignment.middle),
// ])),
RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black87),
children: [
const TextSpan(text: "GPS: "),
WidgetSpan(
child: Obx(() => Icon(
getGpsIcon(controller.robotState.value.gpsPercent),
color: Colors.black54)),
alignment: PlaceholderAlignment.middle),
])),
RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black87),
children: [
const TextSpan(text: "Battery: "),
WidgetSpan(
child: Icon(
getBatteryIcon(
controller.robotState.value.batteryPercent,
controller.robotState.value.isCharging),
color: getBatteryColor(
controller.robotState.value.batteryPercent,
controller.robotState.value.isCharging)),
alignment: PlaceholderAlignment.middle),
]))
])
..mainAxisAlignment = MainAxisAlignment.end
..m = 16
..gap = 8)
])
..p = 16
..expanded;

return n.Row([stateCol, iconsCol]);
}

Color getBatteryColor(double percentage, bool charging) {
if (charging) {
return Colors.green;
}

return Colors.black54;
}

IconData getBatteryIcon(double percentage, bool charging) {
if(charging && percentage > 0.875){
if (charging && percentage > 0.875) {
return Icons.battery_charging_full;
}
if(percentage > 0.875) {
if (percentage > 0.875) {
return Icons.battery_full;
}
if(percentage > 0.75) {
if (percentage > 0.75) {
return Icons.battery_6_bar;
}
if(percentage > 0.625) {
if (percentage > 0.625) {
return Icons.battery_5_bar;
}
if(percentage > 0.5) {
if (percentage > 0.5) {
return Icons.battery_4_bar;
}
if(percentage > 0.375) {
if (percentage > 0.375) {
return Icons.battery_3_bar;
}
if(percentage > 0.25) {
if (percentage > 0.25) {
return Icons.battery_2_bar;
}
if(percentage > 0.125) {
if (percentage > 0.125) {
return Icons.battery_1_bar;
}
return Icons.battery_0_bar;
Expand Down

0 comments on commit 632e50e

Please sign in to comment.