diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-14 11:08:28 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-14 11:08:28 +0100 |
commit | f71d28a3107bf14ad3fa22109a34c746911b3f61 (patch) | |
tree | 4ab337b92db01f69cb6e264f5ff8180347968af3 /qtmips_gui/peripheralsview.cpp | |
parent | 7341a3329994bf655f2490c4e9758929bd95c23f (diff) | |
download | qtmips-f71d28a3107bf14ad3fa22109a34c746911b3f61.tar.gz qtmips-f71d28a3107bf14ad3fa22109a34c746911b3f61.tar.bz2 qtmips-f71d28a3107bf14ad3fa22109a34c746911b3f61.zip |
Implemented graphic representation and update of line and RGB LEDs.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/peripheralsview.cpp')
-rw-r--r-- | qtmips_gui/peripheralsview.cpp | 51 |
1 files changed, 51 insertions, 0 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); } |