Skip to content

Commit

Permalink
V1.1.0FIX
Browse files Browse the repository at this point in the history
1. bug-fix: 修正安卓版的自动重连功能启用后无法手动断开连接的问题
2. 连接如果错误,将具体的错误信息显示出来
3. 双击曲线区域清除曲线数据
4. 检查到新版本后弹出的对话框中增加一个"下载"按钮
  • Loading branch information
cdhigh committed Mar 8, 2022
1 parent abb9abc commit eaa1748
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 77 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# m328v6数控电子负载上位机APP

这个是一乐论坛[M8V6数控电子负载]的升级版[M328V6数控电子负载]的新版上位机。
[M328V6数控电子负载制作链接](https://www.yleee.com.cn/thread-90734-1-1.html)
这个是一乐论坛[**M8V6数控电子负载**]的升级版[**M328V6数控电子负载**]的新版上位机。

## 特性:
1. 支持Android, iOS, Windows, Mac OS, Linux(注1,2)
Expand All @@ -17,7 +16,7 @@



## 屏幕截图:
## 屏幕截图(V1.0.0)

![ScreenshotPortrait](https://raw.githubusercontent.com/cdhigh/m328v6host/main/ref/Screenshots/ScrShotPortrait.png)

Expand Down
5 changes: 3 additions & 2 deletions lib/common/widget_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ Widget buildEmptyRow(double height, {bool hasTopBorder=false, bool hasBottomBord
}

///显示简单的Toast,可以在任何地方调用
void showToast(String text, {TextStyle textStyle = const TextStyle(fontSize: 17, color: Colors.white)}) {
BotToast.showText(text: text, duration: const Duration(seconds: 3), textStyle: textStyle);
void showToast(String text, {TextStyle textStyle = const TextStyle(fontSize: 17, color: Colors.white),
Duration duration = const Duration(seconds: 3)}) {
BotToast.showText(text: text, duration: duration, textStyle: textStyle);
}

///显示简单的顶端通知信息
Expand Down
12 changes: 8 additions & 4 deletions lib/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,19 @@ class _ConnectionPageState extends ConsumerState<ConnectionPage> {
}

final connProvider = ref.watch<ConnectionProvider>(Global.connectionProvider);
bool ret = false;
String ret = "";
try {
ret = await _uniSerial.open(name, baudRate);
} catch (e) {
ret = false;
ret = e.toString();
}

if (!ret) {
showToast("Open device failed".i18n);
if (ret.isNotEmpty) {
if (ret == "Error") { //没有具体错误信息
showToast("Open device failed".i18n);
} else {
showToast("Open device failed".i18n + "\n$ret");
}
return;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/flutter_libserialport_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ library flutter_libserialport;
/// 4. flutter clean
/// 5. flutter build apk
//export 'package:flutter_libserialport/flutter_libserialport.dart';
import 'dart:typed_data';
import 'dart:async';
import 'dart:io';

class SerialPort {
static final availablePorts = <String>[];
int get transport => 0;
static OSError? get lastError => const OSError("", 0);
SerialPort(String name);
void write(Uint8List data) {}
}

class SerialPortTransport {
Expand All @@ -36,4 +41,7 @@ class SerialPortFlowControl {

class SerialPortReader {
SerialPortReader(dynamic port);
void close() {}

Stream<Uint8List> get stream => Stream<Uint8List>.periodic(const Duration(days : 1));
}
1 change: 1 addition & 0 deletions lib/help_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class _HelpPageState extends State<HelpPage> {
"Double-click 'Vset' to set a new value".i18n,
"Double-click 'Iset' to set a new value".i18n,
"Double-click 'Capacity' to clear Ah of device".i18n,
"Double-click 'Curva area' to clear curva data".i18n,
];

//所有需要带链接的帮助信息都放在这里
Expand Down
5 changes: 5 additions & 0 deletions lib/i18n/common.i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ extension Localization on String {
{
"en_us": "There is a new version (%s), the download link has been copied to the clipboard",
"zh_cn": "发现新版本(%s), 下载链接已经拷贝到系统剪贴板",
} +
{
"en_us": "Name of device invalid",
"zh_cn": "设备名字错误",
};


String get i18n => localize(this, t);

//"Hello %s, this is %s".i18n.fill(["John", "Mary"])
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/help.i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ extension Localization on String {
"en_us": "Double-click 'Capacity' to clear Ah of device",
"zh_cn": "双击[容量]可以清零设备的容量值",
} +
{
"en_us": "Double-click 'Curva area' to clear curva data",
"zh_cn": "双击[曲线区域]可以清除曲线数据",
} +
{
"en_us": "Swipe on the left side of the screen to popup the menu",
"zh_cn": "从屏幕左侧往里滑可以弹出操作菜单",
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/main_page.i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ extension Localization on String {
"en_us": "Clear Ah?",
"zh_cn": "清除容量?",
} +
{
"en_us": "Clear curva data?",
"zh_cn": "清除曲线数据?",
} +
{
"en_us": "Turn on the electronic load?",
"zh_cn": "打开负载开始放电?",
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/settings.i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ extension Localization on String {
{
"en_us": "[The download link has been copied to the clipboard]",
"zh_cn": "[下载链接已经拷贝到系统剪贴板]",
} +
{
"en_us": "Download",
"zh_cn": "下载",
};

String get i18n => localize(this, t);
Expand Down
28 changes: 20 additions & 8 deletions lib/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
Future.delayed(const Duration(seconds: 5)).then(checkNewVersion); //延时确定是否需要检查新版本

_timerForExtraData = PausableTimer(const Duration(seconds: 3), qeuryVersionPeriodic);
_timerForExtraData.pause();
//_timerForExtraData.start(); //需要等连接后再启动定时器
_timerForReconnect = PausableTimer(const Duration(seconds: 1), reconnectPeriodic);
_timerForReconnect.pause();
}

//每隔一段时间重发一次请求额外数据的命令,避免下位机中间复位了
Expand All @@ -97,17 +99,17 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
return;
}

bool ret = false;
String ret = "";
try {
ret = await _uniSerial.open(name, baudRate);
} catch (e) {
ret = false;
ret = e.toString();
}

if (ret) { //如果重连成功
if (ret.isEmpty) { //如果重连成功
connProvider.setPort(name, baudRate);
Global.bus.sendBroadcast(EventBus.connectionChanged, arg: "1", sendAsync: false);
} else { //2s后继续重试
} else { //1s后继续重试
_timerForReconnect..reset()..start();
}
}
Expand Down Expand Up @@ -158,6 +160,8 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
void connectionChanged(String isConnect) {
if (mounted) {
final connProvider = ref.read<ConnectionProvider>(Global.connectionProvider);
_timerForReconnect.pause();

if (isConnect == "1") { //连接
//注册监听函数
connProvider.serial.registerListenFunction(newSrlDataReceived);
Expand All @@ -166,10 +170,8 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
Future.delayed(const Duration(milliseconds: 500)).then((_) => connProvider.load.queryVersion());
Future.delayed(const Duration(seconds: 1)).then((_) => connProvider.load.requestExtraData());
_timerForExtraData..reset()..start();
_timerForReconnect.pause();
} else { //断开连接
final rdProvider = ref.read<RunningDataProvider>(Global.runningDataProvider);
connProvider.serial.close();
connProvider.closePort();
rdProvider.reset();
_timerForExtraData.pause();
Expand Down Expand Up @@ -293,7 +295,7 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
return Container(padding: const EdgeInsets.all(10.0),
color: Global.isDarkMode ? Colors.transparent : appInfo.homePageBackgroundColor,
child: ListView(children: [
const CurvaChart(),
GestureDetector(child: const CurvaChart(), onDoubleTap: onDoubleTapCurvaChart),
buildVISetDisplay(context),
buildVIDisplay(context),
buildOtherDisplayData(context),
Expand Down Expand Up @@ -435,7 +437,8 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
color: Global.isDarkMode ? Colors.transparent : appInfo.homePageBackgroundColor,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [CurvaChartLandscape(scrWidth: _scrWidth),
children: [
GestureDetector(child: CurvaChartLandscape(scrWidth: _scrWidth), onDoubleTap: onDoubleTapCurvaChart),
SingleChildScrollView(child: Column(mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: buildRawDataDisplayLandscape(context),
Expand Down Expand Up @@ -599,6 +602,15 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
}
}

///双击曲线区域弹出提问,是否需要清除曲线数据
void onDoubleTapCurvaChart() async {
final bool? ok = await showOkCancelAlertDialog(context: context, title: "Confirm".i18n, content: Text("Clear curva data?".i18n));
if (ok == true) {
final vhProvider = ref.read<VoltHistoryProvider>(Global.vHistoryProvider);
vhProvider.clear();
}
}

///点击标题栏上的Switch按钮,询问是否需要打开关闭放电
void onTapAppBarSwitch(bool isOff) async {
final connProvider = ref.read<ConnectionProvider>(Global.connectionProvider);
Expand Down
20 changes: 15 additions & 5 deletions lib/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
/// 配置页面ui实现
/// Author: cdhigh <https://github.com/cdhigh>
///
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wakelock/wakelock.dart';
import 'package:url_launcher/url_launcher.dart';
import '../common/globals.dart';
import '../common/my_widget_chain.dart';
import '../common/widget_utils.dart';
Expand Down Expand Up @@ -413,14 +415,15 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {

///点击了现在检查新版本
void checkUpdateNow() async {
final ret = await checkUpdate(silent: false);
if (ret == null) {
final newVer = await checkUpdate(silent: false);
if (newVer == null) {
return;
}

final newVer = ret.version;
final whatsnew = ret.whatsNew.replaceAll("<br/>", "\n");
showOkAlertDialog(context: context, title: "Found new version [%s]".i18n.fill([newVer]),
final newVerNo = newVer.version;
final whatsnew = newVer.whatsNew.replaceAll("<br/>", "\n");
final ret = await showOkCancelAlertDialog(context: context, title: "Found new version [%s]".i18n.fill([newVerNo]),
okText: "Download".i18n,
content: Column(mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand All @@ -432,6 +435,13 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
child: Text("[The download link has been copied to the clipboard]".i18n, textScaleFactor: 0.8)),
],),
);
if (ret == true) {
if (Platform.isAndroid || Platform.isIOS || Platform.isFuchsia) {
launch(newVer.androidFile);
} else {
launch(newVer.windowsFile);
}
}
}

}
Loading

0 comments on commit eaa1748

Please sign in to comment.