| 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/stat.h> |
| 4 | #include <fcntl.h> |
| 5 | #include <unistd.h> |
| 6 | #include <sys/ioctl.h> |
| 7 | #include <linux/fb.h> |
| 8 | #include <termios.h> |
| 9 | #include <linux/kd.h> |
| 10 | |
| 11 | int main() |
| 12 | { |
| 13 | struct fb_var_screeninfo fbvar; |
| 14 | struct termios kbd_termios; |
| 15 | int ret, fbdev, kbdfd; |
| 16 | FILE *tios_f; |
| 17 | |
| 18 | fbdev = open("/dev/fb0", O_RDWR); |
| 19 | if (fbdev == -1) { |
| 20 | perror("open"); |
| 21 | return 1; |
| 22 | } |
| 23 | |
| 24 | ret = ioctl(fbdev, FBIOGET_VSCREENINFO, &fbvar); |
| 25 | if (ret == -1) { |
| 26 | perror("FBIOGET_VSCREENINFO ioctl"); |
| 27 | goto end_fb; |
| 28 | } |
| 29 | |
| 30 | if (fbvar.yoffset != 0) { |
| 31 | printf("fixing yoffset.. "); |
| 32 | fbvar.yoffset = 0; |
| 33 | ret = ioctl(fbdev, FBIOPAN_DISPLAY, &fbvar); |
| 34 | if (ret < 0) |
| 35 | perror("ioctl FBIOPAN_DISPLAY"); |
| 36 | else |
| 37 | printf("ok\n"); |
| 38 | } |
| 39 | |
| 40 | end_fb: |
| 41 | close(fbdev); |
| 42 | |
| 43 | tios_f = fopen("/tmp/pico_tios", "rb"); |
| 44 | if (tios_f != NULL) { |
| 45 | kbdfd = open("/dev/tty", O_RDWR); |
| 46 | if (kbdfd == -1) { |
| 47 | perror("open /dev/tty"); |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | if (fread(&kbd_termios, sizeof(kbd_termios), 1, tios_f) == 1) { |
| 52 | if (ioctl(kbdfd, KDSETMODE, KD_TEXT) == -1) |
| 53 | perror("KDSETMODE KD_TEXT"); |
| 54 | |
| 55 | printf("restoring termios.. "); |
| 56 | if (tcsetattr(kbdfd, TCSAFLUSH, &kbd_termios) == -1) |
| 57 | perror("tcsetattr"); |
| 58 | else |
| 59 | printf("ok\n"); |
| 60 | } |
| 61 | |
| 62 | close(kbdfd); |
| 63 | fclose(tios_f); |
| 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | } |