Subclassed winUsbDriver

Created a genericUsbDriver class and then subclassed winUsbDriver to it.
This commit is contained in:
EspoTek 2016-10-18 09:44:58 +11:00
parent ddda840a5e
commit bd8480541c
50 changed files with 2053 additions and 622 deletions

View File

@ -30,7 +30,8 @@ SOURCES += main.cpp\
deviceconnecteddisplay.cpp \
timedtickbox.cpp \
scoperangeenterdialog.cpp \
voltagespinbox.cpp
voltagespinbox.cpp \
genericusbdriver.cpp
HEADERS += mainwindow.h \
qcustomplot.h \
@ -50,7 +51,8 @@ HEADERS += mainwindow.h \
deviceconnecteddisplay.h \
timedtickbox.h \
scoperangeenterdialog.h \
voltagespinbox.h
voltagespinbox.h \
genericusbdriver.h
FORMS += mainwindow.ui \
scoperangeenterdialog.ui

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.1.0, 2016-10-17T14:22:47. -->
<!-- Written by QtCreator 4.1.0, 2016-10-18T08:53:30. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -292,7 +292,7 @@
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">Labrador_libusbK.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">C:/Users/Esposch/Documents/GitHub/Labrador/Desktop Interface/bin</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
Desktop Interface/Thumbs.db Normal file

Binary file not shown.

View File

@ -0,0 +1,267 @@
#include "genericusbdriver.h"
genericUsbDriver::genericUsbDriver(QWidget *parent) : QLabel(parent)
{
}
void genericUsbDriver::setPsu(double voltage){
qDebug() << "New voltage =" << voltage;
currentPsuVoltage = voltage;
//if(deviceMode > 6) qFatal("setPsu is not configured for mode 7!!!");
double vinp = voltage/11;
double vinn = 0;
//double vref = 1.65;
double gainPsu = 1;
dutyPsu = (int) ((vinp - vinn)/vref * gainPsu * PSU_ADC_TOP);
qDebug() << "Going to send value " << dutyPsu;
}
void genericUsbDriver::setFunctionGen(int channel, functionGenControl *fGenControl){
////////////////////////////
////NO RESIZING (YET)!!!////
////////////////////////////
//////////////////////////////////////
//// CH1 is AUX!! CH2 is "MAIN"!!////
//////////////////////////////////////
int length, maxLength, numDivides, maxDivides;
double freq, amplitude, offset;
unsigned char *samples;
//For recalling on crash.
if (channel == 0) fGenPtr_CH1 = fGenControl;
else fGenPtr_CH2 = fGenControl;
//Reading in data
if (channel == 0){
length = fGenControl->length_CH1;
freq = fGenControl->freq_CH1;
amplitude = fGenControl->amplitude_CH1;
offset = fGenControl->offset_CH1;
samples = (unsigned char *) malloc(length);
memcpy(samples, fGenControl->samples_CH1, (unsigned int) length);
numDivides = fGenControl->divisibility_CH1;
}
else if(channel == 1){
length = fGenControl->length_CH2;
freq = fGenControl->freq_CH2;
amplitude = fGenControl->amplitude_CH2;
offset = fGenControl->offset_CH2;
samples = (unsigned char *) malloc(length);
memcpy(samples, fGenControl->samples_CH2, (unsigned int) length);
numDivides = fGenControl->divisibility_CH2;
}
//Triple mode
if ((amplitude+offset) > FGEN_LIMIT){
amplitude = amplitude / 3;
offset = offset / 3;
fGenTriple |= ((unsigned char) !channel + 1);
}
else fGenTriple &= ((unsigned char) (254 - !channel));
//qDebug() << "fGenTriple = " << fGenTriple << "fGenControl = " << fGenControl << "length = " << length << "freq = " << freq << "amplitude = " << amplitude << "offset = " << offset << "samples = " << samples;
//Waveform scaling in V
double tempDouble;
amplitude = (amplitude * 255) / FGEN_LIMIT;
offset = (offset * 255) / FGEN_LIMIT;
if (offset<FGEN_OFFSET){
if (amplitude>5)
amplitude -= FGEN_OFFSET;
else
amplitude = 0;
offset = FGEN_OFFSET;
}
#ifdef INVERT_TRIPLE
unsigned char fGenTemp = 0;
fGenTemp |= (fGenTriple & 0x01)<<1;
fGenTemp |= (fGenTriple & 0x02)>>1;
usbSendControl(0x40, 0xa4, fGenTemp, 0, 0, NULL);
#else
usbSendControl(0x40, 0xa4, fGenTriple, 0, 0, NULL);
#endif
//Applying amplitude and offset to all samples.
for (int i=0;i<length;i++){
tempDouble = (double) samples[i];
tempDouble *= amplitude;
tempDouble /= 255;
tempDouble += offset;
samples[i] = (unsigned char) tempDouble;
}
//Need to increase size of wave if its freq too high, or too low!
maxDivides = numDivides;
bool loop_entered = false;
unsigned char *tempSamples = (unsigned char *) malloc(0);
while(length * freq > DAC_SPS){
loop_entered = true;
numDivides--;
if (numDivides==0){
qDebug("numDivides = 0 - in T-stretching of genericUsbDriver:: setFunctionGen");
}
int shiftTemp = (maxDivides - numDivides);
length = length >> 1;
free(tempSamples);
tempSamples = (unsigned char *) malloc(length);
for (int i=0; i<length;i++){
tempSamples[i] = samples[i<<shiftTemp];
}
}
if(loop_entered){
samples = tempSamples;
}
//Scaling in t here:
// Something something maxLength something
//Timer Setup
int validClockDivs[7] = {1, 2, 4, 8, 64, 256, 1024};
int clkSetting;
for(clkSetting = 0; clkSetting<7; clkSetting++){
if ( (CLOCK_FREQ / (length * validClockDivs[clkSetting] * freq)) < 65535 )
break;
}
int timerPeriod = CLOCK_FREQ / (length * freq * validClockDivs[clkSetting]);
clkSetting++; // Change from [0:n] to [1:n]
if(deviceMode == 5){
qDebug("DEVICE IS IN MODE 5");
}
//qDebug() << "First three samples:" << samples[0] << samples[1] << samples[2];
if(channel){
usbSendControl(0x40, 0xa1, timerPeriod, clkSetting, length, samples);
}
else usbSendControl(0x40, 0xa2, timerPeriod, clkSetting, length, samples);
free(tempSamples);
return;
}
void genericUsbDriver::newDig(int digState){
qDebug() << "newDig";
digitalPinState = digState;
usbSendControl(0x40, 0xa6, digState, 0, 0, NULL);
}
void genericUsbDriver::setBufferPtr(bufferControl *newPtr){
bufferPtr = newPtr;
}
void genericUsbDriver::setDeviceMode(int mode){
int oldMode = deviceMode;
deviceMode = mode;
usbSendControl(0x40, 0xa5, (mode == 5 ? 0 : mode), gainMask, 0, NULL);
if (fGenPtr_CH1!=NULL) setFunctionGen(0, fGenPtr_CH1);
if (fGenPtr_CH2!=NULL) setFunctionGen(1, fGenPtr_CH2);
//switch on new deviceMode!!
switch(deviceMode){
case 0:
if(oldMode > 2) sendClearBuffer(1,0,0);
setVisible_CH2(0);
checkXY(0);
break;
case 1:
if(oldMode > 2) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(1);
checkXY(0);
break;
case 2:
if(oldMode > 2) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(1);
break;
case 3:
if(oldMode != 4) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(0);
checkXY(0);
break;
case 4:
if(oldMode != 3) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(1);
checkXY(0);
break;
case 5:
setVisible_CH2(0);
checkXY(0);
break;
case 6:
sendClearBuffer(0,0,1);
setVisible_CH2(0);
checkXY(0);
break;
case 7:
sendClearBuffer(1,0,0);
enableMMTimer();
checkXY(0);
break;
default:
qFatal("Error in genericUsbDriver::setDeviceMode. Invalid device mode.");
}
}
void genericUsbDriver::psuTick(){
if(dutyTemp == dutyPsu) return;
if (dutyTemp > dutyPsu){
if((dutyTemp - dutyPsu)> PSU_STEP){
dutyTemp -= PSU_STEP;
} else dutyTemp = dutyPsu;
}
if (dutyTemp < dutyPsu){
if((dutyPsu - dutyTemp)> PSU_STEP){
dutyTemp += PSU_STEP;
} else dutyTemp = dutyPsu;
}
if ((dutyTemp>106) || (dutyTemp<21)){
qDebug("PSU DUTY CYCLE TOO LARGE (could underflow on SOF)!!! ABORTING!!!");
}
usbSendControl(0x40, 0xa3, dutyTemp, 0, 0, NULL);
}
void genericUsbDriver::setGain(double newGain){
if (newGain == scopeGain) return; //No update!
gainBuffers(scopeGain/newGain);
scopeGain = newGain;
if (newGain == 0.5){
gainMask = 7<<2 | 7<<10;
}
else gainMask = (unsigned short)(log2(newGain))<<2 | (unsigned short)(log2(newGain))<<10;
qDebug("newGain = %f", newGain);
qDebug("gainMask = %d", gainMask);
usbSendControl(0x40, 0xa5, deviceMode, gainMask, 0, NULL);
}
void genericUsbDriver::avrDebug(void){
usbSendControl(0x40, 0xa0, 0, 0, 0, NULL);
}
void genericUsbDriver::saveState(int *_out_deviceMode, double *_out_scopeGain, double *_out_currentPsuVoltage, int *_out_digitalPinState){
*(_out_deviceMode) = deviceMode;
*(_out_scopeGain) = scopeGain;
*(_out_currentPsuVoltage) = currentPsuVoltage;
*(_out_digitalPinState) = digitalPinState;
return;
}

