Added Content Window

This commit is contained in:
Indy970 2019-02-18 22:15:04 +02:00
parent f51dc60335
commit d6d25e71be
11 changed files with 160 additions and 109 deletions

View file

@ -17,7 +17,18 @@ TEMPLATE = app
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += "VERSION=0"
VERSION_MAJOR = HP_MAJOR_VERSION
VERSION_MINOR = HP_MINOR_VERSION
VERSION_PATCH = HP_MINOR_PATCH
VERSION_BUILD = HP_MINOR_BUILD
DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR"\
"VERSION_MINOR=$$VERSION_MINOR"\
"VERSION_PATCH=$$VERSION_PATCH"\
"VERSION_BUILD=$$VERSION_BUILD"
#Target version
VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_PATCH}$${VERSION_BUILD}
#QMAKE_CFLAGS += -Wno-unused-parameter -Werror=shadow -Werror=write-strings -Werror=redundant-decls -Werror=format -Werror=format-nonliteral -Werror=date-time -Werror=missing-prototypes -Werror=pointer-arith -Wunreachable-code -Werror=format-security -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=return-type -D_FORTIFY_SOURCE=2 -D__LINUX__ -fvisibility=hidden
#QMAKE_CXXFLAGS += -include cctype -include cstdlib
@ -102,8 +113,8 @@ HEADERS += \
hp_infodialog.h \
getnumber.h \
hpusb.h \
hp_settingsdlg.h
hp_settingsdlg.h \
version.h
FORMS += \
mainwindow.ui \

View file

@ -1,8 +1,13 @@
17/02/2019
1 GUI
About
Content - fix icons
Content - fix columns
Content - fix resizing
Create storage path if it does not exist
Load and read program files
Load Screen shot and display
Add options - set default paths
2 Comms
Understand what the calc is doing!
3 Backup to disk

View file

@ -1,11 +1,14 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#include <errorhandler.h>
#include "version.h"
#include "errorhandler.h"
class errorHandler;
extern errorHandler *main_err;
#define log(a) main_err->error(L7,0,QString(a),QString());
#define err(a,b,c) main_err->error(a,b,QString(c),QString());
#endif // GLOBAL_H

View file

@ -109,7 +109,7 @@ void hpCalcData::readScreen() {
hp_Settings hpset;
log("Reading Screen");
qDebug()<<"Reading Screen";
api=getAPI();
handle=getHandle();
@ -123,11 +123,9 @@ void hpCalcData::readScreen() {
if (screenShot!=nullptr) {
delete screenShot;
}
qDebug()<<"New ScreenShot";
screenShot = new QPixmap();
qDebug()<<"Loading data";
qDebug()<<imageData[1];
screenShot->loadFromData(imageData);
}
}

115
hpusb.cpp
View file

