[c5c522c] | 1 | /* |
---|
| 2 | |
---|
| 3 | input.c |
---|
| 4 | |
---|
| 5 | Handles keypad (and other?) input from the user. |
---|
| 6 | |
---|
| 7 | Currently, the keys are as follows: |
---|
| 8 | |
---|
| 9 | Context Key Function |
---|
| 10 | ------- --- -------- |
---|
| 11 | Normal "normal" context is handled in this source file. |
---|
| 12 | A Pause/Continue |
---|
| 13 | B Back(Go to previous screen) |
---|
| 14 | C Forward(Go to next screen) |
---|
| 15 | D Open main menu |
---|
| 16 | E-Z Sent to client, if any; ignored otherwise |
---|
| 17 | |
---|
| 18 | (menu keys are not handled here, but in the menu code) |
---|
| 19 | Menu |
---|
| 20 | A Enter/select |
---|
| 21 | B Up/Left |
---|
| 22 | C Down/Right |
---|
| 23 | D Exit/Cancel |
---|
| 24 | E-Z Ignored |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | #include <stdio.h> |
---|
| 29 | |
---|
| 30 | #include "../shared/sockets.h" |
---|
| 31 | #include "../shared/debug.h" |
---|
| 32 | |
---|
| 33 | #include "drivers/lcd.h" |
---|
| 34 | |
---|
| 35 | #include "client_data.h" |
---|
| 36 | #include "clients.h" |
---|
| 37 | #include "screen.h" |
---|
| 38 | #include "screenlist.h" |
---|
| 39 | #include "menus.h" |
---|
| 40 | |
---|
| 41 | #include "input.h" |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | int server_input(int key); |
---|
| 45 | |
---|
| 46 | // FIXME! The server tends to crash when "E" is pressed.. (?!) |
---|
| 47 | // (but only when the joystick driver is the last one on the list...) |
---|
| 48 | |
---|
| 49 | // Checks for keypad input, and dispatches it |
---|
| 50 | int handle_input() |
---|
| 51 | { |
---|
| 52 | char str[256]; |
---|
| 53 | int key; |
---|
| 54 | screen *s; |
---|
| 55 | client *c; |
---|
| 56 | |
---|
| 57 | key = lcd.getkey(); |
---|
| 58 | |
---|
| 59 | if (!key) return 0; |
---|
| 60 | |
---|
| 61 | debug("handle_input(%c)\n", (char)key); |
---|
| 62 | |
---|
| 63 | if(key) |
---|
| 64 | { |
---|
| 65 | s = screenlist_current(); |
---|
| 66 | if(s) |
---|
| 67 | { |
---|
| 68 | c = s->parent; |
---|
| 69 | if(c) |
---|
| 70 | { |
---|
| 71 | // TODO: Interpret and translate keys! |
---|
| 72 | // If the client should have this keypress... |
---|
| 73 | // Send keypress to client |
---|
| 74 | if(key >= 'E' && key <= 'Z') |
---|
| 75 | { |
---|
| 76 | // TODO: Implement client "acceptable key" lists |
---|
| 77 | sprintf(str, "key %c\n", key); |
---|
| 78 | sock_send_string(c->sock, str); |
---|
| 79 | } |
---|
| 80 | // Otherwise, tell the server about it. |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | server_input(key); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | // If no parent, it means we're on the server screen. |
---|
| 89 | // so, the server gets all keypresses there. |
---|
| 90 | server_input(key); |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | return 0; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | int server_input(int key) |
---|
| 101 | { |
---|
| 102 | debug("server_input(%c)\n", (char)key); |
---|
| 103 | |
---|
| 104 | switch(key) |
---|
| 105 | { |
---|
| 106 | case 'A': |
---|
| 107 | if(screenlist_action == SCR_HOLD) |
---|
| 108 | screenlist_action = 0; |
---|
| 109 | else |
---|
| 110 | screenlist_action = SCR_HOLD; |
---|
| 111 | break; |
---|
| 112 | case 'B': |
---|
| 113 | screenlist_action = SCR_BACK; |
---|
| 114 | screenlist_prev(); |
---|
| 115 | break; |
---|
| 116 | case 'C': |
---|
| 117 | screenlist_action = SCR_SKIP; |
---|
| 118 | screenlist_next(); |
---|
| 119 | break; |
---|
| 120 | case 'D': |
---|
| 121 | debug("got the menu key!\n"); |
---|
| 122 | server_menu(); |
---|
| 123 | break; |
---|
| 124 | default: |
---|
| 125 | debug("server_input: Invalid key \"%c\" (%i)\n", |
---|
| 126 | (char)key, key); |
---|
| 127 | break; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | return 0; |
---|
| 131 | } |
---|