QtHPConnect/hpdata.cpp

439 lines
9.9 KiB
C++
Raw Normal View History

2019-02-10 14:43:00 +01:00
//
//
//
//
// This class acts as a data store for the interface and calls for data as required
//
2019-02-10 14:32:15 +01:00
#include "hpdata.h"
2019-02-10 14:43:00 +01:00
#include "global.h"
#include "errorhandler.h"
2019-02-25 08:36:58 +01:00
#include "abstractdata.h"
2020-01-18 19:27:42 +01:00
#include "hp_typedef.h"
2019-02-25 08:36:58 +01:00
2019-02-10 14:43:00 +01:00
const QString hpCalcData::func_list[FUNC_NUM][2]={{"Application Library",":/icons/apps_32x32.png"},
{"CAS Vars",":/icons/casFolder_32x32.png"},
2020-01-19 17:55:14 +01:00
{"Real",":/icons/real_32x32.png"},
2019-02-10 14:43:00 +01:00
{"Complex",":/icons/complex_32x32.png"},
{"Lists",":/icons/list_32x32.png"},
{"Matrices",":/icons/table_32x32.png"},
{"Notes",":/icons/note_32x32.png"},
{"Programs",":/icons/program_32x32.png"},
{"Variables",":/icons/varFolder_32x32.png"}
};
2019-02-25 08:36:58 +01:00
const hp_DataType hpCalcData::func_type[FUNC_NUM]={HP_APP,
2019-02-10 14:43:00 +01:00
HP_CAS,
2019-02-25 08:36:58 +01:00
HP_REAL,
2019-02-10 14:43:00 +01:00
HP_COMPLEX,
HP_LIST,
2019-02-25 08:36:58 +01:00
HP_MATRIX,
2019-02-10 14:43:00 +01:00
HP_NOTE,
2020-01-18 19:27:42 +01:00
HP_PROG,
2019-02-10 14:43:00 +01:00
HP_VAR
};
2020-01-18 19:27:42 +01:00
2019-02-10 14:43:00 +01:00
//constructor
2020-01-18 19:27:42 +01:00
hpCalcData::hpCalcData(QString name, hpusb * handle)
2019-02-10 14:43:00 +01:00
:QObject()
2019-02-10 14:32:15 +01:00
{
2019-02-10 14:43:00 +01:00
hp_api = handle;
2019-02-25 08:36:58 +01:00
lData.clear();
2020-01-18 19:27:42 +01:00
calculatorName=name;
2019-02-10 14:32:15 +01:00
2019-02-10 14:43:00 +01:00
//open usb port and store the handle
if (hp_api) {
2019-02-20 23:08:14 +01:00
hp_handle.calc=this;
2019-02-10 14:43:00 +01:00
hp_api->hp_open(getHandle());
}
2019-02-10 14:32:15 +01:00
}
2019-02-10 14:43:00 +01:00
//return the interface class
hp_Handle * hpCalcData::getHandle() {
2019-02-20 23:08:14 +01:00
hp_handle.calc=this;
2019-02-10 14:43:00 +01:00
return &hp_handle;
}
//return the interface class
hpusb * hpCalcData::getAPI() {
return hp_api;
}
//data managment
hp_Information hpCalcData::getInfo() {
return hp_info;
}
//get Name
QString hpCalcData::getName() {
return hp_info.name;
}
2020-01-18 19:27:42 +01:00
//get Calculator Name
QString hpCalcData::getCalculatorName() {
return calculatorName;
}
2019-02-12 21:48:35 +01:00
//get Settings
hp_Settings hpCalcData::getSettings() {
return hp_homesettings;
}
2019-02-25 08:36:58 +01:00
//Add a new object to the list
void hpCalcData::addData(AbstractData * data) {
lData.append(data);
}
2020-02-02 18:13:27 +01:00
void hpCalcData::deleteData(AbstractData * data) {
2019-02-25 08:36:58 +01:00
// lData.erase();
2020-02-02 18:13:27 +01:00
if (data!=nullptr) {
QString name=data->getName();
hp_DataType type=data->getType();
QList<AbstractData *>::iterator i;
i=findData(name,type);
lData.erase(i);
delete data;
qDebug()<<"hpCalcData::deleteData - Object Deleted";
}
else {
qDebug()<<"hpCalcData::deleteData - Object not deleted";
}
2019-02-25 08:36:58 +01:00
}
//returns position of entry in list or returns 0;
2020-02-02 18:13:27 +01:00
QList<AbstractData *>::iterator hpCalcData::findData(QString name, hp_DataType dataType) {
2019-02-25 08:36:58 +01:00
2020-02-02 18:13:27 +01:00
QList<AbstractData *>::iterator i;
AbstractData * ldata;
i = lData.begin();
while (i!= lData.end()) {
ldata=*i;
if (ldata->equivalent(name,dataType)) {
2019-02-25 08:36:58 +01:00
return i;
2020-02-02 18:13:27 +01:00
}
2019-02-25 08:36:58 +01:00
}
2020-02-02 18:13:27 +01:00
return nullptr;
2019-02-25 08:36:58 +01:00
}
2019-02-26 20:56:39 +01:00
//returns position of entry in list or returns 0;
AbstractData * hpCalcData::getData(QString name, hp_DataType dataType) {
2020-02-02 18:13:27 +01:00
2019-02-26 20:56:39 +01:00
for (int i = 0; i < lData.size(); ++i) {
if (lData.at(i)->equivalent(name,dataType)) {
2020-01-18 19:27:42 +01:00
qDebug()<<"hpCalcData::Data found"<<name<<" "<<dataType;
2019-02-26 20:56:39 +01:00
return lData.at(i);
}
}
2020-01-18 19:27:42 +01:00
qDebug()<<"hpCalcData::No data found"<<name<<" "<<dataType;;
2019-02-26 20:56:39 +01:00
return nullptr;
}
2019-02-25 08:36:58 +01:00
AbstractData * hpCalcData::dataAt(int i) {
return lData.at(i);
}
int hpCalcData::dataCount() {
return lData.size();
}
2019-03-09 15:39:38 +01:00
void hpCalcData::refresh() {
readInfo();
readSettings();
}
2019-02-12 21:48:35 +01:00
//read Settings via usb
void hpCalcData::readSettings() {
hpusb * api;
hp_Handle * handle;
hp_Settings hpset;
2019-03-09 15:39:38 +01:00
log("hpCalcData::readSettings: -Reading Settings");
2019-02-12 21:48:35 +01:00
qDebug()<<"Reading Settings";
api=getAPI();
handle=getHandle();
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api) {
2019-02-20 23:08:14 +01:00
api->get_settings(handle);
2019-02-12 21:48:35 +01:00
}
}
2019-03-09 15:39:38 +01:00
else {
log("hpCalcData::readSettings Handle null");
}
}
else {
log("hpCalcData::readSettings API null");
2019-02-12 21:48:35 +01:00
}
2019-02-20 23:08:14 +01:00
// hp_homesettings=hpset;
2019-02-12 21:48:35 +01:00
2019-02-20 23:08:14 +01:00
// hp_Change change;
// change.dataChange=HP_MAIN;
// emit dataChanged(change);
2019-02-12 21:48:35 +01:00
}
2019-02-17 17:24:52 +01:00
//read Settings via usb
void hpCalcData::readScreen() {
hpusb * api;
hp_Handle * handle;
hp_Settings hpset;
log("Reading Screen");
2019-02-18 21:15:04 +01:00
2019-02-17 17:24:52 +01:00
api=getAPI();
handle=getHandle();
QByteArray imageData;
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api) {
2019-02-20 23:08:14 +01:00
api->get_screen_shot(handle);
// if (screenShot!=nullptr) {
// delete screenShot;
// }
//
// screenShot = new QPixmap();
// screenShot->loadFromData(imageData);
}
}
}
// emit emitChange(HP_SCREEN);
}
//recieve Screenshot
void hpCalcData::recvScreen(hp_ScreenShot shot) {
log("Recieving Screen");
QByteArray imageData;
if (screenShot!=nullptr) {
2019-03-09 15:39:38 +01:00
delete screenShot;
2019-02-17 17:24:52 +01:00
}
2019-02-20 23:08:14 +01:00
screenShot = shot.image;
2019-02-17 17:24:52 +01:00
2019-02-20 23:08:14 +01:00
emit emitChange(HP_SCREEN);
}
//recieve Setting
2019-03-09 15:39:38 +01:00
void hpCalcData::recvSettings(hp_Data data) {
2019-02-20 23:08:14 +01:00
2019-03-09 15:39:38 +01:00
QString filename;
log("hpCalcData::recvSettings: Recieving Setting");
filename = data.name;
qDebug()<<filename;
2019-02-17 17:24:52 +01:00
2019-03-09 15:39:38 +01:00
if (filename==QStringLiteral("calc.hpsettings")) {
qDebug()<<"hpCalcData::recvSetting - Setting";
qDebug()<<"hpCalcData::recvSetting - Real";
2019-03-09 21:11:43 +01:00
log("hpCalcData::recvSetting - Real");
2019-03-09 15:39:38 +01:00
Real * obj1 = new Real(data.name,HP_REAL);
obj1->setData(data.data);
addData(obj1);
emit emitChange(HP_REAL);
qDebug()<<"hpCalcData::recvSetting - Complex";
2019-03-09 21:11:43 +01:00
log("hpCalcData::recvSetting - Complex");
2019-03-09 15:39:38 +01:00
Complex * obj2 = new Complex(data.name,HP_COMPLEX);
obj2->setData(data.data);
addData(obj2);
emit emitChange(HP_COMPLEX);
}
if (filename== QStringLiteral("cas.hpsettings")) {
qDebug()<<"cas.chps";
qDebug()<<"hpCalcData::recvSetting - CAS";
CASVariables * obj2 = new CASVariables(data.name,HP_CAS);
obj2->setData(data.data);
addData(obj2);
emit emitChange(HP_CAS);
}
if (filename==QStringLiteral("calc.hpvars")) {
qDebug()<<"hpCalcData::recvSetting - Variables";
Variables * var = new Variables(data.name,HP_VAR);
var->setData(data.data);
addData(var);
}
if (filename==QStringLiteral("settings")) {
qDebug()<<"set-";
qDebug()<<"hpCalcData::recvSetting - Variables";
Settings * var = new Settings(data.name,HP_SETTINGS);
var->setData(data.data);
addData(var);
}
emit emitChange(HP_MAIN);
2019-02-17 17:24:52 +01:00
}
2019-02-20 23:08:14 +01:00
2019-02-21 19:51:56 +01:00
//recieve Program
void hpCalcData::recvProg(hp_Prog program) {
log("Recieving Program");
2019-02-25 19:28:45 +01:00
qDebug()<<"hpCalcData::recvProg";
2019-02-21 19:51:56 +01:00
qDebug()<<program.filename;
2019-02-25 19:28:45 +01:00
//qDebug()<<program.prog;
2019-02-25 08:36:58 +01:00
Program * obj = new Program(program.filename,HP_PROG, program.prog);
2019-03-02 20:20:23 +01:00
obj->setData(program.data);
2019-02-25 08:36:58 +01:00
addData(obj);
2019-02-21 19:51:56 +01:00
emit emitChange(HP_PROG);
}
2019-02-26 20:56:39 +01:00
//recieve Program
void hpCalcData::recvNote(hp_Note note) {
log("Recieving Note");
qDebug()<<"hpCalcData::recvNote";
qDebug()<<note.filename;
Notes * obj = new Notes(note.filename,HP_NOTE, note.text);
2019-03-02 20:20:23 +01:00
obj->setData(note.data);
2019-02-26 20:56:39 +01:00
addData(obj);
emit emitChange(HP_NOTE);
}
2019-02-25 08:36:58 +01:00
//recieve Program
void hpCalcData::recvData(hp_Data data) {
log("Recieving Data");
switch (data.type) {
2019-02-25 19:28:45 +01:00
case HP_APP: {
qDebug()<<"hpCalcData::recvData - Application";
Application * obj = new Application(data.name,data.type);
2019-03-02 20:20:23 +01:00
obj->setData(data.data);
2019-02-25 19:28:45 +01:00
addData(obj);
emit emitChange(HP_APP);
}
break;
case HP_LIST: {
2019-02-25 08:36:58 +01:00
List * obj = new List(data.name,data.type);
2019-03-02 20:20:23 +01:00
obj->setData(data.data);
2019-02-25 08:36:58 +01:00
addData(obj);
emit emitChange(HP_LIST);
}
break;
2019-02-25 19:28:45 +01:00
case HP_MATRIX: {
qDebug()<<"hpCalcData::recvData - Matrix";
2019-02-25 08:36:58 +01:00
Matrix * obj = new Matrix(data.name,data.type);
2019-03-02 20:20:23 +01:00
obj->setData(data.data);
2019-02-25 08:36:58 +01:00
addData(obj);
emit emitChange(HP_MATRIX);
}
break;
}
}
2019-02-20 23:08:14 +01:00
2019-02-25 08:36:58 +01:00
void hpCalcData::emitChange(hp_DataType type) {
2019-02-17 17:24:52 +01:00
hp_Change change;
change.dataChange=type;
change.calc = this;
emit dataChanged(change);
}
hp_ScreenShot hpCalcData::getScreenShot() {
hp_ScreenShot scn;
scn.image = screenShot;
scn.format = CALC_SCREENSHOT_FORMAT_PRIME_PNG_320x240x16;
scn.calc = this;
return scn;
}
2019-02-12 21:48:35 +01:00
//set Settings
int hpCalcData::setSettings(hp_Settings set) {
hp_homesettings=set;
}
2019-02-10 14:43:00 +01:00
void hpCalcData::setInfo(hp_Information dtype) {
hp_info=dtype;
return;
}
//read information via hp interface
void hpCalcData::readInfo() {
hpusb * api;
hp_Handle * handle;
hp_Information hpinfo;
api=getAPI();
handle=getHandle();
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api)
2019-02-20 23:08:14 +01:00
api->load_info(handle);
2019-02-10 14:43:00 +01:00
}
}
2019-02-20 23:08:14 +01:00
}
void hpCalcData::recvInfo(hp_Information hpinfo) {
2019-02-10 14:43:00 +01:00
2019-02-20 23:08:14 +01:00
hp_info=hpinfo;
emit emitChange(HP_MAIN);
2019-02-10 14:43:00 +01:00
}
2019-02-20 23:08:14 +01:00
2019-02-10 14:43:00 +01:00
void hpCalcData::vpkt_send_experiments(int cmd) {
hpusb * api;
hp_Handle * handle;
api=getAPI();
handle=getHandle();
if (api) {
if(handle) {
2019-02-17 17:24:52 +01:00
if (api) {
api->is_ready(handle);
2019-02-19 22:10:58 +01:00
// api->vpkt_send_experiments(handle,cmd);
2019-02-17 17:24:52 +01:00
}
2019-02-10 14:43:00 +01:00
}
}
}
hpCalcData::~hpCalcData() {
2020-01-19 17:55:14 +01:00
qDebug()<<"Close ~hpCalcData";
2019-02-10 14:43:00 +01:00
};