blob: 2ac7a9991f9a37c1fa420e8b96325ffee88950c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
}
|