nabaztag_hack_kit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +4 -0
  5. data/README.md +119 -0
  6. data/Rakefile +21 -0
  7. data/bin/mtl_comp +41 -0
  8. data/bin/mtl_merge +22 -0
  9. data/bin/mtl_simu +40 -0
  10. data/bytecode/lib/buffer.mtl +109 -0
  11. data/bytecode/lib/button.mtl +27 -0
  12. data/bytecode/lib/data_helper.mtl +88 -0
  13. data/bytecode/lib/ear.mtl +90 -0
  14. data/bytecode/lib/led.mtl +33 -0
  15. data/bytecode/lib/rfid.mtl +50 -0
  16. data/bytecode/main.mtl +129 -0
  17. data/config.ru +6 -0
  18. data/ext/bytecode/Commands.md +172 -0
  19. data/ext/bytecode/Docs.md +488 -0
  20. data/ext/bytecode/README.md +5 -0
  21. data/ext/bytecode/lib/arp.mtl +159 -0
  22. data/ext/bytecode/lib/cfg.mtl +74 -0
  23. data/ext/bytecode/lib/choreos.mtl +1487 -0
  24. data/ext/bytecode/lib/dhcp.mtl +152 -0
  25. data/ext/bytecode/lib/dns.mtl +89 -0
  26. data/ext/bytecode/lib/http.mtl +84 -0
  27. data/ext/bytecode/lib/tcp.mtl +340 -0
  28. data/ext/bytecode/lib/udp.mtl +49 -0
  29. data/ext/bytecode/lib/util.mtl +74 -0
  30. data/ext/bytecode/lib/var.mtl +15 -0
  31. data/ext/bytecode/lib/wifi.mtl +243 -0
  32. data/ext/bytecode/nominal-ping.mtl +5828 -0
  33. data/ext/mtl/Makefile +42 -0
  34. data/ext/mtl/README.md +13 -0
  35. data/ext/mtl/bc.cpp +1891 -0
  36. data/ext/mtl/conf.bin.sans_password +0 -0
  37. data/ext/mtl/config.txt +5 -0
  38. data/ext/mtl/dumpbc.c +2566 -0
  39. data/ext/mtl/extconf.rb +1 -0
  40. data/ext/mtl/linux_simu.c +271 -0
  41. data/ext/mtl/linux_simuaudio.c +16 -0
  42. data/ext/mtl/linux_simuaudio.h +18 -0
  43. data/ext/mtl/linux_simunet.c +620 -0
  44. data/ext/mtl/linux_simunet.h +7 -0
  45. data/ext/mtl/log.c +297 -0
  46. data/ext/mtl/log.h +20 -0
  47. data/ext/mtl/main_compiler.cpp +104 -0
  48. data/ext/mtl/main_simu.cpp +221 -0
  49. data/ext/mtl/mp3/GTKANAL.H +97 -0
  50. data/ext/mtl/mp3/LAYER3.C +2090 -0
  51. data/ext/mtl/mp3/TABINIT.C +82 -0
  52. data/ext/mtl/mp3/common.c +265 -0
  53. data/ext/mtl/mp3/dct64_i386.c +316 -0
  54. data/ext/mtl/mp3/decode_i386.c +155 -0
  55. data/ext/mtl/mp3/huffman.h +332 -0
  56. data/ext/mtl/mp3/interface.c +258 -0
  57. data/ext/mtl/mp3/mpg123.h +182 -0
  58. data/ext/mtl/mp3/mpglib.h +44 -0
  59. data/ext/mtl/properties.c +293 -0
  60. data/ext/mtl/properties.h +10 -0
  61. data/ext/mtl/simu.c +750 -0
  62. data/ext/mtl/simuaudio.c +662 -0
  63. data/ext/mtl/simuaudio.h +74 -0
  64. data/ext/mtl/simunet.c +400 -0
  65. data/ext/mtl/simunet.h +30 -0
  66. data/ext/mtl/utils/correct_const.sh +34 -0
  67. data/ext/mtl/vaudio.c +677 -0
  68. data/ext/mtl/vaudio.h +46 -0
  69. data/ext/mtl/vbc.h +160 -0
  70. data/ext/mtl/vbc_str.h +166 -0
  71. data/ext/mtl/vcomp/Makefile +29 -0
  72. data/ext/mtl/vcomp/bootstrap.cpp +89 -0
  73. data/ext/mtl/vcomp/compiler.cpp +470 -0
  74. data/ext/mtl/vcomp/compiler.h +200 -0
  75. data/ext/mtl/vcomp/compiler_file.cpp +929 -0
  76. data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
  77. data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
  78. data/ext/mtl/vcomp/compiler_type.cpp +872 -0
  79. data/ext/mtl/vcomp/compiler_var.cpp +289 -0
  80. data/ext/mtl/vcomp/file.cpp +79 -0
  81. data/ext/mtl/vcomp/file.h +39 -0
  82. data/ext/mtl/vcomp/filesystem.h +14 -0
  83. data/ext/mtl/vcomp/interpreter.cpp +85 -0
  84. data/ext/mtl/vcomp/interpreter.h +121 -0
  85. data/ext/mtl/vcomp/memory.cpp +241 -0
  86. data/ext/mtl/vcomp/memory.h +326 -0
  87. data/ext/mtl/vcomp/param.h +95 -0
  88. data/ext/mtl/vcomp/parser.cpp +427 -0
  89. data/ext/mtl/vcomp/parser.h +97 -0
  90. data/ext/mtl/vcomp/parser_xml.cpp +124 -0
  91. data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
  92. data/ext/mtl/vcomp/prodbuffer.h +42 -0
  93. data/ext/mtl/vcomp/resource.h +17 -0
  94. data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
  95. data/ext/mtl/vcomp/terminal.cpp +73 -0
  96. data/ext/mtl/vcomp/terminal.h +30 -0
  97. data/ext/mtl/vcomp/util.cpp +48 -0
  98. data/ext/mtl/vcomp/util.h +31 -0
  99. data/ext/mtl/vinterp.c +1349 -0
  100. data/ext/mtl/vinterp.h +11 -0
  101. data/ext/mtl/vloader.c +127 -0
  102. data/ext/mtl/vloader.h +31 -0
  103. data/ext/mtl/vlog.c +589 -0
  104. data/ext/mtl/vlog.h +69 -0
  105. data/ext/mtl/vmem.c +424 -0
  106. data/ext/mtl/vmem.h +107 -0
  107. data/ext/mtl/vnet.c +255 -0
  108. data/ext/mtl/vnet.h +19 -0
  109. data/lib/nabaztag_hack_kit/message/api.rb +39 -0
  110. data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
  111. data/lib/nabaztag_hack_kit/message.rb +36 -0
  112. data/lib/nabaztag_hack_kit/server.rb +50 -0
  113. data/lib/nabaztag_hack_kit/version.rb +3 -0
  114. data/lib/nabaztag_hack_kit.rb +4 -0
  115. data/nabaztag_hack_kit.gemspec +29 -0
  116. data/public/bytecode.bin +0 -0
  117. data/test/bytecode/helper.mtl +60 -0
  118. data/test/bytecode/native.mtl +28 -0
  119. data/test/bytecode/test.mtl +221 -0
  120. data/test/spec_helper.rb +5 -0
  121. data/test/unit/message_spec.rb +56 -0
  122. metadata +209 -0
