From a621a06268dd8c2c82fd89054ec6e7d3bb6dd083 Mon Sep 17 00:00:00 2001 From: dglaude Date: Wed, 5 Jun 2002 23:30:54 +0000 Subject: [PATCH] Now treat input and display key: X when pressing keyboard --- server/drivers/CFontz633.c | 36 ++- server/drivers/CFontz633io.c | 473 +++++++++++++++++++++++++++++------ server/drivers/CFontz633io.h | 39 ++- 3 files changed, 449 insertions(+), 99 deletions(-) diff --git a/server/drivers/CFontz633.c b/server/drivers/CFontz633.c index b4af4e8..031869e 100644 --- a/server/drivers/CFontz633.c +++ b/server/drivers/CFontz633.c @@ -21,22 +21,28 @@ /* * Driver status * 04/04/2002: Working driver - * BUT - * + No support for keypad (inactive) - * + No checking of LCD response (ACK of each message) + * 05/06/2002: KeyPad handeling are reading of return value + * + * THINGS NOT DONE: * + No checking if right hardware is connected (firmware/hardware) * + No BigNum (but screen is too small ???) * + No support for multiple instance (require private structure) * + No cache of custom char usage (like in MtxOrb) * + * THINGS PARTIALY DONE: + * + Checking of LCD response (message are only read for key detection) + * + * * THINGS DONE: * + Stopping the live reporting (of temperature) * + Stopping the reporting of temp and fan (is it necessary after reboot) * + Use of library for hbar and vbar (good but library could be better) + * + Support for keypad (Using a KeyRing) * * THINGS TO DO: - * + make the caching at least for heartbeat icon - * + + * + Make the caching at least for heartbeat icon + * + Backporting to 0.4.x + * + Create and use the library (for custom char handeling) * */ @@ -83,7 +89,6 @@ MODULE_EXPORT int stay_in_foreground = 1; MODULE_EXPORT int supports_multiple = 0; MODULE_EXPORT char *symbol_prefix = "CFontz633_"; - /* Internal functions */ /* static void CFontz633_linewrap (int on); */ /* static void CFontz633_autoscroll (int on); */ @@ -112,8 +117,10 @@ CFontz633_init (Driver * drvthis, char *args) debug(RPT_INFO, "CFontz633: init(%p,%s)", drvthis, args ); - /* Read config file */ + EmptyKeyRing(); + EmptyReceiveBuffer(); + /* Read config file */ /* Which serial device should be used */ strncpy(device, drvthis->config_get_string ( drvthis->name , "Device" , 0 , DEFAULT_DEVICE),sizeof(device)); device[sizeof(device)-1]=0; @@ -163,7 +170,10 @@ CFontz633_init (Driver * drvthis, char *args) else { report (RPT_WARNING, "CFontz633_init: Speed must be 1200, 2400, 9600 or 19200. Using default value.\n", speed); } - /* New firmware version? */ + /* New firmware version? + * I will try to behave differently for firmware 0.6 or above. + * Currently this is not in use. + */ if(drvthis->config_get_bool( drvthis->name , "NewFirmware" , 0 , 0)) { newfirmware = 1; } @@ -215,13 +225,12 @@ CFontz633_init (Driver * drvthis, char *args) sleep (4); reboot = 0; } - sleep (1); + sleep (2); CFontz633_hidecursor (); CFontz633_set_contrast (drvthis, contrast); CFontz633_no_live_report (); - report (RPT_DEBUG, "CFontz633_init: done\n"); return 0; @@ -302,7 +311,6 @@ memcpy(&old[width], &framebuf[width], width); xp++; xq++; } - } /* @@ -348,7 +356,7 @@ CFontz633_set_contrast (Driver * drvthis, int promille) hardware_contrast = contrast/20; -//send_onebyte_message(fd, CF633_Set_LCD_Contrast, hardware_contrast); +// send_onebyte_message(fd, CF633_Set_LCD_Contrast, hardware_contrast); } /* @@ -665,6 +673,7 @@ CFontz633_set_char (Driver * drvthis, int n, char *dat) for (col = 0; col < cellwidth; col++) { letter <<= 1; letter |= (dat[(row * cellwidth) + col] > 0); + /* I should remove that debug code. */ // if (dat[(row * cellheight) + col] == 0) printf("."); // if (dat[(row * cellheight) + col] == 1) printf("+"); // if (dat[(row * cellheight) + col] == 2) printf("x"); @@ -754,7 +763,7 @@ CFontz633_clear (Driver * drvthis) static void CFontz633_hardware_clear (Driver * drvthis) { -send_zerobyte_message(fd, CF633_Clear_LCD_Screen); + send_zerobyte_message(fd, CF633_Clear_LCD_Screen); } /* @@ -778,3 +787,4 @@ CFontz633_string (Driver * drvthis, int x, int y, char string[]) framebuf[(y * width) + x + i] = string[i]; } } + diff --git a/server/drivers/CFontz633io.c b/server/drivers/CFontz633io.c index 6016784..b91797a 100644 --- a/server/drivers/CFontz633io.c +++ b/server/drivers/CFontz633io.c @@ -1,3 +1,8 @@ +/* This file should be release under the GPL, + * However most of this is translation from the windows code + * from Brent A. Crosby. + * So I have to check with him. + */ /* * =========================================================================== * 633 Test code for linux. @@ -10,8 +15,75 @@ * =========================================================================== */ #include "CFontz633io.h" +#include #include +/*#include */ +/*extern int errono;*/ +/*#include */ + + + +COMMAND_PACKET incoming_command; + +#define RECEIVEBUFFERSIZE 512 +unsigned char SerialReceiveBuffer[RECEIVEBUFFERSIZE]; +int ReceiveBufferHead; +int ReceiveBufferTail; +int ReceiveBufferTailPeek; + + +/* + * KeyRing handeling function. + * This separate the producer from the consumer. + * It is just a small fifo of unsigned char. + */ + +#define KEYRINGSIZE 16 +unsigned char KeyRing[KEYRINGSIZE]; +int KeyHead; +int KeyTail; + +/*-OK-----------------------------------------------------------------------*/ +void EmptyKeyRing(void) + { + KeyHead=KeyTail=0; + } + +/*-OK-----------------------------------------------------------------------*/ +int AddKeyToKeyRing(unsigned char key) { + int oldhead; + + printf("We have key: %d\n", key); + + oldhead=KeyHead; + KeyHead++; + if (KeyHead==KEYRINGSIZE) KeyHead=0; + if (KeyHead!=KeyTail) { + KeyRing[KeyHead]=key; + return 1; + } + /* We have a KeyRing overflow */ + /* We do not accept extra key */ + KeyHead=oldhead; + return 0; + } + +/*-OK-----------------------------------------------------------------------*/ +unsigned char GetKeyFromKeyRing(void) { + int retval=0; + + if (KeyHead!=KeyTail) { + retval=KeyRing[KeyTail]; + KeyTail++; + if (KeyTail==KEYRINGSIZE) KeyTail=0; + } + + return retval; + } + + + /* * ---------------------------------------------------------------------------- * send_packet() send_packet() will send set the CRC in outgoing_response @@ -124,7 +196,6 @@ SendByte(int fd, unsigned char datum) printf("SendByte(): only %d of %d bytes sent.", bytes_written, 1); } -/* printf(" Sent 0x%03x \n ", datum); */ return; } @@ -139,41 +210,10 @@ COMMAND_PACKET outgoing_response; * ---------------------------------------------------------------------------- */ -#if 0 - void send_packet(int fd) { - ubyte i; - - printf("* Packet "); - SendByte(fd, outgoing_response.command); - printf("cmd:%d ", outgoing_response.command); - SendByte(fd, outgoing_response.data_length); - printf("len:%d [ ", outgoing_response.data_length); - for (i = 0; i < outgoing_response.data_length; i++) { - SendByte(fd, outgoing_response.data[i]); - printf("%02x ", outgoing_response.data[i]); - } - printf("] "); - /* - * Set the CRC - */ - outgoing_response.CRC.as_word = - get_crc((ubyte *) & outgoing_response, - outgoing_response.data_length + 2, 0xFFFF); - SendByte(fd, outgoing_response.CRC.as_bytes[0]); - printf("crc: 0x%02x", outgoing_response.CRC.as_bytes[0]); - SendByte(fd, outgoing_response.CRC.as_bytes[1]); - printf("%02x *\n", outgoing_response.CRC.as_bytes[1]); -} - -#else - -void -send_packet(int fd) -{ - ubyte i; + unsigned char i; SendByte(fd, outgoing_response.command); SendByte(fd, outgoing_response.data_length); @@ -184,68 +224,343 @@ send_packet(int fd) * Set the CRC */ outgoing_response.CRC.as_word = - get_crc((ubyte *) & outgoing_response, + get_crc((unsigned char *) & outgoing_response, outgoing_response.data_length + 2, 0xFFFF); SendByte(fd, outgoing_response.CRC.as_bytes[0]); SendByte(fd, outgoing_response.CRC.as_bytes[1]); -} -#endif +/**** TEST STUF ****/ +// print_packet(&outgoing_response); - -/* ======================================================================== */ - - -#if 0 - -unsigned char buffer[10000]; -int buffer_count; - -void -Clear_Buffer(void) -{ - buffer_count = 0; -} - -void -Buffer_Character(int fd, unsigned char datum) -{ - buffer[buffer_count++] = datum; - if (256 <= buffer_count) - Send_Buffer(fd); + /* Every time we send a message, we also check for incomming one. */ + test_packet(fd); } -void -Buffer_String(int fd, char *input) -{ - char this_character; - while ((this_character = *input++)) - Buffer_Character(fd, this_character); -} + +/*============================================================================ + * 635 WinTest Code. + * Copyright 2001, Crystalfontz America, Inc. Written by Brent A. Crosby + * www.crystalfontz.com, brent@crystalfontz.com + *============================================================================ + */ + +/*---------------------------------------------------------------------------*/ +/* This is some code that kind of makes the windows stuff look a little + * like the DOS/633 interrupt driven serial stuff. Basically there is a + * circular buffer, and Sync_Read_Buffer() uses ReadFile() to put data + * into the circular buffer much like the DOS stuff uses an ISR to put + * the data into the buffer. Then the rest of the functions work like + * the counterparts in the 633, + */ -void -Send_Buffer(int fd) -{ -int bytes_written = 0; - if (buffer_count) { - bytes_written = write(fd, &buffer, buffer_count); - if (bytes_written != buffer_count) { - printf("Send_Buffer(): WriteFile()failed."); - } else if (bytes_written != buffer_count) { - printf("Send_Buffer():only % d of % d bytes sent.", - bytes_written, 1); +/* v TailPeek */ +/* -------------------------------------------------- */ +/* ^ Tail ^ Head */ + +/*-OK-----------------------------------------------------------------------*/ +void EmptyReceiveBuffer(void) + { + ReceiveBufferHead=ReceiveBufferTail=0; + } + +/*-OK------------------------------------------------------------------------ + * Gets incoming data from Window's ReadFile() and puts it into + * SerialReceiveBuffer[]. + */ +void Sync_Read_Buffer(int fd, unsigned char expected_bytes) + { + unsigned char Incoming[512]; + int BytesRead; + int i; + + BytesRead = read(fd, Incoming, expected_bytes); + if (BytesRead==-1){ +/* printf("~~~Problem reading: %s .\n", strerror(errno)); */ } - buffer_count = 0; + else + { +/* printf("Readed %d Bytes:", BytesRead); */ + + /* Read the incoming unsigned char, store it, */ + for(i=0; icommand)) >> 6; + cmd=(0x3F&(packet->command)); + len=packet->data_length; + + printf("Message (%d,%d) %d [", top, cmd, len); + + //There is enough data to make a packet. Transfer over the data. + for(i=0;idata_length;i++) + printf(" %02x", packet->data[i]); + + printf(" ] %02x %02x .\n", packet->CRC.as_bytes[0], packet->CRC.as_bytes[1]); +} +//============================================================================ diff --git a/server/drivers/CFontz633io.h b/server/drivers/CFontz633io.h index 49a9471..f954c24 100644 --- a/server/drivers/CFontz633io.h +++ b/server/drivers/CFontz633io.h @@ -30,36 +30,60 @@ #define CF633_Set_Up_Temperature_Reporting 19 #define CF633_Arbitrary_DOW_Transaction 20 #define CF633_Set_Up_Live_Fan_or_Temperature_Display 21 +/* Add all the new message type */ + +/* Those are all the possible keys we know off */ +#define KEY_UP_PRESS 1 +#define KEY_DOWN_PRESS 2 +#define KEY_LEFT_PRESS 3 +#define KEY_RIGHT_PRESS 4 +#define KEY_ENTER_PRESS 5 +#define KEY_EXIT_PRESS 6 +#define KEY_UP_RELEASE 7 +#define KEY_DOWN_RELEASE 8 +#define KEY_LEFT_RELEASE 9 +#define KEY_RIGHT_RELEASE 10 +#define KEY_ENTER_RELEASE 11 +#define KEY_EXIT_RELEASE 12 + typedef unsigned char ubyte; typedef signed char sbyte; typedef unsigned short word; typedef unsigned long dword; typedef union { - ubyte as_bytes[2]; + unsigned char as_bytes[2]; word as_word; } WORD_UNION; +/* KeyRing management */ +void EmptyKeyRing(void); +int AddKeyToKeyRing(unsigned char key); +unsigned char GetKeyFromKeyRing(void); + + void send_bytes_message(int fd, int len, int msg, char *framebuf); void send_onebyte_message(int fd, int msg, int value); void send_zerobyte_message(int fd, int msg); -void EmptyReceiveBuffer(void); +void EmptyReceiveBuffer(void); int Serial_Init(int port, int baud_rate); void Uninit_Serial(); void SendByte(int fd, unsigned char datum); -void Sync_Read_Buffer(ubyte expected_bytes); +void Sync_Read_Buffer(int fd, unsigned char expected_bytes); int BytesAvail(void); -char GetByte(void); +unsigned char GetByte(void); int PeekBytesAvail(void); void Sync_Peek_Pointer(void); void AcceptPeekedData(void); -ubyte PeekByte(void); -void Clear_Buffer(void); +unsigned char PeekByte(void); +void Clear_Buffer(void); void Buffer_Character(int fd, unsigned char datum); void Buffer_String(int fd, char *input); void Send_Buffer(int fd); +int test_packet(int fd); + #define MAX_DATA_LENGTH 16 #define MAX_COMMAND 21 @@ -72,7 +96,8 @@ typedef struct { int get_crc(char * bufptr, int len, int seed); extern COMMAND_PACKET incoming_command; extern COMMAND_PACKET outgoing_response; -ubyte check_for_packet(ubyte expected_length); +unsigned char check_for_packet(int fd, unsigned char expected_length); +void print_packet(COMMAND_PACKET *packet); void send_packet(int fd); #endif