diff --git a/README.md b/README.md index f037eb29032f982dda6f61926799c0f6ac94c452..54c879ec6fd041b386514d57c46c34fe51417073 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ GX芯片下载工具,用于连接USB给GX芯片下载固件/调试固件,持 #### 安装教程 完善中 +#### 更新日志 +1. 2022.07.14 修复设备断连后ISP工具闪退问题 +2. 2022.07.14 更新hidapi库版本 +3. 2022.07.14 修复界面中文乱码问题 +4. 2022.08.01 修复字体加载失败问题,并内置NotoSansSC为默认字体 +5. 2022.08.01 无用代码清理 + #### 使用说明 完善中 @@ -22,15 +29,5 @@ GX芯片下载工具,用于连接USB给GX芯片下载固件/调试固件,持 4. 新建 Pull Request -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) - - #### 致谢 1. 感谢hidapi \ No newline at end of file diff --git a/fonts/NotoSansSC-Regular.otf b/fonts/NotoSansSC-Regular.otf new file mode 100644 index 0000000000000000000000000000000000000000..d350ffa79e30636b1287ba64bd46f083a7af0d4a Binary files /dev/null and b/fonts/NotoSansSC-Regular.otf differ diff --git a/hidapi/hidapi.dll b/hidapi/hidapi.dll index 667ebc695a6753f63ae4dbd94f5aa38b74c458ae..8c78d7843c6753452c206de53b7ee8a86cbb6eec 100644 Binary files a/hidapi/hidapi.dll and b/hidapi/hidapi.dll differ diff --git a/hidapi/hidapi.h b/hidapi/hidapi.h index 3a2dab46e25de204f40480b13d6c839c731fee52..959c9122ab5da305c3d0048091ef53161d0f980d 100644 --- a/hidapi/hidapi.h +++ b/hidapi/hidapi.h @@ -5,9 +5,9 @@ Alan Ott Signal 11 Software - 8/22/2009 + libusb/hidapi Team - Copyright 2009, All Rights Reserved. + Copyright 2022, All Rights Reserved. At the discretion of the user of this library, this software may be licensed under the terms of the @@ -48,18 +48,40 @@ @ingroup API */ -#define HID_API_VERSION_MINOR 11 +#define HID_API_VERSION_MINOR 12 /** @brief Static/compile-time patch version of the library. @ingroup API */ -#define HID_API_VERSION_PATCH 2 +#define HID_API_VERSION_PATCH 0 /* Helper macros */ #define HID_API_AS_STR_IMPL(x) #x #define HID_API_AS_STR(x) HID_API_AS_STR_IMPL(x) #define HID_API_TO_VERSION_STR(v1, v2, v3) HID_API_AS_STR(v1.v2.v3) +/** @brief Coverts a version as Major/Minor/Patch into a number: + <8 bit major><16 bit minor><8 bit patch>. + + This macro was added in version 0.12.0. + + Convenient function to be used for compile-time checks, like: + #if HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) + + @ingroup API +*/ +#define HID_API_MAKE_VERSION(mj, mn, p) (((mj) << 24) | ((mn) << 8) | (p)) + +/** @brief Static/compile-time version of the library. + + This macro was added in version 0.12.0. + + @see @ref HID_API_MAKE_VERSION. + + @ingroup API +*/ +#define HID_API_VERSION HID_API_MAKE_VERSION(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH) + /** @brief Static/compile-time string version of the library. @ingroup API @@ -369,6 +391,8 @@ extern "C" { /** @brief Get a input report from a HID device. + Since version 0.10.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 10, 0) + Set the first byte of @p data[] to the Report ID of the report to be read. Make sure to allow space for this extra byte in @p data[]. Upon return, the first byte will diff --git a/hidapi/hidapi.lib b/hidapi/hidapi.lib index 0d0546282abc2f3b196dfe0c54616fae08f1e3e3..a028cee71212c2668a27e255ce52b300f49ce4bf 100644 Binary files a/hidapi/hidapi.lib and b/hidapi/hidapi.lib differ diff --git a/hidapi/hidapi.pdb b/hidapi/hidapi.pdb new file mode 100644 index 0000000000000000000000000000000000000000..4d00c019de4e47995a525f156ecf5750a04daf2f Binary files /dev/null and b/hidapi/hidapi.pdb differ diff --git a/hidapi/hidapi_winapi.h b/hidapi/hidapi_winapi.h new file mode 100644 index 0000000000000000000000000000000000000000..884712af867afba1a1c08f3bb41f0ed52ea77ab9 --- /dev/null +++ b/hidapi/hidapi_winapi.h @@ -0,0 +1,58 @@ +/******************************************************* + HIDAPI - Multi-Platform library for + communication with HID devices. + + libusb/hidapi Team + + Copyright 2022, All Rights Reserved. + + At the discretion of the user of this library, + this software may be licensed under the terms of the + GNU General Public License v3, a BSD-Style license, or the + original HIDAPI license as outlined in the LICENSE.txt, + LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt + files located at the root of the source distribution. + These files may also be found in the public source + code repository located at: + https://github.com/libusb/hidapi . +********************************************************/ + +/** @file + * @defgroup API hidapi API + * + * Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) + */ + +#ifndef HIDAPI_WINAPI_H__ +#define HIDAPI_WINAPI_H__ + +#include + +#include "hidapi.h" + +#ifdef __cplusplus +extern "C" { +#endif + + /** @brief Get the container ID for a HID device. + + Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) + + This function returns the `DEVPKEY_Device_ContainerId` property of + the given device. This can be used to correlate different + interfaces/ports on the same hardware device. + + @ingroup API + @param dev A device handle returned from hid_open(). + @param guid The device's container ID on return. + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT_CALL hid_winapi_get_container_id(hid_device *dev, GUID *container_id); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/main.cpp b/main.cpp index a87d5ba0573ed269175a2679d7fcbcb3d1df64ac..78fb9faa137e59269e76ce147fbda66e60a3373a 100644 --- a/main.cpp +++ b/main.cpp @@ -31,13 +31,30 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; - QString strFont0 = loadFontFamilyFromFiles("fonts\\FangZhengHeiTiJianTi.ttf"); + // Fixed font loads failed. (1/8 is a good day:D) + // When you compile this project, you can see this file will be appended to resources. + // Also you should do more steps when error above reproducing: + // 1.Download the .ttf file + // 2.Add qrc prefix(file: qrc.qrc). + // + // + // favicon.ico + // + // + // your-font-file.ttf + // + // + // 3.Add your file downloaded. + // 4.Good LUCK :D + QString strFont0 = loadFontFamilyFromFiles(":/fonts/fonts/NotoSansSC-Regular.otf"); qDebug() << "strFont0 is: " << strFont0; - a.setFont(strFont0); - QFont font; - font.setFamily(strFont0); - a.setFont(font); - qApp->setFont(font); + if(strFont0!=""&&!strFont0.isNull()&&!strFont0.isEmpty()){ + a.setFont(strFont0); + QFont font; + font.setFamily(strFont0); + a.setFont(font); + qApp->setFont(font); + } w.show(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 56ae620fbe3d5a2bc18c115518feb107d0454ebf..fcfa0c5fa4edaa40c5723ea1235b45cf19996063 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include +//#include +#include #include MainWindow::MainWindow(QWidget *parent) @@ -18,7 +19,7 @@ MainWindow::MainWindow(QWidget *parent) myusbthread->vid = DEFAULT_VENDOR_ID; myusbthread->pid = DEFAULT_PRODUCT_ID; myusbthread->start(); - qDebug() << myusbthread->vid << "|" << myusbthread->pid << endl; + qDebug() << myusbthread->vid << "|" << myusbthread->pid << Qt::endl; hid_device_list = myusbthread->get_device_list(); device_nums = hid_device_list.size(); ui->comboBox_device->clear(); @@ -115,14 +116,14 @@ void MainWindow::usbdisconnect() qDebug() << "usbdisconnect"; hid_isopen = false; refresh_button(); - ui->textEdit_information->append(QString::fromLocal8Bit("设备已断开")); + ui->textEdit_information->append(QString::fromUtf8("设备已断开")); } void MainWindow::usbsenderror() { qDebug() << "usbsenderror"; myusbthread->pause_thread(); - //QMessageBox::warning(this,QString::fromLocal8Bit("错误"),QString::fromLocal8Bit("USB发送数据异常"),QMessageBox::Ok); + //QMessageBox::warning(this,QString::fromUtf8("错误"),QString::fromUtf8("USB发送数据异常"),QMessageBox::Ok); } void MainWindow::sender_update() @@ -157,7 +158,7 @@ void MainWindow::sender_update() send_data(WRITE16_IN_PC_TO_MCU, gen_data); } refresh_button(); - ui->textEdit_information->append(QString::fromLocal8Bit("下载成功:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("下载成功:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); #endif } } @@ -189,7 +190,7 @@ void MainWindow::sender_update() Delay_MSec(30); check_count = 0; #ifdef DOWNLOAD_AND_CHECK - ui->textEdit_information->append(QString::fromLocal8Bit("下载成功,正在校验:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("下载成功,正在校验:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); check_data(); #else download_end_count = 0; @@ -215,10 +216,10 @@ void MainWindow::sender_update() } downloading = false; refresh_button(); - ui->textEdit_information->append(QString::fromLocal8Bit("下载成功:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("下载成功:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); if(1) { - ui->textEdit_information->append(QString::fromLocal8Bit("运行程序...")); + ui->textEdit_information->append(QString::fromUtf8("运行程序...")); QByteArray gen_data; gen_data.append((char)0x01); send_data(RESET_MCU_MCU_TO_PC, gen_data); @@ -262,7 +263,7 @@ void MainWindow::usbreceivedata(const QByteArray recv_data) QString Flash_ID = "0x" + recv_data.mid(16,2).toHex(0); QString USB_ID = "0x" + recv_data.mid(18,6).toHex(0); // ui->textEdit_information->append(tr("mtlink_version :%1").arg(mtlink_version)); - ui->textEdit_information->append(QString::fromLocal8Bit("找到可操作设备:")+tr("%1").arg(MCU_ID)); + ui->textEdit_information->append(QString::fromUtf8("找到可操作设备:")+tr("%1").arg(MCU_ID)); // ui->textEdit_information->append(tr("Flash_ID :%1").arg(Flash_ID)); // ui->textEdit_information->append(tr("USB_ID :%1").arg(USB_ID)); } @@ -283,14 +284,14 @@ void MainWindow::usbreceivedata(const QByteArray recv_data) if(read_data.left(flash_data.size()) != flash_data) { - ui->textEdit_information->append(QString::fromLocal8Bit("数据校验失败,请重新下载!") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("数据校验失败,请重新下载!") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); //ui->textEdit_information->append("尾部数据校验失败,请重新下载!" + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); QTimer::singleShot(10, this, SLOT(redownload_data())); return; } if(read_data.right(read_data.size()-flash_data.size()) != hex_parser.flash_end_data.left(read_data.size()-flash_data.size())) { - ui->textEdit_information->append(QString::fromLocal8Bit("数据校验失败,请重新下载!") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("数据校验失败,请重新下载!") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); //ui->textEdit_information->append("尾部数据校验失败,请重新下载!" + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); //error download QTimer::singleShot(10, this, SLOT(redownload_data())); @@ -298,7 +299,7 @@ void MainWindow::usbreceivedata(const QByteArray recv_data) } checking_end = false; //ui->textEdit_information->append("尾部数据校验成功,下载完成:" + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); - ui->textEdit_information->append(QString::fromLocal8Bit("校验成功,下载完成:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("校验成功,下载完成:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); //WRITE16_IN_PC_TO_MCU 00 20 00 0B { QByteArray gen_data; @@ -335,7 +336,7 @@ void MainWindow::usbreceivedata(const QByteArray recv_data) } else { - ui->textEdit_information->append(tr("%1").arg(data_cout) + QString::fromLocal8Bit("校验失败,请重新下载!") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(tr("%1").arg(data_cout) + QString::fromUtf8("校验失败,请重新下载!") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); qDebug() << "Read Data:" << read_data.toHex(' '); qDebug() << "Flash Data:" << flash_data.toHex(' '); QTimer::singleShot(10, this, SLOT(redownload_data())); @@ -353,12 +354,12 @@ void MainWindow::on_pushButton_openclose_clicked() { QString usb_path = ui->comboBox_device->currentData().toString(); if(usb_path.isEmpty()){ - QMessageBox::warning(this,"error",QString::fromLocal8Bit("USB打开失败,请检查设备!"),QMessageBox::Ok); + QMessageBox::warning(this,"error",QString::fromUtf8("USB打开失败,请检查设备!"),QMessageBox::Ok); return; } hid_isopen = myusbthread->open_usb(usb_path); if(!hid_isopen){ - QMessageBox::warning(this,"error",QString::fromLocal8Bit("USB打开失败,请检查设备!"),QMessageBox::Ok); + QMessageBox::warning(this,"error",QString::fromUtf8("USB打开失败,请检查设备!"),QMessageBox::Ok); } } } @@ -369,8 +370,8 @@ void MainWindow::on_pushButton_openclose_clicked() void MainWindow::on_pushButton_OpenFile_clicked() { - ui->textEdit_information->append(QString::fromLocal8Bit("打开文件...")); - QString fileName = QFileDialog::getOpenFileName(this,QString::fromLocal8Bit("打开固件文件"), QDir::currentPath(), QString::fromLocal8Bit("HEX文件(*.hex)")); + ui->textEdit_information->append(QString::fromUtf8("打开文件...")); + QString fileName = QFileDialog::getOpenFileName(this,QString::fromUtf8("打开固件文件"), QDir::currentPath(), QString::fromUtf8("HEX文件(*.hex)")); qDebug()<<"文件名: "+fileName; if(fileName.isEmpty()) @@ -381,11 +382,11 @@ void MainWindow::on_pushButton_OpenFile_clicked() if(!load_bin) { QMessageBox::warning(this,"error",hex_parser.error_info,QMessageBox::Ok); - ui->textEdit_information->append(fileName+QString::fromLocal8Bit(" 解析失败")); + ui->textEdit_information->append(fileName+QString::fromUtf8(" 解析失败")); return; } //ui->textEdit_information->append(fileName+" 解析成功, bin长度:" + tr("%1").arg(hex_parser.bin_data.size()-16)); - ui->textEdit_information->append(fileName+QString::fromLocal8Bit("成功")); + ui->textEdit_information->append(fileName+QString::fromUtf8("成功")); refresh_button(); //ui->pushButton_StartDownload->setEnabled(hid_isopen & load_bin & !downloading); } @@ -402,7 +403,7 @@ void MainWindow::on_pushButton_StartDownload_clicked() if(!load_bin) { QMessageBox::warning(this,"error",hex_parser.error_info,QMessageBox::Ok); - ui->textEdit_information->append(ui->lineEdit_FileName->text()+QString::fromLocal8Bit(" 解析失败")); + ui->textEdit_information->append(ui->lineEdit_FileName->text()+QString::fromUtf8(" 解析失败")); return; } #if DEBUG_WRITE_BIN_FILE @@ -654,15 +655,15 @@ void MainWindow::download_data() myusbthread->send_data(gen_data.leftJustified(64, 0x00, true)); } sender_timer->start(1); - ui->textEdit_information->append(QString::fromLocal8Bit("开始下载:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("开始下载:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); } void MainWindow::refresh_button() { if(hid_isopen) - ui->pushButton_openclose->setText(QString::fromLocal8Bit("断开连接")); + ui->pushButton_openclose->setText(QString::fromUtf8("断开连接")); else - ui->pushButton_openclose->setText(QString::fromLocal8Bit("连接设备")); + ui->pushButton_openclose->setText(QString::fromUtf8("连接设备")); ui->pushButton_StartDownload->setEnabled(hid_isopen & load_bin & !downloading); ui->pushButton_StartDownloadFlash->setEnabled(hid_isopen & load_bin & !downloading); ui->comboBox_device->setEnabled(!hid_isopen & !downloading); @@ -847,6 +848,6 @@ void MainWindow::on_pushButton_emptyFlash_clicked() send_data(WRITEN_FLASH_PC_TO_MCU, gen_data); } Delay_MSec(30); - ui->textEdit_information->append(QString::fromLocal8Bit("擦除数据:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); + ui->textEdit_information->append(QString::fromUtf8("擦除数据:") + QDateTime::currentDateTime().toString("hh:mm:ss.zzz")); } diff --git a/mainwindow.ui b/mainwindow.ui index 0412e874419505d8d386dd5375a87f1aa3e8f332..6d2f8f625b64baeacb5d66a76f81e421eb6062f6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 440 - 559 + 477 + 601 @@ -30,7 +30,6 @@ 14 - 75 true @@ -53,7 +52,6 @@ 12 - 75 true @@ -76,14 +74,13 @@ 300 141 - 111 + 131 31 12 - 75 true @@ -139,7 +136,6 @@ 12 - 9 false false @@ -175,14 +171,13 @@ 300 90 - 111 + 131 31 12 - 75 true @@ -233,7 +228,6 @@ 12 - 9 false false @@ -260,7 +254,6 @@ 12 - 9 false false @@ -287,7 +280,6 @@ 12 - 9 false false diff --git a/qrc.qrc b/qrc.qrc index 2d5acc11b7b5d889d17e2f2f12f578e6b09eb74a..912d456407423083380381ab4ab9a5aa98302d1b 100644 --- a/qrc.qrc +++ b/qrc.qrc @@ -2,4 +2,7 @@ favicon.ico + + fonts/NotoSansSC-Regular.otf + diff --git a/usbthread.cpp b/usbthread.cpp index adbf741ed3cd766bf50e47a52520a3e69330f49b..4f32348e6d0b2caf1a604fdf59aab9b9649a2bdc 100644 --- a/usbthread.cpp +++ b/usbthread.cpp @@ -1,5 +1,4 @@ #include "usbthread.h" -#include #include "mainwindow.h" #include @@ -73,7 +72,7 @@ void USBThread::pause_thread() //thread_pause = true; - //关闭USB + //关闭USB,需要判断是否还在线 if(status == USB_CONNECT){ qDebug()<<"hid_close"; hid_close(usbthread_handle); @@ -179,7 +178,7 @@ void USBThread::run() int res; res = hid_get_serial_number_string(usbthread_handle,str,16); qDebug() << "hid_get_serial_number_string:" << res; - if(res!=0) + if(res==0) { status = USB_DISCONNECT; emit usb_disconnect(); @@ -190,6 +189,7 @@ void USBThread::run() case USB_DISCONNECT: { msleep(100); + //qDebug() << "失去链接"; // /* USB未连接的时候,对实时性要求并不高,避免浪费CPU */ // if(QDateTime::currentMSecsSinceEpoch() - tick < 500 ) // break;