aboutsummaryrefslogtreecommitdiff
path: root/drivers/input/touchscreen/mediatek/synaptics_2200/RefCode_F54_FullRawCap.c
blob: ffdbca66273cbd01c27c4c508a32d5806de92d91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/*
   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Copyright (c) 2011 Synaptics, Inc.
   
   Permission is hereby granted, free of charge, to any person obtaining a copy of 
   this software and associated documentation files (the "Software"), to deal in 
   the Software without restriction, including without limitation the rights to use, 
   copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 
   Software, and to permit persons to whom the Software is furnished to do so, 
   subject to the following conditions:
   
   The above copyright notice and this permission notice shall be included in all 
   copies or substantial portions of the Software.
   
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
   SOFTWARE.
 */

#include "RefCode.h"
#include "RefCode_PDTScan.h"

#ifdef _F54_TEST_
#include "RefCode_F54_FullRawCapLimit.h"

#ifdef F54_Porting
static unsigned char ImageBuffer[CFG_F54_TXCOUNT*CFG_F54_RXCOUNT*2];
static signed ImageArray[CFG_F54_TXCOUNT] [CFG_F54_RXCOUNT];

static char buf[6000] = {0};
static unsigned char call_cnt = 0;
static int LimitBack[30][46*2];
#endif

