-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMuVisionSensor.cpp
More file actions
698 lines (650 loc) · 22.6 KB
/
MuVisionSensor.cpp
File metadata and controls
698 lines (650 loc) · 22.6 KB
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
/*
* MU.cpp
*
* Created on: 2018年8月3日
* Author: ysq
*/
#include "MuVisionSensor.h"
#include "mu_vision_sensor_uart_hw_interface.h"
#include "mu_vision_sensor_i2c_hw_interface.h"
#include "MicroBit.h"
MuVisionSensor::MuVisionSensor(uint32_t address)
: address_(address) {
}
MuVisionSensor::~MuVisionSensor() {
if (mu_vs_method) {
delete mu_vs_method;
}
for (int i = 1; i < kVisionMaxType; i++) {
free_vision_buffer(MuVsMessageVisionType(i));
}
}
uint8_t MuVisionSensor::begin(void* communication_port,
MuVsMode mode = kSerialMode) {
if (mu_vs_method) {
delete mu_vs_method;
mu_vs_method = nullptr;
}
mode_ = mode;
switch (mode) {
case kSerialMode:
if (mu_vs_method == nullptr) {
mu_vs_method = new MuVisionSensorUart((MuVsUart *)communication_port,
address_);
}
break;
case kI2CMode:
if (mu_vs_method == nullptr) {
mu_vs_method = new MuVisionSensorI2C((MuVsI2C *)communication_port,
address_);
}
break;
default:
return MU_ERROR_FAIL;
}
// check vs2 protocol version
uint8_t protocol_version = 0;
int err_count = 0;
while (mu_vs_method->Get(kRegProtocolVersion, &protocol_version)
|| protocol_version != MU_PROTOCOL_VERSION) {
++err_count;
if (err_count > 50) {
delete mu_vs_method;
mu_vs_method = nullptr;
return MU_ERROR_UNSUPPROT_PROTOCOL;
}
}
return MU_OK;
}
//Advance interface
uint8_t MuVisionSensor::VisionBegin(MuVisionType vision_type) {
mu_err_t err;
err = VisionSetDefault(vision_type);
if (err) return err;
err = VisionSetStatus(vision_type, true);
if (err) return err;
err = VisionSetOutputMode(kCallBackMode);
if (err) return err;
return MU_OK;
}
uint8_t MuVisionSensor::VisionEnd(MuVisionType vision_type) {
return VisionSetStatus(vision_type, false);
}
int MuVisionSensor::GetValue(MuVisionType vision_type,
MuVsObjectInf object_inf) {
// uint8_t vision_pointer = 0;
// MuVisionType vision_type_src = vision_type;
// while ((vision_type & 0x01) == 0 && vision_pointer < 8) {
// vision_type = vision_type >> 1;
// vision_pointer++;
// }
// if (vision_state_[vision_pointer] == nullptr) return -1;
// if (object_inf == kStatus) {
// while((UpdateResult(vision_type_src, true)&vision_type_src) == 0);
// }
// return (int)read(vision_type_src, object_inf);
// uint8_t vision_pointer = 0;
// MuVisionType vision_type_src = vision_type;
// while ((vision_type & 0x01) == 0 && vision_pointer < 8) {
// vision_type = vision_type >> 1;
// vision_pointer++;
// }
// if (vision_state_[vision_pointer] == nullptr) return -1;
if (object_inf == kStatus) {
while((UpdateResult(vision_type, true)&vision_type) == 0);
}
return (int)read(vision_type, object_inf);
}
//uint8_t MuVisionSensor::VisionSetEnable(MuVisionType vision_type,
// MuVsStreamOutputMode mode) {
// mu_err_t err;
// output_mode_ = mode;
// MuVsVisionConfig1 vision_config1;
// for (int i = 1; i < kVisionMaxType; i++) {
// err = mu_vs_method->Set(kRegVisionId, i);
// if(err) return err;
// err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
// uint8_t status = (vision_type&visionTypeEnumToMacro(i)) ? 1:0;
// if (vision_config1.status != status
// || vision_config1.output_mode != mode) {
// vision_config1.status = status;
// vision_config1.output_mode = mode;
// err = mu_vs_method->Set(kRegVisionConfig1,
// vision_config1.vision_config_reg_value);
// if (err) return err;
// }
// if (status) {
// malloc_vision_buffer(MuVsMessageVisionType(i));
// } else {
// free_vision_buffer(MuVsMessageVisionType(i));
// }
//// output_mode[i-1] = vision_config1.output_mode;
// }
// return err;
//}
uint8_t MuVisionSensor::VisionSetStatus(MuVisionType vision_type, bool enable) {
mu_err_t err;
MuVsVisionConfig1 vision_config1;
for (int i = 1; i < kVisionMaxType; i++) {
if (vision_type & visionTypeEnumToMacro(i)) {
err = mu_vs_method->Set(kRegVisionId, i);
if(err) return err;
err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
if(err) return err;
if (vision_config1.status != enable) {
vision_config1.status = enable;
err = mu_vs_method->Set(kRegVisionConfig1,
vision_config1.vision_config_reg_value);
if (err) return err;
}
if (enable) {
malloc_vision_buffer(MuVsMessageVisionType(i));
} else {
free_vision_buffer(MuVsMessageVisionType(i));
}
// output_mode[i-1] = vision_config1.output_mode;
output_mode_ = vision_config1.output_mode;
}
}
return MU_OK;
}
//uint8_t MuVisionSensor::VisionSetOutputMode(MuVisionType vision_type,
// MuVsStreamOutputMode mode) {
// mu_err_t err;
// MuVsVisionConfig1 vision_config1;
// output_mode_ = mode;
// for (int i = 1; i < kVisionMaxType; i++) {
//// if (vision_type & visionTypeEnumToMacro(i)) {
// if (output_mode[i-1] != mode) {
// output_mode[i-1] = mode;
// err = mu_vs_method->Set(kRegVisionId, i);
// if(err) return err;
// err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
// if (err) return err;
// vision_config1.output_mode = mode;
// err = mu_vs_method->Set(kRegVisionConfig1,
// vision_config1.vision_config_reg_value);
// if (err) return err;
// }
//// }
// }
// return MU_OK;
//}
uint8_t MuVisionSensor::VisionSetOutputMode(MuVsStreamOutputMode mode) {
mu_err_t err;
MuVsVisionConfig1 vision_config1;
output_mode_ = mode;
for (int i = 1; i < kVisionMaxType; ++i) {
if (vision_state_[i-1] != nullptr) {
err = mu_vs_method->Set(kRegVisionId, i);
if(err) return err;
err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
if (err) return err;
if (vision_config1.output_mode != mode) {
vision_config1.output_mode = mode;
err = mu_vs_method->Set(kRegVisionConfig1,
vision_config1.vision_config_reg_value);
if (err) return err;
}
}
}
return MU_OK;
}
uint8_t MuVisionSensor::VisionSetOutputEnable(MuVisionType vision_type, bool status) {
mu_err_t err;
MuVsVisionConfig1 vision_config1;
for (int i = 1; i < kVisionMaxType; ++i) {
if (vision_type & visionTypeEnumToMacro(i)) {
err = mu_vs_method->Set(kRegVisionId, i);
if(err) return err;
err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
if (err) return err;
if (vision_config1.output_enable != status) {
vision_config1.output_enable = status;
err = mu_vs_method->Set(kRegVisionConfig1,
vision_config1.vision_config_reg_value);
if (err) return err;
}
}
}
return MU_OK;
}
uint8_t MuVisionSensor::VisionSetDefault(MuVisionType vision_type) {
mu_err_t err;
MuVsVisionConfig1 vision_config1;
for (int i = 1; i < kVisionMaxType; ++i) {
if (vision_type & visionTypeEnumToMacro(i)) {
err = mu_vs_method->Set(kRegVisionId, i);
if(err) return err;
err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
if (err) return err;
vision_config1.default_setting = 1;
err = mu_vs_method->Set(kRegVisionConfig1,
vision_config1.vision_config_reg_value);
if (err) return err;
while (vision_config1.default_setting) {
err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
if (err) return err;
}
}
}
return MU_OK;
}
uint8_t MuVisionSensor::VisionSetLevel(MuVisionType vision_type,
MuVsVisionLevel level) {
mu_err_t err;
MuVsVisionConfig1 vision_config1;
for (int i = 1; i < kVisionMaxType; ++i) {
if (vision_type & visionTypeEnumToMacro(i)) {
err = mu_vs_method->Set(kRegVisionId, i);
if(err) return err;
err = mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
if (err) return err;
if (vision_config1.level != level) {
vision_config1.level = level;
err = mu_vs_method->Set(kRegVisionConfig1,
vision_config1.vision_config_reg_value);
if (err) return err;
}
}
}
return MU_OK;
}
bool MuVisionSensor::VisionGetStatus(MuVisionType vision_type) {
uint8_t vision_status1 = 0;
mu_vs_method->Get(kRegVisionConfig1, &vision_status1);
return vision_type&vision_status1;
}
MuVsVisionLevel MuVisionSensor::VisionGetLevel(MuVisionType vision_type) {
MuVsVisionConfig1 vision_config1;
for (int i = 1; i < kVisionMaxType; ++i) {
if (vision_type & visionTypeEnumToMacro(i)) {
mu_vs_method->Set(kRegVisionId, i);
mu_vs_method->Get(kRegVisionConfig1, &vision_config1.vision_config_reg_value);
return vision_config1.level;
}
}
return kLevelDefault;
}
MuVsStreamOutputMode MuVisionSensor::VisionGetOutputMode(void) {
return output_mode_;
}
MuVisionType MuVisionSensor::UpdateResult(MuVisionType vision_type,
bool wait_all_result) {
switch (mode_) {
case kSerialMode:
return UartUpdateResult(vision_type, wait_all_result);
case kI2CMode: {
mu_err_t err;
MuVisionType vision_type_output = 0;
MuVsVisionState vision_state;
// {
// SensorLockReg(false); //TODO Patch
// }
err = mu_vs_method->Get(kRegFrameCount, &vision_state.frame);
if (err) return vision_type_output;
//TODO Patch
// {
// if (vision_state.frame == 0) {
// return vision_type_output;
// }
// }
for (uint8_t i = 1; i < kVisionMaxType; ++i) {
if ((vision_type & visionTypeEnumToMacro(i)) && vision_state_[i-1]) {
if (vision_state.frame != vision_state_[i-1]->frame) {
SensorLockReg(true);
err = ((MuVisionSensorI2C *) mu_vs_method)->Read(
(MuVsMessageVisionType) i, &vision_state);
if (err) return vision_type_output;
SensorLockReg(false);
*vision_state_[i-1] = vision_state;
vision_type_output = vision_type_output | visionTypeEnumToMacro(i);
}
}
}
return vision_type_output;
}
default:
return UartUpdateResult(vision_type, wait_all_result);
break;
}
}
MuVisionType MuVisionSensor::UartUpdateResult(MuVisionType vision_type,
bool wait_all_result) {
MuVisionType vision_detect = 0;
MuVsVisionState vision_state;
uint8_t mu_address;
MuVsMessageVisionType mu_vision_type;
mu_err_t err;
switch(output_mode_) {
case kCallBackMode: {
for (int i = 1; i < kVisionMaxType; ++i) {
if ((vision_type & visionTypeEnumToMacro(i)) && vision_state_[i-1]) {
((MuVsUartMethod *)mu_vs_method)->GetMessage((MuVsMessageVisionType)i);
do {
err = ((MuVsUartMethod *)mu_vs_method)->Read(&mu_address, &mu_vision_type, &vision_state);
if (err) return vision_detect;
if (mu_address == address_
&& (vision_type & visionTypeEnumToMacro(mu_vision_type))
&& vision_state_[mu_vision_type-1]->frame != vision_state.frame
&& mu_vision_type
&& mu_vision_type < kVisionMaxType) {
*vision_state_[mu_vision_type-1] = vision_state;
// vision_state_[mu_vision_type-1]->detect = vision_state.detect;
// vision_state_[mu_vision_type-1]->frame = vision_state.frame;
// for (int i = 0; i < vision_state.detect; i++) {
// vision_state_[mu_vision_type-1]->vision_result[i] = vision_state.vision_result[i];
// }
vision_type = vision_type&(~visionTypeEnumToMacro(mu_vision_type));
vision_detect = vision_detect | visionTypeEnumToMacro(mu_vision_type);
if (mu_vision_type == i && !wait_all_result) return vision_detect;
}
} while (mu_address != address_ || mu_vision_type != i);
}
}
break;
}
case kDataFlowMode:
case kEventMode:
while (vision_type) {
err = ((MuVsUartMethod *)mu_vs_method)->Read(&mu_address, &mu_vision_type, &vision_state);
if (err) return vision_detect;
if (mu_address == address_
&& (vision_type & visionTypeEnumToMacro(mu_vision_type))
&& mu_vision_type
&& mu_vision_type < kVisionMaxType
&& vision_state_[mu_vision_type-1]) {
vision_state_[mu_vision_type-1]->detect = vision_state.detect;
vision_state_[mu_vision_type-1]->frame = vision_state.frame;
for (int i = 0; i < vision_state.detect; i++) {
vision_state_[mu_vision_type-1]->vision_result[i] = vision_state.vision_result[i];
}
vision_type = vision_type&(~visionTypeEnumToMacro(mu_vision_type));
vision_detect = vision_detect | visionTypeEnumToMacro(mu_vision_type);
if (!wait_all_result) return vision_detect;
}
}
break;
default:
return vision_detect;
}
return vision_detect;
}
uint8_t MuVisionSensor::write(MuVisionType vision_type,
MuVsObjectInf object_inf,
uint8_t value) {
mu_err_t err;
MuVsRegAddress address;
uint8_t vs_type = 1;
while ((vision_type&0x01) == 0
&& vs_type < kVisionMaxType) {
++vs_type;
vision_type >>= 1;
}
switch(object_inf) {
case kXValue:
address = kRegParamValue1;
break;
case kYValue:
address = kRegParamValue2;
break;
case kWidthValue:
address = kRegParamValue3;
break;
case kHeightValue:
address = kRegParamValue4;
break;
default:
return MU_ERROR_FAIL;
}
err = mu_vs_method->Set(kRegVisionId, vs_type);
if (err) return err;
return mu_vs_method->Set(address, value);
}
uint8_t MuVisionSensor::read(MuVisionType vision_type,
MuVsObjectInf object_inf,
uint8_t result_num) {
result_num = result_num ? (result_num-1):1;
result_num = result_num>MU_MAX_RESULT ? MU_MAX_RESULT:result_num;
uint8_t vision_pointer = 0;
while ((vision_type&0x01) == 0) {
vision_type = vision_type>>1;
vision_pointer++;
}
if (!vision_state_[vision_pointer] || vision_pointer >= kVisionMaxType) return 0;
switch(object_inf) {
case kStatus:
return vision_state_[vision_pointer]->detect;
case kXValue:
return vision_state_[vision_pointer]->vision_result[result_num].x_value;
case kYValue:
return vision_state_[vision_pointer]->vision_result[result_num].y_value;
case kWidthValue:
return vision_state_[vision_pointer]->vision_result[result_num].width;
case kHeightValue:
return vision_state_[vision_pointer]->vision_result[result_num].height;
case kLabel:
return vision_state_[vision_pointer]->vision_result[result_num].lable;
case kGValue:
return vision_state_[vision_pointer]->vision_result[result_num].color_g_value;
case kRValue:
return vision_state_[vision_pointer]->vision_result[result_num].color_r_value;
case kBValue:
return vision_state_[vision_pointer]->vision_result[result_num].color_b_value;
default:
return 0;
}
}
//uint8_t MuVisionSensor::SensorSetStatus(MuVsSensorStatus status) {
// MuVsSensorConfig1 sensor_config1;
// mu_err_t err;
// err = mu_vs_method->Get(kRegSensorConfig1, &sensor_config1.sensor_config_reg_value);
// if (err) return err;
// if (sensor_config1.status != status) {
// sensor_config1.status = status;
// err = mu_vs_method->Set(kRegSensorConfig1, sensor_config1.sensor_config_reg_value);
// if (err) return err;
// }
// return MU_OK;
//}
uint8_t MuVisionSensor::SensorSetRestart(void) {
// MuVsSensorConfig1 sensor_config1;
uint8_t reg_restart = 0;
mu_err_t err;
// sensor_config1.restart = 1;
err = mu_vs_method->Set(kRegRestart, 1);
return err;
}
uint8_t MuVisionSensor::SensorSetDefault(void) {
MuVsSensorConfig1 sensor_config1;
mu_err_t err;
sensor_config1.default_setting = 1;
err = mu_vs_method->Set(kRegSensorConfig1, sensor_config1.sensor_config_reg_value);
return err;
}
uint8_t MuVisionSensor::SensorLockReg(bool lock) {
mu_err_t err;
err = mu_vs_method->Set(kRegLock, lock);
return err;
}
//LED functions
uint8_t MuVisionSensor::LedSetMode(MuVsLed led, bool manual, bool hold) {
MuVsLedConfig led_config;
MuVsRegAddress address;
mu_err_t err;
switch(led) {
case kLed1:
address = kRegLed1;
break;
case kLed2:
address = kRegLed2;
break;
default:
return MU_ERROR_FAIL;
}
err = mu_vs_method->Get(address, &led_config.led_reg_value);
if (err) return err;
if (led_config.manual != manual
|| led_config.hold != hold) {
led_config.manual = manual;
led_config.hold = hold;
err = mu_vs_method->Set(address, led_config.led_reg_value);
if (err) return err;
}
return err;
}
//uint8_t MuVisionSensor::LedSetLevel(uint8_t led1_level,
// uint8_t led2_level) {
// MuVsLedConfig led_config;
// MuVsRegAddress address;
// mu_err_t err;
// uint8_t value = (led1_level&0x0F)|(led2_level<<4);
// return mu_vs_method->Set(kRegLedLevel, value);
//}
uint8_t MuVisionSensor::LedSetColor(MuVsLed led,
MuVsLedColor detected_color,
MuVsLedColor undetected_color,
uint8_t level) {
MuVsLedConfig led_config;
MuVsRegAddress address;
mu_err_t err;
uint8_t led_level;
mu_vs_method->Get(kRegLedLevel, &led_level);
switch(led) {
case kLed1:
address = kRegLed1;
led_level = (led_level&0xF0) | (level&0x0F);
mu_vs_method->Set(kRegLedLevel, led_level);
break;
case kLed2:
address = kRegLed2;
led_level = (led_level&0x0F) | ((level&0x0F)<<4);
mu_vs_method->Set(kRegLedLevel, led_level);
break;
default:
return MU_ERROR_FAIL;
}
err = mu_vs_method->Get(address, &led_config.led_reg_value);
if (err) return err;
if (led_config.detected_color != detected_color
|| led_config.undetected_color != undetected_color) {
led_config.detected_color = detected_color;
led_config.undetected_color = undetected_color;
err = mu_vs_method->Set(address, led_config.led_reg_value);
if (err) return err;
}
return err;
}
//Camera functions
uint8_t MuVisionSensor::CameraSetZoom(MuVsCameraZoom zoom) {
MuVsCameraConfig1 camera_config1;
mu_err_t err;
err = mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
if (camera_config1.zoom != zoom) {
camera_config1.zoom = zoom;
err = mu_vs_method->Set(kRegCameraConfig1, camera_config1.camera_reg_value);
}
return err;
}
uint8_t MuVisionSensor::CameraSetRotate(bool enable) {
MuVsCameraConfig1 camera_config1;
mu_err_t err;
err = mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
if (camera_config1.rotate != enable) {
camera_config1.rotate = enable;
err = mu_vs_method->Set(kRegCameraConfig1, camera_config1.camera_reg_value);
}
return err;
}
uint8_t MuVisionSensor::CameraSetFPS(MuVsCameraFPS fps) {
MuVsCameraConfig1 camera_config1;
mu_err_t err;
err = mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
if (camera_config1.fps != fps) {
camera_config1.fps = fps;
err = mu_vs_method->Set(kRegCameraConfig1, camera_config1.camera_reg_value);
}
return err;
}
uint8_t MuVisionSensor::CameraSetAwb(MuVsCameraWhiteBalance awb) {
MuVsCameraConfig1 camera_config1;
mu_err_t err;
err = mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
if (camera_config1.white_balance != awb) {
camera_config1.white_balance = awb;
err = mu_vs_method->Set(kRegCameraConfig1, camera_config1.camera_reg_value);
}
return err;
}
MuVsCameraZoom MuVisionSensor::CameraGetZoom(void) {
MuVsCameraConfig1 camera_config1;
mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
return camera_config1.zoom;
}
MuVsCameraWhiteBalance MuVisionSensor::CameraGetAwb(void) {
MuVsCameraConfig1 camera_config1;
mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
return camera_config1.white_balance;
}
bool MuVisionSensor::CameraGetRotate(void) {
MuVsCameraConfig1 camera_config1;
mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
return camera_config1.rotate;
}
MuVsCameraFPS MuVisionSensor::CameraGetFPS(void) {
MuVsCameraConfig1 camera_config1;
mu_vs_method->Get(kRegCameraConfig1, &camera_config1.camera_reg_value);
return camera_config1.fps;
}
//Uart functions
uint8_t MuVisionSensor::UartSetBaudrate(MuVsBaudrate baud) {
mu_err_t err;
MuVsUartConfig uart_config;
err = mu_vs_method->Get(kRegUart, &uart_config.uart_reg_value);
if (uart_config.baudrate != baud) {
uart_config.baudrate = baud;
mu_vs_method->Set(kRegUart, uart_config.uart_reg_value);
}
return err;
}
//bool MuVisionSensor::CheckVisionOutputMode(MuVsMessageVisionType vision_type) {
// MuVsVisionConfig1 vision_state;
// switch (output_mode[vision_type-1]) {
// case kCallBackMode:
// mu_vs_method->Set(kRegVisionId, vision_type);
// mu_vs_method->Get(kRegVisionConfig1,
// &vision_state.vision_config_reg_value);
// vision_state.output_enable = 1;
// mu_vs_method->Set(kRegVisionConfig1,
// vision_state.vision_config_reg_value);
// break;
// case kEventMode:
// case kDataFlowMode:
// break;
// default:
// mu_vs_method->Set(kRegVisionId, vision_type);
// mu_vs_method->Get(kRegVisionConfig1,
// &vision_state.vision_config_reg_value);
// output_mode[vision_type-1] = vision_state.output_mode;
// return false;
// }
// return true;
//}
bool MuVisionSensor::malloc_vision_buffer(MuVsMessageVisionType vision_type) {
if (vision_type
&& vision_type < kVisionMaxType
&& vision_state_[vision_type-1] == nullptr) {
vision_state_[vision_type-1] = new MuVsVisionState;
vision_state_[vision_type-1]->detect = 0;
vision_state_[vision_type-1]->frame = 0;
}
return true;
}
bool MuVisionSensor::free_vision_buffer(MuVsMessageVisionType vision_type) {
if (vision_type
&& vision_type < kVisionMaxType
&& vision_state_[vision_type-1]) {
vision_state_[vision_type-1] = new MuVsVisionState;
}
return true;
}