1999-12-09 23:15:14 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
input.c
|
|
|
|
|
|
|
|
|
|
Handles keypad (and other?) input from the user.
|
|
|
|
|
|
|
|
|
|
Currently, the keys are as follows:
|
|
|
|
|
|
|
|
|
|
Context Key Function
|
|
|
|
|
------- --- --------
|
|
|
|
|
Normal "normal" context is handled in this source file.
|
|
|
|
|
A Pause/Continue
|
|
|
|
|
B Back(Go to previous screen)
|
|
|
|
|
C Forward(Go to next screen)
|
|
|
|
|
D Open main menu
|
|
|
|
|
E-Z Sent to client, if any; ignored otherwise
|
|
|
|
|
|
|
|
|
|
(menu keys are not handled here, but in the menu code)
|
|
|
|
|
Menu
|
|
|
|
|
A Enter/select
|
|
|
|
|
B Up/Left
|
|
|
|
|
C Down/Right
|
|
|
|
|
D Exit/Cancel
|
|
|
|
|
E-Z Ignored
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
2001-04-27 02:20:38 +00:00
|
|
|
#include <string.h>
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
#include "../shared/sockets.h"
|
|
|
|
|
#include "../shared/debug.h"
|
|
|
|
|
|
|
|
|
|
#include "drivers/lcd.h"
|
|
|
|
|
|
|
|
|
|
#include "client_data.h"
|
|
|
|
|
#include "clients.h"
|
|
|
|
|
#include "screen.h"
|
2001-04-27 02:20:38 +00:00
|
|
|
#include "widget.h"
|
1999-12-09 23:15:14 +00:00
|
|
|
#include "screenlist.h"
|
|
|
|
|
#include "menus.h"
|
|
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
int server_input (int key);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
// FIXME! The server tends to crash when "E" is pressed.. (?!)
|
|
|
|
|
// (but only when the joystick driver is the last one on the list...)
|
|
|
|
|
|
|
|
|
|
// Checks for keypad input, and dispatches it
|
2000-03-30 20:20:41 +00:00
|
|
|
int
|
|
|
|
|
handle_input ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
char str[256];
|
|
|
|
|
int key;
|
|
|
|
|
screen *s;
|
2001-04-27 02:20:38 +00:00
|
|
|
widget *w;
|
2000-04-03 22:13:57 +00:00
|
|
|
client *c;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
key = lcd.getkey ();
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!key)
|
|
|
|
|
return 0;
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
debug ("handle_input(%c)\n", (char) key);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (key) {
|
2001-04-27 02:20:38 +00:00
|
|
|
// TODO: Interpret and translate keys!
|
|
|
|
|
|
|
|
|
|
// Give current screen a shot at the key first
|
|
|
|
|
s = screenlist_current ();
|
|
|
|
|
w = widget_find( s, KEYS_WIDGETID );
|
|
|
|
|
if( s->parent && w && w->text && strchr( w->text, key ) ) {
|
|
|
|
|
// This screen wants this key. Tell it we got one
|
2001-03-22 22:51:49 +00:00
|
|
|
sprintf(str, "key %c\n", key);
|
2001-04-27 02:20:38 +00:00
|
|
|
sock_send_string(s->parent->sock, str);
|
|
|
|
|
// Nobody else gets this key
|
|
|
|
|
} else {
|
|
|
|
|
// Give key to anyone who wants it
|
|
|
|
|
c = (client *)LL_GetFirst(clients);
|
|
|
|
|
while(c) {
|
|
|
|
|
// If the client should have this keypress...
|
|
|
|
|
s = (screen *)LL_GetFirst(c->data->screenlist);
|
|
|
|
|
while(s) {
|
|
|
|
|
w = widget_find( s, KEYS_WIDGETID );
|
|
|
|
|
if( s->parent && w && w->text && strchr( w->text, key ) ) {
|
|
|
|
|
// Send keypress to client
|
|
|
|
|
sprintf(str, "key %c\n", key);
|
|
|
|
|
sock_send_string(c->sock, str);
|
|
|
|
|
break ; // Screen loop
|
|
|
|
|
}
|
|
|
|
|
s = (screen *)LL_GetNext(c->data->screenlist);
|
|
|
|
|
} // while screens
|
|
|
|
|
c = (client *)LL_GetNext(clients);
|
|
|
|
|
} // while clients
|
|
|
|
|
|
|
|
|
|
// Give server a shot at all keys
|
|
|
|
|
server_input (key);
|
2000-04-03 22:13:57 +00:00
|
|
|
}
|
2001-04-27 02:20:38 +00:00
|
|
|
};
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
int
|
|
|
|
|
server_input (int key)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
debug ("server_input(%c)\n", (char) key);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
switch (key) {
|
|
|
|
|
case 'A':
|
|
|
|
|
if (screenlist_action == SCR_HOLD)
|
|
|
|
|
screenlist_action = 0;
|
|
|
|
|
else
|
|
|
|
|
screenlist_action = SCR_HOLD;
|
|
|
|
|
break;
|
|
|
|
|
case 'B':
|
|
|
|
|
screenlist_action = SCR_BACK;
|
|
|
|
|
screenlist_prev ();
|
|
|
|
|
break;
|
|
|
|
|
case 'C':
|
|
|
|
|
screenlist_action = SCR_SKIP;
|
|
|
|
|
screenlist_next ();
|
|
|
|
|
break;
|
|
|
|
|
case 'D':
|
|
|
|
|
debug ("got the menu key!\n");
|
|
|
|
|
server_menu ();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2001-04-27 02:20:38 +00:00
|
|
|
debug ("server_input: Unused key \"%c\" (%i)\n", (char) key, key);
|
2000-04-03 22:13:57 +00:00
|
|
|
break;
|
|
|
|
|
}
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|