View File

@ -0,0 +1,82 @@
#ifndef GENERICUSBDRIVER_H
#define GENERICUSBDRIVER_H
#include <QWidget>
#include <QLabel>
#include <QDebug>
#include <QTimer>
#include <QThread>
#include "functiongencontrol.h"
#include "xmega.h"
#include "desktop_settings.h"
#include "buffercontrol.h"
//libusbK includes
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "libusbk.h"
#define ISO_PACKET_SIZE 1023
#define ISO_PACKETS_PER_CTX 17
#define NUM_FUTURE_CTX 56
#define MAX_OVERLAP NUM_FUTURE_CTX+1
#define ISO_TIMER_PERIOD 16
#define MAX_VALID_INDEX 374
class genericUsbDriver : public QLabel
{
Q_OBJECT
public:
//State Vars
int deviceMode = INIT_DEVICE_MODE;
double scopeGain = 0.5;
int dutyTemp = 0;
//Generic Vars
unsigned char *outBuffers[2];
unsigned int bufferLengths[2];
//Generic Functions
explicit genericUsbDriver(QWidget *parent = 0);
virtual char *isoRead(unsigned int *newLength) = 0;
void setBufferPtr(bufferControl *newPtr);
void saveState(int *_out_deviceMode, double *_out_scopeGain, double *_out_currentPsuVoltage, int *_out_digitalPinState);
virtual void usbSendControl(int RequestType, int Request, int Value, int Index, int Length, unsigned char *LDATA) = 0;
protected:
//State Vars
unsigned char fGenTriple=0;
unsigned short gainMask = 2056;
functionGenControl *fGenPtr_CH1 = NULL, *fGenPtr_CH2 = NULL;
int dutyPsu = 0;
double currentPsuVoltage;
int digitalPinState = 0;
//Generic Vars
bufferControl *bufferPtr = NULL;
QTimer *psuTimer;
//Generic Functions
virtual unsigned char usbInit(ULONG VIDin, ULONG PIDin) = 0;
virtual unsigned char usbIsoInit(void) = 0;
signals:
void sendClearBuffer(bool ch3751, bool ch3752, bool ch750);
void setVisible_CH2(bool visible);
void gainBuffers(double multiplier);
void disableWindow(bool enabled);
void enableMMTimer();
void checkXY(bool);
void upTick(void);
void killMe(void);
public slots:
void setPsu(double voltage);
void setFunctionGen(int channel, functionGenControl *fGenControl);
void setDeviceMode(int mode);
void newDig(int digState);
void psuTick(void);
void setGain(double newGain);
void avrDebug(void);
virtual void isoTimerTick(void) = 0;
};
#endif // GENERICUSBDRIVER_H

