#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; }