You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1006 lines
15 KiB

4 years ago
//////////////////////////////////////////////////////////////////////////
/// COPYRIGHT NOTICE
/// Copyright (c) 2015, ���ؿƼ�
/// All rights reserved.
///
/// @file app_ALGOration.c
/// @brief app_ALGOration app
///
///�����ļ�ʵ�ֵĹ��ܵ�������
///
/// @version 1.1 CCsens technology
/// @author CC
/// @date 20190105
///
///
/// �޶�˵���������汾
/// Modified by:
/// Modified date:
/// Version:
/// Descriptions:
/// �㷨��
//////////////////////////////////////////////////////////////////////////
///#include "app_calibration.h"
#include "app_algorithm.h"
#include "app_flow.h"
#include "app_paraid.h"
////#include "app_rfSend.h"
#include "../clib/Clib.h"
#include "../clib/bit.h"
///
#ifdef D_buf_test
U8 test_buf[];
U8 test_buf2[660];
#endif
#include "../bsp/bsp_power.h"
#if 0
s1 һҪȥ
s2 ͨ˲ƽƽ,ֵ
s3 ܵʽ
s4 й
low=0 low=0
```````\ /````````````\ /``````
\ / \ /
\ low++ / \ low++ /
0 zero....\.low_zero=low....../..................\.................../........
\ / \ /
\ ___/ \ ___/
\___ / \___ /
\ /high++ \ /
\___/ \___/
high=0
low
/`````````\
/ \
__________________/ \______________
#endif
//>>>>>>>>>>>>>>>>>>>>>0����task
///L2_task_C2_init();
#if 0
1 ֵ
2
3 ֵ
4
1 ֵ
2 ֵ
4
ֵ ֽ
0 ,0
sum, 100
x*k = Sum
100k = Sum100
k=Sum100/100;
x=Sum/k
Sum
x=-------
k
Sum
x=------------
Sum100/100
Sum*100
x = ----------
Sum100
U8 L2_task_ALGO_at(void)
{
}
#endif
vU16 L2_line_algo_media(U8 *buf,vU16 len);
TS_task_ALGO_ ts_task_ALGO;
void L2_task_ALGO_init(void)
{
/// ts_task_ALGO.status = 0;
L1_task_init(&ts_task_ALGO.task);
/// ts_task_ALGO.p_buf2 = s_task_GC032A.buf;
/// ts_task_ALGO.t = 0;
L3_task_s_go(ts_task_ALGO,D_task_init);
}
//>>>>>>>>>>>>>>>>>>>>>0����task
///L2_task_ALGO_init();
///L2_task_ALGO_handle(&ts_task_ALGO);
/// ��������Ҫ���вɼ����ɵı�־��, ����ֵ�˲���������,Ȼ����������(ƽ�� ��ֵ),����
void L2_task_ALGO_handle(TS_task_ALGO_ *s)
{
TTSS_Task_init():
s->ok = D_clear;
s->cali_mode = D_clear;
L2_task_go(D_task_ALGO_wait);
TTSS_Task_step(D_task_ALGO_wait):
TTSS_Task_step(D_task_ALGO_median):
/// s->usSum = L2_line_algo_media(s_task_GC032A.buf,D_pclk_per_hs_570);
L2_task_go(D_task_ALGO_updown);
TTSS_Task_step(D_task_ALGO_updown):
s->usPaperNum = 0xAAAA;
if(s->usSum >= D_paper_EE)///����ͷ���Ż���ǿ��
{
}
else if(s->usSum > D_paper_MAX)////ֽ�Ŵ���������
{
s->usPaperSection = D_cam_top;
}
else if(s->usSum > D_paper_150at_bottom)///bottom --top
{///
s->usPaperSection = D_cam_150at;
}
else if(s->usSum > D_paper_00)//// 0---max ֽ�ŷ����仯 ���� С��������
{
s->usPaperSection = D_cam_00;
//s->usSum
}
else
{
s->usPaperSection = D_cam_erro;
}
/***
if(s_task_GC032A.buf[4] < D_F_low)
{
TS_paer_value.r123.work_mode = D_ready;
}else
{
TS_paer_value.r123.work_mode = D_clear;
}
************/
/// 0----0
/// x -----usSum
///150----usPaper150
/// 3000
s->usPaperNum = s->usSum*15;
s->ustMP = s->usPaper150 / 10;
s->usPaperNum /= s->ustMP;
///
#define D_debug_add_send
#ifdef D_debug_add_send
PrintAlgo_D_send_us(s->usSum);PrintAlgo_L0_uart0_uc(0x09);
PrintAlgo_D_send_us(s->usPaper150);PrintAlgo_L0_uart0_uc(0x09);
PrintAlgo_D_send_us(s->usPaperNum);
//PrintCam_L0_uart0_uc(0x0d);/PrintCam_L0_uart0_uc(0x0a);
#endif
L2_task_go(D_task_ALGO_wait);
/// L2_task_go(D_task_ALGO_cali_mode);
/**************
TTSS_Task_step(D_task_ALGO_cali_mode)
if(D_ON == s->cali_mode)
{///PrintFlow_L0_uart0_uc(0x30+s->cali_delay);
L2_task_go(D_task_ALGO_cali_save);
}else
{
/// ts_task_FLOW.t_stamp_set = 5;// 20s * =
/// LD_gsensor_power(D_PowerMode_suspend);
if(D_cam_EE == s->usPaperSection)
{PrintAlgo_L0_uart0_uc('a');
LD_gsensor_power(D_PowerMode_low);
L3_task_s_go(ts_task_FLOW,0);
L2_task_go(D_task_ALGO_cali_wait);
}else
{
L2_task_go(D_task_ALGO_cali_end);
}
}
TTSS_Task_step(D_task_ALGO_cali_save)
if(s->cali_delay ++ > 8)
{///PrintFlow_L0_uart0_uc('c');
L2_task_go(D_task_ALGO_cali_end);
}else
{///��ʱδ����
L2_task_go(D_task_ALGO_sa);
if(D_cam_150at == s->usPaperSection)
{
//PrintFlow_L0_uart0_uc('a');
if(s->cali_timer ++ > 2)
{
s->usPaper150 = s->usSum; ///
L1_Iap_Write_us(D_paraAdd0_paper150,s->usPaper150);
L1_Iap_Write_us(D_paraAdd1_paper150,s->usPaper150);
PrintAlgo_L0_uart0_uc('f');///PrintFlow_str("flash", 5);
TS_paer_value.r123.cali_timer ++;
L2_task_go(D_task_ALGO_cali_end);
}
}
}
TTSS_Task_step(D_task_ALGO_cali_wait)
/// ֻ��û���жϵ��������ٴε��û��ſ��Եؽ���cali ģʽ
Lc_delay_ms(1);
L0_mcu_WKTC(D_WKTC_500MS); //������ʱ��
L0_mcu_mode_powerdown();//��������״̬
if(BITN_G(DR_who_wakeup, DRB_who_wakeup_action))
{
BITN_0(DR_who_wakeup, DRB_who_wakeup_action);
PrintAlgo_L0_uart0_uc(s->cali_hit+0x30);
// PrintCam_L0_uart0_uc('#');
if(s->cali_hit++ > 22)
{s->cali_hit = 0;
s->hit_ok = D_ready;
PrintAlgo_L0_uart0_uc('L');
s->cali_mode = D_ON;s->cali_timer = s->cali_mode;
TS_paer_value.r123.cali_mode = 1;
L2_task_go(D_task_ALGO_sa);
}
}else
{
s->cali_hit = 0;
if(s->cali_over ++ > 25)///500ms*25 = 50s
{
s->cali_over = 0;
L2_task_go(D_task_ALGO_cali_end);
}
}
TTSS_Task_step(D_task_ALGO_cali_end)
// PrintFlow_str("cali end", 9);//
// PrintAlgo_L0_uart0_uc('E');
s->cali_mode = D_clear;
TS_paer_value.r123.cali_mode = s->cali_mode;
s->cali_delay = 0;
/// L3_task_s_go(ts_task_FLOW,D_task_init);
//
L2_task_go(D_task_ALGO_wait);
TTSS_Task_step(D_task_ALGO_sa)
L3_task_s_go(ts_task_FLOW,D_task_FLOW_wakeup);
L2_task_go(D_task_ALGO_wait);
*****************/
TTSS_Task_end();
}
/****************************
TTSS_Task_step(D_task_ALGO_updown)
L0_uart0_sendArray("paper =", 7);
D_send_ushex(s->usSum);L0_uart0_uc('-');
#define D_paper_max 0x0b10
///0x0b1d 2845
L2_task_go(D_task_ALGO_cal)
//L1_task_Tdelay(D_Tdelay_10ms);
TTSS_Task_step(D_task_ALGO_cal)
#ifdef D_debug_add_send
// L2_line_send();/// �����ݷ�����ȥ������ʹ�� s_task_GC032A.buf
// D_send_us(DR_pclk_n);
//
#endif
s->usSum *= 10; // sum������ֵ���ܳ���
s->usPaper = s->usSum/s->usSum100;
s->ok = D_ready;
L2_task_go(D_task_ALGO_wait);
#define D_F_low 30
#define D_F_high 40
#define D_F_diff 10 //D_F_high - D_F_low
cam һݵǰһ
16
16
16
16
17
18
19
22
25
26
26
27
29
28
28
27
27
26
26
26
25
25
/// ȥ���� ����
/// ______/\___________
/// / \
/// / ...............................\--high
/// / \
/// / \
/// / low \---low
///-16 17-- \
///
***************************/
///#define D_F_low 23
///#define D_F_high 30
///#define D_F_diff 5 //D_F_high - D_F_low
///#define D_F_diff (D_F_high - D_F_low)
vU16 L2_line_algo_media(U8 *buf,vU16 len)
{
vU16 i,usV = 0;//,usi = 0;
U8 cache[3];
U8 f1;
for(i = 1;i < len;i ++)
{
cache[2] = cache[1];
cache[1] = cache[0];
cache[0] = buf[i];
f1 = Lc_U8_media3(cache[2],cache[1],cache[0]);
///--------------------------------------------------
if(f1 > D_F_low)//>
{
if(f1 > D_F_high)//>40
{
f1 = D_F_diff;// 10
}else
{
f1 -= D_F_low;// 40 30
}
}else
{// <=low
f1 = 0;
}
///--------------------------------------------------
/// buf[i] = f1;
usV += f1;///����ֵ 570*7 640*10 =6,400 65,535
}
return usV;
}
#if 0
/// // s->usSum = L2_line_algo_media(test_buf,639);
if(ts_task_ALGO.usSum_temp > D_line_sum)
{
////L3_task_s_go(ts_task_CALIB,D_task_CALIB_wait);
}
if(s->usSum_temp != s->usSum)
{
s->t++;
}else
{
s->t = 0;
}
if(s->t > 5)
{
L0_uart0_uc('X');
}else
{
L0_uart0_uc('F');
}
D_send_ushex(s->t);L0_uart0_uc(0x09);
TTSS_Task_step(D_task_ALGO_updown);
/// // s->usSum = L2_line_algo_media(test_buf,639);
if(ts_task_ALGO.usSum_temp > D_line_sum)
{
////L3_task_s_go(ts_task_CALIB,D_task_CALIB_wait);
}
if(s->usSum_temp >= s->usSum)
{
s->t = s->usSum_temp - s->usSum;
}else
{
s->t = s->usSum - s->usSum_temp;
}
/// L0_uart0_uc(0x09);
L0_uart0_sendArray("paper =", 9);
D_send_ushex(s->usSum);L0_uart0_uc('-');
D_send_ushex(s->usSum_temp);L0_uart0_uc('=');
s->usSum_temp = s->usSum;
#define D_paper_max 2000
///0x0b1d 2845
if(s->usSum > 0x0b10)
{
s->paperMode = D_max;
}else
{
s->paperMode = D_diff;
}
if(s->t > D_paper_max)
{
L0_uart0_uc('X');
}else
{
L0_uart0_uc('F');
}
D_send_ushex(s->t);L0_uart0_uc(0x09);
L2_task_go(D_task_ALGO_cal);
//L1_task_Tdelay(D_Tdelay_10ms);
L2_task_go(D_task_ALGO_updown);
TTSS_Task_step(D_task_ALGO_updown);
s->usLong = L2_line_algo_updown(s->p_buf2,639);
vU16 L2_line_algo_updown(U8 *p_buf,U8 len)
{
vU16 us_i = 0,up_point = 0,down_point = 0;
down_point = DR_pclk_n;
for(us_i = 1;us_i < len ;us_i ++)
{
if((p_buf[us_i - 1] == 0)&&
(p_buf[us_i] == 1))//// _/``������
{
if(p_buf[us_i + 1] == 0)
{//_/`\_ ������Ҫ����
gRccUs03 ++;
}else
{// ___/````�����ؿ�ʼ�ߵ�ƽ
up_point = us_i;
}
}else if((p_buf[us_i - 1] == 1)&&
(p_buf[us_i] == 0))//// ``\_ �½���
{
down_point = gRccUs03;
}else
{
}
}
us_i = down_point - up_point;
return us_i;
}
#endif
#if 0 ///def D_buf_test
U8 test_buf[]
={
19 ,// 0
19 ,// 1
19 ,// 2
20 ,// 3
20 ,// 4
20 ,// 5
20 ,// 6
20 ,// 7
20 ,// 8
20 ,// 9
19 ,// 10
119 ,// 11
19 ,// 12
19 ,// 13
19 ,// 14
19 ,// 15
19 ,// 16
20 ,// 17
20 ,// 18
20 ,// 19
20 ,// 20
20 ,// 21
20 ,// 22
20 ,// 23
20 ,// 24
20 ,// 25
19 ,// 26
19 ,// 27
19 ,// 28
119 ,// 29
19 ,// 30
19 ,// 31
19 ,// 32
19 ,// 33
19 ,// 34
19 ,// 35
19 ,// 36
19 ,// 37
19 ,// 38
19 ,// 39
19 ,// 40
20 ,// 41
20 ,// 42
19 ,// 43
19 ,// 44
19 ,// 45
19 ,// 46
20 ,// 47
20 ,// 48
20 ,// 49
19 ,// 50
19 ,// 51
19 ,// 52
19 ,// 53
19 ,// 54
20 ,// 55
20 ,// 56
20 ,// 57
19 ,// 58
19 ,// 59
19 ,// 60
20 ,// 61
20 ,// 62
20 ,// 63
20 ,// 64
20 ,// 65
20 ,// 66
20 ,// 67
20 ,// 68
20 ,// 69
120 ,// 70
19 ,// 71
19 ,// 72
19 ,// 73
20 ,// 74
20 ,// 75
20 ,// 76
20 ,// 77
20 ,// 78
20 ,// 79
20 ,// 80
20 ,// 81
20 ,// 82
20 ,// 83
20 ,// 84
20 ,// 85
20 ,// 86
20 ,// 87
20 ,// 88
20 ,// 89
20 ,// 90
20 ,// 91
20 ,// 92
121 ,// 93
20 ,// 94
20 ,// 95
20 ,// 96
20 ,// 97
20 ,// 98
21 ,// 99
21 ,// 100
21 ,// 101
22 ,// 102
24 ,// 103
26 ,// 104
28 ,// 105
30 ,// 106
32 ,// 107
35 ,// 108
38 ,// 109
40 ,// 110
42 ,// 111
44 ,// 112
146 ,// 113
50 ,// 114
51 ,// 115
52 ,// 116
52 ,// 117
53 ,// 118
53 ,// 119
54 ,// 120
54 ,// 121
55 ,// 122
55 ,// 123
55 ,// 124
55 ,// 125
55 ,// 126
56 ,// 127
55 ,// 128
55 ,// 129
55 ,// 130
56 ,// 131
55 ,// 132
155 ,// 133
54 ,// 134
53 ,// 135
53 ,// 136
52 ,// 137
52 ,// 138
52 ,// 139
51 ,// 140
49 ,// 141
45 ,// 142
43 ,// 143
41 ,// 144
39 ,// 145
38 ,// 146
36 ,// 147
34 ,// 148
31 ,// 149
129 ,// 150
28 ,// 151
28 ,// 152
27 ,// 153
27 ,// 154
27 ,// 155
27 ,// 156
27 ,// 157
27 ,// 158
26 ,// 159
26 ,// 160
26 ,// 161
25 ,// 162
25 ,// 163
24 ,// 164
25 ,// 165
25 ,// 166
25 ,// 167
25 ,// 168
25 ,// 169
24 ,// 170
24 ,// 171
24 ,// 172
23 ,// 173
23 ,// 174
22 ,// 175
23 ,// 176
22 ,// 177
22 ,// 178
22 ,// 179
22 ,// 180
22 ,// 181
22 ,// 182
22 ,// 183
21 ,// 184
21 ,// 185
21 ,// 186
21 ,// 187
21 ,// 188
22 ,// 189
21 ,// 190
21 ,// 191
21 ,// 192
21 ,// 193
21 ,// 194
21 ,// 195
21 ,// 196
21 ,// 197
21 ,// 198
121 ,// 199
21 ,// 200
21 ,// 201
21 ,// 202
21 ,// 203
21 ,// 204
21 ,// 205
21 ,// 206
21 ,// 207
21 ,// 208
21 ,// 209
20 ,// 210
20 ,// 211
20 ,// 212
20 ,// 213
20 ,// 214
20 ,// 215
21 ,// 216
21 ,// 217
21 ,// 218
20 ,// 219
21 ,// 220
21 ,// 221
20 ,// 222
120 ,// 223
20 ,// 224
20 ,// 225
20 ,// 226
20 ,// 227
20 ,// 228
20 ,// 229
20 ,// 230
20 ,// 231
20 ,// 232
19 ,// 233
19 ,// 234
19 ,// 235
19 ,// 236
20 ,// 237
21 ,// 238
21 ,// 239
21 ,// 240
20 ,// 241
20 ,// 242
20 ,// 243
20 ,// 244
20 ,// 245
20 ,// 246
20 ,// 247
20 ,// 248
20 ,// 249
20 ,// 250
21 ,// 251
21 ,// 252
21 ,// 253
21 ,// 254
21 ,// 255
20 ,// 256
20 ,// 257
20 ,// 258
20 ,// 259
20 ,// 260
20 ,// 261
20 ,// 262
20 ,// 263
20 ,// 264
20 ,// 265
19 ,// 266
19 ,// 267
19 ,// 268
19 ,// 269
19 ,// 270
19 ,// 271
19 ,// 272
19 ,// 273
19 ,// 274
19 ,// 275
19 ,// 276
19 ,// 277
19 ,// 278
19 ,// 279
19 ,// 280
19 ,// 281
19 ,// 282
20 ,// 283
20 ,// 284
20 ,// 285
20 ,// 286
119 ,// 287
19 ,// 288
19 ,// 289
19 ,// 290
19 ,// 291
19 ,// 292
19 ,// 293
19 ,// 294
19 ,// 295
19 ,// 296
19 ,// 297
19 ,// 298
19 ,// 299
19 ,// 300
19 ,// 301
19 ,// 302
19 ,// 303
19 ,// 304
19 ,// 305
19 ,// 306
19 ,// 307
49 ,// 308
19 ,// 309
20 ,// 310
19 ,// 311
19 ,// 312
19 ,// 313
19 ,// 314
19 ,// 315
20 ,// 316
19 ,// 317
19 ,// 318
19 ,// 319
19 ,// 320
19 ,// 321
19 ,// 322
19 ,// 323
19 ,// 324
19 ,// 325
19 ,// 326
19 ,// 327
19 ,// 328
19 ,// 329
20 ,// 330
20 ,// 331
20 ,// 332
19 ,// 333
20 ,// 334
20 ,// 335
20 ,// 336
20 ,// 337
20 ,// 338
19 ,// 339
19 ,// 340
19 ,// 341
19 ,// 342
19 ,// 343
19 ,// 344
19 ,// 345
19 ,// 346
19 ,// 347
20 ,// 348
20 ,// 349
20 ,// 350
20 ,// 351
20 ,// 352
20 ,// 353
20 ,// 354
20 ,// 355
19 ,// 356
19 ,// 357
19 ,// 358
19 ,// 359
19 ,// 360
19 ,// 361
19 ,// 362
19 ,// 363
19 ,// 364
19 ,// 365
19 ,// 366
19 ,// 367
19 ,// 368
19 ,// 369
19 ,// 370
19 ,// 371
19 ,// 372
19 ,// 373
19 ,// 374
19 ,// 375
19 ,// 376
19 ,// 377
19 ,// 378
19 ,// 379
19 ,// 380
19 ,// 381
19 ,// 382
19 ,// 383
19 ,// 384
19 ,// 385
19 ,// 386
19 ,// 387
20 ,// 388
20 ,// 389
19 ,// 390
19 ,// 391
19 ,// 392
19 ,// 393
19 ,// 394
19 ,// 395
19 ,// 396
19 ,// 397
19 ,// 398
19 ,// 399
19 ,// 400
19 ,// 401
19 ,// 402
19 ,// 403
19 ,// 404
19 ,// 405
19 ,// 406
19 ,// 407
19 ,// 408
19 ,// 409
19 ,// 410
20 ,// 411
19 ,// 412
19 ,// 413
19 ,// 414
19 ,// 415
19 ,// 416
19 ,// 417
19 ,// 418
19 ,// 419
19 ,// 420
19 ,// 421
19 ,// 422
19 ,// 423
19 ,// 424
19 ,// 425
19 ,// 426
19 ,// 427
19 ,// 428
19 ,// 429
19 ,// 430
19 ,// 431
19 ,// 432
19 ,// 433
19 ,// 434
19 ,// 435
19 ,// 436
20 ,// 437
19 ,// 438
19 ,// 439
19 ,// 440
19 ,// 441
19 ,// 442
19 ,// 443
19 ,// 444
19 ,// 445
19 ,// 446
19 ,// 447
19 ,// 448
19 ,// 449
19 ,// 450
19 ,// 451
19 ,// 452
19 ,// 453
19 ,// 454
19 ,// 455
19 ,// 456
19 ,// 457
19 ,// 458
19 ,// 459
19 ,// 460
19 ,// 461
19 ,// 462
19 ,// 463
19 ,// 464
19 ,// 465
19 ,// 466
19 ,// 467
19 ,// 468
19 ,// 469
19 ,// 470
19 ,// 471
19 ,// 472
19 ,// 473
19 ,// 474
19 ,// 475
19 ,// 476
19 ,// 477
19 ,// 478
19 ,// 479
19 ,// 480
19 ,// 481
19 ,// 482
19 ,// 483
19 ,// 484
19 ,// 485
19 ,// 486
19 ,// 487
19 ,// 488
19 ,// 489
19 ,// 490
19 ,// 491
19 ,// 492
19 ,// 493
19 ,// 494
19 ,// 495
19 ,// 496
19 ,// 497
18 ,// 498
18 ,// 499
18 ,// 500
19 ,// 501
19 ,// 502
19 ,// 503
19 ,// 504
19 ,// 505
19 ,// 506
19 ,// 507
19 ,// 508
19 // 509
};
#endif