View File

@ -72,6 +72,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui->multimeterMeanDisplay->setVisible(0);
ui->multimeterRmsDisplay->setVisible(0);
*/
//Reset the device to ensure Labrador_libusbk gets handle!!
ui->controller_usb->usbSendControl(0x40, 0xa7, 0, 0, 0, NULL);
}
MainWindow::~MainWindow()
@ -241,49 +245,49 @@ void MainWindow::menuSetup(){
void MainWindow::on_actionGain0_5_triggered()
{
ui->controller_usb->setGain(0.5);
ui->controller_iso->driver->setGain(0.5);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain1_triggered()
{
ui->controller_usb->setGain(1);
ui->controller_iso->driver->setGain(1);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain2_triggered()
{
ui->controller_usb->setGain(2);
ui->controller_iso->driver->setGain(2);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain4_triggered()
{
ui->controller_usb->setGain(4);
ui->controller_iso->driver->setGain(4);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain8_triggered()
{
ui->controller_usb->setGain(8);
ui->controller_iso->driver->setGain(8);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain16_triggered()
{
ui->controller_usb->setGain(16);
ui->controller_iso->driver->setGain(16);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain32_triggered()
{
ui->controller_usb->setGain(32);
ui->controller_iso->driver->setGain(32);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGain64_triggered()
{
ui->controller_usb->setGain(64);
ui->controller_iso->driver->setGain(64);
ui->controller_iso->setAutoGain(0);
}
void MainWindow::on_actionGainAuto_triggered()
@ -1002,7 +1006,6 @@ void MainWindow::reinitUsb(void){
ui->controller_iso->driver->saveState(&deviceMode, &scopeGain, &currentPsuVoltage, &digitalPinState);
delete(ui->controller_iso->driver);
QThread::msleep(1024); //Wait a second for the dust to settle.
ui->controller_iso->driver = new winUsbDriver();
//Reconnect the other objects.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,318 @@
/****************************************************************************
** Meta object code from reading C++ file 'genericusbdriver.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.7.0)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../genericusbdriver.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'genericusbdriver.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.7.0. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_genericUsbDriver_t {
QByteArrayData data[31];
char stringdata0[309];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_genericUsbDriver_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_genericUsbDriver_t qt_meta_stringdata_genericUsbDriver = {
{
QT_MOC_LITERAL(0, 0, 16), // "genericUsbDriver"
QT_MOC_LITERAL(1, 17, 15), // "sendClearBuffer"
QT_MOC_LITERAL(2, 33, 0), // ""
QT_MOC_LITERAL(3, 34, 6), // "ch3751"
QT_MOC_LITERAL(4, 41, 6), // "ch3752"
QT_MOC_LITERAL(5, 48, 5), // "ch750"
QT_MOC_LITERAL(6, 54, 14), // "setVisible_CH2"
QT_MOC_LITERAL(7, 69, 7), // "visible"
QT_MOC_LITERAL(8, 77, 11), // "gainBuffers"
QT_MOC_LITERAL(9, 89, 10), // "multiplier"
QT_MOC_LITERAL(10, 100, 13), // "disableWindow"
QT_MOC_LITERAL(11, 114, 7), // "enabled"
QT_MOC_LITERAL(12, 122, 13), // "enableMMTimer"
QT_MOC_LITERAL(13, 136, 7), // "checkXY"
QT_MOC_LITERAL(14, 144, 6), // "upTick"
QT_MOC_LITERAL(15, 151, 6), // "killMe"
QT_MOC_LITERAL(16, 158, 6), // "setPsu"
QT_MOC_LITERAL(17, 165, 7), // "voltage"
QT_MOC_LITERAL(18, 173, 14), // "setFunctionGen"
QT_MOC_LITERAL(19, 188, 7), // "channel"
QT_MOC_LITERAL(20, 196, 19), // "functionGenControl*"
QT_MOC_LITERAL(21, 216, 11), // "fGenControl"
QT_MOC_LITERAL(22, 228, 13), // "setDeviceMode"
QT_MOC_LITERAL(23, 242, 4), // "mode"
QT_MOC_LITERAL(24, 247, 6), // "newDig"
QT_MOC_LITERAL(25, 254, 8), // "digState"
QT_MOC_LITERAL(26, 263, 7), // "psuTick"
QT_MOC_LITERAL(27, 271, 7), // "setGain"
QT_MOC_LITERAL(28, 279, 7), // "newGain"
QT_MOC_LITERAL(29, 287, 8), // "avrDebug"
QT_MOC_LITERAL(30, 296, 12) // "isoTimerTick"
},
"genericUsbDriver\0sendClearBuffer\0\0"
"ch3751\0ch3752\0ch750\0setVisible_CH2\0"
"visible\0gainBuffers\0multiplier\0"
"disableWindow\0enabled\0enableMMTimer\0"
"checkXY\0upTick\0killMe\0setPsu\0voltage\0"
"setFunctionGen\0channel\0functionGenControl*\0"
"fGenControl\0setDeviceMode\0mode\0newDig\0"
"digState\0psuTick\0setGain\0newGain\0"
"avrDebug\0isoTimerTick"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_genericUsbDriver[] = {
// content:
7, // revision
0, // classname
0, 0, // classinfo
16, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
8, // signalCount
// signals: name, argc, parameters, tag, flags
1, 3, 94, 2, 0x06 /* Public */,
6, 1, 101, 2, 0x06 /* Public */,
8, 1, 104, 2, 0x06 /* Public */,
10, 1, 107, 2, 0x06 /* Public */,
12, 0, 110, 2, 0x06 /* Public */,
13, 1, 111, 2, 0x06 /* Public */,
14, 0, 114, 2, 0x06 /* Public */,
15, 0, 115, 2, 0x06 /* Public */,
// slots: name, argc, parameters, tag, flags
16, 1, 116, 2, 0x0a /* Public */,
18, 2, 119, 2, 0x0a /* Public */,
22, 1, 124, 2, 0x0a /* Public */,
24, 1, 127, 2, 0x0a /* Public */,
26, 0, 130, 2, 0x0a /* Public */,
27, 1, 131, 2, 0x0a /* Public */,
29, 0, 134, 2, 0x0a /* Public */,
30, 0, 135, 2, 0x0a /* Public */,
// signals: parameters
QMetaType::Void, QMetaType::Bool, QMetaType::Bool, QMetaType::Bool, 3, 4, 5,
QMetaType::Void, QMetaType::Bool, 7,
QMetaType::Void, QMetaType::Double, 9,
QMetaType::Void, QMetaType::Bool, 11,
QMetaType::Void,
QMetaType::Void, QMetaType::Bool, 2,
QMetaType::Void,
QMetaType::Void,
// slots: parameters
QMetaType::Void, QMetaType::Double, 17,
QMetaType::Void, QMetaType::Int, 0x80000000 | 20, 19, 21,
QMetaType::Void, QMetaType::Int, 23,
QMetaType::Void, QMetaType::Int, 25,
QMetaType::Void,
QMetaType::Void, QMetaType::Double, 28,
QMetaType::Void,
QMetaType::Void,
0 // eod
};
void genericUsbDriver::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
genericUsbDriver *_t = static_cast<genericUsbDriver *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->sendClearBuffer((*reinterpret_cast< bool(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2])),(*reinterpret_cast< bool(*)>(_a[3]))); break;
case 1: _t->setVisible_CH2((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 2: _t->gainBuffers((*reinterpret_cast< double(*)>(_a[1]))); break;
case 3: _t->disableWindow((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 4: _t->enableMMTimer(); break;
case 5: _t->checkXY((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 6: _t->upTick(); break;
case 7: _t->killMe(); break;
case 8: _t->setPsu((*reinterpret_cast< double(*)>(_a[1]))); break;
case 9: _t->setFunctionGen((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< functionGenControl*(*)>(_a[2]))); break;
case 10: _t->setDeviceMode((*reinterpret_cast< int(*)>(_a[1]))); break;
case 11: _t->newDig((*reinterpret_cast< int(*)>(_a[1]))); break;
case 12: _t->psuTick(); break;
case 13: _t->setGain((*reinterpret_cast< double(*)>(_a[1]))); break;
case 14: _t->avrDebug(); break;
case 15: _t->isoTimerTick(); break;
default: ;
}
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
switch (_id) {
default: *reinterpret_cast<int*>(_a[0]) = -1; break;
case 9:
switch (*reinterpret_cast<int*>(_a[1])) {
default: *reinterpret_cast<int*>(_a[0]) = -1; break;
case 1:
*reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< functionGenControl* >(); break;
}
break;
}
} else if (_c == QMetaObject::IndexOfMethod) {
int *result = reinterpret_cast<int *>(_a[0]);
void **func = reinterpret_cast<void **>(_a[1]);
{
typedef void (genericUsbDriver::*_t)(bool , bool , bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::sendClearBuffer)) {
*result = 0;
return;
}
}
{
typedef void (genericUsbDriver::*_t)(bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::setVisible_CH2)) {
*result = 1;
return;
}
}
{
typedef void (genericUsbDriver::*_t)(double );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::gainBuffers)) {
*result = 2;
return;
}
}
{
typedef void (genericUsbDriver::*_t)(bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::disableWindow)) {
*result = 3;
return;
}
}
{
typedef void (genericUsbDriver::*_t)();
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::enableMMTimer)) {
*result = 4;
return;
}
}
{
typedef void (genericUsbDriver::*_t)(bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::checkXY)) {
*result = 5;
return;
}
}
{
typedef void (genericUsbDriver::*_t)();
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::upTick)) {
*result = 6;
return;
}
}
{
typedef void (genericUsbDriver::*_t)();
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&genericUsbDriver::killMe)) {
*result = 7;
return;
}
}
}
}
const QMetaObject genericUsbDriver::staticMetaObject = {
{ &QLabel::staticMetaObject, qt_meta_stringdata_genericUsbDriver.data,
qt_meta_data_genericUsbDriver, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};
const QMetaObject *genericUsbDriver::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *genericUsbDriver::qt_metacast(const char *_clname)
{
if (!_clname) return Q_NULLPTR;
if (!strcmp(_clname, qt_meta_stringdata_genericUsbDriver.stringdata0))
return static_cast<void*>(const_cast< genericUsbDriver*>(this));
return QLabel::qt_metacast(_clname);
}
int genericUsbDriver::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QLabel::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 16)
qt_static_metacall(this, _c, _id, _a);
_id -= 16;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 16)
qt_static_metacall(this, _c, _id, _a);
_id -= 16;
}
return _id;
}
// SIGNAL 0
void genericUsbDriver::sendClearBuffer(bool _t1, bool _t2, bool _t3)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)), const_cast<void*>(reinterpret_cast<const void*>(&_t3)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
// SIGNAL 1
void genericUsbDriver::setVisible_CH2(bool _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 1, _a);
}
// SIGNAL 2
void genericUsbDriver::gainBuffers(double _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 2, _a);
}
// SIGNAL 3
void genericUsbDriver::disableWindow(bool _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 3, _a);
}
// SIGNAL 4
void genericUsbDriver::enableMMTimer()
{
QMetaObject::activate(this, &staticMetaObject, 4, Q_NULLPTR);
}
// SIGNAL 5
void genericUsbDriver::checkXY(bool _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 5, _a);
}
// SIGNAL 6
void genericUsbDriver::upTick()
{
QMetaObject::activate(this, &staticMetaObject, 6, Q_NULLPTR);
}
// SIGNAL 7
void genericUsbDriver::killMe()
{
QMetaObject::activate(this, &staticMetaObject, 7, Q_NULLPTR);
}
QT_END_MOC_NAMESPACE

Binary file not shown.

View File

@ -19,8 +19,8 @@
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_winUsbDriver_t {
QByteArrayData data[31];
char stringdata0[305];
QByteArrayData data[3];
char stringdata0[27];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -30,47 +30,11 @@ struct qt_meta_stringdata_winUsbDriver_t {
static const qt_meta_stringdata_winUsbDriver_t qt_meta_stringdata_winUsbDriver = {
{
QT_MOC_LITERAL(0, 0, 12), // "winUsbDriver"
QT_MOC_LITERAL(1, 13, 15), // "sendClearBuffer"
QT_MOC_LITERAL(2, 29, 0), // ""
QT_MOC_LITERAL(3, 30, 6), // "ch3751"
QT_MOC_LITERAL(4, 37, 6), // "ch3752"
QT_MOC_LITERAL(5, 44, 5), // "ch750"
QT_MOC_LITERAL(6, 50, 14), // "setVisible_CH2"
QT_MOC_LITERAL(7, 65, 7), // "visible"
QT_MOC_LITERAL(8, 73, 11), // "gainBuffers"
QT_MOC_LITERAL(9, 85, 10), // "multiplier"
QT_MOC_LITERAL(10, 96, 13), // "disableWindow"
QT_MOC_LITERAL(11, 110, 7), // "enabled"
QT_MOC_LITERAL(12, 118, 13), // "enableMMTimer"
QT_MOC_LITERAL(13, 132, 7), // "checkXY"
QT_MOC_LITERAL(14, 140, 6), // "upTick"
QT_MOC_LITERAL(15, 147, 6), // "killMe"
QT_MOC_LITERAL(16, 154, 6), // "setPsu"
QT_MOC_LITERAL(17, 161, 7), // "voltage"
QT_MOC_LITERAL(18, 169, 14), // "setFunctionGen"
QT_MOC_LITERAL(19, 184, 7), // "channel"
QT_MOC_LITERAL(20, 192, 19), // "functionGenControl*"
QT_MOC_LITERAL(21, 212, 11), // "fGenControl"
QT_MOC_LITERAL(22, 224, 13), // "setDeviceMode"
QT_MOC_LITERAL(23, 238, 4), // "mode"
QT_MOC_LITERAL(24, 243, 6), // "newDig"
QT_MOC_LITERAL(25, 250, 8), // "digState"
QT_MOC_LITERAL(26, 259, 7), // "psuTick"
QT_MOC_LITERAL(27, 267, 7), // "setGain"
QT_MOC_LITERAL(28, 275, 7), // "newGain"
QT_MOC_LITERAL(29, 283, 8), // "avrDebug"
QT_MOC_LITERAL(30, 292, 12) // "isoTimerTick"
QT_MOC_LITERAL(1, 13, 12), // "isoTimerTick"
QT_MOC_LITERAL(2, 26, 0) // ""
},
"winUsbDriver\0sendClearBuffer\0\0ch3751\0"
"ch3752\0ch750\0setVisible_CH2\0visible\0"
"gainBuffers\0multiplier\0disableWindow\0"
"enabled\0enableMMTimer\0checkXY\0upTick\0"
"killMe\0setPsu\0voltage\0setFunctionGen\0"
"channel\0functionGenControl*\0fGenControl\0"
"setDeviceMode\0mode\0newDig\0digState\0"
"psuTick\0setGain\0newGain\0avrDebug\0"
"isoTimerTick"
"winUsbDriver\0isoTimerTick\0"
};
#undef QT_MOC_LITERAL
@ -80,51 +44,17 @@ static const uint qt_meta_data_winUsbDriver[] = {
7, // revision
0, // classname
0, 0, // classinfo
16, 14, // methods
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
8, // signalCount
// signals: name, argc, parameters, tag, flags
1, 3, 94, 2, 0x06 /* Public */,
6, 1, 101, 2, 0x06 /* Public */,
8, 1, 104, 2, 0x06 /* Public */,
10, 1, 107, 2, 0x06 /* Public */,
12, 0, 110, 2, 0x06 /* Public */,
13, 1, 111, 2, 0x06 /* Public */,
14, 0, 114, 2, 0x06 /* Public */,
15, 0, 115, 2, 0x06 /* Public */,
0, // signalCount
// slots: name, argc, parameters, tag, flags
16, 1, 116, 2, 0x0a /* Public */,
18, 2, 119, 2, 0x0a /* Public */,
22, 1, 124, 2, 0x0a /* Public */,
24, 1, 127, 2, 0x0a /* Public */,
26, 0, 130, 2, 0x0a /* Public */,
27, 1, 131, 2, 0x0a /* Public */,
29, 0, 134, 2, 0x0a /* Public */,
30, 0, 135, 2, 0x0a /* Public */,
// signals: parameters
QMetaType::Void, QMetaType::Bool, QMetaType::Bool, QMetaType::Bool, 3, 4, 5,
QMetaType::Void, QMetaType::Bool, 7,
QMetaType::Void, QMetaType::Double, 9,
QMetaType::Void, QMetaType::Bool, 11,
QMetaType::Void,
QMetaType::Void, QMetaType::Bool, 2,
QMetaType::Void,
QMetaType::Void,
1, 0, 19, 2, 0x0a /* Public */,
// slots: parameters
QMetaType::Void, QMetaType::Double, 17,
QMetaType::Void, QMetaType::Int, 0x80000000 | 20, 19, 21,
QMetaType::Void, QMetaType::Int, 23,
QMetaType::Void, QMetaType::Int, 25,
QMetaType::Void,
QMetaType::Void, QMetaType::Double, 28,
QMetaType::Void,
QMetaType::Void,
0 // eod
@ -136,99 +66,15 @@ void winUsbDriver::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id
winUsbDriver *_t = static_cast<winUsbDriver *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->sendClearBuffer((*reinterpret_cast< bool(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2])),(*reinterpret_cast< bool(*)>(_a[3]))); break;
case 1: _t->setVisible_CH2((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 2: _t->gainBuffers((*reinterpret_cast< double(*)>(_a[1]))); break;
case 3: _t->disableWindow((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 4: _t->enableMMTimer(); break;
case 5: _t->checkXY((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 6: _t->upTick(); break;
case 7: _t->killMe(); break;
case 8: _t->setPsu((*reinterpret_cast< double(*)>(_a[1]))); break;
case 9: _t->setFunctionGen((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< functionGenControl*(*)>(_a[2]))); break;
case 10: _t->setDeviceMode((*reinterpret_cast< int(*)>(_a[1]))); break;
case 11: _t->newDig((*reinterpret_cast< int(*)>(_a[1]))); break;
case 12: _t->psuTick(); break;
case 13: _t->setGain((*reinterpret_cast< double(*)>(_a[1]))); break;
case 14: _t->avrDebug(); break;
case 15: _t->isoTimerTick(); break;
case 0: _t->isoTimerTick(); break;
default: ;
}
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
switch (_id) {
default: *reinterpret_cast<int*>(_a[0]) = -1; break;
case 9:
switch (*reinterpret_cast<int*>(_a[1])) {
default: *reinterpret_cast<int*>(_a[0]) = -1; break;
case 1:
*reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< functionGenControl* >(); break;
}
break;
}
} else if (_c == QMetaObject::IndexOfMethod) {
int *result = reinterpret_cast<int *>(_a[0]);
void **func = reinterpret_cast<void **>(_a[1]);
{
typedef void (winUsbDriver::*_t)(bool , bool , bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::sendClearBuffer)) {
*result = 0;
return;
}
}
{
typedef void (winUsbDriver::*_t)(bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::setVisible_CH2)) {
*result = 1;
return;
}
}
{
typedef void (winUsbDriver::*_t)(double );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::gainBuffers)) {
*result = 2;
return;
}
}
{
typedef void (winUsbDriver::*_t)(bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::disableWindow)) {
*result = 3;
return;
}
}
{
typedef void (winUsbDriver::*_t)();
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::enableMMTimer)) {
*result = 4;
return;
}
}
{
typedef void (winUsbDriver::*_t)(bool );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::checkXY)) {
*result = 5;
return;
}
}
{
typedef void (winUsbDriver::*_t)();
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::upTick)) {
*result = 6;
return;
}
}
{
typedef void (winUsbDriver::*_t)();
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&winUsbDriver::killMe)) {
*result = 7;
return;
}
}
}
Q_UNUSED(_a);
}
const QMetaObject winUsbDriver::staticMetaObject = {
{ &QLabel::staticMetaObject, qt_meta_stringdata_winUsbDriver.data,
{ &genericUsbDriver::staticMetaObject, qt_meta_stringdata_winUsbDriver.data,
qt_meta_data_winUsbDriver, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};
@ -243,76 +89,23 @@ void *winUsbDriver::qt_metacast(const char *_clname)
if (!_clname) return Q_NULLPTR;
if (!strcmp(_clname, qt_meta_stringdata_winUsbDriver.stringdata0))
return static_cast<void*>(const_cast< winUsbDriver*>(this));
return QLabel::qt_metacast(_clname);
return genericUsbDriver::qt_metacast(_clname);
}
int winUsbDriver::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QLabel::qt_metacall(_c, _id, _a);
_id = genericUsbDriver::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 16)
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 16;
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 16)
qt_static_metacall(this, _c, _id, _a);
_id -= 16;
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
// SIGNAL 0
void winUsbDriver::sendClearBuffer(bool _t1, bool _t2, bool _t3)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)), const_cast<void*>(reinterpret_cast<const void*>(&_t3)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
// SIGNAL 1
void winUsbDriver::setVisible_CH2(bool _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 1, _a);
}
// SIGNAL 2
void winUsbDriver::gainBuffers(double _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 2, _a);
}
// SIGNAL 3
void winUsbDriver::disableWindow(bool _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 3, _a);
}
// SIGNAL 4
void winUsbDriver::enableMMTimer()
{
QMetaObject::activate(this, &staticMetaObject, 4, Q_NULLPTR);
}
// SIGNAL 5
void winUsbDriver::checkXY(bool _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 5, _a);
}
// SIGNAL 6
void winUsbDriver::upTick()
{
QMetaObject::activate(this, &staticMetaObject, 6, Q_NULLPTR);
}
// SIGNAL 7
void winUsbDriver::killMe()
{
QMetaObject::activate(this, &staticMetaObject, 7, Q_NULLPTR);
}
QT_END_MOC_NAMESPACE

