Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include <QApplication>
- // standard libs
- #include <unistd.h>
- #include <iostream>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <linux/input.h>
- using namespace std;
- #define KEY_PRESS 1
- #define KEY_RELEASE 0
- int main(int argc, char *argv[])
- {
- /*if(getuid() != 0)
- {
- std::cout << "Not logged as root: " << getenv("USER") << " quiting" << std::endl;
- return -1;
- }*/
- int fd, count=0;
- struct input_event event[64];
- if(getuid()!=0){
- cout << "You must run this program as root. Exiting." << endl;
- return -1;
- }
- cout << "Starting BB-BONE-GPIO Test (press 10 times to end):" << endl;
- if ((fd = open("/dev/input/event1", O_RDONLY)) < 0){
- perror("Failed to open event1 input device. Exiting.");
- return -1;
- }
- while(count < 20){ // Press and Release are one loop each
- int numbytes = (int)read(fd, event, sizeof(event));
- if (numbytes < (int)sizeof(struct input_event)){
- perror("The input read was invalid. Exiting.");
- return -1;
- }
- for (int i=0; i < numbytes/sizeof(struct input_event); i++){
- int type = event[i].type;
- int val = event[i].value;
- int code = event[i].code;
- if (type == EV_KEY) {
- if (val == KEY_PRESS){
- cout << "Press : Code "<< code <<" Value "<< val<< endl;
- }
- if (val == KEY_RELEASE){
- cout << "Release: Code "<< code <<" Value "<< val<< endl;
- }
- }
- }
- count++;
- }
- close(fd);
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement