source: rtems/c/src/lib/libbsp/arm/nds/touchscreen/reco.c @ 12d853d

4.104.115
Last change on this file since 12d853d was 49a40165, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/08 at 15:47:14

2008-08-19 Joel Sherrill <joel.sherrill@…>

  • dswifi/arm7/makefile, dswifi/include/netinet/in.h, libnds/basicARM7/source/defaultARM7.c, libnds/include/gbfs.h, libnds/include/nds/bios.h, libnds/include/nds/card.h, libnds/include/nds/dma.h, libnds/include/nds/interrupts.h, libnds/include/nds/ipc.h, libnds/include/nds/jtypes.h, libnds/include/nds/registers_alt.h, libnds/include/nds/system.h, libnds/include/nds/timers.h, libnds/include/nds/arm7/audio.h, libnds/include/nds/arm7/clock.h, libnds/include/nds/arm7/serial.h, libnds/include/nds/arm7/touch.h, libnds/include/nds/arm9/boxtest.h, libnds/include/nds/arm9/cache.h, libnds/include/nds/arm9/console.h, libnds/include/nds/arm9/ndsmotion.h, libnds/include/nds/arm9/video.h, libnds/include/nds/arm9/videoGL.h, libnds/source/arm7/audio.c, libnds/source/arm7/clock.c, libnds/source/arm7/microphone.c, libnds/source/arm7/touch.c, libnds/source/arm7/userSettings.c, libnds/source/arm9/boxtest.c, libnds/source/arm9/gurumeditation.c, libnds/source/arm9/ndsmotion.c, libnds/source/arm9/videoGL.c, libnds/source/common/card.c, libnds/source/common/interruptDispatcher.S, touchscreen/reco.c: Fix various warnings by fixing prototypes. Remove unused .bin files. Convert all files to UNIX CF/LF.
  • libnds/source/arm9/COS.bin, libnds/source/arm9/SIN.bin, libnds/source/arm9/TAN.bin, libnds/source/arm9/default_font.bin: Removed.
  • Property mode set to 100644