View File

@ -1,6 +1,6 @@
#include "winusbdriver.h"
winUsbDriver::winUsbDriver(QWidget *parent) : QLabel(parent)
winUsbDriver::winUsbDriver(QWidget *parent) : genericUsbDriver(parent)
{
qDebug() << "Making USB Driver invisible!!";
this->hide();
@ -14,6 +14,7 @@ winUsbDriver::winUsbDriver(QWidget *parent) : QLabel(parent)
bool connected = false;
while(!connected){
QThread::msleep(32);
connected = usbInit(0x03eb, 0xa000);
}
setDeviceMode(deviceMode);
@ -136,163 +137,6 @@ void winUsbDriver::usbSendControl(int RequestType, int Request, int Value, int I
}
}
void winUsbDriver::setPsu(double voltage){
qDebug() << "New voltage =" << voltage;
currentPsuVoltage = voltage;
//if(deviceMode > 6) qFatal("setPsu is not configured for mode 7!!!");
double vinp = voltage/11;
double vinn = 0;
//double vref = 1.65;
double gainPsu = 1;
dutyPsu = (int) ((vinp - vinn)/vref * gainPsu * PSU_ADC_TOP);
qDebug() << "Going to send value " << dutyPsu;
}
void winUsbDriver::setFunctionGen(int channel, functionGenControl *fGenControl){
////////////////////////////
////NO RESIZING (YET)!!!////
////////////////////////////
//////////////////////////////////////
//// CH1 is AUX!! CH2 is "MAIN"!!////
//////////////////////////////////////
int length, maxLength, numDivides, maxDivides;
double freq, amplitude, offset;
unsigned char *samples;
//For recalling on crash.
if (channel == 0) fGenPtr_CH1 = fGenControl;
else fGenPtr_CH2 = fGenControl;
//Reading in data
if (channel == 0){
length = fGenControl->length_CH1;
freq = fGenControl->freq_CH1;
amplitude = fGenControl->amplitude_CH1;
offset = fGenControl->offset_CH1;
samples = (unsigned char *) malloc(length);
memcpy(samples, fGenControl->samples_CH1, (unsigned int) length);
numDivides = fGenControl->divisibility_CH1;
}
else if(channel == 1){
length = fGenControl->length_CH2;
freq = fGenControl->freq_CH2;
amplitude = fGenControl->amplitude_CH2;
offset = fGenControl->offset_CH2;
samples = (unsigned char *) malloc(length);
memcpy(samples, fGenControl->samples_CH2, (unsigned int) length);
numDivides = fGenControl->divisibility_CH2;
}
//Triple mode
if ((amplitude+offset) > FGEN_LIMIT){
amplitude = amplitude / 3;
offset = offset / 3;
fGenTriple |= ((unsigned char) !channel + 1);
}
else fGenTriple &= ((unsigned char) (254 - !channel));
//qDebug() << "fGenTriple = " << fGenTriple << "fGenControl = " << fGenControl << "length = " << length << "freq = " << freq << "amplitude = " << amplitude << "offset = " << offset << "samples = " << samples;
//Waveform scaling in V
double tempDouble;
amplitude = (amplitude * 255) / FGEN_LIMIT;
offset = (offset * 255) / FGEN_LIMIT;
if (offset<FGEN_OFFSET){
if (amplitude>5)
amplitude -= FGEN_OFFSET;
else
amplitude = 0;
offset = FGEN_OFFSET;
}
#ifdef INVERT_TRIPLE
unsigned char fGenTemp = 0;
fGenTemp |= (fGenTriple & 0x01)<<1;
fGenTemp |= (fGenTriple & 0x02)>>1;
usbSendControl(0x40, 0xa4, fGenTemp, 0, 0, NULL);
#else
usbSendControl(0x40, 0xa4, fGenTriple, 0, 0, NULL);
#endif
//Applying amplitude and offset to all samples.
for (int i=0;i<length;i++){
tempDouble = (double) samples[i];
tempDouble *= amplitude;
tempDouble /= 255;
tempDouble += offset;
samples[i] = (unsigned char) tempDouble;
}
//Need to increase size of wave if its freq too high, or too low!
maxDivides = numDivides;
bool loop_entered = false;
unsigned char *tempSamples = (unsigned char *) malloc(0);
while(length * freq > DAC_SPS){
loop_entered = true;
numDivides--;
if (numDivides==0){
qDebug("numDivides = 0 - in T-stretching of winUsbDriver:: setFunctionGen");
}
int shiftTemp = (maxDivides - numDivides);
length = length >> 1;
free(tempSamples);
tempSamples = (unsigned char *) malloc(length);
for (int i=0; i<length;i++){
tempSamples[i] = samples[i<<shiftTemp];
}
}
if(loop_entered){
samples = tempSamples;
}
//Scaling in t here:
// Something something maxLength something
//Timer Setup
int validClockDivs[7] = {1, 2, 4, 8, 64, 256, 1024};
int clkSetting;
for(clkSetting = 0; clkSetting<7; clkSetting++){
if ( (CLOCK_FREQ / (length * validClockDivs[clkSetting] * freq)) < 65535 )
break;
}
int timerPeriod = CLOCK_FREQ / (length * freq * validClockDivs[clkSetting]);
clkSetting++; // Change from [0:n] to [1:n]
if(deviceMode == 5){
qDebug("DEVICE IS IN MODE 5");
}
//qDebug() << "First three samples:" << samples[0] << samples[1] << samples[2];
if(channel){
usbSendControl(0x40, 0xa1, timerPeriod, clkSetting, length, samples);
}
else usbSendControl(0x40, 0xa2, timerPeriod, clkSetting, length, samples);
free(tempSamples);
return;
}
void winUsbDriver::xmegaBreak(void){
usbSendControl(0x40, 0xa0, 0, 0, 0, NULL);
}
void winUsbDriver::newDig(int digState){
qDebug() << "newDig";
digitalPinState = digState;
usbSendControl(0x40, 0xa6, digState, 0, 0, NULL);
}
unsigned char winUsbDriver::usbIsoInit(void){
//Setup the iso stack
int n;
@ -349,116 +193,6 @@ unsigned char winUsbDriver::usbIsoInit(void){
return 1;
}
char *winUsbDriver::isoRead(unsigned int *newLength){
//unsigned char *returnBuffer;
//returnBuffer = (unsigned char *) malloc(numSamples + 8); //8-byte header contains (unsigned long) length
//((unsigned int *)returnBuffer)[0] = 0;
//return (char*) returnBuffer;
//qDebug() << (unsigned char) !currentWriteBuffer;
*(newLength) = bufferLengths[!currentWriteBuffer];
return (char*) outBuffers[(unsigned char) !currentWriteBuffer];
}
void winUsbDriver::setBufferPtr(bufferControl *newPtr){
bufferPtr = newPtr;
}
void winUsbDriver::setDeviceMode(int mode){
int oldMode = deviceMode;
deviceMode = mode;
usbSendControl(0x40, 0xa5, (mode == 5 ? 0 : mode), gainMask, 0, NULL);
if (fGenPtr_CH1!=NULL) setFunctionGen(0, fGenPtr_CH1);
if (fGenPtr_CH2!=NULL) setFunctionGen(1, fGenPtr_CH2);
//switch on new deviceMode!!
switch(deviceMode){
case 0:
if(oldMode > 2) sendClearBuffer(1,0,0);
setVisible_CH2(0);
checkXY(0);
break;
case 1:
if(oldMode > 2) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(1);
checkXY(0);
break;
case 2:
if(oldMode > 2) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(1);
break;
case 3:
if(oldMode != 4) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(0);
checkXY(0);
break;
case 4:
if(oldMode != 3) sendClearBuffer(1,0,0);
sendClearBuffer(0,1,0);
setVisible_CH2(1);
checkXY(0);
break;
case 5:
setVisible_CH2(0);
checkXY(0);
break;
case 6:
sendClearBuffer(0,0,1);
setVisible_CH2(0);
checkXY(0);
break;
case 7:
sendClearBuffer(1,0,0);
enableMMTimer();
checkXY(0);
break;
default:
qFatal("Error in winUsbDriver::setDeviceMode. Invalid device mode.");
}
}
void winUsbDriver::psuTick(){
if(dutyTemp == dutyPsu) return;
if (dutyTemp > dutyPsu){
if((dutyTemp - dutyPsu)> PSU_STEP){
dutyTemp -= PSU_STEP;
} else dutyTemp = dutyPsu;
}
if (dutyTemp < dutyPsu){
if((dutyPsu - dutyTemp)> PSU_STEP){
dutyTemp += PSU_STEP;
} else dutyTemp = dutyPsu;
}
if ((dutyTemp>106) || (dutyTemp<21)){
qDebug("PSU DUTY CYCLE TOO LARGE (could underflow on SOF)!!! ABORTING!!!");
}
usbSendControl(0x40, 0xa3, dutyTemp, 0, 0, NULL);
}
void winUsbDriver::setGain(double newGain){
if (newGain == scopeGain) return; //No update!
gainBuffers(scopeGain/newGain);
scopeGain = newGain;
if (newGain == 0.5){
gainMask = 7<<2 | 7<<10;
}
else gainMask = (unsigned short)(log2(newGain))<<2 | (unsigned short)(log2(newGain))<<10;
qDebug("newGain = %f", newGain);
qDebug("gainMask = %d", gainMask);
usbSendControl(0x40, 0xa5, deviceMode, gainMask, 0, NULL);
}
void winUsbDriver::avrDebug(void){
usbSendControl(0x40, 0xa0, 0, 0, 0, NULL);
}
void winUsbDriver::isoTimerTick(void){
timerCount++;
char subString[3] = "th";
@ -533,10 +267,12 @@ void winUsbDriver::isoTimerTick(void){
return;
}
void winUsbDriver::saveState(int *_out_deviceMode, double *_out_scopeGain, double *_out_currentPsuVoltage, int *_out_digitalPinState){
*(_out_deviceMode) = deviceMode;
*(_out_scopeGain) = scopeGain;
*(_out_currentPsuVoltage) = currentPsuVoltage;
*(_out_digitalPinState) = digitalPinState;
return;
char *winUsbDriver::isoRead(unsigned int *newLength){
//unsigned char *returnBuffer;
//returnBuffer = (unsigned char *) malloc(numSamples + 8); //8-byte header contains (unsigned long) length
//((unsigned int *)returnBuffer)[0] = 0;
//return (char*) returnBuffer;
//qDebug() << (unsigned char) !currentWriteBuffer;
*(newLength) = bufferLengths[!currentWriteBuffer];
return (char*) outBuffers[(unsigned char) !currentWriteBuffer];
}

View File

@ -1,47 +1,17 @@
#ifndef WINUSBDRIVER_H
#define WINUSBDRIVER_H
#include <QWidget>
#include <QLabel>
#include <QDebug>
#include <QTimer>
#include "genericusbdriver.h"
#include "functiongencontrol.h"
#include "xmega.h"
#include "desktop_settings.h"
#include "buffercontrol.h"
//libusbK includes
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "libusbk.h"
#define ISO_PACKET_SIZE 1023
#define ISO_PACKETS_PER_CTX 17
#define NUM_FUTURE_CTX 56
#define MAX_OVERLAP NUM_FUTURE_CTX+1
#define ISO_TIMER_PERIOD 16
#define MAX_VALID_INDEX 374
class winUsbDriver : public QLabel
class winUsbDriver : public genericUsbDriver
{
Q_OBJECT
public:
//State Vars
int deviceMode = INIT_DEVICE_MODE;
double scopeGain = 0.5;
int dutyTemp = 0;
//Generic Vars
unsigned char *outBuffers[2];
unsigned int bufferLengths[2];
//Generic Functions
explicit winUsbDriver(QWidget *parent = 0);
char *isoRead(unsigned int *newLength);
~winUsbDriver();
void setBufferPtr(bufferControl *newPtr);
void saveState(int *_out_deviceMode, double *_out_scopeGain, double *_out_currentPsuVoltage, int *_out_digitalPinState);
void usbSendControl(int RequestType, int Request, int Value, int Index, int Length, unsigned char *LDATA);
char *isoRead(unsigned int *newLength);
private:
//USB Vars
KUSB_HANDLE handle = NULL;
@ -54,39 +24,11 @@ private:
QTimer *isoTimer;
unsigned char currentWriteBuffer = 0;
unsigned long timerCount = 0;
//State Vars
unsigned char fGenTriple=0;
unsigned short gainMask = 2056;
functionGenControl *fGenPtr_CH1 = NULL, *fGenPtr_CH2 = NULL;
int dutyPsu = 0;
double currentPsuVoltage;
int digitalPinState = 0;
//Generic Vars
bufferControl *bufferPtr = NULL;
QTimer *psuTimer;
//Generic Functions
unsigned char usbInit(ULONG VIDin, ULONG PIDin);
void usbSendControl(int RequestType, int Request, int Value, int Index, int Length, unsigned char *LDATA);
void xmegaBreak(void);
unsigned char usbIsoInit(void);
signals:
void sendClearBuffer(bool ch3751, bool ch3752, bool ch750);
void setVisible_CH2(bool visible);
void gainBuffers(double multiplier);
void disableWindow(bool enabled);
void enableMMTimer();
void checkXY(bool);
void upTick(void);
void killMe(void);
public slots:
void setPsu(double voltage);
void setFunctionGen(int channel, functionGenControl *fGenControl);
void setDeviceMode(int mode);
void newDig(int digState);
void psuTick(void);
void setGain(double newGain);
void avrDebug(void);
void isoTimerTick(void);
};