Massive changes (first commit), including but not limited to:
* Ability to specify port and address to bind to * By default, binds only to 127.0.0.1 port 13666 * Client commands now return usage when no options given * New driver command: getinfo * Added comments all over the place * Used #defines to further document code * Used #defines to set up compile-time defaults, etc. * Cleaned up client command argument analysis in client_functions.c * Beginning support of syslog * Some bug fixes
This commit is contained in:
+117
-52
@@ -24,9 +24,49 @@
|
||||
E-Z Ignored
|
||||
*/
|
||||
|
||||
// These are the keys for a (likely) properly functioning LK202-25...
|
||||
// #define KEY_UP 'I'
|
||||
// #define KEY_DOWN 'J'
|
||||
// #define KEY_LEFT 'O'
|
||||
// #define KEY_RIGHT 'E'
|
||||
// #define KEY_F1 'N'
|
||||
// #define KEY_F2 'M'
|
||||
// #define KEY_ENTER 'H'
|
||||
|
||||
// These are the keys for my (possibly) broken LK202-25...
|
||||
#define KEY_UP 'I'
|
||||
#define KEY_DOWN 'F'
|
||||
#define KEY_LEFT 'K'
|
||||
#define KEY_RIGHT 'A'
|
||||
#define KEY_F1 'N'
|
||||
// #define KEY_F2 'M'
|
||||
// #define KEY_ENTER 'H'
|
||||
|
||||
// TODO: Generalize these into each driver...
|
||||
//
|
||||
// Really, what this comes down to, is different settings for
|
||||
// different displays. Unless you want to recompile for all
|
||||
// the defaults, these key settings must be in the driver.
|
||||
//
|
||||
// But then, which driver is active and which screen takes which
|
||||
// input and... (sigh).
|
||||
//
|
||||
#define PAUSE_KEY KEY_F1
|
||||
#define BACK_KEY KEY_LEFT
|
||||
#define FORWARD_KEY KEY_RIGHT
|
||||
#define MAIN_MENU_KEY KEY_DOWN
|
||||
|
||||
// This seems somewhat arbitrary, but it IS the original settings:
|
||||
//
|
||||
// #define PAUSE_KEY 'A'
|
||||
// #define BACK_KEY 'B'
|
||||
// #define FORWARD_KEY 'C'
|
||||
// #define MAIN_MENU_KEY 'D'
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "shared/sockets.h"
|
||||
#include "shared/debug.h"
|
||||
@@ -42,6 +82,11 @@
|
||||
|
||||
#include "input.h"
|
||||
|
||||
#define KeyWanted(a,b) ((a) && strchr((a), (b)))
|
||||
#define CurrentScreen screenlist_current
|
||||
#define FirstClient(a) (client *)LL_GetFirst(a);
|
||||
#define NextClient(a) (client *)LL_GetNext(a);
|
||||
|
||||
int server_input (int key);
|
||||
|
||||
// FIXME! The server tends to crash when "E" is pressed.. (?!)
|
||||
@@ -51,46 +96,65 @@ int server_input (int key);
|
||||
int
|
||||
handle_input ()
|
||||
{
|
||||
char str[256];
|
||||
char str[15];
|
||||
int key;
|
||||
screen *s;
|
||||
widget *w;
|
||||
client *c;
|
||||
|
||||
key = lcd.getkey ();
|
||||
|
||||
if (!key)
|
||||
if ((key = lcd.getkey ()) == 0)
|
||||
return 0;
|
||||
|
||||
debug ("handle_input(%c)\n", (char) key);
|
||||
//debug ("handle_input(%c)\n", (char) key);
|
||||
|
||||
if (key) {
|
||||
// TODO: Interpret and translate keys!
|
||||
// Sequence:
|
||||
// Does the current screen want the key?
|
||||
// IfTrue: handle and quit
|
||||
// IfFalse:
|
||||
// Let ALL clients handle it if they want
|
||||
// Let Server handle it, too
|
||||
//
|
||||
// This leads to a unique situation:
|
||||
// First: multiple clients may handle the same key in multiple ways
|
||||
// Second: the server may handle the key differently yet
|
||||
//
|
||||
// Solution: Only the current screen can handle the key press.
|
||||
// Alternately, only one client can handle the key press.
|
||||
|
||||
// Give current screen a shot at the key first
|
||||
s = screenlist_current ();
|
||||
if( s->keys && strchr( s->keys, key ) ) {
|
||||
// This screen wants this key. Tell it we got one
|
||||
sprintf(str, "key %c\n", key);
|
||||
sock_send_string(s->parent->sock, str);
|
||||
// Nobody else gets this key
|
||||
} else {
|
||||
// Give key to clients who want it
|
||||
c = (client *)LL_GetFirst(clients);
|
||||
while(c) {
|
||||
// If the client should have this keypress...
|
||||
if( c->data->client_keys && strchr(c->data->client_keys, key) ) {
|
||||
// Send keypress to client
|
||||
sprintf(str, "key %c\n", key);
|
||||
sock_send_string(c->sock, str);
|
||||
};
|
||||
c = (client *)LL_GetNext(clients);
|
||||
} // while clients
|
||||
// TODO: Interpret and translate keys!
|
||||
|
||||
// Give server a shot at all keys
|
||||
server_input (key);
|
||||
}
|
||||
};
|
||||
// Give current screen a shot at the key first
|
||||
s = CurrentScreen ();
|
||||
|
||||
if (KeyWanted(s->keys, key)) {
|
||||
// This screen wants this key. Tell it we got one
|
||||
snprintf(str, sizeof(str), "key %c\n", key);
|
||||
sock_send_string(s->parent->sock, str);
|
||||
// Nobody else gets this key
|
||||
}
|
||||
|
||||
// if the current screen doesn't want it,
|
||||
// ignore the key...
|
||||
|
||||
// else {
|
||||
// // Give key to clients who want it
|
||||
//
|
||||
// c = FirstClient(clients);
|
||||
//
|
||||
// while (c) {
|
||||
// // If the client should have this keypress...
|
||||
// if(KeyWanted(c->data->client_keys,key)) {
|
||||
// // Send keypress to client
|
||||
// snprintf(str, sizeof(str), "key %c\n", key);
|
||||
// sock_send_string(c->sock, str);
|
||||
// break; // first come, first serve
|
||||
// };
|
||||
// c = NextClient(clients);
|
||||
// } // while clients
|
||||
//
|
||||
// // Give server a shot at all keys
|
||||
// server_input (key);
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -99,29 +163,30 @@ int
|
||||
server_input (int key)
|
||||
{
|
||||
debug ("server_input(%c)\n", (char) key);
|
||||
syslog(LOG_DEBUG, "key %d pressed on device", key);
|
||||
|
||||
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:
|
||||
debug ("server_input: Unused key \"%c\" (%i)\n", (char) key, key);
|
||||
break;
|
||||
switch ((char) key) {
|
||||
case PAUSE_KEY:
|
||||
if (screenlist_action == SCR_HOLD)
|
||||
screenlist_action = 0;
|
||||
else
|
||||
screenlist_action = SCR_HOLD;
|
||||
break;
|
||||
case BACK_KEY:
|
||||
screenlist_action = SCR_BACK;
|
||||
screenlist_prev ();
|
||||
break;
|
||||
case FORWARD_KEY:
|
||||
screenlist_action = SCR_SKIP;
|
||||
screenlist_next ();
|
||||
break;
|
||||
case MAIN_MENU_KEY:
|
||||
debug ("got the menu key!\n");
|
||||
server_menu ();
|
||||
break;
|
||||
default:
|
||||
debug ("server_input: Unused key \"%c\" (%i)\n", (char) key, key);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user