File size: 5.8 KB
Line 
1
2#include <nds.h>
3#include "reco.h"
4
5PA_StylusPosition PA_StylusPos[20000];
6
7PA_RecoValues PA_Reco;
8
9char PA_RecoShape[16];
10
11u8 PA_UseGraffiti = true;
12
13u8 PA_CustomReco = 0; // number of custom shapes
14PA_FormType PA_CustomShape[200];
15
16PA_RecoInfos PA_RecoInfo;
17
18PA_FormType PA_Graffiti[PA_RECOTESTS] = {
19  {' ', "AAAAAAAAAAAAAAA"},
20  {'a', "FGGGGGFB;:;;;;;"},
21  {'b', "JJJJJIGC>:8=<62"},
22  {'c', "01234689;<>?@BC"},
23  {'d', "=995KJIFB?=;853"},
24  {'e', "1236;>@136;=?@A"},
25  {'f', "121111399998779"},
26  {'g', "235689;=@CFIJEA"},
27  {'h', "8999999;HFEA><:"},
28  {'i', "999999999999999"},
29  {'j', "999999998653100"},
30  {'k', "654320NIDCA?==="},
31  {'l', "999999988<AA@@@"},
32  {'m', "HGGEA<;EFDA=;99"},
33  {'n', "HHHIE<;;;<GIHHH"},
34  {'o', "4689;<?BDFHKMO0"},
35  {'p', "<KJIIIHGEB>;853"},
36  {'q', "4679<?CDFHKMJBA"},
37  {'r', "999IIIIGC?:53<="},
38  {'s', "0235:>?>>;73100"},
39  {'t', "AAAA@@@;8999999"},
40  {'u', "899:;<>ACEGHHIH"},
41  {'v', ";;:::::?FGGHHGF"},
42  {'w', "::;=BA<<@CDEFGH"},
43  {'x', ";;;;;;;;;;;;;;;"},
44  {'y', ">;=AFF899974OIF"},
45  {'z', ">A@@>843348?@AA"},
46  {'0', "35789;=AEGHIJKM"},
47  {'1', "CDEFFE988889999"},
48  {'2', "GDB@>:6546>AAAA"},
49  {'3', "CA>833A@=953210"},
50  {'4', "55558>@A@>97778"},
51  {'5', "00037:@@=;7310O"},
52  {'6', "346779;>@CFKN02"},
53  {'7', "AAAAAA@>9655556"},
54  {'8', "37;=;71MIECCGM1"},
55  {'9', "8<@CGL28<<;6311"},
56  {PA_BACKSPACE, "000000000000000"},
57  {PA_ENTER, "555555555555555"},
58  //    {'?', "FCA@><8655799::"},
59  {'.', "LLLLLLLLLLLLLLL"}
60};
61
62
63
64void PA_AddStylusPos(u8 x, u8 y){
65  if (!((x == PA_StylusPos[PA_Reco.nvalues-1].x) && (y == PA_StylusPos[PA_Reco.nvalues-1].y))){
66    PA_StylusPos[PA_Reco.nvalues].x = x;
67    PA_StylusPos[PA_Reco.nvalues].y = y;
68    PA_Reco.nvalues++;
69  }
70}
71
72
73void PA_StylusLine(u8 x1, u8 y1, u8 x2, u8 y2){
74  int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
75
76  dx=x2-x1;      /* the horizontal distance of the line */
77  dy=y2-y1;      /* the vertical distance of the line */
78  dxabs = dx;
79  sdx = 1;
80  if (dx < 0) {
81    dxabs = -dx;
82    sdx = -1;
83  }
84  dyabs = dy;
85  sdy = 1;
86  if (dy < 0) {
87    dyabs = -dy;
88    sdy = -1;
89  }
90
91  x=dyabs>>1;
92  y=dxabs>>1;
93  px=x1;
94  py=y1;
95
96  PA_AddStylusPos(px, py);
97
98
99  if (dxabs>=dyabs) {
100    for(i=0;i<dxabs;i++)  {
101      y+=dyabs;
102      if (y>=dxabs)  {
103        y-=dxabs;
104        py+=sdy;
105      }
106      px+=sdx;
107      PA_AddStylusPos(px, py);
108    }
109  }
110  else {
111    for(i=0;i<dyabs;i++) {
112      x+=dxabs;
113      if (x>=dyabs)  {
114        x-=dyabs;
115        px+=sdx;
116      }
117      py+=sdy;
118      PA_AddStylusPos(px, py);
119    }
120  }
121}
122
123
124#define PA_ShapeAddPoint(i, value){                                     \
125    points[i] = PA_StylusPos[value];                                    \
126    if (points[i].x < PA_RecoInfo.minX) PA_RecoInfo.minX = points[i].x; \
127    else if (points[i].x > PA_RecoInfo.maxX) PA_RecoInfo.maxX = points[i].x; \
128    if (points[i].y < PA_RecoInfo.minY) PA_RecoInfo.minY = points[i].y; \
129    else if (points[i].y > PA_RecoInfo.maxY) PA_RecoInfo.maxY = points[i].y;    }
130
131
132
133
134char PA_AnalyzeShape(void){
135  s32 i;
136  //  for (i = 0; i < 32; i++) PA_OutputSimpleText(1, 0, i, "             ");
137
138  PA_StylusPosition points[17];
139  for (i = 0; i < 16; i++){
140    PA_ShapeAddPoint(i, (PA_Reco.nvalues*i)>>4)
141      }
142  PA_ShapeAddPoint(16, PA_Reco.nvalues-1)
143    //points[16] = PA_StylusPos[PA_Reco.nvalues-1];
144    PA_RecoInfo.endX = PA_StylusPos[PA_Reco.nvalues-1].x; // last values
145  PA_RecoInfo.endY = PA_StylusPos[PA_Reco.nvalues-1].y; // last values
146  PA_RecoInfo.Length = PA_Reco.nvalues; // Total length
147  PA_RecoInfo.Angle = PA_GetAngle(points[0].x, points[0].y, points[16].x, points[16].y);
148
149  //Better values
150  if (PA_RecoInfo.minX > 1) PA_RecoInfo.minX-=2;
151  if (PA_RecoInfo.maxX <254) PA_RecoInfo.maxX+=2;
152  if (PA_RecoInfo.minY > 1) PA_RecoInfo.minY-=2;
153  if (PA_RecoInfo.maxY <190) PA_RecoInfo.maxY+=2;
154
155  u16 angles[15];
156  for (i = 0; i < 15; i++) angles[i] = PA_GetAngle(points[i+2].x, points[i+2].y, points[i].x, points[i].y);
157
158  for (i = 0; i < 15; i++) PA_RecoShape[i] = '0' + (((angles[i]+16)&511)>>4);
159  PA_RecoShape[15] = 0;
160  //  printk("%s\n", PA_RecoShape);
161
162  u8 letter = 0; // 0 par défaut
163  s32 diff = 65000; // Diff max par défaut
164
165  u8 j;
166
167  if(PA_UseGraffiti){
168    for (j = 0; j < PA_RECOTESTS; j++){
169      s32 tempvalue = 0;
170      s32 tempdiff = 0;
171      for (i = 0; i < 15; i++) {
172        tempvalue = (PA_RecoShape[i]-PA_Graffiti[j].code[i])&31;
173        tempvalue -= (tempvalue >> 4)<<5; // normalise
174        if (tempvalue < 0) tempvalue = -tempvalue;
175        tempdiff += tempvalue; // value
176      }
177
178      if (tempdiff < diff){ // Nouvelle lettre !
179        diff = tempdiff;
180        letter = PA_Graffiti[j].letter;
181      }
182    }
183  }
184  if (PA_CustomReco > 0){
185    for (j = 0; j < PA_CustomReco; j++){
186      s32 tempvalue = 0;
187      s32 tempdiff = 0;
188      for (i = 0; i < 15; i++) {
189        tempvalue = (PA_RecoShape[i]-PA_CustomShape[j].code[i])&31;
190        tempvalue -= (tempvalue >> 4)<<5; // normalise
191        if (tempvalue < 0) tempvalue = -tempvalue;
192        tempdiff += tempvalue; // value
193      }
194
195      if (tempdiff < diff){ // Nouvelle lettre !
196        diff = tempdiff;
197        letter = PA_CustomShape[j].letter;
198      }
199    }
200
201  }
202  PA_RecoInfo.Difference = diff; // Difference to perfect shape
203  PA_RecoInfo.Shape = letter;
204
205  return letter;
206}
207
208int old_down = 0;
209
210char PA_CheckLetter(int down, int x, int y){
211  if(!old_down && down){
212    PA_Reco.nvalues = 0; // Start over again
213    PA_Reco.oldn = 0;
214    PA_Reco.veryold = 0;
215
216    PA_RecoInfo.startX = PA_StylusPos[PA_Reco.nvalues].x = x; // start values
217    PA_RecoInfo.startY = PA_StylusPos[PA_Reco.nvalues].y = y;
218    PA_RecoInfo.minX = PA_RecoInfo.maxX = PA_RecoInfo.startX;
219    PA_RecoInfo.minY = PA_RecoInfo.maxY = PA_RecoInfo.startY;
220    PA_Reco.nvalues++;
221  }
222  else if(old_down && down) {
223    PA_StylusLine(PA_StylusPos[PA_Reco.nvalues-1].x, PA_StylusPos[PA_Reco.nvalues-1].y, x, y);
224
225  }
226
227
228  if(old_down && !down){ // Start analyzing...
229    PA_Reco.nvalues = PA_Reco.veryold;
230    old_down = down;
231    return PA_AnalyzeShape();
232  }
233  PA_Reco.veryold = PA_Reco.oldn;
234  PA_Reco.oldn = PA_Reco.nvalues;
235  old_down = down;
236  return 0;
237}
238
239
Note: See TracBrowser for help on using the repository browser.