-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfp_info_command.cc
103 lines (90 loc) · 2.53 KB
/
fp_info_command.cc
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
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "biod/fp_info_command.h"
namespace biod {
// TODO(b/162949739): this can be removed when C++17 is enabled.
constexpr int FpInfoCommand::kDeadPixelsUnknown;
/**
* @return non-owning pointer which can be nullptr if command hasn't been run.
*/
SensorId* FpInfoCommand::sensor_id() {
if (!Resp()) {
return nullptr;
}
if (!sensor_id_) {
sensor_id_ =
std::make_unique<SensorId>(Resp()->vendor_id, Resp()->product_id,
Resp()->model_id, Resp()->version);
}
return sensor_id_.get();
}
/**
* @return non-owning pointer which can be nullptr if command hasn't been run.
*/
SensorImage* FpInfoCommand::sensor_image() {
if (!Resp()) {
return nullptr;
}
if (!sensor_image_) {
sensor_image_ = std::make_unique<SensorImage>(
Resp()->width, Resp()->height, Resp()->frame_size, Resp()->pixel_format,
Resp()->bpp);
}
return sensor_image_.get();
}
/**
* @return non-owning pointer which can be nullptr if command hasn't been run.
*/
TemplateInfo* FpInfoCommand::template_info() {
if (!Resp()) {
return nullptr;
}
if (!template_info_) {
template_info_ = std::make_unique<TemplateInfo>(
Resp()->template_version, Resp()->template_size, Resp()->template_max,
Resp()->template_valid, Resp()->template_dirty);
}
return template_info_.get();
}
/**
* @return number of dead pixels or kDeadPixelsUnknown
*/
int FpInfoCommand::NumDeadPixels() {
if (!Resp()) {
return kDeadPixelsUnknown;
}
uint16_t num_dead_pixels = Resp()->errors;
if (num_dead_pixels == FP_ERROR_DEAD_PIXELS_UNKNOWN) {
return kDeadPixelsUnknown;
}
return num_dead_pixels;
}
/**
* @return FpSensorErrors
*/
FpSensorErrors FpInfoCommand::GetFpSensorErrors() {
FpSensorErrors ret = FpSensorErrors::kNone;
if (!Resp()) {
return ret;
}
auto errors = Resp()->errors;
if (errors & FP_ERROR_NO_IRQ) {
ret |= FpSensorErrors::kNoIrq;
}
if (errors & FP_ERROR_BAD_HWID) {
ret |= FpSensorErrors::kBadHardwareID;
}
if (errors & FP_ERROR_INIT_FAIL) {
ret |= FpSensorErrors::kInitializationFailure;
}
if (errors & FP_ERROR_SPI_COMM) {
ret |= FpSensorErrors::kSpiCommunication;
}
if ((FP_ERROR_DEAD_PIXELS(errors) != FP_ERROR_DEAD_PIXELS_UNKNOWN) &&
(FP_ERROR_DEAD_PIXELS(errors) != 0)) {
ret |= FpSensorErrors::kDeadPixels;
}
return ret;
}
} // namespace biod