unsigned char F54_FullRawCap(int mode)
// mode - 0:For sensor, 1:For FPC, 2:CheckTSPConnection, 3:Baseline, 4:Delta image
{
   signed short temp=0;
   int Result = 0;
#ifdef F54_Porting
	int ret = 0;
	unsigned char product_id[11];
#endif
    int TSPCheckLimit=700;
	short Flex_LowerLimit = -100;
	short Flex_UpperLimit = 500;

	int i, j, k;
	unsigned short length;
	
	unsigned char command;

	length = numberOfTx * numberOfRx* 2;

	//check product id to set basecap array
	readRMI(F01_Query_Base+11, &product_id[0], sizeof(product_id));
	
	if(!strncmp(product_id, "PLG245", 6)) {
		printk("set limit array to PLG245 value.\n");
		//memcpy(Limit, Limit_PLG245, sizeof(Limit_PLG245));
	} else if(!strncmp(product_id, "PLG260", 6)) {
		printk("set limit array to PLG260 value.\n");
		//memcpy(Limit, Limit_PLG260, sizeof(Limit_PLG260));
	} else {
		printk("set limit array to LGIT value.\n");
	}
	
	//set limit array
	if(call_cnt == 0){
		printk("Backup Limit to LimitBack array\n");
		memset(LimitBack, 0, sizeof(LimitBack));
//		memcpy(LimitBack, Limit, sizeof(LimitBack));
#if defined(LGE_USE_DOME_KEY)
		memcpy(LimitBack, Limit_PLG260, sizeof(LimitBack));		
#else
		memcpy(LimitBack, Limit_PLG245, sizeof(LimitBack));		
#endif
	}
	if(get_limit(numberOfTx, numberOfRx) > 0) {
		printk("Get limit from file success!!Use Limit array from file data.\n");		
//		memcpy(Limit, LimitFile, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
		memcpy(Limit_PLG260, LimitFile, sizeof(Limit_PLG260));
#else
		memcpy(Limit_PLG245, LimitFile, sizeof(Limit_PLG260));
#endif
	} else {
		printk("Get limit from file fail!!Use Limit array from image data\n");
		//memcpy(Limit, LimitBack, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
		memcpy(Limit_PLG260, LimitBack, sizeof(Limit_PLG260));
#else
		memcpy(Limit_PLG245, LimitBack, sizeof(Limit_PLG245));
#endif

	}
	call_cnt++;
	if(call_cnt > 0) call_cnt = 1;

	if(mode == 3 || mode == 4)
	{
/*		// Disable CBC
		command = 0x00;
		writeRMI(F54_CBCSettings, &command, 1);
		writeRMI(F54_CBCPolarity, &command, 1);
*/	}

	// No sleep
	command = 0x04;
	writeRMI(F01_Ctrl_Base, &command, 1);

	// Set report mode to to run the AutoScan
	if(mode >= 0 && mode < 4)	command = 0x03;
	if(mode == 4)				command = 0x02;
	writeRMI(F54_Data_Base, &command, 1);

	if(mode == 3 || mode == 4)
	{
/*		//NoCDM4
		command = 0x01;
		writeRMI(NoiseMitigation, &command, 1);
*/	}

	if(mode != 3 && mode != 4)
	{
		// Force update & Force cal
		command = 0x06;
		writeRMI(F54_Command_Base, &command, 1);

		do {
			delayMS(1); //wait 1ms
			readRMI(F54_Command_Base, &command, 1);
		} while (command != 0x00);
	}

	// Enabling only the analog image reporting interrupt, and turn off the rest
	command = 0x08;
	writeRMI(F01_Cmd_Base+1, &command, 1);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);
 
	// Set the GetReport bit to run the AutoScan
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);
 
	// Wait until the command is completed
	do {
	 delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
 
	//readRMI(F54_Data_Buffer, &ImageBuffer[0], length);
	longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length);

	if( (numberOfTx > 29) || (numberOfRx > 45) ) {
		printk("Limit Index overflow. Test result: Fail\n");
		return 0;
	}

	switch(mode)
	{
		case 0:
		case 1:
#ifdef F54_Porting
			memset(buf, 0, sizeof(buf));
			ret = sprintf(buf, "#ofTx\t%d\n", numberOfTx);
			ret += sprintf(buf+ret, "#ofRx\t%d\n", numberOfRx);

			ret += sprintf(buf+ret, "\n#3.03	Full raw capacitance Test\n");
#else
			printk("#ofTx\t%d\n", numberOfTx);
			printk("#ofRx\t%d\n", numberOfRx);

			printk("\n#3.03	Full raw capacitance Test\n");
#endif
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", i);
#else
				printk("%d\t", i);
#endif
				for (j = 0; j < numberOfRx; j++)
				{
						temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
						if(CheckButton[i][j] != 1)
						{
							if(mode==0)
							{
#ifdef F54_Porting
								//if ((temp >= Limit[i][j*2]) && (temp <= Limit[i][j*2+1]))
#if defined(LGE_USE_DOME_KEY)
								if ((temp >= Limit_PLG260[i][j*2]) && (temp <= Limit_PLG260[i][j*2+1]))
#else
								if ((temp >= Limit_PLG245[i][j*2]) && (temp <= Limit_PLG245[i][j*2+1]))
#endif
#else
								if ((temp >= Limit[i][j*2]*1000) && (temp <= Limit[i][j*2+1]*1000))
#endif
								{
									Result++;
#ifdef F54_Porting									
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
								else {
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
							}
							else
							{
								if ((temp >= Flex_LowerLimit) && (temp <= Flex_UpperLimit))
								{
									Result++;
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif									
								}
								else {
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
							}
						}
						else
						{
							Result++;
#ifdef F54_Porting
							ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
							printk("%d\t", temp); //It's for getting log for limit set
#endif							
						}
				  k = k + 2;
				}
#ifdef F54_Porting
				ret += sprintf(buf+ret, "\n");
#else
				printk("\n"); //It's for getting log for limit set
#endif				
			}

#ifdef F54_Porting
			ret += sprintf(buf+ret, "#3.04	Full raw capacitance Test END\n");
			ret += sprintf(buf+ret, "\n#3.01	Full raw capacitance Test Limit\n");

			// Print Capacitance Imgae for getting log for Excel format
			ret += sprintf(buf+ret, "\t");
#else
			printk("#3.04	Full raw capacitance Test END\n");

			printk("\n#3.01	Full raw capacitance Test Limit\n");
			// Print Capacitance Imgae for getting log for Excel format
			printk("\t");
#endif			
			for (j = 0; j < numberOfRx; j++) {
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d-Min\t%d-Max\t", j, j);
#else
				printk("%d-Min\t%d-Max\t", j, j);
#endif
			}

#ifdef F54_Porting
			ret += sprintf(buf+ret, "\n");
#else
			printk("\n");
#endif

			for (i = 0; i < numberOfTx; i++)
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", i);
#else
				printk("%d\t", i);
#endif
				for (j = 0; j < numberOfRx; j++)
				{
					if(mode==0) {
#ifdef F54_Porting
#if defined(LGE_USE_DOME_KEY)
						//printk("%d\t%d\t", Limit[i][j*2], Limit[i][j*2+1]);
						//ret += sprintf(buf+ret, "%d\t%d\t", Limit[i][j*2], Limit[i][j*2+1]);
						ret += sprintf(buf+ret, "%d\t%d\t", Limit_PLG260[i][j*2], Limit_PLG260[i][j*2+1]);
#else
						ret += sprintf(buf+ret, "%d\t%d\t", Limit_PLG245[i][j*2], Limit_PLG245[i][j*2+1]);
#endif
#else
						printk("%d\t%d\t", Limit[i][j*2]*1000, Limit[i][j*2+1]*1000);
#endif
					} else {
#ifdef F54_Porting
						ret += sprintf(buf+ret, "%d\t%d\t", Flex_LowerLimit, Flex_UpperLimit);
#else
						printk("%d\t%d\t", Flex_LowerLimit, Flex_UpperLimit);
#endif
					}
				}
#ifdef F54_Porting
				ret += sprintf(buf+ret, "\n");
#else
				printk("\n");
#endif
			}
#ifdef F54_Porting
			ret += sprintf(buf+ret, "#3.02	Full raw cap Limit END\n");
#else
			printk("#3.02	Full raw cap Limit END\n");
#endif
			break;

		case 2:
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
				for (j = 0; j < numberOfRx; j++)
				{
						temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
						   if (temp > TSPCheckLimit)
						   Result++;
				  k = k + 2;
				}	   
			}
			break;

		case 3:
		case 4:
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
				for (j = 0; j < numberOfRx; j++)
				{
						ImageArray[i][j] = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
				  k = k + 2;
				}	   
			}
