-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTC1126_data.c
executable file
·7975 lines (7327 loc) · 266 KB
/
TC1126_data.c
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* 版权所有(C) TRUECOREING
* DEPARTMENT:
* MANUAL_PERCENT:
* 文件名称: CN1000_data.c
* 文件标识:
* 内容摘要:
* 其它说明:
* 当前版本:
* 作 者:
* 完成日期:
* 当前责任人:
*
* 修改记录1: 代码合规
* 修改日期: 2014-09-15
* 版 本 号:
* 修 改 人: Wangpc
* 修改内容:
*
* 修改记录2: Add one feature that acquire 10 fingers then parse 5 fingers
* 修改日期: 2014-11-12
* 版 本 号:
* 修 改 人: Wangpc(R01)
* 修改内容:
*
* 修改记录3: Rebuild structure of register
* 修改日期: 2014-11-19
* 版 本 号:
* 修 改 人: Wangpc(R02)
* 修改内容:
*****************************************************************************/
#ifndef CN1100_DATA_C
#define CN1100_DATA_C
#include "include/CN1100_common.h"
//#ifdef CN1100_LINUX
#include "include/CN1100_linux.h"
//#endif
#include "include/CN1100_Function.h"
inline int16_t abs16(int16_t x) { return (x < 0) ? -x : x; }
inline uint32_t multiply16by16(uint16_t x, uint16_t y) { return (uint32_t) x * y; }
RegTab RegTab_t;
BasData_t bdt;
bd_t *bd;
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
/*this function is used for reducing the time of divide*/
int16_t divideINT16byUINT8(int16_t num, uint8_t den)
{
uint8_t para_div[13] ={85,64,51,42,36,32,28,25,23,21,19,18,17};
if(0 == den)
{
return MAX_INT16;
}
else if(den >= 1 && den <= 2)
{
return num>>(den-1);
}
else if(den >= 3 && den <= 15)
{
return (num * para_div[den - 3])>>8;
}
else
{
return num/den;
}
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t msbPos(uint32_t val)
{
uint16_t pos = 0;
if ((val & 0xFFFF0000) != 0)
{
pos += 16;
val >>= 16;
}
if ((val & 0xFFFFFF00) != 0)
{
pos += 8;
val >>= 8;
}
if ((val & 0xFFFFFFF0) != 0)
{
pos += 4;
val >>= 4;
}
if ((val & 0xFFFFFFFC) != 0)
{
pos += 2;
val >>= 2;
}
if ((val & 0xFFFFFFFE) != 0)
{
pos += 1;
}
return (pos);
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t lsbPos(uint32_t val)
{
uint16_t pos = 0;
if ((val & 0x0000FFFF) == 0)
{
pos += 16;
val >>= 16;
}
if ((val & 0x000000FF) == 0)
{
pos += 8;
val >>= 8;
}
if ((val & 0x0000000F) == 0)
{
pos += 4;
val >>= 4;
}
if ((val & 0x00000003) == 0)
{
pos += 2;
val >>= 2;
}
if ((val & 0x00000001) == 0)
{
pos += 1;
}
return (pos);
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void clearArray(uint16_t* p, uint16_t size)
{
uint16_t i;
for (i = 0;i< size;i++)
{
*p = 0;
p++;
}
}
/*******************************************************************************
* Function Name : Baseline_FingerupdateTX
* Description : When finger is touching the cover od SD card, NOISE is huge
* in some special TX or RX lines
* Input :
* Output :
* Return :
*******************************************************************************/
void Baseline_FingerupdateTX(void)
{
uint16_t Max_num,i,j,average;
int16_t Max_sum;
uint16_t Max_cnt, Max_maxcnt, IvdCnt,IvdCnt1;
IvdCnt = 0;
IvdCnt1 = 0;
for(j=0; j<RECV_NUM; j++)
{
Max_sum = 0;
average = 0; // averagesum
Max_num = 0;
Max_cnt = 0;
Max_maxcnt = 0;
for(i=0; i<XMTR_NUM; i++)
{
// if(bdt.DeltaDat16A[i][j] < Min_sum) Min_sum = bdt.DeltaDat16A[i][j];
if(bdt.DeltaDat16A[i][j] > BASE_UPDATETXRXTHR)
{
Max_sum += bdt.DeltaDat16A[i][j];
Max_num++;
Max_cnt++;
}
else
{
if(Max_cnt > Max_maxcnt)
{
Max_maxcnt = Max_cnt;
average = Max_sum/Max_cnt;
}
Max_cnt = 0;
Max_sum = 0;
}
}
if(average > 60)
{
if(Max_maxcnt == 15)
{
bdt.PowerOnWithFinger = 1;
return ;
}
else if(Max_maxcnt >= 7)
{
IvdCnt++;
if(IvdCnt>=2)
{
bdt.PowerOnWithFinger = 1;
return ;
}
}
else if(Max_maxcnt >=5 ) IvdCnt1++;
if(IvdCnt1 >=4 )
{
bdt.PowerOnWithFinger = 1;
return;
}
}
}
}
/*******************************************************************************
* Function Name : Baseline_FingerupdateRX
* Description : When finger is touching the cover od SD card, NOISE is huge
* in some special TX or RX lines
* Input :
* Output :
* Return :
*******************************************************************************/
void Baseline_FingerupdateRX(void)
{
uint16_t Max_num,i,j,average;
int16_t Min_sum,Max_sum;
uint16_t Max_cnt, Max_maxcnt, IvdCnt;
Min_sum = 0;
Max_num = 0;
Max_sum = 0;
Max_cnt = 0;
Max_maxcnt = 0;
IvdCnt = 0;
for(i=0; i<XMTR_NUM; i++)
{
Max_sum = 0;
average = 0; // averagesum
Min_sum = 32767; // mini
Max_num = 0;
Max_cnt = 0;
Max_maxcnt = 0;
for(j=0; j<RECV_NUM; j++)
{
if(bdt.DeltaDat16A[i][j] < Min_sum)
Min_sum = bdt.DeltaDat16A[i][j];
if(bdt.DeltaDat16A[i][j] > BASE_UPDATETXRXTHR)
{
Max_sum += bdt.DeltaDat16A[i][j];
Max_num++;
Max_cnt++;
}
else
{
if(Max_cnt > Max_maxcnt)
{
Max_maxcnt = Max_cnt;
average = Max_sum/Max_cnt;
}
Max_cnt = 0;
Max_sum = 0;
}
}
if(average > 60)
{
if(Max_maxcnt == 10)
{
bdt.PowerOnWithFinger = 1;
return ;
}
else if(Max_maxcnt >= 7)
{
IvdCnt++;
if(IvdCnt>=2)
{
bdt.PowerOnWithFinger = 1;
return ;
}
}
else if(Max_maxcnt >=5 )
IvdCnt++;
if(IvdCnt >= 3)
{
bdt.PowerOnWithFinger = 1;
return;
}
}
}
}
/*******************************************************************************
* Function Name : Baseline_Fingerupdatenoise
* Description : When Palm is coving the Touch Panel, Big Noise is appeared
* Input :
* Output :
* Return :
*******************************************************************************/
void Baseline_Fingerupdatenoise(void)
{
if(bdt.MaxNoise_Sum > BIGNOISE )
{
bdt.MaxNoise_SumCount++;
bdt.PowerOnWithFinger = 0;
}
if(bdt.MaxNoise_SumCount>80)
{
bdt.MaxNoise_SumCount = 0;
bdt.MaxNoise_Sum = 0;
bdt.updatecount = 100;
bdt.PowerOnWithFinger = 1;
return;
}
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void Baseline_FingerJuge(uint16_t *buffer)
{
#ifdef BSLN_WATERJUDGE
uint16_t num,flag,x,y;
if( bdt.BFD.BufDeltSum > 10 ) // ??????
{
bdt.PowerOnWithFinger = 1;
bdt.BFD.BufAbnomalProtectflag = 1; //异常保护时间标志
bdt.BFD.BufAbnomalflag = 1;
bdt.BFD.WaterProtectTime = 0;
return;
} // 处理有水上电
if(bdt.BFD.WaterProtectTime < 100 && bdt.BFD.BufAbnomalProtectflag == 1)
{
bdt.PowerOnWithFinger = 1;
return;
}
if(bdt.BFD.BufAbnomalflag == 1)
{
flag = 0;
x = bdt.FRM_MAX_X_XMTR;
y = bdt.FRM_MAX_Y_RECV;
num = abs16(bdt.BFD.BufDatSaved[x][y] - buffer[x*RECV_NUM + y]);
if(num < (bdt.MaxValueInFrame - (bdt.MaxValueInFrame >> 2)))
{
flag = 1;
}
if(flag == 1)
{
bdt.PowerOnWithFinger = 1;
bdt.BFD.BufAbnomalProtectflag = 1; //异常保护时间标志
bdt.BFD.WaterProtectTime = 0;
return;
}
else
{
bdt.BFD.BufAbnomalflag = 0;
bdt.BFD.BufAbnomalProtectflag = 0; //无异常清零
}
}
#endif
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void Baseline_FingerExistedHandled(uint16_t *buffer)
{
uint16_t Min_num,Max_num,i,j;
int16_t Min_sum,Max_sum;
Min_num = 0;
Min_sum = 0;
Max_num = 0;
Max_sum = 0;
Baseline_Fingerupdatenoise();
Baseline_FingerupdateTX();
Baseline_FingerupdateRX();
#ifdef BSLN_WATERJUDGE
Baseline_FingerJuge(buffer);
#endif
if(bdt.PowerOnWithFinger)
return;
if(bdt.MinValueInFrame < (0-(bdt.PCBA.FrameMaxSample<<1)))
{
if(bdt.MEM_MIN_XY_Count > ABNORMAL_HOLD_TIME)
{
if((ABNORMAL_HOLD_TIME+1) == bdt.MEM_MIN_XY_Count)
{
bdt.PowerOnWithFinger = 1;
return ;
}
}
/*****************************************************************************
* 完全相等,似乎是有些太强的条件约束了
*****************************************************************************/
if((bdt.MEM_MIN_X_XMTR == bdt.FRM_MIN_X_XMTR) && (bdt.MEM_MIN_Y_RECV == bdt.FRM_MIN_Y_RECV))
{
for(i=0;i<XMTR_NUM;i++)
for(j=0;j<RECV_NUM;j++)
{
if(bdt.DeltaDat16A[i][j] >= bdt.PCBA.FrameMaxSample)
{
Max_num++;
Max_sum += bdt.DeltaDat16A[i][j];
}else if(bdt.DeltaDat16A[i][j] <= (0 - bdt.PCBA.FrameMaxSample))
{
Min_num++;
Min_sum += bdt.DeltaDat16A[i][j];
}
}
if(0 == Max_num)
{
bdt.MEM_MIN_XY_Count++;
}
else if(Min_num != 0)
{
if((Max_sum/Max_num) + (Min_sum/Min_num) < 5)
{
bdt.MEM_MIN_XY_Count++;
}
}
}
else
{
bdt.MEM_MIN_XY_Count = 0;
}
}
bdt.PowerOnWithFinger = 0;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t Baseline_TwoFrameBufDelta(uint16_t *buffer)
{
#ifdef BSLN_WATERJUDGE
uint16_t i,j;
uint16_t buf[XMTR_NUM * RECV_NUM];
bdt.BFD.BufDeltSum = 0;
bdt.BFD.BufDeltMax = 0;
for (i=0;i<XMTR_NUM;i++)
for (j=0;j<RECV_NUM;j++)
{
buf[ (i*RECV_NUM) + j] = abs16(buffer[(i*RECV_NUM) + j] - bdt.BFD.BufDatSaved[i][j]);
bdt.BFD.BufDeltSum+=buf[ (i*RECV_NUM) + j];
if(bdt.BFD.BufDeltMax < buf[ (i*RECV_NUM) + j])
{
bdt.BFD.BufDeltMax = buf[ (i*RECV_NUM) + j];
}
}
bdt.BFD.BufDeltSum = bdt.BFD.BufDeltSum >> 7; //相邻两帧无指原始值的差值
if(bdt.BFD.BufDeltSum > 5 || bdt.BFD.BufDeltMax > 25)
return 1;
else
return 0;
//根据原始值变化判断是否有水滴被擦除
#endif
return 0;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint8_t Baseline_HugeInvalidDatainDeltaFrame(void)
{
uint8_t result = BASE_FRAME_HOLD;
uint16_t Min_num,Max_num,i,j;
int16_t Min_sum,Max_sum;
Min_num = 0;
Min_sum = 0;
Max_num = 0;
Max_sum = 0;
/*********************************************************************************
* If we have large value ,update base data, +100/-100
*********************************************************************************/
if(bdt.MaxValueInFrame > bdt.PCBA.FrameMaxSample)
{
if(bdt.MEM_MAX_XY_Count > ABNORMAL_HOLD_TIME)
{
/*bdt.MEM_MAX_XY_Count = 0;*/
result = BASE_FRAME_UPDATE;
}
/*****************************************************************************
* 完全相等,似乎是有些太强的条件约束了
*****************************************************************************/
if((bdt.MEM_MAX_X_XMTR == bdt.FRM_MAX_X_XMTR) && (bdt.MEM_MAX_Y_RECV == bdt.FRM_MAX_Y_RECV))
{
bdt.MEM_MAX_XY_Count++;
}
else
{
bdt.MEM_MAX_XY_Count = 0;
}
}
else
{
bdt.MEM_MAX_XY_Count = 0;
}
if(bdt.MinValueInFrame<(0-bdt.PCBA.FrameMaxSample))
{
/*CN1100_print("2."); */
if(bdt.MEM_MIN_XY_Count > ABNORMAL_HOLD_TIME)
{
/*bdt.MEM_MIN_XY_Count = 0; */
result = BASE_FRAME_UPDATE;
}
/*****************************************************************************
* 完全相等,似乎是有些太强的条件约束了
*****************************************************************************/
/*CN1100_print("X0,X1,Y0,Y1=%d,%d,%d,%d\n",bdt.MEM_MIN_X_XMTR,bdt.FRM_MIN_X_XMTR,bdt.MEM_MIN_Y_RECV,bdt.FRM_MIN_Y_RECV);*/
if((bdt.MEM_MIN_X_XMTR == bdt.FRM_MIN_X_XMTR) && (bdt.MEM_MIN_Y_RECV == bdt.FRM_MIN_Y_RECV))
{
for(i=0;i<XMTR_NUM;i++)
for(j=0;j<RECV_NUM;j++)
{
if(bdt.DeltaDat16A[i][j] >= bdt.PCBA.FrameMaxSample)
{
Max_num++;
Max_sum += bdt.DeltaDat16A[i][j];
}else if(bdt.DeltaDat16A[i][j] <= (0 - bdt.PCBA.FrameMaxSample))
{
Min_num++;
Min_sum += bdt.DeltaDat16A[i][j];
}
}
if(0 == Max_num)
{
bdt.MEM_MIN_XY_Count++;
}
else if(Min_num != 0)
{
if((Max_sum/Max_num) + (Min_sum/Min_num) < 5)
{
bdt.MEM_MIN_XY_Count++;
}
}
}
else
{
bdt.MEM_MIN_XY_Count = 0;
}
}
else
{
bdt.MEM_MIN_XY_Count = 0;
}
return result;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint8_t Baseline_ManyBigInvalidSampleinDeltaFrame(void)
{
uint16_t i, j;
uint32_t temp_count = 0;
/***********************************************************************
* 如果一个差分帧内:
* 数值超过"bdt.PCBA.AbnormalMaxDiff = ABNORMAL_MAX_DIFF(15)"
* 个数超过"bdt.PCBA.AbnormalNumDiff = ABNORMAL_NUM_DIFF(1/4帧)"
* 次数超过 ABNORMAL_HOLD_TIME(5)
***********************************************************************/
for (i=0;i<XMTR_NUM;i++)
for (j=0;j<RECV_NUM;j++)
{
if(abs16(bdt.DeltaDat16A[i][j]) <= bdt.ThresholdInFrame)
if(abs16(bdt.DeltaDat16A[i][j]) >= bdt.PCBA.AbnormalMaxDiff)
temp_count++;
}
if(temp_count > bdt.PCBA.AbnormalNumDiff)
{
bdt.BFD.AbnormalUpdateDelay++;
if(bdt.BFD.AbnormalUpdateDelay > ABNORMAL_HOLD_TIME)
{
return BASE_FRAME_UPDATE;
}
}
else
{
bdt.BFD.AbnormalUpdateDelay = 0;
}
return BASE_FRAME_HOLD;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint8_t Baseline_IsNeedUpdateBaseBuffer(void)
{
uint16_t i, j;
uint8_t result = BASE_FRAME_HOLD;
/*********************************************************************************
* Step 1: Compute the sum of delta data
*********************************************************************************/
bdt.BFD.DeltaSum = 0;
for (i=0;i<XMTR_NUM;i++)
for (j=0;j<RECV_NUM;j++)
{
bdt.BFD.DeltaSum += abs16(bdt.DeltaDat16A[i][j]);
}
/*********************************************************************************
* Step 2: We have two cases to handle
* Case 1: It's time to update, we should make sure that we do it or not.
* Case 2: It's Time to hold, but already updated base for a while
*********************************************************************************/
switch(bdt.BFD.bbdc.BaseUpdateCase)
{
case BASELINE_UPDATING_CASE:
{
/*************************************************************************
* 这是主动要Update Baseline的时刻
*************************************************************************/
if(bdt.BFD.AfterBaseUpdatedTime < MAX_HOLDTIME_AFTERUPDATE)
{
return BASE_FRAME_HOLD;
}
if(bdt.BFD.FingerLeftProtectTime < bdt.PCBA.ProtectTime)
{
return BASE_FRAME_HOLD;
}
if(bdt.BFD.TooLongTime4BaseUpdate >= bdt.PCBA.MaxUpdateTime)
{
/**********************************************************
* 主动要Update的时刻,差分值一直都够小,很久了...
**********************************************************/
bdt.BFD.bbdc.BaseUpdateCase = BASELINE_HOLDING_CASE;
bdt.BFD.TooLongTime4BaseUpdate = 0;
}
else
{
/**********************************************************
* 主动要Update的时刻,必须差分值够小才可以做这件事
**********************************************************/
if(bdt.BFD.DeltaSum < (bdt.BFD.DeltaSumMaxThreshold) )
{
return BASE_FRAME_UPDATE;
}
else
{
return BASE_FRAME_HOLD;
}
}
break;
}
case BASELINE_HOLDING_CASE:
{
if(BASE_FRAME_UPDATE == Baseline_HugeInvalidDatainDeltaFrame())
{
return BASE_FRAME_UPDATE;
}
if(BASE_FRAME_UPDATE == Baseline_ManyBigInvalidSampleinDeltaFrame())
{
return BASE_FRAME_UPDATE;
}
/*********************************************************************************
* If Update base data is not happened for more than MaxUpdateTime,
* update base data shall be happened
*********************************************************************************/
if(bdt.BFD.TooLongTime4BaseUpdate >= bdt.PCBA.MaxUpdateTime)
{
/*****************************************************************************
* It is too loog without update, we have to update base now;
*****************************************************************************/
bdt.BFD.bbdc.BaseUpdateCase = BASELINE_UPDATING_CASE;
bdt.BFD.TooLongTime4BaseUpdate = 0;
}
break;
}
default:
break;
}
return result;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void Baseline_BaseBufferHandled(uint16_t *buffer)
{
int i, j;
/************************************************************************
* if bufdata is abnormal, Hold for Protection Time
************************************************************************/
#ifdef BSLN_WATERJUDGE
if( bdt.BFD.BufAbnomalProtectflag == 1)
{
bdt.BFD.WaterProtectTime++;
}
#endif
/************************************************************************
* After finger is just left, Hold for Protection Time
************************************************************************/
if(bdt.BFD.FingerLeftProtectTime < bdt.PCBA.ProtectTime)
{
bdt.BFD.FingerLeftProtectTime++;
}
/************************************************************************
* Too Long for us not to Update Baseline: MAX_MUST_UPDATE_PERIOD(4000)
************************************************************************/
if(bdt.BFD.TooLongTime4BaseUpdate < bdt.PCBA.MaxUpdateTime)
{
bdt.BFD.TooLongTime4BaseUpdate++;
}
/************************************************************************
* After Updating Baseline, Hold for: MAX_HOLDTIME_AFTERUPDATE (2000)
************************************************************************/
if(bdt.BFD.AfterBaseUpdatedTime < MAX_HOLDTIME_AFTERUPDATE)
{
bdt.BFD.AfterBaseUpdatedTime++;
}
#ifdef TPD_PROXIMITY
if(FACE_DETECT_NEAR == bdt.FDC.Flag) return;
#endif
if(bdt.BFD.bbdc.FingerExist == NO_FINGER)
{
#if ( defined (CONFIG_ARCH_SUN8IW3P1) || defined (CONFIG_ARCH_SUN8IW5P1) )// A23 and A33 || defined(CN1100_ATM)
if(bdt.updatecount)
bdt.updatecount--;
#endif
#ifdef BSLN_WATERJUDGE
k = Baseline_TwoFrameBufDelta(buffer);
#endif
/*******************************************************
* Record how many time for the case of NO_FINGER
*******************************************************/
bdt.MTD.NoFingerCnt4Doze++;
if(BASE_FRAME_HOLD == Baseline_IsNeedUpdateBaseBuffer())
{
/***************************************************
* 基准值不需要更新, 于此故意设为有手指
***************************************************/
bdt.BFD.bbdc.PreFingerExt = FINGER_SHOW;
return;
}
#ifdef BSLN_WATERJUDGE
if(k > 0)
{
/***************************************************
* 原始值错误停止更新
***************************************************/
bdt.BFD.BufAbnomalflag = 1;
bdt.BFD.bbdc.NoFingerCnt4Base = 0;
bdt.BFD.bbdc.PreFingerExt = FINGER_SHOW;
return;
}
#endif
if(bdt.BFD.bbdc.PreFingerExt != bdt.BFD.bbdc.FingerExist)
{
/*******************************************************
* 更新基准数据,于此是第一帧,总共要4帧才得完成
*******************************************************/
bdt.BFD.bbdc.NoFingerCnt4Base = 0;
for (i=0;i<XMTR_NUM;i++)
for (j=0;j<RECV_NUM;j++)
{
bdt.BFD.SumBaseDat[i][j] = buffer[ (i*RECV_NUM) + j];
}
}
else
{
for (i=0;i<XMTR_NUM;i++)
for (j=0;j<RECV_NUM;j++)
{
bdt.BFD.SumBaseDat[i][j] += buffer[ (i*RECV_NUM) + j];
}
}
bdt.BFD.bbdc.NoFingerCnt4Base++;
if(BASE_COUNT_MAX == bdt.BFD.bbdc.NoFingerCnt4Base)
{
/****************************************************************
* 四帧无手指原始数据求和,得到基准数据
****************************************************************/
if(bdt.BaseChangeFlag < 65535) bdt.BaseChangeFlag++; /* Counting 1 for baseline updating */
if(bdt.BaseChangeFlag<=3)
{
bdt.BFD.TooLongTime4BaseUpdate = MAX_MUST_UPDATE_PERIOD - 20; /* Reset the Timing Count*/
bdt.BFD.AfterBaseUpdatedTime = MAX_HOLDTIME_AFTERUPDATE - 20; /* Reset the Timing Count*/
}
else
{
bdt.BFD.TooLongTime4BaseUpdate = 0; /* Reset the Timing Count */
bdt.BFD.AfterBaseUpdatedTime = 0; /* Reset the Timing Count */
}
bdt.MEM_MAX_XY_Count = 0;
bdt.BFD.bbdc.BaseUpdateCase = BASELINE_HOLDING_CASE;
#ifdef STM32VC_LCD
#ifdef FHBS_DEBUG_INFOSHOW
TFT_ShowNum(10, 20, bdt.BaseChangeFlag, LCD_COLOR_BLUE, LCD_COLOR_GREEN);
#endif
#endif
for(i=0;i<XMTR_NUM;i++)
for(j=0;j<RECV_NUM;j++)
{
/************************************************
* 1. 利用上次得到的基准数据
* 2. 记录这次得到的基准数据,以备下次使用
************************************************/
bdt.BFD.BaseDat[i][j] = bdt.BFD.BaseDatSaved[i][j];
bdt.BFD.BaseDatSaved[i][j] = (bdt.BFD.SumBaseDat[i][j])>>BASE_FRAME_SHIFT;
bdt.BFD.SumBaseDat[i][j] = 0;
}
/*****************************************************************
* Reset the Base Data Frame Integration
*****************************************************************/
bdt.BFD.bbdc.NoFingerCnt4Base = 0;
}
}
else
{
bdt.BFD.bbdc.NoFingerCnt4Base = 0;
bdt.BFD.FingerLeftProtectTime = 0;
Baseline_FingerExistedHandled(buffer);
if(0 == bdt.PrevFingerDetectNum2)
{
for (i=0;i<XMTR_NUM;i++)
for (j=0;j<RECV_NUM;j++)
{
bdt.BFD.BaseDatSaved[i][j] = bdt.BFD.BaseDat[i][j];
}
}
/*******************************************************
* Reset the Record = 0 when any finger is coming
*******************************************************/
bdt.MTD.NoFingerCnt4Doze = 0;
}
/****************************************
* Save the Finger existing status
****************************************/
bdt.BFD.bbdc.PreFingerExt = bdt.BFD.bbdc.FingerExist;
}
/*******************************************************************************
* Function Name : FingProc_Dist2PMeasure
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t FingProc_Dist2PMeasure(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
int16_t x, y, t;
int16_t distance;
x = x1 - x2;
y = y1 - y2;
if(x<0)
{
x = 0 - x;
}
if(y<0)
{
y = 0 - y;
}
t = y - x;
if(t>=0)
{
y -= t;
x += t;
}
distance = x + (y>>3) + (y>>2);
return ((uint16_t)distance);
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
uint16_t FingProc_Dist4Uint16Var(uint16_t x0, uint16_t x1)
{
if(x0>x1)
{
return (x0-x1);
}
else
{
return (x1-x0);
}
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void FingProc_DistanceFilter(uint16_t i, uint16_t x1, uint16_t y1, uint16_t *pX, uint16_t *pY)
{
}