mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
Add sim test
This commit is contained in:
@@ -35,6 +35,10 @@ set(PROJECT_SOURCES
|
|||||||
sim-scope_mux_tester.cpp
|
sim-scope_mux_tester.cpp
|
||||||
sim-scope_mux_tester.ui
|
sim-scope_mux_tester.ui
|
||||||
|
|
||||||
|
sim-test.h
|
||||||
|
sim-test.cpp
|
||||||
|
sim-test.ui
|
||||||
|
|
||||||
simulatorbase.h
|
simulatorbase.h
|
||||||
simulatorbase.cpp
|
simulatorbase.cpp
|
||||||
helpers.h
|
helpers.h
|
||||||
|
|||||||
+3
-1
@@ -4,6 +4,7 @@
|
|||||||
#include "sim-scope_mux_tester.h"
|
#include "sim-scope_mux_tester.h"
|
||||||
#include "sim-can_debugger.h"
|
#include "sim-can_debugger.h"
|
||||||
#include "sim-cvs_i10.h"
|
#include "sim-cvs_i10.h"
|
||||||
|
#include "sim-test.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
@@ -12,7 +13,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
error_dialog(new NetworkError(this)),
|
error_dialog(new NetworkError(this)),
|
||||||
sims{{"Can_Debugger", new Can_Debugger(m_web_socket, this)},
|
sims{{"Can_Debugger", new Can_Debugger(m_web_socket, this)},
|
||||||
{"Scope_Mux_Tester", new Scope_Mux_Tester(m_web_socket, this)},
|
{"Scope_Mux_Tester", new Scope_Mux_Tester(m_web_socket, this)},
|
||||||
{"CVS_I10", new CVS_I10(m_web_socket, this)}}
|
{"CVS_I10", new CVS_I10(m_web_socket, this)},
|
||||||
|
{"Test_Sim", new Test_Sim(m_web_socket, this)}}
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("Simulator Selector");
|
this->setWindowTitle("Simulator Selector");
|
||||||
|
|||||||
+175
@@ -0,0 +1,175 @@
|
|||||||
|
#include "sim-test.h"
|
||||||
|
#include "ui_sim-test.h"
|
||||||
|
|
||||||
|
Test_Sim::Test_Sim(Web_socket_wrapper* web_socket, QWidget* parent) :
|
||||||
|
SimulatorBase(web_socket, parent),
|
||||||
|
ui(new Ui::Test_Sim)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
button_lookup = {
|
||||||
|
{button_lookup_e::button, ui->button}
|
||||||
|
};
|
||||||
|
slider_lookup = {
|
||||||
|
{slider_lookup_e::slider, ui->Slider}
|
||||||
|
};
|
||||||
|
led_lookup = {
|
||||||
|
{led_lookup_e::led, ui->led}
|
||||||
|
};
|
||||||
|
|
||||||
|
combobox_lookup = {
|
||||||
|
{combobox_lookup_e::combobox, ui->combobox}
|
||||||
|
};
|
||||||
|
label_lookup = {
|
||||||
|
{label_lookup_e::label, ui->label}
|
||||||
|
};
|
||||||
|
|
||||||
|
setup_buttons();
|
||||||
|
setup_comboboxes();
|
||||||
|
setup_sliders();
|
||||||
|
setup_sliders();
|
||||||
|
}
|
||||||
|
|
||||||
|
Test_Sim::~Test_Sim() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_Sim::setup_buttons(void)
|
||||||
|
{
|
||||||
|
for (Iterable<button_lookup_e> lookup; lookup < button_lookup_e::end; lookup++)
|
||||||
|
{
|
||||||
|
switch (lookup)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
connect(button_lookup[lookup], &QPushButton::clicked, this, [=]{button_update(lookup);});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_Sim::setup_sliders(void)
|
||||||
|
{
|
||||||
|
for (Iterable<slider_lookup_e> lookup; lookup < slider_lookup_e::end; lookup++)
|
||||||
|
{
|
||||||
|
connect(slider_lookup[lookup], &QwtSlider::valueChanged, this, [=]{
|
||||||
|
// Update the text while moving the slider
|
||||||
|
//value_lookup_e lookup_v = thermo_to_value_lookup(lookup);
|
||||||
|
//value_lookup[lookup_v]->setText(format_value(lookup_v, thermo_lookup[lookup]->value()));
|
||||||
|
});
|
||||||
|
connect(slider_lookup[lookup], &QwtSlider::sliderPressed, this, [=]{
|
||||||
|
// When changing the sliders lock that slider
|
||||||
|
slider_lock[lookup] = true;
|
||||||
|
});
|
||||||
|
connect(slider_lookup[lookup], &QwtSlider::sliderReleased, this, [=]{
|
||||||
|
// Only trigger the update event when the slider is released and unlock the slider
|
||||||
|
slider_update(lookup);
|
||||||
|
slider_lock[lookup] = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_Sim::setup_comboboxes(void)
|
||||||
|
{
|
||||||
|
for (Iterable<combobox_lookup_e> lookup; lookup < combobox_lookup_e::end; lookup++)
|
||||||
|
{
|
||||||
|
connect(combobox_lookup[lookup], &QComboBox::currentIndexChanged, this, [=]{combobox_update(lookup);});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_Sim::button_update(button_lookup_e lookup)
|
||||||
|
{
|
||||||
|
m_web_socket->send_event(Web_socket_wrapper::Event::clicked, QString(magic_enum::enum_name(lookup).data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_Sim::slider_update(slider_lookup_e lookup)
|
||||||
|
{
|
||||||
|
m_web_socket->send_event(Web_socket_wrapper::Event::clicked, QString(magic_enum::enum_name(lookup).data()),
|
||||||
|
slider_lookup[lookup]->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_Sim::combobox_update(combobox_lookup_e lookup)
|
||||||
|
{
|
||||||
|
m_web_socket->send_event(Web_socket_wrapper::Event::selected, QString(magic_enum::enum_name(lookup).data()),
|
||||||
|
combobox_lookup[lookup]->currentText());
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel* Test_Sim::id_to_label(QString name)
|
||||||
|
{
|
||||||
|
label_lookup_e lookup = magic_enum::enum_cast<label_lookup_e>(name.toStdString()).value_or(label_lookup_e::end);
|
||||||
|
if (lookup == label_lookup_e::end)
|
||||||
|
{
|
||||||
|
QD << "label lookup == end, instead of " << name;
|
||||||
|
emit quit();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return label_lookup[lookup];
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton* Test_Sim::id_to_led(QString name)
|
||||||
|
{
|
||||||
|
led_lookup_e lookup = magic_enum::enum_cast<led_lookup_e>(name.toStdString()).value_or(led_lookup_e::end);
|
||||||
|
if (lookup == led_lookup_e::end)
|
||||||
|
{
|
||||||
|
QD << "led lookup == end, instead of " << name;
|
||||||
|
emit quit();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return led_lookup[lookup];
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton* Test_Sim::id_to_button(QString name)
|
||||||
|
{
|
||||||
|
button_lookup_e lookup = magic_enum::enum_cast<button_lookup_e>(name.toStdString()).value_or(button_lookup_e::end);
|
||||||
|
if (lookup == button_lookup_e::end)
|
||||||
|
{
|
||||||
|
QD << "button lookup == end, instead of" << name;
|
||||||
|
emit quit();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return button_lookup[lookup];
|
||||||
|
}
|
||||||
|
|
||||||
|
QwtSlider* Test_Sim::id_to_slider(QString name)
|
||||||
|
{
|
||||||
|
slider_lookup_e lookup = magic_enum::enum_cast<slider_lookup_e>(name.toStdString()).value_or(slider_lookup_e::end);
|
||||||
|
if (lookup == slider_lookup_e::end)
|
||||||
|
{
|
||||||
|
QD << "thermo lookup == end, instead of " << name;
|
||||||
|
emit quit();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the slider is being changed
|
||||||
|
if (slider_lock[lookup])
|
||||||
|
{
|
||||||
|
QD << "Slider in lock retrurning null";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return slider_lookup[lookup];
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel* Test_Sim::id_to_slider_label(QString name)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Test_Sim::format_slider_value(QString name, double val)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QComboBox* Test_Sim::id_to_combobox(QString name)
|
||||||
|
{
|
||||||
|
combobox_lookup_e lookup = magic_enum::enum_cast<combobox_lookup_e>(name.toStdString()).value_or(combobox_lookup_e::end);
|
||||||
|
if (lookup == combobox_lookup_e::end)
|
||||||
|
{
|
||||||
|
QD << "combobox lookup == end, instead of " << name;
|
||||||
|
emit quit();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return combobox_lookup[lookup];
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#ifndef SIM_TEST_H
|
||||||
|
#define SIM_TEST_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include "simulatorbase.h"
|
||||||
|
#include "web_socket_wrapper.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class Test_Sim;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Test_Sim : public SimulatorBase {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ITERABLE_ENUM_BEGIN(button_lookup_e)
|
||||||
|
button
|
||||||
|
ITERABLE_ENUM_END;
|
||||||
|
ITERABLE_ENUM_BEGIN(led_lookup_e)
|
||||||
|
led
|
||||||
|
ITERABLE_ENUM_END;
|
||||||
|
ITERABLE_ENUM_BEGIN(label_lookup_e)
|
||||||
|
label
|
||||||
|
ITERABLE_ENUM_END;
|
||||||
|
ITERABLE_ENUM_BEGIN(slider_lookup_e)
|
||||||
|
slider
|
||||||
|
ITERABLE_ENUM_END;
|
||||||
|
ITERABLE_ENUM_BEGIN(combobox_lookup_e)
|
||||||
|
combobox
|
||||||
|
ITERABLE_ENUM_END;
|
||||||
|
|
||||||
|
explicit Test_Sim(Web_socket_wrapper* web_socket, QWidget* parent = nullptr);
|
||||||
|
~Test_Sim();
|
||||||
|
|
||||||
|
void setup_buttons(void);
|
||||||
|
void setup_sliders(void);
|
||||||
|
void setup_comboboxes(void);
|
||||||
|
|
||||||
|
void button_update(button_lookup_e lookup);
|
||||||
|
void slider_update(slider_lookup_e lookup);
|
||||||
|
void combobox_update(combobox_lookup_e lookup);
|
||||||
|
|
||||||
|
QLabel* id_to_label(QString name);
|
||||||
|
QPushButton* id_to_led(QString name);
|
||||||
|
QPushButton* id_to_button(QString name);
|
||||||
|
QwtSlider* id_to_slider(QString name);
|
||||||
|
QLabel* id_to_slider_label(QString name);
|
||||||
|
QString format_slider_value(QString name, double val);
|
||||||
|
QComboBox* id_to_combobox(QString name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::Test_Sim* ui;
|
||||||
|
std::unordered_map<button_lookup_e, QPushButton*> button_lookup;
|
||||||
|
std::unordered_map<slider_lookup_e, bool> slider_lock;
|
||||||
|
std::unordered_map<slider_lookup_e, QwtSlider*> slider_lookup;
|
||||||
|
std::unordered_map<led_lookup_e, QPushButton*> led_lookup;
|
||||||
|
std::unordered_map<combobox_lookup_e, QComboBox*> combobox_lookup;
|
||||||
|
std::unordered_map<label_lookup_e, QLabel*> label_lookup;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SIM_TEST_H
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Test_Sim</class>
|
||||||
|
<widget class="QMainWindow" name="Test_Sim">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0" rowspan="4">
|
||||||
|
<widget class="QwtSlider" name="Slider"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="led">
|
||||||
|
<property name="text">
|
||||||
|
<string>PushButton</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="button">
|
||||||
|
<property name="text">
|
||||||
|
<string>PushButton</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QComboBox" name="combobox"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</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>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QwtSlider</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qwt_slider.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user