Added GLK12232-25SM support with glk driver.

Fixed lots of small problems in various places.
Added new protocol commands screen_add/del_key so screens
   can request keystrokes when they are being displayed.
Lots of work on CPU GRAPH and BIG NUMBER CLOCK screens.
Fixed 'output' function in MtxOrb.c
This commit is contained in:
ppokorny
2001-04-27 02:20:38 +00:00
parent bb10988d10
commit 877d8ac8e8
12 changed files with 247 additions and 75 deletions
+41 -55
View File
@@ -31,12 +31,11 @@ kstat_ctl_t *kc;
#endif #endif
int load_fd = 0; int load_fd = 0;
static void get_load (struct load *result); static void get_load (struct load * result, struct load * last_load );
static void static void
get_load (struct load *result) get_load (struct load *result, struct load * last_load )
{ {
static struct load last_load = { 0, 0, 0, 0, 0 };
struct load curr_load; struct load curr_load;
#ifndef HAVE_LIBKSTAT #ifndef HAVE_LIBKSTAT
@@ -65,16 +64,13 @@ get_load (struct load *result)
curr_load.nice=0; curr_load.nice=0;
#endif #endif
curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle; curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle;
result->total = curr_load.total - last_load.total; result->total = curr_load.total - last_load->total;
result->user = curr_load.user - last_load.user; result->user = curr_load.user - last_load->user;
result->nice = curr_load.nice - last_load.nice; result->nice = curr_load.nice - last_load->nice;
result->system = curr_load.system - last_load.system; result->system = curr_load.system - last_load->system;
result->idle = curr_load.idle - last_load.idle; result->idle = curr_load.idle - last_load->idle;
last_load.total = curr_load.total;
last_load.user = curr_load.user; *last_load = curr_load ;
last_load.nice = curr_load.nice;
last_load.system = curr_load.system;
last_load.idle = curr_load.idle;
} }
int int
@@ -122,6 +118,7 @@ cpu_screen (int rep, int display)
static int first = 1; static int first = 1;
float value; float value;
static float cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch static float cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch
static struct load last_load = { 0, 0, 0, 0, 0 };
struct load load; struct load load;
if (first) { if (first) {
@@ -169,7 +166,7 @@ cpu_screen (int rep, int display)
} }
//else return 0; //else return 0;
get_load (&load); get_load (&load, &last_load);
// Shift values over by one // Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++) for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
@@ -314,13 +311,13 @@ cpu_graph_screen (int rep, int display)
{ {
int i, j, n = 0; int i, j, n = 0;
static int first = 1; static int first = 1;
float value, maxload; float value ;
#undef CPU_BUF_SIZE #undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 2 #define CPU_BUF_SIZE 2
static float cpu[CPU_BUF_SIZE + 1]; // last buffer is scratch static float cpu[CPU_BUF_SIZE];
static int cpu_past[LCD_MAX_WIDTH]; static int cpu_past[LCD_MAX_WIDTH];
static struct load last_load;
struct load load; struct load load;
int status = 0;
if (first) { if (first) {
first = 0; first = 0;
@@ -341,66 +338,55 @@ cpu_graph_screen (int rep, int display)
sock_send_string (sock, tmp); sock_send_string (sock, tmp);
sprintf (tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt); sprintf (tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt);
sock_send_string (sock, tmp); sock_send_string (sock, tmp);
} cpu_past[i - 1] = 0 ;
} };
get_load (&load); // Clear out CPU averaging array
for (i = 0 ; i < CPU_BUF_SIZE ; ++i) {
cpu[i] = 0 ;
};
}
// Shift values over by one // Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++) for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
cpu[i] = cpu[i + 1]; cpu[i] = cpu[i + 1];
// Read new data // Read and save new data
get_load (&load, &last_load);
cpu[CPU_BUF_SIZE - 1] = ((float) load.user + (float) load.system + (float) load.nice) / (float) load.total; cpu[CPU_BUF_SIZE - 1] = ((float) load.user + (float) load.system + (float) load.nice) / (float) load.total;
// Only clear on first display...
if (!rep) {
/*
// Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++)
cpu[i] = cpu[CPU_BUF_SIZE-1];
*/
}
// Average values for final result // Average values for final result
value = 0; value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) { for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[j]; value += cpu[j];
} }
value /= (float) CPU_BUF_SIZE; value /= (float) CPU_BUF_SIZE;
cpu[CPU_BUF_SIZE] = value;
maxload = 0; // Scale result to available height
for (i = 0; i < lcd_wid - 1; i++) {
cpu_past[i] = cpu_past[i + 1];
j = cpu_past[i];
sprintf (tmp, "widget_set G %i %i %i %i\n", i + 1, i + 1, lcd_hgt, j);
if (display)
sock_send_string (sock, tmp);
if (cpu_past[i] > maxload)
maxload = cpu_past[i];
}
value = cpu[CPU_BUF_SIZE];
if (lcd_hgt > 2) if (lcd_hgt > 2)
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt - 1)); n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt - 1));
else else
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt)); n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt));
// Shift and update display the graph
for (i = 0; i < lcd_wid - 1; i++) {
cpu_past[i] = cpu_past[i + 1];
if (display) {
sprintf (tmp, "widget_set G %i %i %i %i\n",
i + 1, i + 1, lcd_hgt, cpu_past[i] );
sock_send_string (sock, tmp);
};
};
// Save the newest entry and display it
cpu_past[lcd_wid - 1] = n; cpu_past[lcd_wid - 1] = n;
sprintf (tmp, "widget_set G %i %i %i %i\n", lcd_wid, lcd_wid, lcd_hgt, n); if (display) {
if (display) sprintf (tmp, "widget_set G %i %i %i %i\n", lcd_wid, lcd_wid, lcd_hgt, n);
sock_send_string (sock, tmp); sock_send_string (sock, tmp);
};
if (n > maxload)
maxload = n;
if (cpu_past[lcd_wid - 1] > 0)
status = BACKLIGHT_ON;
if (maxload < 1)
status = BACKLIGHT_OFF;
// return status;
return 0; return 0;
} // End cpu_graph_screen() } // End cpu_graph_screen()
+147 -2
View File
@@ -34,6 +34,8 @@ client_function commands[] = {
{"client_set", client_set_func}, {"client_set", client_set_func},
{"client_add_key", client_add_key_func}, {"client_add_key", client_add_key_func},
{"client_del_key", client_del_key_func}, {"client_del_key", client_del_key_func},
{"screen_add_key", screen_add_key_func},
{"screen_del_key", screen_del_key_func},
{"screen_add", screen_add_func}, {"screen_add", screen_add_func},
{"screen_del", screen_del_func}, {"screen_del", screen_del_func},
{"screen_set", screen_set_func}, {"screen_set", screen_set_func},
@@ -144,7 +146,7 @@ client_add_key_func (client * c, int argc, char **argv)
if (!c->data->ack) if (!c->data->ack)
return 1; return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet. Try using screen_add_key.\n");
return 0; return 0;
} }
@@ -160,7 +162,150 @@ client_del_key_func (client * c, int argc, char **argv)
if (!c->data->ack) if (!c->data->ack)
return 1; return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet. Try using screen_del_key.\n");
return 0;
}
///////////////////////////////////////////////////////////////////////////
// Tells the server the client would like to accept keypresses
// of a particular type when the given screen is active on the display
//
int
screen_add_key_func (client * c, int argc, char **argv)
{
widget * w ; /* Keys are stored on a WID_KEYS widget */
screen * s ; /* Attached to a specific screen */
char * id ; /* Screen ID */
char * keys ; /* Keys wanted */
if (!c->data->ack)
return 1;
if (argc < 2) {
sock_send_string (c->sock, "huh? You must specify a screen id\n");
return 0;
}
if (argc < 3) {
sock_send_string (c->sock, "huh? You must specify a key list\n");
return 0;
}
if (argc > 3) {
sock_send_string (c->sock, "huh? Too many parameters...\n");
return 0;
}
id = argv[1];
keys = argv[2];
debug ("screen_add_key: Adding key(s) %s to screen %s\n", keys, id);
// Find the screen
s = screen_find (c, id);
if (!s) {
sock_send_string (c->sock, "huh? Invalid screen id\n");
return 0;
}
// Find the keys widget
w = widget_find( s, KEYS_WIDGETID );
if (!w) {
int err ;
// No keys widget, create a new one
err = widget_add (s, KEYS_WIDGETID, types[WID_KEYS], NULL, c->sock);
if (err < 0) {
fprintf (stderr, "screen_add_key: Error creating keys widget\n");
} else {
w = widget_find (s, KEYS_WIDGETID );
}
};
if (w) {
// Have a widget
if (!w->text) {
// Save supplied key list
w->text = strdup( keys );
} else {
// Add supplied keys to existing list
// NOTE: There could be duplicates in the resulting list
// That's OK, it's the existence of the key in the list
// that's important. We'll be more careful in the delete
// key function.
char * new ;
new = realloc( w->text, strlen(w->text) + strlen(keys) +1 );
if( new ) {
w->text = new ;
strcat( new, keys );
}
}
}
if (!w) {
sock_send_string(c->sock, "huh? failed\n");
} else
sock_send_string(c->sock, "success\n");
return 0;
}
///////////////////////////////////////////////////////////////////////////
// Tells the server the client would NOT like to accept keypresses
// of a particular type when the given screen is active on the display
//
int
screen_del_key_func (client * c, int argc, char **argv)
{
widget * w ; /* Keys are stored on a WID_KEYS widget */
screen * s ; /* Attached to a specific screen */
char * id ; /* Screen ID */
char * keys ; /* Keys wanted */
if (!c->data->ack)
return 1;
if (argc < 2) {
sock_send_string (c->sock, "huh? You must specify a screen id\n");
return 0;
}
if (argc < 3) {
sock_send_string (c->sock, "huh? You must specify a key list\n");
return 0;
}
if (argc > 3) {
sock_send_string (c->sock, "huh? Too many parameters...\n");
return 0;
}
id = argv[1] ;
keys = argv[2] ;
debug ("screen_del_key: Deleting key(s) %s from screen %s\n", keys, id);
// Find the screen
s = screen_find (c, id);
if (!s) {
sock_send_string (c->sock, "huh? Invalid screen id\n");
return 0;
}
// Find the keys widget
w = widget_find( s, KEYS_WIDGETID );
if (w && w->text) {
// Got the widget, remove keys from the text member
// NOTE: We let malloc/realloc remember the length
// of the allocated storage. If keys are later
// added, realloc (in add_key above) will make
// sure there is enough space at w->text
char * from ;
char * to ;
to = from = w->text ;
while( *from ) {
// Is this key to be deleted from the list?
if( strchr( keys, *from ) ) {
// Yes, skip it
++from ;
} else {
// No, save it
*to++ = *from++ ;
}
}
}
sock_send_string(c->sock, "success\n");
return 0; return 0;
} }
+2
View File
@@ -17,6 +17,8 @@ int hello_func (client * c, int argc, char **argv);
int client_set_func (client * c, int argc, char **argv); int client_set_func (client * c, int argc, char **argv);
int client_add_key_func (client * c, int argc, char **argv); int client_add_key_func (client * c, int argc, char **argv);
int client_del_key_func (client * c, int argc, char **argv); int client_del_key_func (client * c, int argc, char **argv);
int screen_add_key_func (client * c, int argc, char **argv);
int screen_del_key_func (client * c, int argc, char **argv);
int screen_add_func (client * c, int argc, char **argv); int screen_add_func (client * c, int argc, char **argv);
int screen_del_func (client * c, int argc, char **argv); int screen_del_func (client * c, int argc, char **argv);
int screen_set_func (client * c, int argc, char **argv); int screen_set_func (client * c, int argc, char **argv);
+2 -1
View File
@@ -10,6 +10,7 @@ EXTRA_libLCDdrivers_a_SOURCES = MtxOrb.c MtxOrb.h text.c text.h \
hd44780-low.h hd44780-drivers.h \ hd44780-low.h hd44780-drivers.h \
port.h joy.c joy.h irmanin.c irmanin.h \ port.h joy.c joy.h irmanin.c irmanin.h \
bayrad.h bayrad.c \ bayrad.h bayrad.c \
CFontz.c CFontz.h lircin.c lircin.h debug.h CFontz.c CFontz.h lircin.c lircin.h debug.h \
glk.c glk.h glkproto.c glkproto.h
libLCDdrivers_a_DEPENDENCIES = @DRIVERS@ libLCDdrivers_a_DEPENDENCIES = @DRIVERS@
libLCDdrivers_a_LIBADD = @DRIVERS@ libLCDdrivers_a_LIBADD = @DRIVERS@
+1 -1
View File
@@ -347,7 +347,7 @@ MtxOrb_output (int on)
if ( on & (1 << i) ) { if ( on & (1 << i) ) {
sprintf (out, "%cW%c", 254, i+1); sprintf (out, "%cW%c", 254, i+1);
} else { } else {
sprintf (out, "%cW%c", 254, i+1); sprintf (out, "%cV%c", 254, i+1);
} }
write (fd, out, 3); write (fd, out, 3);
} }
+7
View File
@@ -64,6 +64,10 @@
#include "bayrad.h" #include "bayrad.h"
#endif #endif
#ifdef GLK_DRV
#include "glk.h"
#endif
// TODO: Make a Windows server, and clients...? // TODO: Make a Windows server, and clients...?
lcd_logical_driver lcd; lcd_logical_driver lcd;
@@ -105,6 +109,9 @@ lcd_physical_driver drivers[] = {
#endif #endif
#ifdef BAYRAD_DRV #ifdef BAYRAD_DRV
{"BayRAD", bayrad_init,}, {"BayRAD", bayrad_init,},
#endif
#ifdef GLK_DRV
{"glk", glk_init,},
#endif #endif
{NULL, NULL,}, {NULL, NULL,},
+35 -12
View File
@@ -26,6 +26,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "../shared/sockets.h" #include "../shared/sockets.h"
#include "../shared/debug.h" #include "../shared/debug.h"
@@ -35,6 +36,7 @@
#include "client_data.h" #include "client_data.h"
#include "clients.h" #include "clients.h"
#include "screen.h" #include "screen.h"
#include "widget.h"
#include "screenlist.h" #include "screenlist.h"
#include "menus.h" #include "menus.h"
@@ -52,6 +54,7 @@ handle_input ()
char str[256]; char str[256];
int key; int key;
screen *s; screen *s;
widget *w;
client *c; client *c;
key = lcd.getkey (); key = lcd.getkey ();
@@ -62,19 +65,39 @@ handle_input ()
debug ("handle_input(%c)\n", (char) key); debug ("handle_input(%c)\n", (char) key);
if (key) { if (key) {
/* s = screenlist_current (); */ // TODO: Interpret and translate keys!
c = (client *)LL_GetFirst(clients);
while(c) { // Give current screen a shot at the key first
// TODO: Interpret and translate keys! s = screenlist_current ();
// If the client should have this keypress... w = widget_find( s, KEYS_WIDGETID );
// Send keypress to client if( s->parent && w && w->text && strchr( w->text, key ) ) {
// TODO: Implement client "acceptable key" lists // This screen wants this key. Tell it we got one
sprintf(str, "key %c\n", key); sprintf(str, "key %c\n", key);
sock_send_string(c->sock, str); sock_send_string(s->parent->sock, str);
c = (client *)LL_GetNext(clients); // 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);
} }
server_input (key); };
}
return 0; return 0;
} }
@@ -104,7 +127,7 @@ server_input (int key)
server_menu (); server_menu ();
break; break;
default: default:
debug ("server_input: Invalid key \"%c\" (%i)\n", (char) key, key); debug ("server_input: Unused key \"%c\" (%i)\n", (char) key, key);
break; break;
} }
+2 -1
View File
@@ -422,7 +422,8 @@ draw_frame (LL * list, char fscroll, int left, int top, int right, int bottom, i
} }
break; break;
case WID_NUM: // FIXME: doesn't work in frames... case WID_NUM: // FIXME: doesn't work in frames...
if ((w->x > 0) && (w->y >= 0) && (w->y <= 9)) { // NOTE: y=10 means COLON (:)
if ((w->x > 0) && (w->y >= 0) && (w->y <= 10)) {
if (reset) { if (reset) {
lcd.init_num (); lcd.init_num ();
reset = 0; reset = 0;
+3 -3
View File
@@ -153,9 +153,6 @@ screen_remove (client * c, char *id)
// TODO: Check for errors here? // TODO: Check for errors here?
LL_Remove (c->data->screenlist, (void *) s); LL_Remove (c->data->screenlist, (void *) s);
// ... and here?
screen_destroy (s);
// Now, remove it from the screenlist... // Now, remove it from the screenlist...
if (screenlist_remove_all (s) < 0) { if (screenlist_remove_all (s) < 0) {
// Not a serious error.. // Not a serious error..
@@ -163,5 +160,8 @@ screen_remove (client * c, char *id)
return 0; return 0;
} }
// TODO: Check for errors here too?
screen_destroy (s);
return 0; return 0;
} }
+1
View File
@@ -17,6 +17,7 @@ char *types[] = { "none",
"scroller", "scroller",
"frame", "frame",
"num", "num",
"keys",
//"", //"",
NULL, NULL,
}; };
+4
View File
@@ -26,11 +26,15 @@ typedef struct widget {
#define WID_SCROLLER 6 #define WID_SCROLLER 6
#define WID_FRAME 7 #define WID_FRAME 7
#define WID_NUM 8 #define WID_NUM 8
#define WID_KEYS 9
#define WID_MAX_DIR 4 #define WID_MAX_DIR 4
extern char *types[]; extern char *types[];
// RESERVED widget ID for keys active on a screen
#define KEYS_WIDGETID "screenkeys"
widget *widget_create (); widget *widget_create ();
int widget_destroy (widget * w); int widget_destroy (widget * w);
+2
View File
@@ -1,6 +1,8 @@
#ifndef DEBUG_H #ifndef DEBUG_H
#define DEBUG_H #define DEBUG_H
#include "../config.h"
#ifdef DEBUG #ifdef DEBUG
#define debug printf #define debug printf