From f71d28a3107bf14ad3fa22109a34c746911b3f61 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 14 Feb 2019 11:08:28 +0100 Subject: Implemented graphic representation and update of line and RGB LEDs. Signed-off-by: Pavel Pisa --- qtmips_gui/peripheralsview.cpp | 51 ++++++++++ qtmips_gui/peripheralsview.h | 5 + qtmips_gui/peripheralsview.ui | 212 +++++++++++++++++++++++++++++++++++++---- qtmips_machine/peripspiled.cpp | 3 + 4 files changed, 255 insertions(+), 16 deletions(-) diff --git a/qtmips_gui/peripheralsview.cpp b/qtmips_gui/peripheralsview.cpp index 231de90..655b101 100644 --- a/qtmips_gui/peripheralsview.cpp +++ b/qtmips_gui/peripheralsview.cpp @@ -38,4 +38,55 @@ void PeripheralsView::setup(const machine::PeripSpiLed *perip_spi_led) { val = ui->spinBlue->value(); ui->spinBlue->setValue(val - 1); ui->spinBlue->setValue(val); + + ui->labelRgb1->setAutoFillBackground(true); + ui->labelRgb2->setAutoFillBackground(true); + + connect(perip_spi_led, SIGNAL(led_line_changed(uint)), this, SLOT(led_line_changed(uint))); + connect(perip_spi_led, SIGNAL(led_rgb1_changed(int)), this, SLOT(led_rgb1_changed(int))); + connect(perip_spi_led, SIGNAL(led_rgb2_changed(int)), this, SLOT(led_rgb2_changed(int))); + + led_line_changed(0); + led_rgb1_changed(0); + led_rgb2_changed(0); +} + +void PeripheralsView::led_line_changed(uint val) { + QString s, t; + s = QString::number(val, 16); + t.fill('0', 8 - s.count()); + ui->lineEditHex->setText(t + s); + s = QString::number(val, 10); + ui->lineEditDec->setText(s); + s = QString::number(val, 2); + t.fill('0', 32 - s.count()); + ui->lineEditBin->setText(t + s); +} + +static void set_widget_background_color(QWidget *w, int val) { + int r = (val >> 16) & 0xff; + int g = (val >> 8) & 0xff; + int b = (val >> 0) & 0xff; + QPalette::ColorRole brole = w->backgroundRole(); + QPalette pal = w->palette(); + pal.setColor(brole, QColor(r, g, b)); + w->setPalette(pal); +} + +void PeripheralsView::led_rgb1_changed(int val) { + QString s, t; + s = QString::number(val, 16); + t.fill('0', 8 - s.count()); + ui->lineEditRgb1->setText(t + s); + + set_widget_background_color(ui->labelRgb1, val); +} + +void PeripheralsView::led_rgb2_changed(int val) { + QString s, t; + s = QString::number(val, 16); + t.fill('0', 8 - s.count()); + ui->lineEditRgb2->setText(t + s); + + set_widget_background_color(ui->labelRgb2, val); } diff --git a/qtmips_gui/peripheralsview.h b/qtmips_gui/peripheralsview.h index 8aaf9b9..30e85f1 100644 --- a/qtmips_gui/peripheralsview.h +++ b/qtmips_gui/peripheralsview.h @@ -19,6 +19,11 @@ public: void setup(const machine::PeripSpiLed *perip_spi_led); +public slots: + void led_line_changed(uint val); + void led_rgb1_changed(int val); + void led_rgb2_changed(int val); + private: Ui::PeripheralsView *ui; }; diff --git a/qtmips_gui/peripheralsview.ui b/qtmips_gui/peripheralsview.ui index 59a1e4d..60726a2 100644 --- a/qtmips_gui/peripheralsview.ui +++ b/qtmips_gui/peripheralsview.ui @@ -19,6 +19,93 @@ QLayout::SetMaximumSize + + + + + + + + + + LED RGB 1 + + + Qt::AlignCenter + + + + + + + + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + true + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + LED RGB 2 + + + Qt::AlignCenter + + + + + + + + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + true + + + + + + + + + @@ -36,6 +123,16 @@ + + + + Red Knob + + + Qt::AlignCenter + + + @@ -73,6 +170,16 @@ + + + + Green Knob + + + Qt::AlignCenter + + + @@ -110,6 +217,16 @@ + + + + Blue Knob + + + Qt::AlignCenter + + + @@ -127,31 +244,94 @@ - - - b31 + + + + + Word hexadecimal + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + + + + Qt::AlignCenter + + + true + + + + + + + + + Qt::Horizontal - - false + + + 40 + 20 + - + - - - b30 - - + + + + + Word decimal + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + - - - b29 - - + + + + + Word binary + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + Qt::AlignCenter + + + true + + + diff --git a/qtmips_machine/peripspiled.cpp b/qtmips_machine/peripspiled.cpp index f811714..03b74f9 100644 --- a/qtmips_machine/peripspiled.cpp +++ b/qtmips_machine/peripspiled.cpp @@ -61,12 +61,15 @@ bool PeripSpiLed::wword(std::uint32_t address, std::uint32_t value) { switch (address) { case SPILED_REG_LED_LINE_o: spiled_reg_led_line = value; + emit led_line_changed(value); break; case SPILED_REG_LED_RGB1_o: spiled_reg_led_rgb1 = value; + emit led_rgb1_changed(value); break; case SPILED_REG_LED_RGB2_o: spiled_reg_led_rgb2 = value; + emit led_rgb2_changed(value); break; default: break; -- cgit v1.2.3