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:
+41
-55
@@ -31,12 +31,11 @@ kstat_ctl_t *kc;
|
||||
#endif
|
||||
|
||||
int load_fd = 0;
|
||||
static void get_load (struct load *result);
|
||||
static void get_load (struct load * result, struct load * last_load );
|
||||
|
||||
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;
|
||||
|
||||
#ifndef HAVE_LIBKSTAT
|
||||
@@ -65,16 +64,13 @@ get_load (struct load *result)
|
||||
curr_load.nice=0;
|
||||
#endif
|
||||
curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle;
|
||||
result->total = curr_load.total - last_load.total;
|
||||
result->user = curr_load.user - last_load.user;
|
||||
result->nice = curr_load.nice - last_load.nice;
|
||||
result->system = curr_load.system - last_load.system;
|
||||
result->idle = curr_load.idle - last_load.idle;
|
||||
last_load.total = curr_load.total;
|
||||
last_load.user = curr_load.user;
|
||||
last_load.nice = curr_load.nice;
|
||||
last_load.system = curr_load.system;
|
||||
last_load.idle = curr_load.idle;
|
||||
result->total = curr_load.total - last_load->total;
|
||||
result->user = curr_load.user - last_load->user;
|
||||
result->nice = curr_load.nice - last_load->nice;
|
||||
result->system = curr_load.system - last_load->system;
|
||||
result->idle = curr_load.idle - last_load->idle;
|
||||
|
||||
*last_load = curr_load ;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -122,6 +118,7 @@ cpu_screen (int rep, int display)
|
||||
static int first = 1;
|
||||
float value;
|
||||
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;
|
||||
|
||||
if (first) {
|
||||
@@ -169,7 +166,7 @@ cpu_screen (int rep, int display)
|
||||
}
|
||||
//else return 0;
|
||||
|
||||
get_load (&load);
|
||||
get_load (&load, &last_load);
|
||||
|
||||
// Shift values over by one
|
||||
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;
|
||||
static int first = 1;
|
||||
float value, maxload;
|
||||
float value ;
|
||||
#undef CPU_BUF_SIZE
|
||||
#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 struct load last_load;
|
||||
struct load load;
|
||||
int status = 0;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
@@ -341,66 +338,55 @@ cpu_graph_screen (int rep, int display)
|
||||
sock_send_string (sock, tmp);
|
||||
sprintf (tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt);
|
||||
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
|
||||
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
|
||||
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;
|
||||
|
||||
// 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
|
||||
value = 0;
|
||||
for (j = 0; j < CPU_BUF_SIZE; j++) {
|
||||
value += cpu[j];
|
||||
}
|
||||
value /= (float) CPU_BUF_SIZE;
|
||||
cpu[CPU_BUF_SIZE] = value;
|
||||
|
||||
maxload = 0;
|
||||
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];
|
||||
// Scale result to available height
|
||||
if (lcd_hgt > 2)
|
||||
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt - 1));
|
||||
else
|
||||
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;
|
||||
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);
|
||||
};
|
||||
|
||||
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;
|
||||
} // End cpu_graph_screen()
|
||||
|
||||
+147
-2
@@ -34,6 +34,8 @@ client_function commands[] = {
|
||||
{"client_set", client_set_func},
|
||||
{"client_add_key", client_add_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_del", screen_del_func},
|
||||
{"screen_set", screen_set_func},
|
||||
@@ -144,7 +146,7 @@ client_add_key_func (client * c, int argc, char **argv)
|
||||
if (!c->data->ack)
|
||||
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;
|
||||
}
|
||||
@@ -160,7 +162,150 @@ client_del_key_func (client * c, int argc, char **argv)
|
||||
if (!c->data->ack)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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_add_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_del_func (client * c, int argc, char **argv);
|
||||
int screen_set_func (client * c, int argc, char **argv);
|
||||
|
||||
@@ -10,6 +10,7 @@ EXTRA_libLCDdrivers_a_SOURCES = MtxOrb.c MtxOrb.h text.c text.h \
|
||||
hd44780-low.h hd44780-drivers.h \
|
||||
port.h joy.c joy.h irmanin.c irmanin.h \
|
||||
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_LIBADD = @DRIVERS@
|
||||
|
||||
@@ -347,7 +347,7 @@ MtxOrb_output (int on)
|
||||
if ( on & (1 << i) ) {
|
||||
sprintf (out, "%cW%c", 254, i+1);
|
||||
} else {
|
||||
sprintf (out, "%cW%c", 254, i+1);
|
||||
sprintf (out, "%cV%c", 254, i+1);
|
||||
}
|
||||
write (fd, out, 3);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@
|
||||
#include "bayrad.h"
|
||||
#endif
|
||||
|
||||
#ifdef GLK_DRV
|
||||
#include "glk.h"
|
||||
#endif
|
||||
|
||||
// TODO: Make a Windows server, and clients...?
|
||||
|
||||
lcd_logical_driver lcd;
|
||||
@@ -105,6 +109,9 @@ lcd_physical_driver drivers[] = {
|
||||
#endif
|
||||
#ifdef BAYRAD_DRV
|
||||
{"BayRAD", bayrad_init,},
|
||||
#endif
|
||||
#ifdef GLK_DRV
|
||||
{"glk", glk_init,},
|
||||
#endif
|
||||
{NULL, NULL,},
|
||||
|
||||
|
||||
+35
-12
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../shared/sockets.h"
|
||||
#include "../shared/debug.h"
|
||||
@@ -35,6 +36,7 @@
|
||||
#include "client_data.h"
|
||||
#include "clients.h"
|
||||
#include "screen.h"
|
||||
#include "widget.h"
|
||||
#include "screenlist.h"
|
||||
#include "menus.h"
|
||||
|
||||
@@ -52,6 +54,7 @@ handle_input ()
|
||||
char str[256];
|
||||
int key;
|
||||
screen *s;
|
||||
widget *w;
|
||||
client *c;
|
||||
|
||||
key = lcd.getkey ();
|
||||
@@ -62,19 +65,39 @@ handle_input ()
|
||||
debug ("handle_input(%c)\n", (char) key);
|
||||
|
||||
if (key) {
|
||||
/* s = screenlist_current (); */
|
||||
c = (client *)LL_GetFirst(clients);
|
||||
while(c) {
|
||||
// TODO: Interpret and translate keys!
|
||||
// If the client should have this keypress...
|
||||
// Send keypress to client
|
||||
// TODO: Implement client "acceptable key" lists
|
||||
// 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
|
||||
sprintf(str, "key %c\n", key);
|
||||
sock_send_string(c->sock, str);
|
||||
c = (client *)LL_GetNext(clients);
|
||||
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);
|
||||
}
|
||||
server_input (key);
|
||||
}
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -104,7 +127,7 @@ server_input (int key)
|
||||
server_menu ();
|
||||
break;
|
||||
default:
|
||||
debug ("server_input: Invalid key \"%c\" (%i)\n", (char) key, key);
|
||||
debug ("server_input: Unused key \"%c\" (%i)\n", (char) key, key);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -422,7 +422,8 @@ draw_frame (LL * list, char fscroll, int left, int top, int right, int bottom, i
|
||||
}
|
||||
break;
|
||||
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) {
|
||||
lcd.init_num ();
|
||||
reset = 0;
|
||||
|
||||
+3
-3
@@ -153,9 +153,6 @@ screen_remove (client * c, char *id)
|
||||
// TODO: Check for errors here?
|
||||
LL_Remove (c->data->screenlist, (void *) s);
|
||||
|
||||
// ... and here?
|
||||
screen_destroy (s);
|
||||
|
||||
// Now, remove it from the screenlist...
|
||||
if (screenlist_remove_all (s) < 0) {
|
||||
// Not a serious error..
|
||||
@@ -163,5 +160,8 @@ screen_remove (client * c, char *id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: Check for errors here too?
|
||||
screen_destroy (s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ char *types[] = { "none",
|
||||
"scroller",
|
||||
"frame",
|
||||
"num",
|
||||
"keys",
|
||||
//"",
|
||||
NULL,
|
||||
};
|
||||
|
||||
@@ -26,11 +26,15 @@ typedef struct widget {
|
||||
#define WID_SCROLLER 6
|
||||
#define WID_FRAME 7
|
||||
#define WID_NUM 8
|
||||
#define WID_KEYS 9
|
||||
|
||||
#define WID_MAX_DIR 4
|
||||
|
||||
extern char *types[];
|
||||
|
||||
// RESERVED widget ID for keys active on a screen
|
||||
#define KEYS_WIDGETID "screenkeys"
|
||||
|
||||
widget *widget_create ();
|
||||
int widget_destroy (widget * w);
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define debug printf
|
||||
|
||||
Reference in New Issue
Block a user