diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/neo/keyboard.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/apps/neo/keyboard.c b/apps/neo/keyboard.c index 9f02f2a9c8..714295c945 100644 --- a/apps/neo/keyboard.c +++ b/apps/neo/keyboard.c | |||
@@ -28,6 +28,12 @@ | |||
28 | #include "lang.h" | 28 | #include "lang.h" |
29 | #include "debug.h" | 29 | #include "debug.h" |
30 | 30 | ||
31 | /* Two functions that are part of the firmware for the Neo-builds only. | ||
32 | TODO: make them proper "official" firmware functions or replace them | ||
33 | with apps code */ | ||
34 | extern void lcd_cursor(int x, int y); | ||
35 | extern int button_add(unsigned int button); | ||
36 | |||
31 | #define KEYBOARD_MAX_LENGTH 255 | 37 | #define KEYBOARD_MAX_LENGTH 255 |
32 | 38 | ||
33 | static unsigned char* kbd_screens[3] = { | 39 | static unsigned char* kbd_screens[3] = { |
@@ -51,10 +57,15 @@ static void kbd_show_legend( int nb ) | |||
51 | lcd_puts( 0, 3, &kbd_screens[nb][20] ); | 57 | lcd_puts( 0, 3, &kbd_screens[nb][20] ); |
52 | } | 58 | } |
53 | 59 | ||
54 | /* returns text len | 60 | /* |
55 | Max = KEYBOARD_MAX_LENGTH characters | 61 | Returns text len Max = KEYBOARD_MAX_LENGTH characters. |
62 | |||
63 | This function MUST NOT fill in more than 'buflen' bytes into the given | ||
64 | buffer! | ||
56 | */ | 65 | */ |
57 | int kbd_input( char* text, int buflen ) | 66 | static char kbdbuffer[KEYBOARD_MAX_LENGTH+1]; /* no use to alloc this huge one |
67 | on the stack */ | ||
68 | int kbd_input(char* text, int buflen) | ||
58 | { | 69 | { |
59 | char* pstart; | 70 | char* pstart; |
60 | char* pcursor; | 71 | char* pcursor; |
@@ -62,7 +73,6 @@ int kbd_input( char* text, int buflen ) | |||
62 | int bufferlen; | 73 | int bufferlen; |
63 | char cursorpos = 0; | 74 | char cursorpos = 0; |
64 | int ret = 0; | 75 | int ret = 0; |
65 | char buffer[KEYBOARD_MAX_LENGTH+1]; | ||
66 | bool done = false; | 76 | bool done = false; |
67 | int key; | 77 | int key; |
68 | int screen = 0; | 78 | int screen = 0; |
@@ -72,21 +82,21 @@ int kbd_input( char* text, int buflen ) | |||
72 | 82 | ||
73 | bufferlen = strlen(text); | 83 | bufferlen = strlen(text); |
74 | 84 | ||
75 | if( bufferlen > KEYBOARD_MAX_LENGTH ) | 85 | if(bufferlen > KEYBOARD_MAX_LENGTH) |
76 | bufferlen = KEYBOARD_MAX_LENGTH; | 86 | bufferlen = KEYBOARD_MAX_LENGTH; |
77 | 87 | ||
78 | strncpy( buffer, text, bufferlen ); | 88 | strncpy(kbdbuffer, text, bufferlen); |
79 | buffer[bufferlen] = 0; | 89 | kbdbuffer[bufferlen] = 0; |
80 | 90 | ||
81 | lcd_clear_display(); | 91 | lcd_clear_display(); |
82 | 92 | ||
83 | /* Initial setup */ | 93 | /* Initial setup */ |
84 | lcd_puts( 0, 0, buffer ); | 94 | lcd_puts(0, 0, kbdbuffer); |
85 | kbd_show_legend( screen ); | 95 | kbd_show_legend(screen); |
86 | lcd_cursor( cursorpos, 0 ); | 96 | lcd_cursor(cursorpos, 0); |
87 | lcd_write(true,LCD_BLINKCUR); | 97 | lcd_write(true, LCD_BLINKCUR); |
88 | 98 | ||
89 | pstart = pcursor = buffer; | 99 | pstart = pcursor = kbdbuffer; |
90 | 100 | ||
91 | while(!done) { | 101 | while(!done) { |
92 | /* We want all the keys except the releases and the repeats */ | 102 | /* We want all the keys except the releases and the repeats */ |
@@ -119,9 +129,8 @@ int kbd_input( char* text, int buflen ) | |||
119 | 129 | ||
120 | case BUTTON_PLAY: | 130 | case BUTTON_PLAY: |
121 | case BUTTON_IR|NEO_IR_BUTTON_PLAY: | 131 | case BUTTON_IR|NEO_IR_BUTTON_PLAY: |
122 | |||
123 | if( bufferlen ) { | 132 | if( bufferlen ) { |
124 | strncpy(text, buffer, bufferlen); | 133 | strncpy(text, kbdbuffer, bufferlen); |
125 | text[bufferlen] = 0; | 134 | text[bufferlen] = 0; |
126 | ret = bufferlen; | 135 | ret = bufferlen; |
127 | } | 136 | } |
@@ -171,7 +180,7 @@ int kbd_input( char* text, int buflen ) | |||
171 | 180 | ||
172 | /* Insert left */ | 181 | /* Insert left */ |
173 | 182 | ||
174 | if(bufferlen >= KEYBOARD_MAX_LENGTH ) | 183 | if(bufferlen >= buflen) |
175 | break; | 184 | break; |
176 | 185 | ||
177 | pold = pcursor; | 186 | pold = pcursor; |
@@ -197,17 +206,17 @@ int kbd_input( char* text, int buflen ) | |||
197 | 206 | ||
198 | /* Insert Right */ | 207 | /* Insert Right */ |
199 | 208 | ||
200 | if(bufferlen >= KEYBOARD_MAX_LENGTH ) | 209 | if(bufferlen >= buflen) |
201 | break; | 210 | break; |
202 | 211 | ||
203 | pold = pcursor; | 212 | pold = pcursor; |
204 | 213 | ||
205 | /* Goto end */ | 214 | /* Goto end */ |
206 | while( *pcursor ) | 215 | while(*pcursor) |
207 | pcursor++; | 216 | pcursor++; |
208 | 217 | ||
209 | /* Move string content to the right */ | 218 | /* Move string content to the right */ |
210 | while( pcursor > pold ){ | 219 | while(pcursor > pold){ |
211 | *(pcursor+1) = *pcursor; | 220 | *(pcursor+1) = *pcursor; |
212 | pcursor--; | 221 | pcursor--; |
213 | } | 222 | } |
@@ -229,7 +238,7 @@ int kbd_input( char* text, int buflen ) | |||
229 | left */ | 238 | left */ |
230 | 239 | ||
231 | /* Check for start of string */ | 240 | /* Check for start of string */ |
232 | if( pcursor > buffer ) { | 241 | if(pcursor > kbdbuffer) { |
233 | 242 | ||
234 | screenidx = -1; | 243 | screenidx = -1; |
235 | cursorpos--; | 244 | cursorpos--; |