data/ext/mtl/simu.c ADDED
@@ -0,0 +1,750 @@
1
+ /*
2
+ PROJECT VLOWCOST 1.0
3
+ copyright 2004
4
+ Sylvain HUET
5
+ amberMind
6
+ */
7
+
8
+ #define PROTORABBIT
9
+ //#define PROTODAL
10
+
11
+ // commenter la ligne suivante pour la version windows
12
+ //#define VMICROCHIP
13
+
14
+
15
+ #define uchar unsigned char
16
+ #define ulong unsigned long
17
+ #ifndef uint
18
+ #define uint unsigned short int
19
+ #endif
20
+ #define vub unsigned char
21
+ #define vsb signed char
22
+
23
+ #define vuw unsigned short int
24
+ #define vsw signed short int
25
+
26
+ #define vud unsigned long
27
+ #define vsd signed long
28
+
29
+ #ifdef PROTORABBIT
30
+ #define VLISP_HARDWARE "NAB2"
31
+ #define NBLED 15
32
+ #define VL_MOTORS
33
+ #define VL_MUSIC
34
+ #define VL_3STATE
35
+ #define NBMOTOR 2
36
+ #endif
37
+
38
+ #ifdef PROTODAL
39
+ #define VLISP_HARDWARE "4"
40
+ #define NBLED 27
41
+ #define VL_PRESS
42
+ #endif
43
+
44
+ #ifdef VMICROCHIP
45
+ int simuInit(){ return 0;}
46
+ int simuDoLoop(){ return 0;}
47
+ void simuSetLed(vub i,vub val){}
48
+ void simuSetMotor(vub i,vub val){}
49
+
50
+ #else
51
+ #include<stdio.h>
52
+ #include<stdlib.h>
53
+ #include<string.h>
54
+ #include<io.h>
55
+ #include<time.h>
56
+
57
+ #include"my_simuaudio.h"
58
+ #include"my_simunet.h"
59
+
60
+ // d�finition de l'�chelle d'affichage de la simulation
61
+ #define SCALE 2
62
+
63
+ #define NBHOLES 20
64
+ #define MASKEDHOLES 3
65
+ // MAXMOTORVAL doit �tre inf�rieur � 256
66
+ #define MAXMOTORVAL 100
67
+
68
+ int motorwheel[256];
69
+
70
+ // gestion des couleurs
71
+ // ---------------------
72
+ uchar coloradd[256*256];
73
+ uchar colormul[256*256];
74
+
75
+ #define COLORADD(x,y) (coloradd[(x)+((y)<<8)])
76
+ #define COLORMUL(x,y) (colormul[(x)+((y)<<8)])
77
+
78
+ #define RGBTOINT(r,g,b) (( (((int)r)&255)<<16)+((((int)g)&255)<<8)+(((int)b)&255))
79
+ #define INTTOR(c) ((c>>16)&255)
80
+ #define INTTOG(c) ((c>>8)&255)
81
+ #define INTTOB(c) (c&255)
82
+
83
+ // initialisation des tables de couleur
84
+ void colortabInit()
85
+ {
86
+ int i,j,k;
87
+
88
+ for(i=0;i<256;i++)
89
+ for(j=0;j<256;j++)
90
+ {
91
+ k=i+j;
92
+ coloradd[i+(j<<8)]=(k<=255)?k:255;
93
+
94
+ k=i*j/255;
95
+ colormul[i+(j<<8)]=k;
96
+ }
97
+ }
98
+
99
+ // d�finition physique des leds
100
+
101
+ int diodeval[NBLED];
102
+ #ifdef VL_MOTORS
103
+ int motorval[NBMOTOR];
104
+ int motorcount[NBMOTOR];
105
+ int motordir[NBMOTOR];
106
+ #endif
107
+
108
+ int xclicsimu=-1;
109
+ int yclicsimu=-1;
110
+ int rclicsimu=0;
111
+ int movesimu=0;
112
+
113
+ int lastmovex=0;
114
+ int lastmovey=0;
115
+
116
+ #ifdef PROTORABBIT
117
+ int diodex[NBLED]={80,80,80,40,40,40,80,80,80,120,120,120,80,80,80};
118
+ int diodey[NBLED]={40,40,40,90,90,90,90,90,90,90,90,90,130,130,130};
119
+ int diodergb[NBLED]=
120
+ {0x0000ff,0x00ff00,0xff0000,
121
+ 0x0000ff,0x00ff00,0xff0000,
122
+ 0x0000ff,0x00ff00,0xff0000,
123
+ 0x0000ff,0x00ff00,0xff0000,
124
+ 0x0000ff,0x00ff00,0xff0000
125
+ };
126
+ HWND buttoncheck;
127
+ HWND button3;
128
+ HWND buttonrfid;
129
+ #define SUPP_HIGH 60
130
+ int width=160*SCALE;
131
+ int height=160*SCALE;
132
+ #endif
133
+
134
+ #ifdef PROTODAL
135
+ int diodex[NBLED]={40,40,40,80,80,80,120,120,120,40,40,40,80,80,80,120,120,120,40,40,40,80,80,80,120,120,120};
136
+ int diodey[NBLED]={40,40,40,40,40,40,40,40,40,80,80,80,80,80,80,80,80,80,120,120,120,120,120,120,120,120,120};
137
+ int diodergb[NBLED]=
138
+ {0x0000ff,0x00ff00,0xff0000,
139
+ 0x0000ff,0x00ff00,0xff0000,
140
+ 0x0000ff,0x00ff00,0xff0000,
141
+ 0x0000ff,0x00ff00,0xff0000,
142
+ 0x0000ff,0x00ff00,0xff0000,
143
+ 0x0000ff,0x00ff00,0xff0000,
144
+ 0x0000ff,0x00ff00,0xff0000,
145
+ 0x0000ff,0x00ff00,0xff0000,
146
+ 0x0000ff,0x00ff00,0xff0000
147
+ };
148
+ HWND buttoncheck;
149
+ #define SUPP_HIGH 20
150
+ int width=160*SCALE;
151
+ int height=160*SCALE;
152
+ #endif
153
+
154
+
155
+
156
+ #define FlagMainWindow (WS_VISIBLE|WS_CAPTION)
157
+ #define V_FONT ANSI_FIXED_FONT
158
+
159
+
160
+
161
+ HWND mainwin;
162
+ HBITMAP mainbmp;
163
+ char * mainbmppnt ;
164
+ int mainbmpnextline ;
165
+ DIBSECTION mainbmpinfo ;
166
+
167
+
168
+ void winrepaint()
169
+ {
170
+
171
+ HDC Dcw , Dcb ;
172
+ HBITMAP OldBitmap ;
173
+ PAINTSTRUCT ps;
174
+
175
+ Dcw=BeginPaint(mainwin,&ps);
176
+ Dcb=CreateCompatibleDC(Dcw);
177
+ OldBitmap=SelectObject(Dcb,mainbmp);
178
+ BitBlt(Dcw,0,0,width,height,Dcb,0,0,SRCCOPY);
179
+ SelectObject(Dcb,OldBitmap);
180
+ DeleteDC(Dcb);
181
+
182
+ EndPaint(mainwin,&ps);
183
+ }
184
+
185
+ void winupdate()
186
+ {
187
+ InvalidateRect(mainwin,NULL,FALSE);
188
+ UpdateWindow(mainwin);
189
+ }
190
+
191
+ void mire()
192
+ {
193
+ int i,j;
194
+ char *pnt,*pnt0;
195
+ int next;
196
+ int increment=4;
197
+
198
+ pnt0=mainbmppnt;
199
+ next=mainbmpnextline;
200
+
201
+ for(i=0;i<height;i++)
202
+ {
203
+ pnt=pnt0;
204
+ for(j=0;j<width;j++)
205
+ {
206
+ pnt[0]=i&255;
207
+ pnt[1]=j&255;
208
+ pnt[2]=(i+j)&255;
209
+ pnt+=increment;
210
+ }
211
+ pnt0+=next;
212
+ }
213
+ }
214
+
215
+ void erasebmp()
216
+ {
217
+ int i;
218
+ char *pnt;
219
+ int next;
220
+ int increment=4;
221
+
222
+ pnt=mainbmppnt;
223
+ next=mainbmpnextline;
224
+
225
+ for(i=0;i<height;i++)
226
+ {
227
+ memset(pnt,0,increment*width);
228
+ pnt+=next;
229
+ }
230
+ }
231
+
232
+ #define DIODELEN (20*SCALE)
233
+
234
+ void plot(int x,int y,int rgb)
235
+ {
236
+ int r,g,b;
237
+ uchar *pnt;
238
+ int next;
239
+ int increment=4;
240
+ x*=SCALE;
241
+ y*=SCALE;
242
+ r=INTTOR(rgb);
243
+ g=INTTOG(rgb);
244
+ b=INTTOB(rgb);
245
+ if ((x<0)||(y<0)||(x>=width)||(y>=height)) return;
246
+ pnt=mainbmppnt;
247
+ next=mainbmpnextline;
248
+ pnt+=y*mainbmpnextline+x*increment;
249
+ pnt[0]=r;
250
+ pnt[1]=g;
251
+ pnt[2]=b;
252
+ }
253
+
254
+ void diodedraw(int num,int val)
255
+ {
256
+ int i,j,x,y,r,g,b,rgb;
257
+ uchar *pnt,*pnt0;
258
+ int next;
259
+ int increment=4;
260
+
261
+ if ((num<0)||(num>=NBLED)) return;
262
+ x=diodex[num]*SCALE-DIODELEN/2;
263
+ y=diodey[num]*SCALE-DIODELEN/2;
264
+ rgb=diodergb[num];
265
+ r=COLORMUL(INTTOR(rgb),(uchar)val);
266
+ g=COLORMUL(INTTOG(rgb),(uchar)val);
267
+ b=COLORMUL(INTTOB(rgb),(uchar)val);
268
+
269
+ if ((x<0)||(y<0)||(x+DIODELEN>width)||(y+DIODELEN>height)) return;
270
+
271
+ pnt0=mainbmppnt;
272
+ next=mainbmpnextline;
273
+ pnt0+=y*mainbmpnextline+x*increment;
274
+
275
+ for(i=0;i<DIODELEN;i++)
276
+ {
277
+ pnt=pnt0;
278
+ for(j=0;j<DIODELEN;j++)
279
+ {
280
+ pnt[0]=COLORADD(r,pnt[0]);
281
+ pnt[1]=COLORADD(g,pnt[1]);
282
+ pnt[2]=COLORADD(b,pnt[2]);
283
+ pnt+=increment;
284
+ }
285
+ pnt0+=next;
286
+ }
287
+ }
288
+
289
+ #define MOTORLEN (20*SCALE)
290
+
291
+ void motordraw(int x0,int val)
292
+ {
293
+ int i,j,x,y,r,g,b,rgb;
294
+ uchar *pnt,*pnt0;
295
+ int next;
296
+ int increment=4;
297
+
298
+ x=x0*SCALE-MOTORLEN/2;
299
+ y=(height*(val+128)>>9)-MOTORLEN/2;
300
+ rgb=0xc0c0c0;
301
+ r=INTTOR(rgb);
302
+ g=INTTOG(rgb);
303
+ b=INTTOB(rgb);
304
+
305
+ if ((x<0)||(y<0)||(x+MOTORLEN>width)||(y+MOTORLEN>height)) return;
306
+
307
+ pnt0=mainbmppnt;
308
+ next=mainbmpnextline;
309
+ pnt0+=y*mainbmpnextline+x*increment;
310
+
311
+ for(i=0;i<MOTORLEN;i++)
312
+ {
313
+ pnt=pnt0;
314
+ for(j=0;j<MOTORLEN;j++)
315
+ {
316
+ if (!((j+i+1)&3))
317
+ {
318
+ pnt[0]=COLORADD(r,pnt[0]);
319
+ pnt[1]=COLORADD(g,pnt[1]);
320
+ pnt[2]=COLORADD(b,pnt[2]);
321
+ }
322
+ pnt+=increment;
323
+ }
324
+ pnt0+=next;
325
+ }
326
+ }
327
+
328
+ HWND crText (char *text,HWND Parent,int x, int y, int w,int h)
329
+ {
330
+ HWND hwnd;
331
+ int Flags=ES_READONLY|WS_CHILD | ES_RIGHT ;
332
+
333
+ hwnd=CreateWindowEx ( 0 ,
334
+ "Edit" ,
335
+ text , Flags ,
336
+ x,y,w,h,
337
+ Parent , NULL ,
338
+ NULL/*thisinst*/ , NULL ) ;
339
+ SendMessage(hwnd,WM_SETFONT,(WPARAM)GetStockFont(V_FONT),(LPARAM)TRUE);
340
+
341
+ ShowWindow(hwnd,SW_SHOW);
342
+ UpdateWindow(hwnd);
343
+ return hwnd;
344
+ }
345
+
346
+ HWND crEdit (char *text,HWND Parent,int x, int y, int w,int h)
347
+ {
348
+ HWND hwnd;
349
+ int Flags=WS_CHILD ;
350
+
351
+ hwnd=CreateWindowEx ( WS_EX_CLIENTEDGE ,
352
+ "Edit" ,
353
+ text , Flags ,
354
+ x,y,w,h,
355
+ Parent , NULL ,
356
+ NULL/*thisinst*/ , NULL ) ;
357
+ SendMessage(hwnd,WM_SETFONT,(WPARAM)GetStockFont(V_FONT),(LPARAM)TRUE);
358
+ ShowWindow(hwnd,SW_SHOW);
359
+ UpdateWindow(hwnd);
360
+ return hwnd;
361
+ }
362
+
363
+ void setText(HWND h,int v)
364
+ {
365
+ char buf[32];
366
+ sprintf(buf,"%d",v);
367
+ SetWindowText(h,buf);
368
+ }
369
+
370
+ char* getTextStr(HWND h,char *buf)
371
+ {
372
+ int s;
373
+ *(int*)buf=255;
374
+ s=SendMessage(h,EM_GETLINE,0,(LPARAM)buf);
375
+ buf[s]=0;
376
+ return buf;
377
+ }
378
+
379
+ int getText(HWND h)
380
+ {
381
+ char buf[256];
382
+ int s;
383
+ *(int*)buf=255;
384
+ s=SendMessage(h,EM_GETLINE,0,(LPARAM)buf);
385
+ buf[s]=0;
386
+ return atoi(buf);
387
+ }
388
+
389
+
390
+ HWND crCheck (char *text,HWND Parent,int x, int y, int w,int h)
391
+ {
392
+ HWND hwnd;
393
+ int Flags=WS_CHILD|BS_AUTOCHECKBOX ;
394
+
395
+ hwnd=CreateWindowEx ( 0 ,
396
+ "button" ,
397
+ text , Flags ,
398
+ x,y,w,h,
399
+ Parent , NULL ,
400
+ NULL/*thisinst*/ , NULL ) ;
401
+ ShowWindow(hwnd,SW_SHOW);
402
+ UpdateWindow(hwnd);
403
+ return hwnd;
404
+ }
405
+
406
+ void setCheck(HWND h,int v)
407
+ {
408
+ SendMessage(h,BM_SETCHECK,v,0);
409
+ }
410
+
411
+ int getCheck(HWND h)
412
+ {
413
+ return SendMessage(h,BM_GETCHECK,0,0);
414
+ }
415
+ #ifdef PROTORABBIT
416
+ void setButton(int v)
417
+ {
418
+ setCheck(buttoncheck,v);
419
+ }
420
+ int getButton()
421
+ {
422
+ return getCheck(buttoncheck);
423
+ }
424
+ #endif
425
+
426
+ #ifdef PROTODAL
427
+ void setButton(int v)
428
+ {
429
+ setCheck(buttoncheck,v);
430
+ }
431
+ int getButton()
432
+ {
433
+ return getCheck(buttoncheck);
434
+ }
435
+ #endif
436
+
437
+ LRESULT CALLBACK WindowProc( HWND hwnd, unsigned msg,
438
+ UINT wParam, LONG lParam )
439
+ {
440
+ int d,v,k,last;
441
+
442
+ switch( msg ) {
443
+
444
+ case WM_DESTROY:
445
+ exit(0);//PostQuitMessage(0);
446
+ break;
447
+ case WM_PAINT:
448
+ winrepaint();
449
+ break;
450
+ case WM_MOUSEMOVE :
451
+ d=LOWORD(lParam)-lastmovex;
452
+ movesimu+=(d>0)?d:-d;
453
+ d=HIWORD(lParam)-lastmovey;
454
+ movesimu+=(d>0)?d:-d;
455
+ lastmovex=LOWORD(lParam);
456
+ lastmovey=HIWORD(lParam);
457
+ if (rclicsimu)
458
+ {
459
+ xclicsimu=LOWORD(lParam)*1000/width;
460
+ yclicsimu=HIWORD(lParam)*1000/height;
461
+ d=-1;
462
+ if ((yclicsimu>=250)&&(yclicsimu<750))
463
+ {
464
+ if (xclicsimu<150) d=0;
465
+ if (xclicsimu>850) d=1;
466
+ }
467
+ if (d>=0)
468
+ {
469
+ v=MAXMOTORVAL*(yclicsimu-250)/500;
470
+ if (v<motorval[d])
471
+ for(k=motorval[d];k>v;k--)
472
+ {
473
+ last=motorwheel[motorval[d]];
474
+ motorval[d]--;
475
+ if (last<motorwheel[motorval[d]]) motorcount[d]++;
476
+ }
477
+ else
478
+ for(k=motorval[d];k<v;k++)
479
+ {
480
+ last=motorwheel[motorval[d]];
481
+ motorval[d]++;
482
+ if (last<motorwheel[motorval[d]]) motorcount[d]++;
483
+ }
484
+ // printf("move ear %d - %d\n",motorval[d],motorcount[d]);
485
+ }
486
+ }
487
+ break;
488
+ case WM_LBUTTONDOWN :
489
+ rclicsimu=1;
490
+ xclicsimu=LOWORD(lParam)*1000/width;
491
+ yclicsimu=HIWORD(lParam)*1000/height;
492
+ if ((xclicsimu>150)&&(xclicsimu<850))
493
+ {
494
+ setButton(1);
495
+ }
496
+ break;
497
+ case WM_LBUTTONUP :
498
+ rclicsimu=0;
499
+ setButton(0);
500
+ xclicsimu=-1;
501
+ yclicsimu=-1;
502
+ break;
503
+ case MM_WOM_DONE:
504
+ audioEventPlayData(msg,wParam,lParam);
505
+ break;
506
+ case MM_WIM_DATA:
507
+ audioEventRecData(msg,wParam,lParam);
508
+ break;
509
+ case UDPEVENT:
510
+ udpevent(msg,wParam,lParam);
511
+ break;
512
+ case TCPEVENT:
513
+ tcpevent(msg,wParam,lParam);
514
+ break;
515
+
516
+ default:
517
+ return( DefWindowProc( hwnd, msg, wParam, lParam ) );
518
+ }
519
+
520
+ return 0;
521
+ }
522
+
523
+
524
+ int initWindow()
525
+ {
526
+ char buf[256];
527
+
528
+ RECT r;
529
+ r.bottom=height+SUPP_HIGH;
530
+ r.right=width;
531
+ r.left=0;
532
+ r.top=0;
533
+
534
+ AdjustWindowRect(&r,FlagMainWindow,FALSE);
535
+
536
+ mainwin = CreateWindow("GenericClass",TEXT("Vlisp - "VLISP_HARDWARE), FlagMainWindow,
537
+ 600,0,r.right-r.left,r.bottom-r.top,
538
+ NULL,NULL,NULL,NULL);
539
+
540
+ if (!mainwin)
541
+ {
542
+ wsprintf(buf,TEXT("%d"),GetLastError());
543
+ MessageBox(NULL,TEXT("window error"),buf,MB_OK);
544
+ return -1;
545
+ }
546
+
547
+ ShowWindow(mainwin,SW_SHOW);
548
+ UpdateWindow(mainwin);
549
+ #ifdef PROTORABBIT
550
+ crText("button=",mainwin,0,height,width/2,20);
551
+ buttoncheck=crCheck("",mainwin,width/2,height,width/2,20);
552
+ crText("b3=",mainwin,0,height+20,width/2,20);
553
+ button3=crEdit("0",mainwin,width/2,height+20,width/2,20);
554
+ crText("rfid=",mainwin,0,height+40,width/2,20);
555
+ buttonrfid=crEdit("",mainwin,width/2,height+40,width/2,20);
556
+ #endif
557
+ #ifdef PROTODAL
558
+ crText("button=",mainwin,0,height,width/2,20);
559
+ buttoncheck=crCheck("",mainwin,width/2,height,width/2,20);
560
+ #endif
561
+ return 0;
562
+ }
563
+
564
+ int initBitmap ( )
565
+ {
566
+ BITMAPINFO Bi ;
567
+ int tf ;
568
+ HDC dc ;
569
+ char buf[256];
570
+
571
+ dc = NULL ;
572
+
573
+ Bi.bmiHeader.biSize = sizeof ( BITMAPINFOHEADER ) ;
574
+ Bi.bmiHeader.biWidth = width ;
575
+
576
+ Bi.bmiHeader.biHeight = - height ;
577
+
578
+ Bi.bmiHeader.biPlanes = 1 ;
579
+ Bi.bmiHeader.biBitCount = 32 ;
580
+ Bi.bmiHeader.biCompression = BI_RGB ;
581
+ Bi.bmiHeader.biSizeImage = 0 ;
582
+ Bi.bmiHeader.biXPelsPerMeter = 0 ;
583
+ Bi.bmiHeader.biYPelsPerMeter = 0 ;
584
+ Bi.bmiHeader.biClrUsed = 0 ;
585
+ tf = DIB_RGB_COLORS ;
586
+ Bi.bmiHeader.biClrImportant = Bi.bmiHeader.biClrUsed ;
587
+
588
+ // Bi.bmiColors[0] = NULL ;
589
+
590
+ mainbmp = CreateDIBSection ( dc , (BITMAPINFO * ) & Bi , tf , & mainbmppnt , NULL , 0 ) ;
591
+
592
+ if (mainbmp == NULL )
593
+ {
594
+ wsprintf(buf,TEXT("%d"),GetLastError());
595
+ MessageBox(NULL,TEXT("bitmap error"),buf,MB_OK);
596
+ return -1;
597
+ }
598
+
599
+ GetObject ( mainbmp , sizeof( DIBSECTION ) , &mainbmpinfo ) ;
600
+ mainbmpnextline=mainbmpinfo.dsBm.bmWidthBytes ;
601
+ return 0 ;
602
+ }
603
+
604
+ static BOOL FirstInstance()
605
+ {
606
+ WNDCLASS wc;
607
+ BOOL rc;
608
+
609
+ wc.style = CS_HREDRAW | CS_VREDRAW;
610
+ wc.lpfnWndProc = (LPVOID) WindowProc;
611
+ wc.cbClsExtra = 0;
612
+ wc.cbWndExtra = 0;
613
+ wc.hInstance = NULL;
614
+ wc.hIcon = 0;
615
+ wc.hCursor = LoadCursor( NULL, IDC_ARROW );
616
+ wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
617
+ wc.lpszMenuName = 0;
618
+ wc.lpszClassName = "GenericClass";
619
+ rc = RegisterClass( &wc );
620
+
621
+ return( rc );
622
+ }
623
+
624
+ // fonction d'affichage des diodes
625
+ int simuDisplay(int* intensity)
626
+ {
627
+ int i;
628
+ erasebmp();
629
+ for(i=0;i<NBLED;i++)
630
+ {
631
+ diodedraw(i,intensity[i]);
632
+ #ifdef VL_MOTORS
633
+ plot(2,(160*128)>>9,0xffffff);
634
+ plot(2,(160*(128+256))>>9,0xffffff);
635
+ plot(160-2,(160*128)>>9,0xffffff);
636
+ plot(160-2,(160*(128+256))>>9,0xffffff);
637
+ motordraw(15,motorval[0]*256/MAXMOTORVAL);
638
+ motordraw(160-15,motorval[1]*256/MAXMOTORVAL);
639
+ #endif
640
+ // VPRINT("led %d = %d\n",i,intensity[i]);
641
+ }
642
+
643
+ winupdate();
644
+ return 0;
645
+ }
646
+
647
+
648
+ // initialisation du simulateur
649
+ vsd simuInit()
650
+ {
651
+ int i;
652
+ colortabInit();
653
+
654
+ for(i=0;i<NBLED;i++) diodeval[i]=255;
655
+ srand(GetTickCount());
656
+ #ifdef VL_MOTORS
657
+ for(i=0;i<NBMOTOR;i++)
658
+ {
659
+ motorval[i]=60;//(rand()&255)*MAXMOTORVAL/256;
660
+ motorcount[i]=motordir[i]=0;
661
+ }
662
+ for(i=0;i<256;i++) motorwheel[i]=0;
663
+ for(i=0;i<MAXMOTORVAL;i++)
664
+ {
665
+ if ((i*2*NBHOLES/MAXMOTORVAL)&1) motorwheel[i]=1;
666
+ if (i*NBHOLES/MAXMOTORVAL>=NBHOLES-MASKEDHOLES) motorwheel[i]=1;
667
+ }
668
+ #endif
669
+ FirstInstance();
670
+ if (initBitmap ( )) return FALSE;
671
+ mire();
672
+ if (initWindow()) return FALSE;
673
+ winupdate();
674
+ // setButton(1);
675
+ simuaudioinit();
676
+ simunetinit();
677
+ return 0;
678
+ }
679
+
680
+
681
+
682
+ // fonction � appeler r�guli�rement, pour traiter les messages de la fen�tre du simulateur
683
+ vsd simuDoLoop()
684
+ {
685
+ MSG msg;
686
+ #ifdef VL_MOTORS
687
+ int i,last;
688
+ #endif
689
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
690
+ {
691
+ TranslateMessage( &msg );
692
+ DispatchMessage( &msg );
693
+ }
694
+
695
+ #ifdef VL_MOTORS
696
+ for(i=0;i<NBMOTOR;i++)
697
+ {
698
+ last=motorwheel[motorval[i]];
699
+ if (1) motorval[i]+=motordir[i];
700
+ if (motorval[i]<0) motorval[i]+=MAXMOTORVAL;
701
+ if (motorval[i]>=MAXMOTORVAL) motorval[i]-=MAXMOTORVAL;
702
+ if (last<motorwheel[motorval[i]]) motorcount[i]++;
703
+ }
704
+ #endif
705
+ simuDisplay(diodeval);
706
+ return 0;
707
+ }
708
+
709
+ // r�glagle d'une led
710
+ void simuSetLed(int i,int val)
711
+ {
712
+ i*=3;
713
+ if ((i<0)||(i>=NBLED)) return;
714
+ diodeval[i]=(val>>16)&255;
715
+ diodeval[i+1]=(val>>8)&255;
716
+ diodeval[i+2]=(val)&255;
717
+ }
718
+
719
+ #ifdef VL_MOTORS
720
+ // r�glagle d'un moteur
721
+ void set_motor_dir(int num_motor, int sens)
722
+ {
723
+ motordir[num_motor?1:0]=(sens==0)?0:((sens==1)?1:-1);
724
+ }
725
+
726
+ int get_motor_val(int i)
727
+ {
728
+ return motorcount[i?1:0];
729
+ }
730
+ #else
731
+ int get_motor_val(int i)
732
+ {
733
+ return 128;
734
+ }
735
+ #endif
736
+
737
+ int get_button3()
738
+ {
739
+ return getText(button3);
740
+ }
741
+
742
+ char buf_rfid[256];
743
+
744
+ char* get_rfid()
745
+ {
746
+ getTextStr(buttonrfid,buf_rfid);
747
+ if (strlen(buf_rfid)) return buf_rfid;
748
+ return NULL;
749
+ }
750
+ #endif