Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 157014 Details for
Bug 243067
Kernel panic using USB serial I/O
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
cfa631.c program which opens/closes USB serial
cfa631.c (text/plain), 46.91 KB, created by
Greg Bailey
on 2007-06-14 15:53:37 UTC
(
hide
)
Description:
cfa631.c program which opens/closes USB serial
Filename:
MIME Type:
Creator:
Greg Bailey
Created:
2007-06-14 15:53:37 UTC
Size:
46.91 KB
patch
obsolete
>/*************************************************************************/ >/** **/ >/** cfa631 - Crystalfontz CFA-631 USB LCD module utility **/ >/** **/ >/** Greg Bailey <gebailey@inter-tel.com> **/ >/** November 13, 2005 **/ >/** **/ >/** cfa631 Copyright (C) 2005 Inter-Tel, Inc. **/ >/** Copyright FontzControl 2005 Keven Tipping **/ >/** Copyright Cfont631Lib 2004 Guillermo Alcaraz **/ >/** **/ >/** cfa631/FontzControl/cfont631lib is free software; you can **/ >/** redistribute it and/or modify it under the terms of the GNU **/ >/** General Public License as published by the Free Software **/ >/** Foundation; either version 2 of the License, or (at your option) **/ >/** any later version. **/ >/** **/ >/** cfa631/FontzControl/cfont631lib is distributed in the hope that **/ >/** it will be useful, but WITHOUT ANY WARRANTY; without even the **/ >/** implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR **/ >/** PURPOSE. See the GNU General Public License for more details. **/ >/** **/ >/** You should have received a copy of the GNU General Public License **/ >/** along with this program; if not, write to the Free Software **/ >/** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA **/ >/** 02111-1307, USA **/ >/** **/ >/** cfa631 is based on "FontzControl", which is used to control a **/ >/** Crystalfontz CFA-631 USB LCD module. "FontzControl" was **/ >/** downloaded from the CrystalFontz forums web site. **/ >/** **/ >/** CONFIGURATION: Please change the location SERIAL_PORT to wherever **/ >/** your display is. (usually ucom0 for FreeBSD, ttyUSB0 for Linux, **/ >/** etc). "Dmesg | Grep fontz" should tell you where the display is **/ >/** hooked into through Dev if you have the FTDI modules installed in **/ >/** your kernel. Note that FreeBSD users will have to put **/ >/** uftdi_load="YES" in their Boot Configuration to load the FTDI **/ >/** driver up before the UGEN driver grabs the display. In Linux, **/ >/** you'll need to "usbserial" and "ftdi_sio" modules loaded. **/ >/** **/ >/*************************************************************************/ > >/*************************************************************************/ >/** INCLUDES **/ >/*************************************************************************/ > >#include <stdlib.h> >#include <stdio.h> >#include <string.h> >#include <pthread.h> >#include <termios.h> >#include <unistd.h> >#include <fcntl.h> >#include <ctype.h> >#include <sys/time.h> >#include <sys/types.h> > >/*************************************************************************/ >/** CONFIGURATION **/ >/*************************************************************************/ > >#define SERIAL_PORT "/dev/ttyUSB0" >#define POLLING_INTERVAL 100000 > >/*************************************************************************/ >/** TYPEDEFS **/ >/*************************************************************************/ > >typedef int int32; >typedef unsigned short int uint16; >typedef unsigned char uchar8; >typedef unsigned char uint8; >typedef unsigned int uint32; > >typedef union { > uint16 word; > uint8 byte[2]; >} WORD; > >typedef struct { > uint8 type; > uint8 length; > uint8 info[24]; >} LCD_PACKET_DATA; > >typedef struct { > int type; /* type of event: 0 keypress, 1 keyrelease */ > int keycode; /* keycode of the key pressed or released */ >} CFONT631_KEY_EVENT; > >typedef union { > int type; /* type of event */ > CFONT631_KEY_EVENT key; /* keyevents */ >} CFONT631_EVENT; > >typedef union { > LCD_PACKET_DATA packet; > uint8 buffer[256]; >} LCD_SEND_DATA; > >typedef union { > LCD_PACKET_DATA packet; > uint8 buffer[256]; >} LCD_RECEIVE_DATA; > >#define BUFFER_MAX_SIZE 256 > >typedef struct { > LCD_SEND_DATA *buffer[BUFFER_MAX_SIZE]; > int len; > int tail; > int head; > void (*event_handler) (CFONT631_EVENT *e, void *info); > void *info; > int reset_after_end; >} LCD_SEND_BUFFER; > >/*************************************************************************/ >/** STATIC DECLARATIONS **/ >/*************************************************************************/ > >static LCD_SEND_BUFFER __lcd_send_buffer; >static pthread_t __lcd_thread; >static pthread_mutex_t __send_buffer_mutex; >static int __thread_loop = 1; >static int __fd = 0; > >static void send_data_with_crc (LCD_SEND_DATA *data); >static uint16 get_crc(uint8 *bufptr, uint16 len, uint16 seed); >static void *lcd_631_thread (void *thread_data); > >static void dispatch_lcd_key_event (CFONT631_KEY_EVENT *key_event); > >/*************************************************************************/ >/** CONSTANTS **/ >/*************************************************************************/ > >/* Event Types */ >#define CFONT631_EVENT_KEYPRESS 0 >#define CFONT631_EVENT_KEYRELEASE 1 > >/* Keycodes */ >#define CFONT631_KEY_UP_LEFT 1 >#define CFONT631_KEY_UP_RIGHT 2 >#define CFONT631_KEY_DOWN_LEFT 3 >#define CFONT631_KEY_DOWN_RIGHT 4 > >/* Cursor Styles */ >#define CFONT631_CURSOR_STYLE_NO_CURSOR 0 >#define CFONT631_CURSOR_STYLE_BLINK 1 >#define CFONT631_CURSOR_STYLE_UNDERSCORE 2 >#define CFONT631_CURSOR_STYLE_BLINK_UNDER 3 >#define CFONT631_CURSOR_STYLE_INVERTING_BLINK 4 > >/* Key Legends */ >#define CFONT631_KEY_LEGEND_BLANK 0 >#define CFONT631_KEY_LEGEND_CANCEL 1 >#define CFONT631_KEY_LEGEND_CHECK 2 >#define CFONT631_KEY_LEGEND_UP 3 >#define CFONT631_KEY_LEGEND_DOWN 4 >#define CFONT631_KEY_LEGEND_RIGHT 5 >#define CFONT631_KEY_LEGEND_LEFT 6 >#define CFONT631_KEY_LEGEND_PLUS 7 >#define CFONT631_KEY_LEGEND_MINUS 8 >#define CFONT631_KEY_LEGEND_NONE 9 > >/*************************************************************************/ >/** FUNCTION PROTOTYPES **/ >/*************************************************************************/ > >int cfont631_open (char *device); >void cfont631_reset (); >void cfont631_close (); >void cfont631_reset_after_end (int on); >void cfont631_reboot (); >void cfont631_clear (); >void cfont631_set_cursor_position (int x, int y); >void cfont631_set_cursor_style (int style); >void cfont631_set_contrast (int level_percent); >void cfont631_set_backlight (int level_percent); >void cfont631_write_xy (int x, int y, char *s); >void cfont631_write_char_xy (int x, int y, uint8 c); >void cfont631_define_char (int index, uint8 matrix[8]); >void cfont631_enable_key_legend (int kul, int kur, int kll, int klr); >void cfont631_disable_key_legend (); >void cfont631_store_boot_state (); >void cfont631_register_event_handler (void (*event_handler) (CFONT631_EVENT *e, void *info), void *info); > >/*************************************************************************/ >/** USAGE **/ >/*************************************************************************/ > >void usage( char *argv[] ) >{ > printf( "\n" ); > printf( "cfa631 - Crystalfontz CFA-631 USB LCD module utility\n" ); > printf( "\n" ); > printf( "Usage: %s COMMAND OPTION1 OPTION2...\n", argv[0] ); > printf( "\n" ); > printf( " cursor OPTION1 : Set the cursor. 0=No Cursor, 1=Blink, 2=Underscore,\n" ); > printf( " 3=Blink Underscore, 4=Inverting Blink\n" ); > printf( " getkey OPTION1 OPTION2 : Retrieves a key event from the CFA-631. When\n" ); > printf( " OPTION1 is 0, the program will wait OPTION2 seconds until exiting. If\n" ); > printf( " no key is pressed, program will print 0. If OPTION1 is 1, the program\n" ); > printf( " will wait indefinitely until a key is pressed, then print the code of\n" ); > printf( " the key. Key Codes are as follows:\n" ); > printf( " 1 = Upper Left PRESS 10 = Upper Left RELEASE\n" ); > printf( " 2 = Upper Right PRESS 20 = Upper Right RELEASE\n" ); > printf( " 3 = Lower Left PRESS 30 = Lower Left RELEASE\n" ); > printf( " 4 = Lower Right PRESS 40 = Lower Right RELEASE\n" ); > printf( " keylegend OPTION1 OPTION2 OPTION3 OPTION4 : Set the desired keylegend for\n" ); > printf( " OPTION1, where the option is 0=Blank, 1=Cancel, 2=Check, 3=Up,\n" ); > printf( " 4=Down, 5=Right, 6=Left, 7=Plus, 8=Minus, 9=Empty, Use in format UL\n" ); > printf( " UR BL BR, so 1 2 3 4 would set UL=Cancel, UR=Check, BL=Up, BR=Down.\n" ); > printf( " keydisable : Disable the keylegend\n" ); > printf( " backlight OPTION1 : Set the backlight to 0-99 for OPTION1.\n" ); > printf( " contrast OPTION1 : Set the contrast to 0-100 for OPTION1.\n" ); > printf( " reset : Reset the 631 Unit.\n" ); > printf( " reboot : Reboot the 631 Unit.\n" ); > printf( " cursorpos OPTION1 OPTION2 : Set the cursor to X (OPTION1), Y(OPTION2)\n" ); > printf( " storeboot : Store the CURRENT display contents to boot ROM.\n" ); > printf( " clear : Clear the contents of the display\n" ); > printf( " writetext OPTION1 OPTION2 'OPTION3' : Write text to X (OPTION1),\n" ); > printf( " Y (OPTION2), and Text to be displayed as 'OPTION3'.\n" ); > printf( " writechar OPTION1 OPTION2 OPTION3 : Write a charactor as X (OPTION1),\n" ); > printf( " Y (OPTION2), and the Charactor number as OPTION3.\n" ); > printf( " menu OPTION1 OPTION2 ... : Write a menu. Returns the index of the\n" ); > printf( " option selected; 'cancel' if user pressed 'cancel'.\n" ); > printf( " ip OPTION1 : Edit an IP address. OPTION1 must be of form\n" ); > printf( " 'DDD.DDD.DDD.DDD'. Returns modified IP address or 'cancel'.\n" ); > printf( "\n" ); >} > >int cfont631_open (char *device) { > struct termios portset; > > __fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY); > > if (__fd == -1) { > fprintf (stderr, "Error opening Crystalfontz 631 usb lcd\n"); > return -1; > } > > tcgetattr (__fd, &portset); > > // configuration > portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP > | INLCR | IGNCR | ICRNL | IXON ); > portset.c_oflag &= ~OPOST; > portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); > portset.c_cflag &= ~( CSIZE | PARENB | CSTOPB | CRTSCTS ); > portset.c_cflag |= CS8 | CREAD | CLOCAL ; > > cfsetospeed (&portset, B115200); > cfsetispeed (&portset, B0); /* same than output speed */ > > if (tcsetattr (__fd, TCSANOW, &portset) == -1) { > perror ("CFONTZ631: "); > } > > /* init the lcd send buffer */ > __lcd_send_buffer.head = __lcd_send_buffer.tail = 0; > __lcd_send_buffer.len = 0; > > __lcd_send_buffer.reset_after_end = 1; > > /* launch the main thread */ > __thread_loop = 1; > > pthread_mutex_init(&__send_buffer_mutex, NULL); > pthread_create(&__lcd_thread, NULL, lcd_631_thread, NULL); > > return __fd; >} > >void cfont631_reset () { > cfont631_set_backlight (100); > cfont631_set_contrast (37); > cfont631_disable_key_legend (); > cfont631_set_cursor_style (CFONT631_CURSOR_STYLE_NO_CURSOR); > cfont631_clear (); >} > >void cfont631_close () { > > if (__fd == 0) { > return; > } > //commented out so the display doesn't reset after closing the program. > //if (__lcd_send_buffer.reset_after_end) { > // cfont631_reset (); > //} > > __thread_loop = 0; > > pthread_join (__lcd_thread, NULL); > > pthread_mutex_destroy (&__send_buffer_mutex); >} > >void cfont631_reset_after_end (int on) { > > __lcd_send_buffer.reset_after_end = on; > >} > >void cfont631_reboot () { > LCD_SEND_DATA data; > > data.packet.type = 5; > data.packet.length = 3; > data.packet.info[0] = 8; > data.packet.info[1] = 18; > data.packet.info[2] = 99; > > send_data_with_crc (&data); >} > >void cfont631_clear () { > LCD_SEND_DATA data; > > data.packet.type = 6; > data.packet.length = 0; > > send_data_with_crc (&data); >} > >void cfont631_set_cursor_position (int x, int y) { > LCD_SEND_DATA data; > > if (x < 1 || x > 20 || y < 1 || y > 2) { > return; > } > > data.packet.type = 11; > data.packet.length = 2; > data.packet.info[0] = (uint8) x - 1; > data.packet.info[1] = (uint8) y - 1; > > send_data_with_crc (&data); >} > >void cfont631_set_cursor_style (int style) { > LCD_SEND_DATA data; > > data.packet.type = 12; > data.packet.length = 1; > data.packet.info[0] = (uint8) style; > > send_data_with_crc (&data); >} > >void cfont631_set_contrast (int level_percent) { > LCD_SEND_DATA data; > int level; > > if (level_percent < 0 || level_percent > 100) { > return; > } > > level = (level_percent * 255) / 100; > > data.packet.type = 13; > data.packet.length = 1; > data.packet.info[0] = (uint8) level; > > send_data_with_crc (&data); >} > >void cfont631_set_backlight (int level_percent) { > LCD_SEND_DATA data; > int level; > > if (level_percent < 0 || level_percent > 100) { > return; > } > > level = level_percent; > > data.packet.type = 14; > data.packet.length = 1; > data.packet.info[0] = (uint8) level; > > send_data_with_crc (&data); >} > >/* >static uint8 cfont631_ascii_translation[256] = { > {36, '$', 162}, > {64, '@', 160}, > {91, '[', 250}, > {92, '\', 251}, > {93, ']', 252}, > {94, '^', 29}, > {95, '_', 196}, > {96, '`', 000}, > {123, '{', 253}, > {124, '|', 254}, > {125, '}', 255}, > {126, '~', 206}, > {183, '·', 221}, > {209, 'Ã', 93}, > {225, 'á', 231}, > {233, 'é', 165}, > {237, 'Ã', 232}, > {243, 'ó', 233}, > {241, 'ñ', 125}, > {250, 'ú', 234}, > > {220, 'Ã', 94}, > {252, 'ü', 126}, > {191, '¿', 96}, > {161, '¡', 64}, > {186, 'º', 128}, > {231, 'ç', 200}, > {199, 'Ã', 169}, >}; >*/ > >static uint8 cfont631_ascii_translation[256] = { > 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, > 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, > 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, > 30, 31, 32, 33, 34, 35, 162, 37, 38, 39, > 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, > 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, > 60, 61, 62, 63, 160, 65, 66, 67, 68, 69, > 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, > 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, > 90, 250, 251, 252, 29, 196, 96, 97, 98, 99, > 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, > 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, > 120, 121, 122, 253, 254, 255, 206, 127, 128, 129, > 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, > 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, > 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, > 160, 64, 162, 163, 164, 165, 166, 167, 168, 169, > 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, > 180, 181, 182, 221, 184, 185, 128, 187, 188, 189, > 190, 96, 192, 193, 194, 195, 196, 197, 198, 169, > 200, 201, 202, 203, 204, 205, 206, 207, 208, 93, > 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, > 94, 221, 222, 223, 224, 231, 226, 227, 228, 229, > 230, 200, 232, 165, 234, 235, 236, 232, 238, 239, > 240, 125, 242, 233, 244, 245, 246, 247, 248, 249, > 234, 251, 126, 253, 254, 255 >}; > >void cfont631_write_xy (int x, int y, char *s) { > LCD_SEND_DATA data; > int len; > int i; > > > if (s == NULL || y > 2 || y < 1 || x > 20 || x < 1) { > return; > } > > len = strlen (s); > > if (x + len - 1 > 20) { > len = 20 - x + 1; > } > > data.packet.type = 31; > data.packet.length = len + 2; > data.packet.info[0] = (uint8) x - 1; > data.packet.info[1] = (uint8) y - 1; > for (i=0; i < len; i++) { > data.packet.info[2+i] = cfont631_ascii_translation[(uint8) s[i]]; > } > > send_data_with_crc (&data); >} > >void cfont631_write_char_xy (int x, int y, uint8 c) { > LCD_SEND_DATA data; > > if (y > 2 || y < 1 || x > 20 || x < 1) { > return; > } > > data.packet.type = 31; > data.packet.length = 3; > data.packet.info[0] = (uint8) x - 1; > data.packet.info[1] = (uint8) y - 1; > data.packet.info[2] = cfont631_ascii_translation[c]; > > send_data_with_crc (&data); >} > > >void cfont631_define_char (int index, uint8 matrix[8]) { > LCD_SEND_DATA data; > int i; > > if (index < 0 || index > 7) { > return; > } > > data.packet.type = 9; > data.packet.length = 9; > data.packet.info[0] = (uint8) index; > for (i=0; i < 8; i++) { > data.packet.info[i+1] = matrix[i]; > } > > send_data_with_crc (&data); >} > >void cfont631_enable_key_legend (int kul, int kur, int kll, int klr) { > LCD_SEND_DATA data; > > data.packet.type = 32; > data.packet.length = 5; > data.packet.info[0] = 1; > data.packet.info[1] = (uint8) kul; > data.packet.info[2] = (uint8) kur; > data.packet.info[3] = (uint8) kll; > data.packet.info[4] = (uint8) klr; > > send_data_with_crc (&data); >} > >void cfont631_disable_key_legend () { > LCD_SEND_DATA data; > > data.packet.type = 32; > data.packet.length = 1; > data.packet.info[0] = 0; > > send_data_with_crc (&data); >} > >void cfont631_store_boot_state () { > LCD_SEND_DATA data; > > data.packet.type = 4; > data.packet.length = 0; > > send_data_with_crc (&data); >} > >static void send_data_with_crc (LCD_SEND_DATA *data) { > WORD crc; > LCD_SEND_DATA *packet; > > if (__fd == 0) { > // avoid packaging manager without serial connection > return; > } > > crc.word = get_crc (data->buffer, data->packet.length + 2, 0xffff); > data->packet.info[data->packet.length] = crc.byte[0]; > data->packet.info[data->packet.length+1] = crc.byte[1]; > > packet = (LCD_SEND_DATA *) malloc (sizeof(LCD_SEND_DATA)); > > memcpy (packet, data, data->packet.length + 4); > > /* tail */ > /* mutex exclusion */ > pthread_mutex_lock (&__send_buffer_mutex); > > __lcd_send_buffer.buffer[__lcd_send_buffer.tail] = packet; > __lcd_send_buffer.tail ++; > if (__lcd_send_buffer.tail == BUFFER_MAX_SIZE) { > __lcd_send_buffer.tail = 0; > } > __lcd_send_buffer.len ++; > > pthread_mutex_unlock (&__send_buffer_mutex); >} > > >/* key event dispatcher */ >static void dispatch_lcd_key_event (CFONT631_KEY_EVENT *key_event) { > CFONT631_EVENT e; > > if (key_event==NULL) { > return; > } > > e.key.type = key_event->type; > e.key.keycode = key_event->keycode; > > if (__lcd_send_buffer.event_handler) { > __lcd_send_buffer.event_handler (&e, __lcd_send_buffer.info); > } > >} > >void cfont631_register_event_handler (void (*event_handler) (CFONT631_EVENT *e, void *info), void *info) { > __lcd_send_buffer.event_handler = event_handler; > __lcd_send_buffer.info = info; >} > > >/* key */ >static CFONT631_KEY_EVENT *lcd_key_event_new (uint8 keydata) { > > CFONT631_KEY_EVENT *lcd_key = NULL; > > lcd_key = (CFONT631_KEY_EVENT *) malloc (sizeof(CFONT631_KEY_EVENT)); > > switch (keydata) { > case 13: > lcd_key->type = CFONT631_EVENT_KEYPRESS; > lcd_key->keycode = CFONT631_KEY_UP_LEFT; > break; > case 14: > lcd_key->type = CFONT631_EVENT_KEYPRESS; > lcd_key->keycode = CFONT631_KEY_UP_RIGHT; > break; > case 15: > lcd_key->type = CFONT631_EVENT_KEYPRESS; > lcd_key->keycode = CFONT631_KEY_DOWN_LEFT; > break; > case 16: > lcd_key->type = CFONT631_EVENT_KEYPRESS; > lcd_key->keycode = CFONT631_KEY_DOWN_RIGHT; > break; > case 17: > lcd_key->type = CFONT631_EVENT_KEYRELEASE; > lcd_key->keycode = CFONT631_KEY_UP_LEFT; > break; > case 18: > lcd_key->type = CFONT631_EVENT_KEYRELEASE; > lcd_key->keycode = CFONT631_KEY_UP_RIGHT; > break; > case 19: > lcd_key->type = CFONT631_EVENT_KEYRELEASE; > lcd_key->keycode = CFONT631_KEY_DOWN_LEFT; > break; > case 20: > lcd_key->type = CFONT631_EVENT_KEYRELEASE; > lcd_key->keycode = CFONT631_KEY_DOWN_RIGHT; > break; > default: > free (lcd_key); > lcd_key = NULL; > } > > return lcd_key; > >} > >static void lcd_key_event_free (CFONT631_KEY_EVENT *lcd_key) { > free (lcd_key); >} > >//CRC table >static uint16 cfont631_crc_table[256] = > {0x00000,0x01189,0x02312,0x0329B,0x04624,0x057AD,0x06536,0x074BF, > 0x08C48,0x09DC1,0x0AF5A,0x0BED3,0x0CA6C,0x0DBE5,0x0E97E,0x0F8F7, > 0x01081,0x00108,0x03393,0x0221A,0x056A5,0x0472C,0x075B7,0x0643E, > 0x09CC9,0x08D40,0x0BFDB,0x0AE52,0x0DAED,0x0CB64,0x0F9FF,0x0E876, > 0x02102,0x0308B,0x00210,0x01399,0x06726,0x076AF,0x04434,0x055BD, > 0x0AD4A,0x0BCC3,0x08E58,0x09FD1,0x0EB6E,0x0FAE7,0x0C87C,0x0D9F5, > 0x03183,0x0200A,0x01291,0x00318,0x077A7,0x0662E,0x054B5,0x0453C, > 0x0BDCB,0x0AC42,0x09ED9,0x08F50,0x0FBEF,0x0EA66,0x0D8FD,0x0C974, > 0x04204,0x0538D,0x06116,0x0709F,0x00420,0x015A9,0x02732,0x036BB, > 0x0CE4C,0x0DFC5,0x0ED5E,0x0FCD7,0x08868,0x099E1,0x0AB7A,0x0BAF3, > 0x05285,0x0430C,0x07197,0x0601E,0x014A1,0x00528,0x037B3,0x0263A, > 0x0DECD,0x0CF44,0x0FDDF,0x0EC56,0x098E9,0x08960,0x0BBFB,0x0AA72, > 0x06306,0x0728F,0x04014,0x0519D,0x02522,0x034AB,0x00630,0x017B9, > 0x0EF4E,0x0FEC7,0x0CC5C,0x0DDD5,0x0A96A,0x0B8E3,0x08A78,0x09BF1, > 0x07387,0x0620E,0x05095,0x0411C,0x035A3,0x0242A,0x016B1,0x00738, > 0x0FFCF,0x0EE46,0x0DCDD,0x0CD54,0x0B9EB,0x0A862,0x09AF9,0x08B70, > 0x08408,0x09581,0x0A71A,0x0B693,0x0C22C,0x0D3A5,0x0E13E,0x0F0B7, > 0x00840,0x019C9,0x02B52,0x03ADB,0x04E64,0x05FED,0x06D76,0x07CFF, > 0x09489,0x08500,0x0B79B,0x0A612,0x0D2AD,0x0C324,0x0F1BF,0x0E036, > 0x018C1,0x00948,0x03BD3,0x02A5A,0x05EE5,0x04F6C,0x07DF7,0x06C7E, > 0x0A50A,0x0B483,0x08618,0x09791,0x0E32E,0x0F2A7,0x0C03C,0x0D1B5, > 0x02942,0x038CB,0x00A50,0x01BD9,0x06F66,0x07EEF,0x04C74,0x05DFD, > 0x0B58B,0x0A402,0x09699,0x08710,0x0F3AF,0x0E226,0x0D0BD,0x0C134, > 0x039C3,0x0284A,0x01AD1,0x00B58,0x07FE7,0x06E6E,0x05CF5,0x04D7C, > 0x0C60C,0x0D785,0x0E51E,0x0F497,0x08028,0x091A1,0x0A33A,0x0B2B3, > 0x04A44,0x05BCD,0x06956,0x078DF,0x00C60,0x01DE9,0x02F72,0x03EFB, > 0x0D68D,0x0C704,0x0F59F,0x0E416,0x090A9,0x08120,0x0B3BB,0x0A232, > 0x05AC5,0x04B4C,0x079D7,0x0685E,0x01CE1,0x00D68,0x03FF3,0x02E7A, > 0x0E70E,0x0F687,0x0C41C,0x0D595,0x0A12A,0x0B0A3,0x08238,0x093B1, > 0x06B46,0x07ACF,0x04854,0x059DD,0x02D62,0x03CEB,0x00E70,0x01FF9, > 0x0F78F,0x0E606,0x0D49D,0x0C514,0x0B1AB,0x0A022,0x092B9,0x08330, > 0x07BC7,0x06A4E,0x058D5,0x0495C,0x03DE3,0x02C6A,0x01EF1,0x00F78}; > >static uint16 get_crc(uint8 *buffer, uint16 len, uint16 s) { > uint16 crc = 0x0ffff; > crc=s; > > //Algorithim based on the IrDA LAP example. > while(len--) { > crc = (crc >> 8) ^ cfont631_crc_table[(crc ^ *buffer++) & 0xff]; > } > > return(~crc); >} > >static void* lcd_631_thread (void *thread_data) { > LCD_SEND_DATA *data; > int waiting_for_ack = 0; > LCD_RECEIVE_DATA receive; > fd_set readfs; > int res; > struct timeval timeout; > int num_send = 0; > > int leidos; > int state=1, sig_state = 0; > int k = 0, crc_i = 0; > uint8 buf[256]; > int i; > > timeout.tv_sec = 0; > > FD_ZERO (&readfs); > data = NULL; > > while (__thread_loop || (__lcd_send_buffer.len > 0 || data != NULL)) { > if (!waiting_for_ack && __lcd_send_buffer.len > 0) { > pthread_mutex_lock (&__send_buffer_mutex); > data = __lcd_send_buffer.buffer[__lcd_send_buffer.head++]; > __lcd_send_buffer.len --; > if (__lcd_send_buffer.head == BUFFER_MAX_SIZE) { > __lcd_send_buffer.head = 0; > } > pthread_mutex_unlock (&__send_buffer_mutex); > > write (__fd, data->buffer, data->packet.length+4); > num_send = 1; > waiting_for_ack = 1; > } > > FD_SET (__fd, &readfs); > timeout.tv_usec = 250000; > res = select(FD_SETSIZE, &readfs, NULL, NULL, &timeout); > if (res == 0) { // timeout > // repeat last send if any > if (data) { > if (num_send >= 3) { > fprintf (stderr, "CFONTZ631: Packet lost %d\n", data->packet.type); > free (data); > data = NULL; > waiting_for_ack = 0; > } else { > write (__fd, data->buffer, data->packet.length+4); > num_send ++; > waiting_for_ack = 1; > } > } > } else { // data available, maybe ack or asynchronous message > > leidos = read (__fd, buf, 256); > > for (i=0; i < leidos; i++) { > /* a simple state machine read data from buffer */ > switch (state) { > case 1: > receive.packet.type = buf[i]; > sig_state = 2; > break; > case 2: > receive.packet.length = buf[i]; > k = 0; > if (receive.packet.length==0) { > crc_i = 0; > sig_state = 4; > } else { > sig_state = 3; > } > break; > case 3: > receive.packet.info[k] = buf[i]; > k++; > if (k == receive.packet.length) { > crc_i = 0; > sig_state = 4; > } else { > sig_state = 3; > } > break; > case 4: > receive.packet.info[k + crc_i] = buf [i]; > crc_i ++; > if (crc_i == 2) { > sig_state = 1; > switch (receive.packet.type & 0xc0) { > case 0x40: // normal response > if (waiting_for_ack && > (0x40 | data->packet.type)==receive.packet.type) { > free (data); > data = NULL; > waiting_for_ack = 0; > } > break; > case 0x80: // report > switch (receive.packet.type) { > case 0x80: // key event > { > CFONT631_KEY_EVENT *keyevent; > keyevent = lcd_key_event_new ( > receive.packet.info[0]); > dispatch_lcd_key_event (keyevent); > lcd_key_event_free (keyevent); > } > break; > } > break; > case 0xc0: > break; > } > } else { > sig_state = 4; > } > break; > } > state = sig_state; > } > } > } > > close (__fd); > __fd = 0; > > pthread_exit(NULL); > return NULL; >} > >static int fin; > >void handler (CFONT631_EVENT *e, void *info) { > if (e->type == CFONT631_EVENT_KEYPRESS) { > if (e->key.keycode == CFONT631_KEY_UP_LEFT) { > fin = 1; > } else if(e->key.keycode == CFONT631_KEY_UP_RIGHT) { > fin = 2; > } else if(e->key.keycode == CFONT631_KEY_DOWN_LEFT) { > fin = 3; > } else if(e->key.keycode == CFONT631_KEY_DOWN_RIGHT) { > fin = 4; > } > } > if (e->type == CFONT631_EVENT_KEYRELEASE) { > if (e->key.keycode == CFONT631_KEY_UP_LEFT) { > fin = 10; > } else if(e->key.keycode == CFONT631_KEY_UP_RIGHT) { > fin = 20; > } else if(e->key.keycode == CFONT631_KEY_DOWN_LEFT) { > fin = 30; > } else if(e->key.keycode == CFONT631_KEY_DOWN_RIGHT) { > fin = 40; > } > } >} > >int comparestr(char string1[255], char string2[255]) >{ > int found=0,counter=0; > while(counter<strlen(string1) && found < strlen(string1)) > { > if(string1[found]==string2[counter]) > { > found++; > } else > { > found=0; > } > counter++; > } > if(found==strlen(string1)) > { > return 1; > } else > { > return -1; > } >} > >/*************************************************************************/ >/** runcommands() **/ >/*************************************************************************/ > >void runcommands( int argc, char *args[] ) >{ > int opt1 = 0, opt2 = 0, opt3 = 0, opt4 = 0; > > if ( comparestr( args[1], "cursor" ) > 0 ) > { > if ( argc == 2 || atoi( args[2] ) < 0 || atoi( args[2] ) > 4 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > cfont631_set_cursor_style( opt1 ); > return; > } > else if ( comparestr( args[1], "getkey" ) > 0 ) > { > if ( argc != 4 || atoi( args[2] ) < 0 || atoi( args[2] ) > 1 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > fin = 0; > cfont631_register_event_handler( handler, NULL ); > opt1 = atoi( args[2] ); > opt2 = atoi( args[3] ); > if ( opt1 == 1 ) > { > while ( fin == 0 ) > { > usleep( POLLING_INTERVAL ); > } > printf( "%d", fin ); > return; > } > else > { > clock_t endwait; > endwait = time( (time_t *)0 ) + opt2; > while ( time( (time_t *)0 ) < endwait && fin == 0 ) > { > usleep( POLLING_INTERVAL ); > } > printf( "%d", fin ); > return; > } > return; > } > else if ( comparestr( args[1], "keylegend" ) > 0 ) > { > if ( argc != 6 || atoi( args[2] ) < 0 || atoi( args[2] ) > 9 > || atoi( args[3] ) < 0 || atoi( args[3] ) > 9 > || atoi( args[4] ) < 0 || atoi( args[4] ) > 9 > || atoi( args[5] ) < 0 || atoi( args[5] ) > 9 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > opt2 = atoi( args[3] ); > opt3 = atoi( args[4] ); > opt4 = atoi( args[5] ); > cfont631_enable_key_legend( opt1, opt2, opt3, opt4 ); > return; > } > else if ( comparestr( args[1], "keydisable" ) > 0 ) > { > cfont631_disable_key_legend(); > return; > } > else if ( comparestr( args[1], "backlight" ) > 0 ) > { > if ( argc == 2 || atoi( args[2] ) < 0 || atoi( args[2] ) > 99 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > cfont631_set_backlight( opt1 ); > return; > } > else if ( comparestr( args[1], "contrast" ) > 0 ) > { > if ( argc == 2 || atoi( args[2] ) < 0 || atoi( args[2] ) > 99 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > cfont631_set_contrast( opt1 ); > return; > } > else if ( comparestr( args[1], "reset" ) > 0 ) > { > cfont631_reset(); > return; > } > else if ( comparestr( args[1], "reboot" ) > 0 ) > { > cfont631_reboot(); > return; > } > else if ( comparestr( args[1], "cursorpos" ) > 0 ) > { > if ( argc != 4 || atoi( args[2] ) < 1 || atoi( args[2] ) > 20 > || atoi( args[3] ) < 1 || atoi( args[3] ) > 2 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > opt2 = atoi( args[3] ); > cfont631_set_cursor_position( opt1, opt2 ); > return; > } > else if ( comparestr( args[1], "storeboot" ) > 0 ) > { > cfont631_store_boot_state(); > return; > } > else if ( comparestr( args[1], "clear" ) > 0 ) > { > cfont631_clear(); > return; > } > else if ( comparestr( args[1], "writetext" ) > 0 ) > { > if ( argc != 5 || atoi( args[2] ) < 1 || atoi( args[2] ) > 20 > || atoi( args[3] ) < 1 || atoi( args[3] ) > 2 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > opt2 = atoi( args[3] ); > cfont631_write_xy( opt1, opt2, args[4] ); > return; > } > else if ( comparestr( args[1], "writechar" ) > 0 ) > { > if ( argc != 5 || atoi( args[2] ) < 1 || atoi( args[2] ) > 20 > || atoi( args[3] ) < 1 || atoi( args[3] ) > 2 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > opt1 = atoi( args[2] ); > opt2 = atoi( args[3] ); > opt3 = atoi( args[4] ); > cfont631_write_char_xy( opt1, opt2, opt3 ); > return; > } > else if ( comparestr( args[1], "menu" ) > 0 ) > { > int current_index = 1; > int current_line = 1; > if ( argc < 3 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > cfont631_enable_key_legend ( CFONT631_KEY_LEGEND_UP, CFONT631_KEY_LEGEND_CHECK, > CFONT631_KEY_LEGEND_DOWN, CFONT631_KEY_LEGEND_CANCEL ); > cfont631_clear(); > cfont631_write_char_xy( 1, current_line, 16 ); > cfont631_write_xy( 2, current_line, args[current_index+1] ); > if ( ( current_index + 2 ) < argc ) > { > cfont631_write_xy( 2, 2, args[current_index+2] ); > } > cfont631_register_event_handler( handler, NULL ); > while ( 1 ) > { > fin = 0; > while ( fin == 0 ) > { > usleep( POLLING_INTERVAL ); > } > if ( fin == CFONT631_KEY_UP_LEFT ) > { > current_index--; > if ( current_index < 1 ) current_index = 1; > current_line--; > if ( current_line < 1 ) current_line = 1; > } > else if ( fin == CFONT631_KEY_UP_RIGHT ) > { > printf( "%d\n", current_index ); > break; > } > else if ( fin == CFONT631_KEY_DOWN_LEFT ) > { > current_index++; > if ( current_index > ( argc - 2 ) ) current_index = ( argc - 2 ); > current_line++; > if ( current_line > 2 ) current_line = 2; > } > else if ( fin == CFONT631_KEY_DOWN_RIGHT ) > { > printf( "cancel\n" ); > break; > } > cfont631_clear(); > cfont631_write_char_xy( 1, current_line, 16 ); > cfont631_write_xy( 2, current_line, args[current_index+1] ); > if ( ( current_line == 1 ) && ( ( current_index + 2 ) < argc ) ) > { > cfont631_write_xy( 2, 2, args[current_index+2] ); > } > else if ( ( current_line == 2 ) && ( current_index > 1 ) ) > { > cfont631_write_xy( 2, 1, args[current_index] ); > } > } > cfont631_disable_key_legend(); > return; > } > else if ( comparestr( args[1], "ip" ) > 0 ) > { > char ip_addr[16]; > int current_digit = 1; > int current_octet; > char ascii_octet[4]; > if ( argc != 3 ) > { > printf( "Error, invalid or no option!\n" ); > return; > } > strncpy( ip_addr, args[2], 15 ); > ip_addr[15] = '\0'; > if ( ! ( ( isdigit( ip_addr[0] ) ) && ( isdigit( ip_addr[1] ) ) && ( isdigit( ip_addr[2] ) ) && ( ip_addr[3] == '.' ) > && ( isdigit( ip_addr[4] ) ) && ( isdigit( ip_addr[5] ) ) && ( isdigit( ip_addr[6] ) ) && ( ip_addr[7] == '.' ) > && ( isdigit( ip_addr[8] ) ) && ( isdigit( ip_addr[9] ) ) && ( isdigit( ip_addr[10] ) ) && ( ip_addr[11] == '.' ) > && ( isdigit( ip_addr[12] ) ) && ( isdigit( ip_addr[13] ) ) && ( isdigit( ip_addr[14] ) ) ) ) > { > printf( "Error, invalid IP address!\n" ); > return; > } > cfont631_enable_key_legend ( CFONT631_KEY_LEGEND_MINUS, CFONT631_KEY_LEGEND_PLUS, > CFONT631_KEY_LEGEND_LEFT, CFONT631_KEY_LEGEND_RIGHT ); > cfont631_set_cursor_style( CFONT631_CURSOR_STYLE_BLINK_UNDER ); > cfont631_set_cursor_position( 1, 2 ); > cfont631_register_event_handler( handler, NULL ); > while ( 1 ) > { > cfont631_write_xy( 1, 2, ip_addr ); > fin = 0; > while ( fin == 0 ) > { > usleep( POLLING_INTERVAL ); > } > if ( fin == CFONT631_KEY_UP_LEFT ) > { > if ( current_digit == 0 ) > { > printf( "cancel\n" ); > break; > } > else > { > // Subtract from current digit > current_octet = atoi( (char *)&ip_addr[current_digit - ( current_digit % 4 )] ); > if ( ( current_digit % 4 ) == 1 ) current_octet -= 100; > else if ( ( current_digit % 4 ) == 2 ) current_octet -= 10; > else current_octet--; > if ( current_octet < 0 ) current_octet = 0; > sprintf( ascii_octet, "%03d", current_octet ); > strncpy( (char *)&ip_addr[current_digit - ( current_digit % 4 )], ascii_octet, 3 ); > } > } > else if ( fin == CFONT631_KEY_UP_RIGHT ) > { > if ( current_digit == 0 ) > { > printf( "%s\n", ip_addr ); > break; > } > else > { > // Add to current digit > current_octet = atoi( (char *)&ip_addr[current_digit - ( current_digit % 4 )] ); > if ( ( current_digit % 4 ) == 1 ) current_octet += 100; > else if ( ( current_digit % 4 ) == 2 ) current_octet += 10; > else current_octet++; > if ( current_octet > 255 ) current_octet = 255; > sprintf( ascii_octet, "%03d", current_octet ); > strncpy( (char *)&ip_addr[current_digit - ( current_digit % 4 )], ascii_octet, 3 ); > } > } > else if ( fin == CFONT631_KEY_DOWN_LEFT ) > { > if ( current_digit == 0 ) current_digit = 16; > current_digit--; > if ( current_digit == 4 || current_digit == 8 || current_digit == 12 ) current_digit--; > if ( current_digit == 0 ) > { > // Cursor is off of the IP; allow control functions > cfont631_enable_key_legend( CFONT631_KEY_LEGEND_CANCEL, CFONT631_KEY_LEGEND_CHECK, > CFONT631_KEY_LEGEND_LEFT, CFONT631_KEY_LEGEND_RIGHT ); > cfont631_set_cursor_style( CFONT631_CURSOR_STYLE_NO_CURSOR ); > } > else > { > // Cursor is on of the IP; allow decrement/increment functions > cfont631_enable_key_legend( CFONT631_KEY_LEGEND_MINUS, CFONT631_KEY_LEGEND_PLUS, > CFONT631_KEY_LEGEND_LEFT, CFONT631_KEY_LEGEND_RIGHT ); > cfont631_set_cursor_style( CFONT631_CURSOR_STYLE_BLINK_UNDER ); > cfont631_set_cursor_position( current_digit, 2 ); > } > } > else if ( fin == CFONT631_KEY_DOWN_RIGHT ) > { > current_digit++; > if ( current_digit == 16 ) current_digit = 0; > if ( current_digit == 4 || current_digit == 8 || current_digit == 12 ) current_digit++; > if ( current_digit == 0 ) > { > // Cursor is off of the IP; allow control functions > cfont631_enable_key_legend( CFONT631_KEY_LEGEND_CANCEL, CFONT631_KEY_LEGEND_CHECK, > CFONT631_KEY_LEGEND_LEFT, CFONT631_KEY_LEGEND_RIGHT ); > cfont631_set_cursor_style( CFONT631_CURSOR_STYLE_NO_CURSOR ); > } > else > { > // Cursor is on of the IP; allow decrement/increment functions > cfont631_enable_key_legend( CFONT631_KEY_LEGEND_MINUS, CFONT631_KEY_LEGEND_PLUS, > CFONT631_KEY_LEGEND_LEFT, CFONT631_KEY_LEGEND_RIGHT ); > cfont631_set_cursor_style( CFONT631_CURSOR_STYLE_BLINK_UNDER ); > cfont631_set_cursor_position( current_digit, 2 ); > } > } > } > cfont631_disable_key_legend(); > cfont631_set_cursor_style( CFONT631_CURSOR_STYLE_NO_CURSOR ); > return; > } > > printf( "\n" ); > printf( "cfa631 Error: Unknown command entered!\n\n" ); > > return; >} > >/*************************************************************************/ >/** MAIN **/ >/*************************************************************************/ > >int main( int argc, char *argv[] ) >{ > if ( argc <= 1 ) > { > usage( argv ); > exit( 1 ); > } > else > { > int fd; > > // . . . . . . 000 . . . . . . 000 > // . * * * * * 037 * * * * . . 074 > // * * * . . . 070 * * * * * . 076 > // . . . . . . 000 . . . . . . 000 > // . . . * * * 007 . . . . . . 000 > // * * * * * * 077 * * * * * . 076 > // . * * * * * 037 * * * * . . 074 > // . . . . . . 000 . . . . . . 000 > > uint8 logo0[8] = { 000, 037, 070, 000, 007, 077, 037, 000 }; > uint8 logo1[8] = { 000, 074, 076, 000, 000, 076, 074, 000 }; > > fd = cfont631_open( SERIAL_PORT ); > if ( fd == -1 ) > { > return( -1 ); > } > > cfont631_define_char( 0, logo0 ); > cfont631_define_char( 1, logo1 ); > > runcommands( argc, argv ); > > cfont631_close(); > > return( 0 ); > } >} > >/*************************************************************************/ >/** END **/ >/*************************************************************************/
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 243067
:
156429
|
156430
|
156952
| 157014 |
319713