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

Change display with mW #91

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/utils/utils_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ double valueToDouble(dynamic value) {
return 0.0;
}

// Show W, mW or micro W in function of value,
// if 0.001 W show 1 mW
String formatValueInBaseMilliMicro(double value, String prefix, String suffix) {

String newSuffix = suffix;
double newValue = value;
// If value inferior to 1 show it in milli
if (newValue < 1.0) {
newValue *= 1000;
newSuffix = "m$suffix";
// If value in milli inferior to 1 show it in milli
if (newValue < 1.0) {
newValue *= 1000;
newSuffix = "µ$suffix";
}
}

if (newValue == 0.0 ) {
newSuffix = suffix;
}
return "$prefix$newValue $newSuffix";

// typeAttribute example : "power"
// attributeName example : "value"
// attributeValue example : 1.1
Expand Down
12 changes: 9 additions & 3 deletions lib/widgets/userspace_widgets/ic_blc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:panduza_sandbox_flutter/utils/const.dart';
import 'templates.dart';
import '../../utils/utils_objects/interface_connection.dart';
import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart';
import 'package:panduza_sandbox_flutter/utils/utils_functions.dart';

import 'package:mqtt_client/mqtt_client.dart';
Expand Down Expand Up @@ -315,8 +315,9 @@ class _IcBlcState extends State<IcBlc> {
const SizedBox(
height: 20,
),
// Show power in percentage and the value
Text(
'Power : ${double.parse(_powerPercentageReq!.toStringAsFixed(_powerDecimals))}%',
'Power : ${double.parse(_powerPercentageReq!.toStringAsFixed(_powerDecimals))}% (${formatValueInBaseMilliMicro(double.parse(_powerValueReq!.toStringAsFixed(_powerDecimals)), "", "W")})',
style: TextStyle(
color: black
),
Expand All @@ -327,6 +328,11 @@ class _IcBlcState extends State<IcBlc> {
setState(() {
_powerPercentageReq =
double.parse((value).toStringAsFixed(_powerDecimals));

// Transform percentage in value
double powerValue = (1/100) * _powerPercentageReq! * _powerMax!;
_powerValueReq =
double.parse((powerValue).toStringAsFixed(_powerDecimals));
sendRequestNewValues();
});
},
Expand All @@ -342,7 +348,7 @@ class _IcBlcState extends State<IcBlc> {
height: 20,
),
Text(
'Current : ${double.parse(_currentValueReq!.toStringAsFixed(_currentDecimals))}A',
formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_currentDecimals)), "Current : ", "A"),
style: TextStyle(
color: black
),
Expand Down
101 changes: 42 additions & 59 deletions lib/widgets/userspace_widgets/ic_bpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,68 +281,51 @@ class _IcBpcState extends State<IcBpc> {
_currentValueReq != null) {
// Full bpc
return Card(
child: Column(
children: [
Row(
children: [
cardHeadLine2(widget._interfaceConnection),
const Spacer(),
Switch(
value: _enableValueEff!,
onChanged: enableValueSwitchOnChanged()
),
],
),
Text(
'Voltage : ${double.parse(_voltageValueReq!.toStringAsFixed(_voltageDecimal))}V',
style: TextStyle(
color: black
),
),
Slider(
value: _voltageValueReq!,
onChanged: (value) {
setState(() {
_voltageValueReq = value;

// Send value to broker only after timer
applyVoltageCurrentRequest();
});
},
min: _voltageMin,
max: _voltageMax
),
Text(
'Current : ${double.parse(_currentValueReq!.toStringAsFixed(_currentDecimal))}A',
style: TextStyle(
color: black
child: Column(
children: [
Row(
children: [
cardHeadLine2(widget._interfaceConnection),
const Spacer(),
Switch(
value: _enableValueEff!,
onChanged: enableValueSwitchOnChanged()
),
],
),
Text(
formatValueInBaseMilliMicro(double.parse(_voltageValueReq!.toStringAsFixed(_voltageDecimal)), 'Voltage : ', 'V'),
style: TextStyle(
color: black
),
Slider(
value: _currentValueReq!,
onChanged: (value) {
setState(() {
_currentValueReq = value;
applyVoltageCurrentRequest();
});
},
min: _currentMin,
max: _currentMax,
),
Slider(
value: _voltageValueReq!,
onChanged: (value) {
setState(() {
_voltageValueReq = value;
});
},
min: _voltageMin,
max: _voltageMax
),
Text(
formatValueInBaseMilliMicro(double.parse(_currentValueReq!.toStringAsFixed(_voltageDecimal)), 'Current : ', 'A'),
style: TextStyle(
color: black
),
// Row(
// children: [
// const SizedBox(
// width: 10,
// ),
// const Spacer(),
// Switch(
// value: _enableValueEff!,
// onChanged: enableValueSwitchOnChanged()
// ),
// ],
// )
],
)
),
Slider(
value: _currentValueReq!,
onChanged: (value) {
setState(() {
_currentValueReq = value;
});
},
min: _currentMin,
max: _currentMax,
),
])
);
} else {
return Card(
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/userspace_widgets/ic_powermeter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:panduza_sandbox_flutter/utils/const.dart';
import 'templates.dart';
import 'package:panduza_sandbox_flutter/utils/utils_objects/interface_connection.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:panduza_sandbox_flutter/utils/utils_functions.dart';


class IcPowermeter extends StatefulWidget {
Expand Down Expand Up @@ -125,7 +127,7 @@ class _IcPowermeterState extends State<IcPowermeter> {
children: [
cardHeadLine(widget._interfaceConnection),
Text(
"${double.parse(_value.toStringAsFixed(_measureDecimal))} W",
formatValueInBaseMilliMicro(double.parse(_value.toStringAsFixed(_measureDecimal)), "", "W"),
style: TextStyle(
color: black
),
Expand Down
Loading