vt100: include pgmspace.h as we use PROGMEM macro
[aversive.git] / modules / ihm / vt100 / vt100.h
1 /*  
2  *  Copyright Droids Corporation (2007)
3  *  Olivier MATZ <zer0@droids-corp.org>
4  * 
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  *  Revision : $Id: vt100.h,v 1.1.2.2 2009-04-07 20:01:16 zer0 Exp $
20  *
21  *
22  */
23
24 #ifndef _VT100_H_
25 #define _VT100_H_
26
27 #include <aversive/pgmspace.h>
28
29 #define vt100_bell         "\007"
30 #define vt100_bs           "\010"
31 #define vt100_bs_clear     "\010 \010"
32 #define vt100_tab          "\011"
33 #define vt100_crnl         "\012\015"
34 #define vt100_clear_right  "\033[0K"
35 #define vt100_clear_left   "\033[1K"
36 #define vt100_clear_down   "\033[0J"
37 #define vt100_clear_up     "\033[1J"
38 #define vt100_clear_line   "\033[2K"
39 #define vt100_clear_screen "\033[2J"
40 #define vt100_up_arr       "\033\133\101"
41 #define vt100_down_arr     "\033\133\102"
42 #define vt100_right_arr    "\033\133\103"
43 #define vt100_left_arr     "\033\133\104"
44 #define vt100_multi_right  "\033\133%uC"
45 #define vt100_multi_left   "\033\133%uD"
46 #define vt100_suppr        "\033\133\063\176"
47 #define vt100_home         "\033M\033E"
48 #define vt100_word_left    "\033\142"
49 #define vt100_word_right   "\033\146"
50
51
52 /* Result of parsing : it must be synchronized with vt100_commands[]
53  * in vt100.c */
54 #define KEY_UP_ARR 0
55 #define KEY_DOWN_ARR 1
56 #define KEY_RIGHT_ARR 2
57 #define KEY_LEFT_ARR 3
58 #define KEY_BKSPACE 4
59 #define KEY_RETURN 5
60 #define KEY_CTRL_A 6
61 #define KEY_CTRL_E 7
62 #define KEY_CTRL_K 8
63 #define KEY_CTRL_Y 9
64 #define KEY_CTRL_C 10
65 #define KEY_CTRL_F 11
66 #define KEY_CTRL_B 12
67 #define KEY_SUPPR 13
68 #define KEY_TAB 14
69 #define KEY_CTRL_D 15
70 #define KEY_CTRL_L 16
71 #define KEY_RETURN2 17
72 #define KEY_META_BKSPACE 18
73 #define KEY_WLEFT 19
74 #define KEY_WRIGHT 20
75 #define KEY_HELP 21
76
77 extern const char * const PROGMEM vt100_commands[];
78
79 enum vt100_parser_state {
80         VT100_INIT,
81         VT100_ESCAPE,
82         VT100_ESCAPE_CSI,
83 };
84
85 #define VT100_BUF_SIZE 8
86 struct vt100 {
87         uint8_t bufpos;
88         char buf[VT100_BUF_SIZE];
89         enum vt100_parser_state state;
90 };
91
92 /**
93  * Init
94  */
95 void vt100_init(struct vt100 *vt);
96
97 /**
98  * Input a new character. 
99  * Return -1 if the character is not part of a control sequence
100  * Return -2 if c is not the last char of a control sequence
101  * Else return the index in vt100_commands[]
102  */
103 int8_t vt100_parser(struct vt100 *vt, char c);
104
105 #endif