Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/stat.h> |
| 4 | #include <dirent.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <unistd.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <linux/input.h> |
| 9 | |
| 10 | int open_fingerprint() { |
| 11 | DIR *dir=opendir("/dev/input"); |
| 12 | if(!dir) { |
| 13 | return -1; |
| 14 | } |
| 15 | int fd; |
| 16 | struct dirent *entry; |
| 17 | while( (entry=readdir(dir))!=NULL) { |
| 18 | if(entry->d_type!=DT_CHR) |
| 19 | continue; |
| 20 | if(strncmp(entry->d_name, "event", 5)==0) { |
| 21 | fd = openat(dirfd(dir), entry->d_name, O_RDONLY); |
| 22 | if(fd < 0) continue; |
| 23 | |
| 24 | char buf[64]; |
| 25 | int ret = ioctl(fd, EVIOCGNAME(sizeof(buf)), buf); |
| 26 | if(ret < 0) { |
| 27 | close(fd); |
| 28 | continue; |
| 29 | } |
| 30 | |
| 31 | if(strcmp(buf, "fingerprint") != 0) { |
| 32 | close(fd); |
| 33 | continue; |
| 34 | } |
| 35 | |
| 36 | ioctl(fd, EVIOCGRAB, 1); |
| 37 | closedir(dir); |
| 38 | return fd; |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | closedir(dir); |
| 43 | return -1; |
| 44 | } |
| 45 | |
| 46 | #define FINGERPRINT_CLICK 0xae |
| 47 | #define FINGERPRINT_LONGPRESS 0x1c |
| 48 | #define FINGERPRINT_RIGHT 0x6a |
| 49 | #define FINGERPRINT_LEFT 0x69 |
| 50 | #define FINGERPRINT_UP 0x67 |
| 51 | #define FINGERPRINT_DOWN 0x6c |
| 52 | #define FINGERPRINT_DOUBLECLICK 0x6f |
| 53 | int main() { |
| 54 | int fd = open_fingerprint(); |
| 55 | if(fd<0) return 1; |
| 56 | |
| 57 | struct input_event ev; |
| 58 | while(read(fd, &ev, sizeof(ev)) == sizeof(ev)) { |
| 59 | if(ev.type != EV_KEY) continue; |
| 60 | //Huawei kernel code automatically generates both up and down events, just take one |
| 61 | if(ev.value != 1) continue; |
| 62 | |
| 63 | switch(ev.code) { |
| 64 | case FINGERPRINT_CLICK: |
Pierre-Hugues Husson | 7b7fe45 | 2018-01-15 00:10:05 +0100 | [diff] [blame] | 65 | system("input keyevent KEYCODE_HOME &"); |
Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 66 | break; |
| 67 | case FINGERPRINT_LEFT: |
Pierre-Hugues Husson | 7b7fe45 | 2018-01-15 00:10:05 +0100 | [diff] [blame] | 68 | system("input keyevent KEYCODE_BACK &"); |
Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 69 | break; |
| 70 | case FINGERPRINT_RIGHT: |
Pierre-Hugues Husson | 7b7fe45 | 2018-01-15 00:10:05 +0100 | [diff] [blame] | 71 | system("input keyevent KEYCODE_VOICE_ASSIST &"); |
Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 72 | break; |
| 73 | case FINGERPRINT_UP: |
Pierre-Hugues Husson | 7b7fe45 | 2018-01-15 00:10:05 +0100 | [diff] [blame] | 74 | system("cmd statusbar expand-settings &"); |
Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 75 | break; |
| 76 | case FINGERPRINT_DOWN: |
Pierre-Hugues Husson | 7b7fe45 | 2018-01-15 00:10:05 +0100 | [diff] [blame] | 77 | system("cmd statusbar expand-notifications &"); |
Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 78 | break; |
| 79 | case FINGERPRINT_LONGPRESS: |
Pierre-Hugues Husson | 0dedfd6 | 2018-01-15 00:26:40 +0100 | [diff] [blame^] | 80 | system("input keyevent KEYCODE_APP_SWITCH &"); |
Pierre-Hugues Husson | d1cf8d8 | 2018-01-14 22:49:15 +0100 | [diff] [blame] | 81 | break; |
| 82 | }; |
| 83 | } |
| 84 | } |