From e5382e43fcc8d143db24d80833a02b44b9c0b78e Mon Sep 17 00:00:00 2001 From: John Ogness Date: Fri, 15 Feb 2019 12:50:06 +0106 Subject: schulung_tools: leds: add Qt leds application for host The leds application runs on the host and is used to simulate PCI hardware with 3 LEDs. See the README for information about how to build and use it. Signed-off-by: John Ogness --- schulung_tools/leds/leds.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 schulung_tools/leds/leds.cpp (limited to 'schulung_tools/leds/leds.cpp') diff --git a/schulung_tools/leds/leds.cpp b/schulung_tools/leds/leds.cpp new file mode 100644 index 0000000..2ac7a99 --- /dev/null +++ b/schulung_tools/leds/leds.cpp @@ -0,0 +1,52 @@ +#include "leds.h" +#include "ui_leds.h" + +#include +#include +#include +#include +#include + +void Leds::poll_shm(void) { + for (int i = 0; i < 3; i++) { + radioButton[i]->setChecked(shm->leds[i]); + } +} + +Leds::Leds(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::Leds) +{ +} + +int Leds::init(void) { + int fd = open("/dev/shm/ivshmem", O_RDONLY); + if (fd == -1) { + fprintf(stderr, "open shm failed!"); + return -1; + } + + shm = (struct ivmshmem *) mmap(NULL, 1024, PROT_READ, MAP_PRIVATE, fd, 0); + if (shm == MAP_FAILED) { + fprintf(stderr, "map shm failed!"); + return -1; + } + + ui->setupUi(this); + + radioButton[0] = ui->radioButton_1; + radioButton[1] = ui->radioButton_2; + radioButton[2] = ui->radioButton_3; + + timer.setInterval(10); + connect(&timer, SIGNAL(timeout()), this, SLOT(poll_shm())); + timer.start(); + + return 0; +} + +Leds::~Leds() +{ + timer.stop(); + delete ui; +} -- cgit v1.2.3