Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • danc/MicroCART
  • snawerdt/MicroCART_17-18
  • bbartels/MicroCART_17-18
  • jonahu/MicroCART
4 results
Show changes
/** @file
@brief Header
@date 2011
@author
Ryan Pavlik
<rpavlik@iastate.edu> and <abiryan@ryand.net>
http://academic.cleardefinition.com/
Iowa State University Virtual Reality Applications Center
Human-Computer Interaction Graduate Program
*/
// Copyright Iowa State University 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
// Internal Includes
// - none
// Library/third-party includes
#include <QMainWindow>
#include <QSharedPointer>
#include <QPair>
// Standard includes
// - none
namespace Ui {
class MainWindow;
}
class QTimer;
class QLabel;
class QMenu;
class HIDDevice;
class vrpn_HidAcceptor;
class Inspector;
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(vrpn_HidAcceptor * acceptor, QWidget *parent = 0);
~MainWindow();
public slots:
void gotReport(QByteArray buf);
void addSignedLEInspector() {
_addInspector(true, false);
}
void addUnsignedLEInspector() {
_addInspector(false, false);
}
void addSignedBEInspector() {
_addInspector(true, true);
}
void addUnsignedBEInspector() {
_addInspector(false, true);
}
void on_actionInt8_2_triggered() {
_addInspector(1, true, false);
}
void on_actionUint8_2_triggered() {
_addInspector(1, false, false);
}
void on_actionInt16_LE_triggered() {
_addInspector(2, true, false);
}
void on_actionInt16_BE_triggered() {
_addInspector(2, true, true);
}
void on_actionUint16_LE_triggered() {
_addInspector(2, false, false);
}
void on_actionUint16_BE_triggered() {
_addInspector(2, false, true);
}
void on_actionRemove_all_inspectors_triggered();
void on_reportContents_selectionChanged();
void on_reportContents_customContextMenuRequested(const QPoint & pos);
private:
/// @brief return the offset and the length, in bytes, of the selection,
/// or -1, -1 if no selection.
QPair<int, int> _getSelectionByteOffsetLength() const;
/// @brief Helper function to add an inspector from the selection
void _addInspector(bool signedVal, bool bigEndian);
/// @brief Helper function to add an inspector from the menu, prompting for offset
void _addInspector(std::size_t size, bool signedVal, bool bigEndian);
/// @brief Helper function called by the other overloads adding an inspector once
/// we know all the parameters
void _addInspector(std::size_t offset, std::size_t size, bool signedVal, bool bigEndian);
typedef QSharedPointer<Inspector> InspectorPtr;
Ui::MainWindow *ui;
QSharedPointer<HIDDevice> _device;
QSharedPointer<QTimer> _timer;
std::vector<InspectorPtr> _inspectors;
QSharedPointer<QMenu> _singlebyteIntMenu;
QSharedPointer<QMenu> _multibyteIntMenu;
/// ownership transferred to status bar
QLabel * _selectionLabel;
};
/**
@file
@brief Implementation
@date 2011
@author
Ryan Pavlik
<rpavlik@iastate.edu> and <abiryan@ryand.net>
http://academic.cleardefinition.com/
Iowa State University Virtual Reality Applications Center
Human-Computer Interaction Graduate Program
*/
// Copyright Iowa State University 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Internal Includes
#include "QuickChart.h"
#include "ui_plot.h"
// Library/third-party includes
#include <QGraphicsScene>
// Standard includes
// - none
QuickChart::QuickChart(QWidget * parent)
: QFrame(parent)
, ui(new Ui::Plot)
, _x(0)
, _last(0)
, _min(0)
, _max(255)
, _sampleWidth(10)
, _gotOne(false)
, _scene(new QGraphicsScene) {
ui->setupUi(this);
ui->graphicsView->setScene(_scene.data());
updateViewFit();
}
QuickChart::~QuickChart() {
delete ui;
}
void QuickChart::addSample(float sample) {
addSample(_x + 1, sample);
}
void QuickChart::addSample(float x, float sample) {
if (_gotOne) {
_scene->addLine(_x, _last, x, sample);
}
_gotOne = true;
_last = sample;
_x = x;
setSceneRect();
ui->lastValue->setText(QString("(%1, %2)").arg(x).arg(sample));
}
void QuickChart::updateViewFit() {
const QSize s = ui->graphicsView->size();
const float h(s.height());
const float w(s.width());
const float xScale = w / _sampleWidth;
const float yScale = h / (_max - _min);
ui->graphicsView->setTransform(QTransform::fromScale(xScale, yScale).translate(-_min, 0));
setSceneRect();
}
void QuickChart::setSceneRect() {
float xmin = 0;
float width = _x;
if (_x < _sampleWidth) {
xmin = _x - _sampleWidth;
width = _sampleWidth;
}
_scene->setSceneRect(xmin, _min, width, _max - _min);
}
void QuickChart::setSampleWidth(float w) {
_sampleWidth = w;
updateViewFit();
}
void QuickChart::setLabel(QString const& l) {
ui->label->setText(l);
}
/** @file
@brief Header
@date 2011
@author
Ryan Pavlik
<rpavlik@iastate.edu> and <abiryan@ryand.net>
http://academic.cleardefinition.com/
Iowa State University Virtual Reality Applications Center
Human-Computer Interaction Graduate Program
*/
// Copyright Iowa State University 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
// Internal Includes
// - none
// Library/third-party includes
#include <QFrame>
#include <QSharedPointer>
// Standard includes
// - none
namespace Ui {
class Plot;
}
class QGraphicsScene;
class QuickChart : public QFrame {
Q_OBJECT
public:
explicit QuickChart(QWidget *parent = 0);
~QuickChart();
/// set minimum y value
void setMin(float v) {
_min = v;
updateViewFit();
}
/// get minimum y value
float getMin(void) const {
return _min;
}
/// set maximum y value
void setMax(float v) {
_max = v;
updateViewFit();
}
/// get maximum y value
float getMax(void) const {
return _max;
}
/// set width of x values we should fit in the control at once
void setSampleWidth(float w);
/// Set the text of the label
void setLabel(QString const& l);
public slots:
/// Add a sample, with x defaulted to 1 + previous x
void addSample(float sample);
/// Add a sample specifying both x and the sample (y)
void addSample(float x, float sample);
void updateViewFit();
void setSceneRect();
private:
Ui::Plot *ui;
float _x;
float _last;
float _min;
float _max;
float _sampleWidth;
bool _gotOne;
QSharedPointer<QGraphicsScene> _scene;
};
/**
@file
@brief Implementation
@date 2011
@author
Ryan Pavlik
<rpavlik@iastate.edu> and <abiryan@ryand.net>
http://academic.cleardefinition.com/
Iowa State University Virtual Reality Applications Center
Human-Computer Interaction Graduate Program
*/
// Copyright Iowa State University 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Internal Includes
#include "MainWindow.h"
#include "vrpn_HumanInterface.h"
// Library/third-party includes
#include <QtGui/QApplication>
// Standard includes
#include <sstream>
#include <stdio.h>
int usage(char * argv0) {
printf("Usage:\n\n"
"%s -h|--help\n"
" Display this help text.\n\n"
"%s [N]\n"
" Open HID device number N (default to 0)\n\n"
"%s VEND PROD [N]\n"
" Open HID device number N (default to 0) that matches\n"
" vendor VEND and product PROD, in _decimal_\n\n"
,
argv0, argv0, argv0);
return 1;
}
int failedOnArgument(int argNum, const char * expected, char * argv[]) {
fprintf(stderr, "Failed to interpret argument %d: expected %s, got '%s' - usage help follows.\n\n", argNum, expected, argv[argNum]);
return usage(argv[0]);
}
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
if (argc > 1 && (std::string("-h") == argv[1] || std::string("--help") == argv[1])) {
return usage(argv[0]);
}
vrpn_HidAcceptor * acceptor = NULL;
unsigned N = 0; // Which device to open?
if (argc >= 3) {
vrpn_uint16 vend;
std::istringstream vendS(argv[1]);
if (!(vendS >> vend)) {
return failedOnArgument(1, "a decimal vendor ID", argv);
}
vrpn_uint16 prod;
std::istringstream prodS(argv[2]);
if (!(prodS >> prod)) {
return failedOnArgument(2, "a decimal product ID", argv);
}
if (argc >= 4) {
std::istringstream nS(argv[3]);
if (!(nS >> N)) {
return failedOnArgument(3, "a number indicating which matching device to pick, or nothing for the default '0'", argv);
}
}
printf("Will accept HID device number %u that has vendor:product %04x:%04x\n", N, vend, prod);
acceptor = new vrpn_HidProductAcceptor(vend, prod);
} else {
if (argc == 2) {
std::istringstream nS(argv[1]);
if (!(nS >> N)) {
return failedOnArgument(1, "a number indicating which device to pick, or nothing for the default '0'", argv);
}
}
printf("Will accept HID device number %u\n", N);
acceptor = new vrpn_HidAlwaysAcceptor;
}
MainWindow w(new vrpn_HidNthMatchAcceptor(N, acceptor));
w.show();
return a.exec();
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>768</height>
</rect>
</property>
<property name="windowTitle">
<string>VRPN HID Tool</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>780</width>
<height>445</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="chartBox"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Last Report:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="reportSizeLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="reportContents">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="textLog">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="action_Quit"/>
</widget>
<widget class="QMenu" name="menu_Inspect">
<property name="title">
<string>&amp;Inspect</string>
</property>
<addaction name="actionInt8_2"/>
<addaction name="actionUint8_2"/>
<addaction name="actionInt16_LE"/>
<addaction name="actionInt16_BE"/>
<addaction name="actionUint16_LE"/>
<addaction name="actionUint16_BE"/>
<addaction name="separator"/>
<addaction name="actionRemove_all_inspectors"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Inspect"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="action_Quit">
<property name="text">
<string>&amp;Quit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionUint8">
<property name="text">
<string>uint8</string>
</property>
</action>
<action name="actionInt8">
<property name="text">
<string>int8</string>
</property>
</action>
<action name="actionBig_Endian">
<property name="text">
<string>Big Endian</string>
</property>
</action>
<action name="actionLittle_Endian">
<property name="text">
<string>Little Endian</string>
</property>
</action>
<action name="actionInt8_LE">
<property name="text">
<string>int8 (LE)</string>
</property>
</action>
<action name="actionInt8_BE">
<property name="text">
<string>int8 (BE)</string>
</property>
</action>
<action name="actionInt8_2">
<property name="text">
<string>int8</string>
</property>
</action>
<action name="actionUint8_2">
<property name="text">
<string>uint8</string>
</property>
</action>
<action name="actionInt16_LE">
<property name="text">
<string>int16 (LE)</string>
</property>
</action>
<action name="actionInt16_BE">
<property name="text">
<string>int16 (BE)</string>
</property>
</action>
<action name="actionUint16_LE">
<property name="text">
<string>uint16 (LE)</string>
</property>
</action>
<action name="actionUint16_BE">
<property name="text">
<string>uint16 (BE)</string>
</property>
</action>
<action name="actionRemove_all_inspectors">
<property name="text">
<string>Remove all inspectors</string>
</property>
</action>
</widget>
<resources/>
<connections>
<connection>
<sender>action_Quit</sender>
<signal>activated()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Plot</class>
<widget class="QFrame" name="Plot">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>633</width>
<height>116</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lastValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="renderHints">
<set>QPainter::Antialiasing|QPainter::TextAntialiasing</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>