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
Select Git revision
  • cli_segfault_test
  • commands-dev
  • commands-dev-backend
  • commands-to-make-andy-happy
  • groundStation-dev-cli
  • groundStation-dev-cli-setpoint
  • groundStation-dev-frontend-pid
  • groundStation-dev-getpid
  • groundStation-dev-quad-response
  • groundstation-datalog-vrpn
  • groundstation-dev-cliCommandHelpMessages
  • master
  • new-commands
  • new-uart
  • new-uart-circ
  • quad-auto-height
  • update-commands
17 results

Target

Select target project
  • danc/MicroCART
  • snawerdt/MicroCART_17-18
  • bbartels/MicroCART_17-18
  • jonahu/MicroCART
4 results
Select Git revision
  • develop
  • master
  • 2020-team-final-state
  • Lab_Part_1_tag
  • Lab_Part_2_tag
  • sdmay25-32-final
  • team_17-16_demo
  • team_17-16_v1
  • team_17-16_v2
  • team_18-17
10 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 <QObject>
#include <QByteArray>
// Standard includes
// - none
/// Class to extract bytes from an array and turn into some kind of value
class Inspector : public QObject {
Q_OBJECT
public:
explicit Inspector(std::size_t first_index, std::size_t length, bool signedVal, bool bigEndian = false, QObject * parent = NULL);
~Inspector() {}
signals:
void newValue(float val);
void newValue(float elapsed, float val);
public slots:
void updatedData(QByteArray buf, qint64 timestamp);
private:
void _sendNewValue(qint64 timestamp, float val);
std::size_t _first;
std::size_t _length;
bool _signed;
bool _bigEndian;
};
/**
@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 "ui_mainwindow.h"
#include "HIDDevice.h"
#include "Inspector.h"
#include "QuickChart.h"
// Library/third-party includes
#include <QTimer>
#include <QInputDialog>
// Standard includes
#include <cmath>
MainWindow::MainWindow(vrpn_HidAcceptor * acceptor, QWidget * parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, _device(new HIDDevice(acceptor))
, _timer(new QTimer)
, _singlebyteIntMenu(new QMenu)
, _multibyteIntMenu(new QMenu)
, _selectionLabel(new QLabel) {
ui->setupUi(this);
/// When the device has a message, add it to the log.
connect(_device.data(), SIGNAL(message(QString const&)), ui->textLog, SLOT(append(QString const&)));
/// When the device gets an input report, update our controls
connect(_device.data(), SIGNAL(inputReport(QByteArray, qint64)), this, SLOT(gotReport(QByteArray)));
/// Update the HID device every 20 ms
connect(_timer.data(), SIGNAL(timeout()), _device.data(), SLOT(do_update()));
_timer->start(20);
/// Widget for showing what offset and length are selected
statusBar()->addPermanentWidget(_selectionLabel);
_selectionLabel->setText(QString("No selected bytes"));
/// Create context menu for when a single byte is selected
_singlebyteIntMenu->addAction(QString("Inspect as signed integer"), this, SLOT(addSignedLEInspector()));
_singlebyteIntMenu->addAction(QString("Inspect as unsigned integer"), this, SLOT(addUnsignedLEInspector()));
/// Create context menu for when 2, 4 bytes are selected
QMenu * submenu = _multibyteIntMenu->addMenu(QString("Inspect as signed integer"));
submenu->addAction(QString("Big endian"), this, SLOT(addSignedBEInspector()));
submenu->addAction(QString("Little endian"), this, SLOT(addSignedLEInspector()));
submenu = _multibyteIntMenu->addMenu(QString("Inspect as unsigned integer"));
submenu->addAction(QString("Big endian"), this, SLOT(addUnsignedBEInspector()));
submenu->addAction(QString("Little endian"), this, SLOT(addUnsignedLEInspector()));
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::gotReport(QByteArray buf) {
/// Update display of report size
ui->reportSizeLabel->setText(QString("%1 bytes").arg(buf.size()));
/// Save selection range, if applicable
int initialStart = -1;
int initialLength = -1;
if (ui->reportContents->hasSelectedText()) {
initialStart = ui->reportContents->selectionStart();
initialLength = ui->reportContents->selectedText().length();
}
/// Update text
ui->reportContents->setText(buf.toHex());
/// Restore selection range
if (initialStart >= 0) {
ui->reportContents->setSelection(initialStart, initialLength);
}
}
void MainWindow::on_actionRemove_all_inspectors_triggered() {
/// remove all inspectors
_inspectors.clear();
/// remove all charts
QLayoutItem * child;
while ((child = ui->chartBox->takeAt(0)) != NULL) {
delete child->widget();
delete child;
}
}
void MainWindow::on_reportContents_selectionChanged() {
if (ui->reportContents->hasSelectedText()) {
const QPair<int, int> offsetLength = _getSelectionByteOffsetLength();
const int byteOffset = offsetLength.first;
const int byteLength = offsetLength.second;
const int initialStart = ui->reportContents->selectionStart();
const int initialLength = ui->reportContents->selectedText().length();
/// Normalize selection if needed
if (initialStart != byteOffset * 2 || initialLength != byteLength * 2) {
ui->reportContents->setSelection(byteOffset * 2, byteLength * 2);
}
_selectionLabel->setText(QString("Offset %1, length %2").arg(byteOffset).arg(byteLength));
} else {
_selectionLabel->setText(QString("No selected bytes"));
}
}
void MainWindow::on_reportContents_customContextMenuRequested(const QPoint & pos) {
QPoint globalPos = ui->reportContents->mapToGlobal(pos);
const QPair<int, int> offsetLength = _getSelectionByteOffsetLength();
const int byteLength = offsetLength.second;
switch (byteLength) {
case -1:
/// no selection, no menu.
statusBar()->showMessage("No bytes selected to inspect.");
break;
case 1:
/// Single byte
_singlebyteIntMenu->popup(globalPos);
break;
case 2:
case 4:
/// Valid multibyte
_multibyteIntMenu->popup(globalPos);
break;
default:
/// Some other number of bytes - not handled
statusBar()->showMessage("Can only inspect integers with powers of 2 lengths.");
break;
}
}
QPair<int, int> MainWindow::_getSelectionByteOffsetLength() const {
if (ui->reportContents->hasSelectedText()) {
int initialStart = ui->reportContents->selectionStart();
int initialLength = ui->reportContents->selectedText().length();
int endingCharacter = initialStart + initialLength;
/// get the initial byte
int startingByte = initialStart / 2;
int endingByte = (endingCharacter + 1) / 2;
int byteLength = endingByte - startingByte;
return QPair<int, int>(startingByte, byteLength);
}
/// Default case for when there's no selection
return QPair<int, int>(-1, -1);
}
void MainWindow::_addInspector(bool signedVal, bool bigEndian) {
const QPair<int, int> offsetLength = _getSelectionByteOffsetLength();
const int byteOffset = offsetLength.first;
const int byteLength = offsetLength.second;
_addInspector(byteOffset, byteLength, signedVal, bigEndian);
}
void MainWindow::_addInspector(std::size_t size, bool signedVal, bool bigEndian) {
bool ok;
std::size_t offset = QInputDialog::getInt(this,
QString("Starting index"),
QString("What (0-based) index should we start at? Current report length is %1.")
.arg(ui->reportSizeLabel->text()),
0, 0, 255, 1, &ok);
if (ok) {
_addInspector(offset, size, signedVal, bigEndian);
}
}
void MainWindow::_addInspector(std::size_t offset, std::size_t size, bool signedVal, bool bigEndian) {
QuickChart * chart = new QuickChart(this);
int range = std::pow(2.0, 8.0 * size);
chart->setMin(signedVal ? - range / 2 : 0);
chart->setMax(signedVal ? range / 2 : range);
QString label = QString("Offset %1 as %2-endian %3 int %4")
.arg(offset)
.arg(bigEndian ? "big" : "little")
.arg(signedVal ? "signed" : "unsigned")
.arg(size * 8);
chart->setLabel(label);
ui->chartBox->addWidget(chart);
InspectorPtr inspect(new Inspector(offset, size, signedVal, bigEndian));
connect(_device.data(), SIGNAL(inputReport(QByteArray, qint64)), inspect.data(), SLOT(updatedData(QByteArray, qint64)));
connect(inspect.data(), SIGNAL(newValue(float, float)), chart, SLOT(addSample(float, float)));
_inspectors.push_back(inspect);
}
/** @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);
}