summaryrefslogtreecommitdiff
path: root/apps/recorder
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder')
-rw-r--r--apps/recorder/keyboard.c189
1 files changed, 73 insertions, 116 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
index dd91daf2e2..d974752b84 100644
--- a/apps/recorder/keyboard.c
+++ b/apps/recorder/keyboard.c
@@ -19,6 +19,7 @@
19#include "lcd.h" 19#include "lcd.h"
20#include "button.h" 20#include "button.h"
21#include "kernel.h" 21#include "kernel.h"
22#include "system.h"
22#include "version.h" 23#include "version.h"
23#include "debug_menu.h" 24#include "debug_menu.h"
24#include "sprintf.h" 25#include "sprintf.h"
@@ -74,41 +75,40 @@
74 75
75static void kbd_setupkeys(const char* line[KEYBOARD_LINES], int page) 76static void kbd_setupkeys(const char* line[KEYBOARD_LINES], int page)
76{ 77{
77 switch (page) { 78 switch (page)
78 case 0: 79 {
79 line[0] = "ABCDEFG !?\" @#$%+'"; 80 case 0:
80 line[1] = "HIJKLMN 789 &_()-`"; 81 line[0] = "ABCDEFG !?\" @#$%+'";
81 line[2] = "OPQRSTU 456 §|{}/<"; 82 line[1] = "HIJKLMN 789 &_()-`";
82 line[3] = "VWXYZ.,0123 ~=[]*>"; 83 line[2] = "OPQRSTU 456 §|{}/<";
83 break; 84 line[3] = "VWXYZ.,0123 ~=[]*>";
84 85 break;
85 case 1: 86
86 line[0] = "abcdefg ¢£¤¥¦§©®¬"; 87 case 1:
87 line[1] = "hijklmn «»°ºª¹²³¶"; 88 line[0] = "abcdefg ¢£¤¥¦§©®¬";
88 line[2] = "opqrstu ¯±×÷¡¿µ·¨"; 89 line[1] = "hijklmn «»°ºª¹²³¶";
89 line[3] = "vwxyz., ¼½¾ "; 90 line[2] = "opqrstu ¯±×÷¡¿µ·¨";
90 break; 91 line[3] = "vwxyz., ¼½¾ ";
91 92 break;
92 case 2: 93
93 line[0] = "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË"; 94 case 2:
94 line[1] = "àáâãäåæ ìíîï èéêë"; 95 line[0] = "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË";
95 line[2] = "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ"; 96 line[1] = "àáâãäåæ ìíîï èéêë";
96 line[3] = "òóôõöø çðþýÿ ùúûü"; 97 line[2] = "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ";
97 break; 98 line[3] = "òóôõöø çðþýÿ ùúûü";
99 break;
98 } 100 }
99} 101}
100 102
101/* helper function to spell a char if voice UI is enabled */ 103/* helper function to spell a char if voice UI is enabled */
102void kbd_spellchar(char c) 104static void kbd_spellchar(char c)
103{ 105{
104 char spell_char[2]; /* store char to pass to talk_spell */ 106 static char spell_char[2] = "\0\0"; /* store char to pass to talk_spell */
105 107
106 if (global_settings.talk_menu) /* voice UI? */ 108 if (global_settings.talk_menu) /* voice UI? */
107 { 109 {
108 spell_char[0] = c; 110 spell_char[0] = c;
109 spell_char[1] = '\0'; /* mark end of char string */ 111 talk_spell(spell_char, false);
110
111 talk_spell(spell_char, false);
112 } 112 }
113} 113}
114 114
@@ -120,9 +120,9 @@ int kbd_input(char* text, int buflen)
120 int font_w = 0, font_h = 0, i; 120 int font_w = 0, font_h = 0, i;
121 int x = 0, y = 0; 121 int x = 0, y = 0;
122 int main_x, main_y, max_chars, margin; 122 int main_x, main_y, max_chars, margin;
123 int status_y1, status_y2, curpos; 123 int status_y1, status_y2;
124 int len; 124 int len;
125 int editpos; 125 int editpos, curpos, leftpos;
126 bool redraw = true; 126 bool redraw = true;
127 const char* line[KEYBOARD_LINES]; 127 const char* line[KEYBOARD_LINES];
128#ifdef KBD_MODES 128#ifdef KBD_MODES
@@ -146,7 +146,7 @@ int kbd_input(char* text, int buflen)
146 146
147 editpos = strlen(text); 147 editpos = strlen(text);
148 148
149 max_chars = LCD_WIDTH / font_w; 149 max_chars = LCD_WIDTH / font_w - 2; /* leave room for < and > */
150 kbd_setupkeys(line, page); 150 kbd_setupkeys(line, page);
151 151
152 if (global_settings.talk_menu) /* voice UI? */ 152 if (global_settings.talk_menu) /* voice UI? */
@@ -159,75 +159,38 @@ int kbd_input(char* text, int buflen)
159 if(redraw) 159 if(redraw)
160 { 160 {
161 lcd_clear_display(); 161 lcd_clear_display();
162
163 lcd_setfont(FONT_SYSFIXED);
164 162
163 lcd_setfont(FONT_SYSFIXED);
164
165 /* draw page */ 165 /* draw page */
166 for (i=0; i < KEYBOARD_LINES; i++) 166 for (i=0; i < KEYBOARD_LINES; i++)
167 lcd_putsxy(0, 8+i * font_h, line[i]); 167 lcd_putsxy(0, 8+i * font_h, line[i]);
168 168
169 /* separator */ 169 /* separator */
170 lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin); 170 lcd_drawline(0, main_y - margin, LCD_WIDTH - 1, main_y - margin);
171 171
172 /* write out the text */ 172 /* write out the text */
173 if (editpos < max_chars - 3 ) 173 curpos = MIN(editpos, max_chars - MIN(len - editpos, 2));
174 { 174 leftpos = editpos - curpos;
175 strncpy(outline, text, max_chars - 2); 175 strncpy(outline, text + leftpos, max_chars);
176 if (len > max_chars - 2) 176 outline[max_chars] = 0;
177 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
178 curpos = (1 + editpos) * font_w;
179 }
180 else
181 {
182 /* not room for all text, cut left, right or both */
183 if (editpos == len )
184 {
185 if ( max_chars - 3 == len)
186 {
187 strncpy(outline, text, max_chars - 2);
188 curpos = (1 + editpos) * font_w;
189 }
190 else
191 {
192 strncpy(outline, text + editpos - max_chars + 2,
193 max_chars - 2);
194 if (len > max_chars - 2)
195 lcd_putsxy(0, main_y, "<");
196 curpos = ( max_chars - 1) * font_w;
197 }
198 }
199 else
200 {
201 if (len - 1 == editpos)
202 {
203 strncpy(outline, text + editpos - max_chars + 3,
204 max_chars - 2);
205 curpos = ( max_chars - 2) * font_w;
206 }
207 else
208 {
209 strncpy(outline, text + editpos - max_chars + 4,
210 max_chars - 2);
211 curpos = ( max_chars - 3) * font_w;
212 }
213 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
214 lcd_putsxy(0, main_y, "<");
215 }
216 }
217
218 /* Zero terminate the string */
219 outline[max_chars - 2] = '\0';
220 177
221 lcd_putsxy(font_w,main_y,outline); 178 lcd_putsxy(font_w, main_y, outline);
179
180 if (leftpos)
181 lcd_putsxy(0, main_y, "<");
182 if (len - leftpos > max_chars)
183 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
222 184
223 /* cursor */ 185 /* cursor */
224 lcd_drawline(curpos, main_y, curpos, main_y + font_h); 186 i = (curpos + 1) * font_w;
225 187 lcd_drawline(i, main_y, i, main_y + font_h);
188
226#if CONFIG_KEYPAD == RECORDER_PAD 189#if CONFIG_KEYPAD == RECORDER_PAD
227 /* draw the status bar */ 190 /* draw the status bar */
228 buttonbar_set("Shift", "OK", "Del"); 191 buttonbar_set("Shift", "OK", "Del");
229 buttonbar_draw(); 192 buttonbar_draw();
230#endif 193#endif
231 194
232#ifdef KBD_MODES 195#ifdef KBD_MODES
233 if (!line_edit) 196 if (!line_edit)
@@ -265,11 +228,11 @@ int kbd_input(char* text, int buflen)
265#ifdef KBD_MODES 228#ifdef KBD_MODES
266 if (line_edit) /* right doubles as cursor_right in line_edit */ 229 if (line_edit) /* right doubles as cursor_right in line_edit */
267 { 230 {
268 editpos++; 231 if (editpos < len)
269 if (editpos > len) 232 {
270 editpos = len; 233 editpos++;
271 else
272 kbd_spellchar(text[editpos]); 234 kbd_spellchar(text[editpos]);
235 }
273 } 236 }
274 else 237 else
275#endif 238#endif
@@ -294,11 +257,11 @@ int kbd_input(char* text, int buflen)
294#ifdef KBD_MODES 257#ifdef KBD_MODES
295 if (line_edit) /* left doubles as cursor_left in line_edit */ 258 if (line_edit) /* left doubles as cursor_left in line_edit */
296 { 259 {
297 editpos--; 260 if (editpos)
298 if (editpos < 0) 261 {
299 editpos = 0; 262 editpos--;
300 else
301 kbd_spellchar(text[editpos]); 263 kbd_spellchar(text[editpos]);
264 }
302 } 265 }
303 else 266 else
304#endif 267#endif
@@ -382,38 +345,34 @@ int kbd_input(char* text, int buflen)
382 { 345 {
383 if (editpos > 0) 346 if (editpos > 0)
384 { 347 {
385 for (i = editpos; i <= (len - 1);i++) 348 for (i = editpos; i < len; i++)
386 {
387 text[i-1] = text[i]; 349 text[i-1] = text[i];
388 } 350 text[i-1] = '\0';
389 text[i-1]='\0';
390 editpos--; 351 editpos--;
391 if (editpos < 0)
392 editpos=0;
393 } 352 }
394 } 353 }
395 else 354 else
396#endif 355#endif
397 { 356 {
398 if (len<buflen) 357 if (len < buflen)
399 { 358 {
400 c = line[y][x]; 359 c = line[y][x];
401 if ( editpos == len ) 360 if (editpos == len)
402 { 361 {
403 text[len] = c; 362 text[len] = c;
404 text[len+1] = 0; 363 text[len+1] = 0;
405 } 364 }
406 else 365 else
407 { 366 {
408 for (i = len ; i + 1 > editpos; i--) 367 for (i = len ; i >= editpos; i--)
409 text[i+1] = text[i]; 368 text[i+1] = text[i];
410 text[editpos] = c; 369 text[editpos] = c;
411 } 370 }
412 editpos++; 371 editpos++;
413 } 372 }
414 if (global_settings.talk_menu) /* voice UI? */
415 talk_spell(text, false); /* speak revised text */
416 } 373 }
374 if (global_settings.talk_menu) /* voice UI? */
375 talk_spell(text, false); /* speak revised text */
417 break; 376 break;
418 377
419#ifndef KBD_MODES 378#ifndef KBD_MODES
@@ -421,33 +380,31 @@ int kbd_input(char* text, int buflen)
421 case KBD_BACKSPACE | BUTTON_REPEAT: 380 case KBD_BACKSPACE | BUTTON_REPEAT:
422 if (editpos > 0) 381 if (editpos > 0)
423 { 382 {
424 for (i = editpos; i <= (len - 1);i++) 383 for (i = editpos; i < len; i++)
425 {
426 text[i-1] = text[i]; 384 text[i-1] = text[i];
427 } 385 text[i-1] = '\0';
428 text[i-1]='\0';
429 editpos--; 386 editpos--;
430 if (editpos < 0)
431 editpos=0;
432 } 387 }
388 if (global_settings.talk_menu) /* voice UI? */
389 talk_spell(text, false); /* speak revised text */
433 break; 390 break;
434 391
435 case KBD_CURSOR_RIGHT: 392 case KBD_CURSOR_RIGHT:
436 case KBD_CURSOR_RIGHT | BUTTON_REPEAT: 393 case KBD_CURSOR_RIGHT | BUTTON_REPEAT:
437 editpos++; 394 if (editpos < len)
438 if (editpos > len) 395 {
439 editpos = len; 396 editpos++;
440 else
441 kbd_spellchar(text[editpos]); 397 kbd_spellchar(text[editpos]);
398 }
442 break; 399 break;
443 400
444 case KBD_CURSOR_LEFT: 401 case KBD_CURSOR_LEFT:
445 case KBD_CURSOR_LEFT | BUTTON_REPEAT: 402 case KBD_CURSOR_LEFT | BUTTON_REPEAT:
446 editpos--; 403 if (editpos)
447 if (editpos < 0) 404 {
448 editpos = 0; 405 editpos--;
449 else
450 kbd_spellchar(text[editpos]); 406 kbd_spellchar(text[editpos]);
407 }
451 break; 408 break;
452#endif /* !KBD_MODES */ 409#endif /* !KBD_MODES */
453 410