#ifdef F54_Porting
				 // Print Capacitance Imgae for getting log for Excel format
				 ret += sprintf(ret+buf, "\n\t");
#else
				 // Print Capacitance Imgae for getting log for Excel format
				 printk("\n\t");
#endif
				 for (j = 0; j < numberOfRx; j++) {
#ifdef F54_Porting
					ret += sprintf(ret+buf, "RX%d\t", RxChannelUsed[j]);
#else
				 	printk("RX%d\t", RxChannelUsed[j]);
#endif
				 }
				 
#ifdef F54_Porting
				 ret += sprintf(buf+ret, "\n");
#else
				 printk("\n");
#endif
				 
				 for (i = 0; i < numberOfTx; i++)
				 {
#ifdef F54_Porting
					 ret += sprintf(buf+ret, "TX%d\t", TxChannelUsed[i]);
#else
					 printk("TX%d\t", TxChannelUsed[i]);
#endif
					 for (j = 0; j < numberOfRx; j++)
					 {
#ifdef F54_Porting					 
						if(mode == 3)		ret += sprintf(buf+ret, "%d\t", (ImageArray[i][j]) / 1000);
						else if(mode == 4)	ret += sprintf(buf+ret, "%d\t", ImageArray[i][j]);
#else
						if(mode == 3)	   printk("%d\t", (ImageArray[i][j]) / 1000);
						else if(mode == 4) printk("%d\t", ImageArray[i][j]);
						//if(mode == 3)	   printk("%1.3f\t", (float)(ImageArray[i][j]) / 1000);
						//else if(mode == 4) printk("%d\t", ImageArray[i][j]);
#endif
						 
					  }
#ifdef F54_Porting
				  ret += sprintf(ret+buf, "\n");
#else
				  printk("\n");
#endif
				 }
			break;

		default:
			break;
	}

	if(mode != 3 && mode != 4)
	{
		//Reset
		command= 0x01;
		writeRMI(F01_Cmd_Base, &command, 1);
		delayMS(200);
		readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
	}
	
	if(mode >= 0 && mode < 2)
	{
		if(Result == numberOfTx * numberOfRx)
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "Test Result: Pass\n");
			write_log(buf);
