diff options
Diffstat (limited to 'schulung_tools/leds/leds.cpp')
| -rw-r--r-- | schulung_tools/leds/leds.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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 <stdio.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> + +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; +} |