@ -298,7 +298,6 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) {
b_9=raw[9];
b_10=raw[10];
qDebug()<<QString("Extract Header");
b_0=raw[0];
@ -362,7 +361,7 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
int trans_c=0;
int chunks;
uint8_t raw[1024];
QByteArray in_buffer(1024,0);
log("Recieve...");
@ -377,11 +376,14 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
if (!devh)
return -1;
memset((void *)pktin->data, 0, sizeof(pktin->size));
ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,1024,&trans,5000);
extract_header(raw,&uh1);
memcpy(pktin->data,raw,trans);
in_buffer.insert(0,(const char *)raw,trans);
in_buffer.resize(trans);
qDebug()<<QString("Looking for %1 items: %2 bytes read").arg(uh1.items).arg(trans);
if ((uh1.type==HP_HDR_FIRST)&&(uh1.items>0x00)) {
@ -392,11 +394,31 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
//read additional chuncks
ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,1024,&trans_c,5000);
extract_header(raw, &uh2);
qDebug()<<QString("Copying %1 bytes").arg(trans_c);
memcpy(&pktin->data[trans],raw,trans_c);
//check for empty packet
if (trans_c>0) {
qDebug()<<QString("Copying %1 bytes").arg(trans_c);
in_buffer.append((const char *)raw,trans_c);
qDebug()<<QString("another chunk read %1/%2").arg(chunks).arg(uh2.chunk);
trans+=trans_c;
}
}
}
qDebug()<<QString("another chunk read %1/%2").arg(chunks).arg(uh2.chunk);
trans+=trans_c;
if ((uh1.type==HP_HDR_STD)&&(uh1.items>0x00)) {
qDebug()<<QString("First std chunk detected %1").arg(uh1.items);
for (chunks=1; chunks<uh1.items; chunks++) {
trans_c=0;
//read additional chuncks
ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,1024,&trans_c,5000);
extract_header(raw, &uh2);
//check for empty packet
if (trans_c>0) {
qDebug()<<QString("Copying %1 bytes").arg(trans_c);
in_buffer.append((const char *)raw,trans_c);
qDebug()<<QString("another chunk read %1/%2").arg(chunks).arg(uh2.chunk);
trans+=trans_c;
}
}
}
@ -411,12 +433,12 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
//read additional chuncks
ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,1024,&trans_c,5000);
extract_header(raw, &uh2);
if (trans_c>2) {
//check for empty packet
if (trans_c>0) {
qDebug()<<QString("PNG: Copying %1 bytes").arg(trans_c);
//Assume first byte a chunck count
memcpy(&pktin->data[trans],&raw[headerlen],trans_c-headerlen);
in_buffer.append((const char *)&raw[headerlen],trans_c-headerlen);
trans+=trans_c-headerlen;
pktin->size=trans;
}
else
{
@ -427,17 +449,15 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
}
}
qDebug()<<QString("%1: Recieved ").arg(__FUNCTION__)<<trans<<" bytes";
log(QString().sprintf("read: %d\n", trans));
pktin->array=in_buffer;
if (ret){
log(QString().sprintf("ERROR in interrupt read: %s\n", libusb_error_name(ret)));
}
else{
//printf("%d receive %d bytes from device: %s\n");
qDebug()<<QString("Exiting %1 ret %2").arg(__FUNCTION__).arg(ret);
log(QString().sprintf("%d bytes received",trans));
main_err-> dump(pktin->data,trans);
main_err-> dump((uint8_t *)pktin->array.constData(),trans);
}
return ret;
}
@ -462,7 +482,6 @@ int hpusb::get_screen_shot(hp_Handle * handle, QByteArray * imageData) {
if (handle != NULL) {
uint8_t transferbuffer[LEN_IN_BUFFER+8];
uint8_t in_buffer[LEN_IN_BUFFER*16];
hp_pkt_in pktin;
hp_pkt_out pktout;
@ -477,22 +496,19 @@ int hpusb::get_screen_shot(hp_Handle * handle, QByteArray * imageData) {
if (!(res=submit_sync_s_transfer(handle,&pktout))){
pktin.cmd= CMD_PRIME_RECV_SCREEN;
pktin.data=in_buffer;
pktin.size=sizeof(in_buffer);
log(QString("%1: Waiting for a reply").arg(__FUNCTION__));
if (!submit_sync_r_transfer(handle,&pktin)){
log(QString("%1: Recieved a reply").arg(__FUNCTION__));
//Trying to understand reply
int endpos;
QByteArray rd= QByteArray(reinterpret_cast<const char*>(pktin.data), pktin.size);
QByteArray rd = pktin.array;
endpos = rd.indexOf("IEND");
qDebug()<<"End pos:"<<endpos;
*imageData = QByteArray(rd.mid(14,endpos+4-14));
// qDebug()<<*imageData;
log(QString().sprintf("%d bytes received",pktin.size));
main_err-> dump((uint8_t *)imageData->data(),imageData->size());;
log(QString().sprintf("%d bytes received",pktin.array.size()));
}
}
@ -529,14 +545,14 @@ int hpusb::is_ready(hp_Handle * handle) {
if (!(res=submit_sync_s_transfer(handle,&pktout))){
pktin.cmd= CMD_PRIME_CHECK_READY;
pktin.data=in_buffer;
pktin.size=1024;
// pktin.data=in_buffer;
// pktin.size=1024;
log(QString("%1: Waiting for a reply").arg(__FUNCTION__));
if (!submit_sync_r_transfer(handle,&pktin)){
log(QString("%1: Recieved a reply").arg(__FUNCTION__));
//Trying to understand reply
QByteArray rd= QByteArray(reinterpret_cast<const char*>(pktin.data), pktin.size);
// QByteArray rd= QByteArray(reinterpret_cast<const char*>(pktin.data), pktin.size);
// lookfordouble(rd,64);
}
}
@ -551,7 +567,7 @@ int hpusb::is_ready(hp_Handle * handle) {
int hpusb::load_info(hp_Handle * handle, hp_Information * hpinfo) {
uint8_t transferbuffer[LEN_IN_BUFFER+8];
uint8_t in_buffer[LEN_IN_BUFFER+8];
// uint8_t in_buffer[LEN_IN_BUFFER+8];
hp_pkt_in pktin;
hp_pkt_out pktout;
@ -586,26 +602,22 @@ int hpusb::load_info(hp_Handle * handle, hp_Information * hpinfo) {
else
{
//recieve response
pktin.data=in_buffer;
pktin.size=sizeof(in_buffer);
// pktout.size=PRIME_RAW_HID_DATA_SIZE+16;
if(!submit_sync_r_transfer(handle,&pktin)) {
//unpack data
log("unpacking data");
//unpack data
log("unpacking data");
int ind=0;
QTextCodec * codec = QTextCodec::codecForName("UTF-8");
QByteArray rd= QByteArray(reinterpret_cast<const char*>(pktin.data), pktin.size);
int ind=0;
QTextCodec * codec = QTextCodec::codecForName("UTF-8");
QByteArray rd= pktin.array;
//find name
ind=rd.indexOf(QChar(0x6c),0)+1;
QByteArray str1 =rd.mid(ind,64);
//find name
ind=rd.indexOf(QChar(0x6c),0)+1;
QByteArray str1 =rd.mid(ind,64);
QString name;
name = codec->toUnicode(str1);
hpinfo->name=name;
QString name;
name = codec->toUnicode(str1);
hpinfo->name=name;
//find OS Version
unsigned char searchstr[] = {0x80,0x20,0x80,0x01,0x62,0x01};
@ -631,13 +643,11 @@ int hpusb::load_info(hp_Handle * handle, hp_Information * hpinfo) {
ind+=16;
str1 =rd.mid(ind,16);
// QByteArray db= QByteArray(reinterpret_cast<const double*>(&pktout.buffer[ind]), pktout.size-ind);
return 0;
return 0;
}
else {
log("failed to read info from device");
return 1;
log("failed to read info from device");
return 1;
}
}
return 0;
@ -673,7 +683,6 @@ int hpusb::get_settings(hp_Handle * handle, hp_Settings * set) {
hp_Settings inset;
uint8_t transferbuffer[LEN_IN_BUFFER+8];
uint8_t in_buffer[LEN_IN_BUFFER+8];
hp_pkt_in pktin;
hp_pkt_out pktout;
@ -684,9 +693,6 @@ int hpusb::get_settings(hp_Handle * handle, hp_Settings * set) {
pktout.data=transferbuffer;
pktout.size=1024;
pktin.data=in_buffer;
pktin.size=sizeof(in_buffer);
// pktout.size=PRIME_RAW_HID_DATA_SIZE+16;
if(!handle) {
err(L3,0,"Passed 0 handle");
return -1;
@ -716,7 +722,6 @@ int hpusb::set_settings(hp_Handle * handle, hp_Settings set) {
int hpusb::vpkt_send_experiments(hp_Handle * handle, int cmd) {
uint8_t transferbuffer[LEN_IN_BUFFER*8 ];
uint8_t in_buffer[LEN_IN_BUFFER+8];
hp_pkt_in pktin;
hp_pkt_out pktout;
@ -790,10 +795,6 @@ int hpusb::vpkt_send_experiments(hp_Handle * handle, int cmd) {
pktout.data=transferbuffer;
pktout.size=1024;
pktin.data=in_buffer;
pktin.size=sizeof(in_buffer);
// pktout.size=PRIME_RAW_HID_DATA_SIZE+16;
submit_sync_s_transfer(handle,&pktout);
submit_sync_r_transfer(handle,&pktin);
@ -883,9 +884,9 @@ int hpusb::submit_async_transfer(hp_Handle * handle, hp_pkt_in * pktin, hp_pkt_o
//Filling
//libusb_fill_interrupt_setup(in_buffer,LIBUSB_RECIPIENT_DEVICE ,LIBUSB_REQUEST_TYPE_STANDARD,0,0,16);
libusb_fill_control_transfer( transfer_in, devh,
pktin->data, // Note: in_buffer is where input data written.
cb_in, nullptr, 1000); // no user data
// libusb_fill_control_transfer( transfer_in, devh,
// pktin->data, // Note: in_buffer is where input data written.
// cb_in, nullptr, 1000); // no user data
//take the initial time measurement
clock_gettime(CLOCK_REALTIME, &t1);

View file

@ -81,13 +81,14 @@ struct hp_cmd {
};
struct hp_pkt_in {
uint8_t * data;
QByteArray array;
uint32_t size;
uint8_t cmd;
};
struct hp_pkt_out {
uint8_t * data;
QByteArray array= QByteArray(1024,0);
uint32_t size;
uint8_t cmd;
};

View file

@ -9,16 +9,16 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("QtProject");
QCoreApplication::setApplicationName("Linux HP Connect");
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
QCoreApplication::setOrganizationName("");
QCoreApplication::setApplicationName("Linux QtHP Connect");
QCoreApplication::setApplicationVersion(HP_VERSION_STRING);
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName());
parser.setApplicationDescription(QCoreApplication::applicationName());
//REWORK
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", "The file to open.");
// parser.addPositionalArgument("file", "The file to open.");
parser.process(a);
MainWindow w;

View file

@ -22,16 +22,17 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QTableView>
#include <QMessageBox>
#include <QTreeView>
#include <QLabel>
#include <QInputDialog>
#include <QFile>
#include <QTextStream>
#include <QFileIconProvider>
#include "global.h"
#include "hpusb.h"
#include "datamodel.h"
#include "treemodel.h"
@ -42,7 +43,6 @@
#include "hpdata.h"
#include "hp_mdivariableedit.h"
#include "hp_mditexteditor.h"
#include <QInputDialog>
errorHandler *main_err;
#define log(a) main_err->error(L7,0,QString(a),QString());
@ -52,10 +52,15 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
//setup
QCoreApplication::setOrganizationName("Private");
QCoreApplication::setOrganizationName("IRGP");
QCoreApplication::setOrganizationDomain("");
QCoreApplication::setApplicationName("Linux HP Prime Interface");
QSettings appSettings;
QCoreApplication::setApplicationName("Linux QtHPConnect");
QSettings appSettings("IRGP","QtHPconnect");
//Set config file location (default used)
// appSettings->setPath(QSettings::NativeFormat,QSettings::UserScope,"");
appSettings.setValue("contentPath",QDir::homePath()+"/.local/share/qthpconnect/contents/");
//error handler
main_err = new errorHandler(this);
@ -77,6 +82,7 @@ MainWindow::MainWindow(QWidget *parent) :
createActions();
createLogWindow();
setTreeMenu();
setContentWindow();
//setup trees
ui->tvCalculators->setModel(hpTreeModel);
@ -302,10 +308,9 @@ void MainWindow::clickedCalculator(QModelIndex index) {
void MainWindow::about()
{
QMessageBox::about(this, tr("About Application"),
tr("The <b>Application</b> example demonstrates how to "
"write modern GUI applications using Qt, with a menu bar, "
"toolbars, and a status bar."));
QMessageBox::about(this, tr("About QtHP Connect"),
QString("Version: ")+HP_VERSION_STRING);
}
//Dummy from examples -- edit
@ -321,12 +326,33 @@ void MainWindow::createActions()
//show or hide content window
void MainWindow::showContent() {
if (ui->dwContent_2->isVisible()) {
ui->dwContent_2->hide();
if (ui->dwContent->isVisible()) {
ui->dwContent->hide();
}
else
{
ui->dwContent_2->show();
ui->dwContent->show();
}
}
//Setup the content window to show saved content
void MainWindow::setContentWindow() {
QSettings appSettings("IRGP","QtHPconnect");
QString path;
path=appSettings.value("contentPath").toString();
qDebug()<<"Content Path:"<<path;
contentModel.setRootPath(path);
contentModel.iconProvider()->setOptions(QFileIconProvider::DontUseCustomDirectoryIcons);
ui->tvContent->setModel(&contentModel);
if (!path.isEmpty()) {
const QModelIndex rootIndex = contentModel.index(QDir::cleanPath(path));
if (rootIndex.isValid()) {
ui->tvContent->setRootIndex(rootIndex);
}
}
}
@ -376,7 +402,6 @@ void MainWindow::dataChange(hp_Change hpchange) {
break;
case HP_SCREEN: {
qDebug()<<"Reciebed screenshot changed";
if (hpchange.calc!=nullptr) {
hp_ScreenShot scrn;
scrn = hpchange.calc->getScreenShot();
@ -390,9 +415,7 @@ void MainWindow::dataChange(hp_Change hpchange) {
//Add screen shots to the message window
void MainWindow::monitorAddImage(hp_ScreenShot scrnshot) {
qDebug()<<"In Monitor Add Screen Shot";
QPixmap * pic;
QPixmap * pic;
int col;
int row;
int count;
@ -413,8 +436,8 @@ void MainWindow::monitorAddImage(hp_ScreenShot scrnshot) {
col=count%maxcol;
row=count/maxcol;
qDebug()<<"Row set"<<row;
qDebug()<<"Column set"<<col;
// qDebug()<<"Row set"<<row;
// qDebug()<<"Column set"<<col;
ui->wMonitorGrid->addWidget(label,row,col,Qt::AlignTop);
}
else

View file

@ -7,6 +7,7 @@
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QSettings>
#include <QFileSystemModel>
#include "global.h"
#include "errorhandler.h"
@ -53,7 +54,7 @@ private slots:
void createLogWindow();
void testFunction();
treeModel * getTreeModel();
void setTreeMenu();
void treeMenuAction(bool);
void on_tvCalculators_customContextMenuRequested(const QPoint &pos);
@ -66,11 +67,14 @@ private:
hpusb * hpapi;
QMdiSubWindow * msgWindow=0;
hp_MdiWindow * logWindow=0;
QFileSystemModel contentModel;
QTextEdit * logEdit=0;
Ui::MainWindow *ui;
void loadTextFile();
void createTextWindow();
QMdiArea * getMdi();
void setContentWindow();
void setTreeMenu();
void monitorAddImage(hp_ScreenShot scrnshot);

View file

@ -111,8 +111,8 @@
</property>
<property name="maximumSize">
<size>
<width>272</width>
<height>524287</height>
<width>524287</width>
<height>524290</height>
</size>
</property>
<property name="baseSize">
@ -188,13 +188,19 @@
<addaction name="actionTestSettings"/>
<addaction name="actionTestScreen"/>
</widget>
<widget class="QDockWidget" name="dwContent_2">
<widget class="QDockWidget" name="dwContent">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>130</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>524287</width>
@ -204,7 +210,7 @@
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="wContent_2">
<widget class="QWidget" name="wContent">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -213,19 +219,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeWidget" name="twContent">
<property name="columnCount">
<number>1</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>1</string>
</property>
</column>
</widget>
<widget class="QTreeView" name="tvContent"/>
</item>
</layout>
</widget>

11
version.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef VERSION_H
#define VERSION_H
#define HP_VERSION_MAJOR 0
#define HP_VERSION_MINOR 1
#define HP_VERSION_PATCH 0
#define HP_VERSION_BUILD ""
#define HP_VERSION_STRING QString("%1.%2.%3%4").arg(HP_VERSION_MAJOR).arg(HP_VERSION_MINOR).arg(HP_VERSION_PATCH).arg(HP_VERSION_BUILD)
#endif // VERSION_H