#else
			printk("Test Result: Pass\n");
#endif
			return 1; //Pass
		}
		else
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "Test Result: Fail\n");
			write_log(buf);
#else
			printk("Test Result: Fail\n");
#endif
			return 0; //Fail
		}
	}
	else if(mode == 2)
	{
		if(Result == 0) return 0; //TSP Not connected
		else return 1; //TSP connected 
	 }
	else
	{
#ifdef F54_Porting
		write_log(buf);
#endif
		return 0;
	}
}

// mode - 0:For sensor, 1:For FPC, 2:CheckTSPConnection, 3:Baseline, 4:Delta image
int F54_GetFullRawCap(int mode, char *buf) {
	signed short temp=0;
	//int Result = 0;
	int ret = 0;
	unsigned char product_id[11];
	int TSPCheckLimit=700;
	// short Flex_LowerLimit = -100;
	// short Flex_UpperLimit = 500;

	int i, j, k;
	unsigned short length;

	unsigned char command;

	int waitcount;

	if (mode < 0 && mode > 4)
		return ret;

	length = numberOfTx * numberOfRx * 2;

	//check product id to set basecap array
	readRMI(F01_Query_Base + 11, &product_id[0], sizeof(product_id));

	if(!strncmp(product_id, "PLG245", 6)) {
		pr_info("set limit array to PLG245 value.\n");
		//memcpy(Limit, Limit_PLG245, sizeof(Limit_PLG245));
	} else if(!strncmp(product_id, "PLG260", 6)) {
		pr_info("set limit array to PLG260 value.\n");
		//memcpy(Limit, Limit_PLG260, sizeof(Limit_PLG260));
	} else {
		pr_info("set limit array to LGIT value.\n");
	}

	//set limit array
	if (call_cnt == 0)
	{
		pr_info("Backup Limit to LimitBack array\n");
		memset(LimitBack, 0, sizeof(LimitBack));		
//		memcpy(LimitBack, Limit, sizeof(LimitBack));
#if defined(LGE_USE_DOME_KEY)
		memcpy(LimitBack, Limit_PLG260, sizeof(LimitBack));
#else
		memcpy(LimitBack, Limit_PLG245, sizeof(LimitBack));
#endif
	}

	if (get_limit(numberOfTx, numberOfRx) > 0) {
		pr_info("Get limit from file success!!Use Limit array from file data.\n");
//		memcpy(Limit, LimitFile, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
		memcpy(Limit_PLG260, LimitFile, sizeof(Limit_PLG260));
#else
		memcpy(Limit_PLG245, LimitFile, sizeof(Limit_PLG245));
#endif
	} else {
		pr_info("Get limit from file fail!!Use Limit array from image data\n");		
//		memcpy(Limit, LimitBack, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
		memcpy(Limit_PLG260, LimitBack, sizeof(Limit_PLG260));
#else
		memcpy(Limit_PLG245, LimitBack, sizeof(Limit_PLG245));
#endif
	}

	call_cnt++;

	if (call_cnt > 0)
		call_cnt = 1;

	// No sleep
	command = 0x04;
	writeRMI(F01_Ctrl_Base, &command, 1);

	// Set report mode to to run the AutoScan
	command = (mode == 4) ? 0x02 : 0x03;
	writeRMI(F54_Data_Base, &command, 1);

#if 0
	if (mode == 3 || mode == 4) {
		/*		//NoCDM4
				command = 0x01;
				writeRMI(NoiseMitigation, &command, 1);
		 */
	}


	if (mode != 3 && mode != 4) {
		// Force update & Force cal
		command = 0x06;
		writeRMI(F54_Command_Base, &command, 1);

		waitcount = 0;
		do {
			if (++waitcount > 100) {
				pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
				break;
			}
			delayMS(1); //wait 1ms
			readRMI(F54_Command_Base, &command, 1);
		} while (command != 0x00);
	}
#endif

	// Enabling only the analog image reporting interrupt, and turn off the rest
	readRMI(F01_Cmd_Base+1, &command, 1);
	command |= 0x08;
	writeRMI(F01_Cmd_Base+1, &command, 1);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);

	// Set the GetReport bit to run the AutoScan
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);

	// Wait until the command is completed
	waitcount = 0;
	do {
		if (++waitcount > 100) {
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			break;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	//readRMI(F54_Data_Buffer, &ImageBuffer[0], length);
	longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length);

	readRMI(F01_Cmd_Base+1, &command, 1);
	command &= ~0x08;
	writeRMI(F01_Cmd_Base+1, &command, 1);

	if ( (numberOfTx > 29) || (numberOfRx > 45) ) {
		ret = sprintf(buf, "ERROR: Limit Index overflow. Test result: Fail\n");
		return ret;
	}

	*buf = 0;

	ret = sprintf(buf, "Info: Tx=%d Rx=%d\n", numberOfTx, numberOfRx);

	switch(mode) {
	case 0:
	case 1:
		//ret += sprintf(buf+ret, "Full raw capacitance Test\n");
		k = 0;
		for (i = 0; i < numberOfTx; i++) {
			// ret += sprintf(buf+ret, "%d\t", i);
			for (j = 0; j < numberOfRx; j++) {
				temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
				/*
				if(CheckButton[i][j] != 1) {
					if(mode==0) {
						if ((temp >= Limit[i][j*2]) && (temp <= Limit[i][j*2+1]))
							Result++;
					} else {
						if ((temp >= Flex_LowerLimit) && (temp <= Flex_UpperLimit))
							Result++;
					}
				} else {
					Result++;
				}
				*/
				ret += sprintf(buf+ret, "%d", temp); //It's for getting log for limit set

				if(j < (numberOfRx-1))
					ret += sprintf(buf+ret, " ");

				k = k + 2;
			}
			ret += sprintf(buf+ret, "\n");
		}
		break;

	case 2:
		k = 0;
		for (i = 0; i < numberOfTx; i++) {
			for (j = 0; j < numberOfRx; j++) {
				temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));

				if (temp > TSPCheckLimit) {
					ret += sprintf(buf+ret, "1");
					//Result++;
				} else {
					ret += sprintf(buf+ret, "0");
				}

				if(j < (numberOfRx-1))
					ret += sprintf(buf+ret, " ");

				k = k + 2;
			}
			ret += sprintf(ret+buf, "\n");
		}
		break;

	case 3:
	case 4:
		k = 0;

		for (i = 0; i < numberOfTx; i++) {
			for (j = 0; j < numberOfRx; j++) {
				ImageArray[i][j] = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
				k = k + 2;
			}
		}

		for (i = 0; i < numberOfTx; i++) {
			//ret += sprintf(buf+ret, "TX%d\t", TxChannelUsed[i]);
			for (j = 0; j < numberOfRx; j++) {
				ret += sprintf(buf+ret, "%d", ((mode == 3) ? (ImageArray[i][j] / 1000) : (ImageArray[i][j])));

				if(j < (numberOfRx - 1))
					ret += sprintf(buf+ret, " ");
			}
			ret += sprintf(ret+buf, "\n");
		}
		break;

	default:
		break;
	}
	//if (mode < 3)
	/*
	{
		//Reset
		command = 0x01;
		writeRMI(F01_Cmd_Base, &command, 1);
		//delayMS(200);
		delayMS(1);
		readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
	}
	*/
	return ret;
}
#endif