QtHPConnect/hpdata.cpp

214 lines
4.5 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-10 14:32:15 +01:00
2019-02-10 14:43:00 +01:00
#define FUNC_NUM 9
const QString hpCalcData::func_list[FUNC_NUM][2]={{"Application Library",":/icons/apps_32x32.png"},
{"CAS Vars",":/icons/casFolder_32x32.png"},
{"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"},
{"Real",":/icons/real_32x32.png"},
{"Variables",":/icons/varFolder_32x32.png"}
};
const DataType hpCalcData::func_type[FUNC_NUM]={HP_APP,
HP_CAS,
HP_COMPLEX,
HP_LIST,
HP_MATRIC,
HP_NOTE,
HP_PROG,
HP_REAL,
HP_VAR
};
//constructor
hpCalcData::hpCalcData(hpusb * handle)
:QObject()
2019-02-10 14:32:15 +01:00
{
2019-02-10 14:43:00 +01:00
hp_api = handle;
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) {
hp_api->hp_open(getHandle());
}
2019-02-17 17:24:52 +01:00
2019-02-10 14:32:15 +01:00
}
2019-02-10 14:43:00 +01:00
//return the interface class
hp_Handle * hpCalcData::getHandle() {
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;
}
2019-02-12 21:48:35 +01:00
//get Settings
hp_Settings hpCalcData::getSettings() {
return hp_homesettings;
}
//read Settings via usb
void hpCalcData::readSettings() {
hpusb * api;
hp_Handle * handle;
hp_Settings hpset;
log("Reading Settings");
qDebug()<<"Reading Settings";
api=getAPI();
handle=getHandle();
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api) {
api->get_settings(handle,&hpset);
}
}
}
hp_homesettings=hpset;
hp_Change change;
change.dataChange=HP_MAIN;
emit dataChanged(change);
}
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) {
api->get_screen_shot(handle,&imageData);
if (screenShot!=nullptr) {
delete screenShot;
}
2019-02-18 21:15:04 +01:00
2019-02-17 17:24:52 +01:00
screenShot = new QPixmap();
screenShot->loadFromData(imageData);
}
}
}
emit emitChange(HP_SCREEN);
}
void hpCalcData::emitChange(DataType type) {
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)
api->load_info(handle,&hpinfo);
}
}
hp_info=hpinfo;
2019-02-17 17:24:52 +01:00
emit emitChange(HP_MAIN);
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() {
};