Skip to content

Commit 3b62c08

Browse files
authored
Merge pull request #151 from quo/dft-check-group
Only use DFT button signal if it is from same group as position signal
2 parents 9cbefc4 + 3263267 commit 3b62c08

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/core/generic/dft.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DftStylus {
2525

2626
i32 m_real = 0;
2727
i32 m_imag = 0;
28+
std::optional<u32> m_group = std::nullopt;
2829

2930
public:
3031
DftStylus(Config config, std::optional<const ipts::Metadata> metadata)
@@ -95,6 +96,7 @@ class DftStylus {
9596
dft.y[0].real[IPTS_DFT_NUM_COMPONENTS / 2];
9697
m_imag = dft.x[0].imag[IPTS_DFT_NUM_COMPONENTS / 2] +
9798
dft.y[0].imag[IPTS_DFT_NUM_COMPONENTS / 2];
99+
m_group = dft.group;
98100

99101
f64 x = this->interpolate_position(dft.x[0]);
100102
f64 y = this->interpolate_position(dft.y[0]);
@@ -159,6 +161,11 @@ class DftStylus {
159161
if (dft.rows <= 0)
160162
return;
161163

164+
// The position and button signals must be from the same group,
165+
// otherwise the relative phase is meaningless.
166+
if (!m_group.has_value() || m_group != dft.group)
167+
return;
168+
162169
bool button = false;
163170
bool rubber = false;
164171

src/ipts/data.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct Heatmap {
3434
};
3535

3636
struct DftWindow {
37+
std::optional<u32> group = std::nullopt;
3738
u8 rows = 0;
3839
u8 type = 0;
3940

src/ipts/parser.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Parser {
3939
private:
4040
struct ipts_dimensions m_dim {};
4141
struct ipts_timestamp m_time {};
42+
struct ipts_pen_metadata m_pen_meta {};
4243

4344
public:
4445
/*!
@@ -231,6 +232,9 @@ class Parser {
231232
case IPTS_REPORT_TYPE_HEATMAP:
232233
this->parse_heatmap_data(sub);
233234
break;
235+
case IPTS_REPORT_TYPE_PEN_METADATA:
236+
this->parse_pen_metadata(sub);
237+
break;
234238
case IPTS_REPORT_TYPE_PEN_DFT_WINDOW:
235239
this->parse_dft_window(sub);
236240
break;
@@ -426,6 +430,12 @@ class Parser {
426430
dft.rows = window.num_rows;
427431
dft.type = window.data_type;
428432

433+
if (window.seq_num == m_pen_meta.seq_num &&
434+
window.data_type == m_pen_meta.data_type) {
435+
const auto g = m_pen_meta.group_counter;
436+
dft.group = g;
437+
}
438+
429439
dft.dim = m_dim;
430440
dft.time = m_time;
431441

@@ -434,6 +444,18 @@ class Parser {
434444

435445
this->on_dft(dft);
436446
}
447+
448+
/*!
449+
* Parses a pen metadata report.
450+
*
451+
* A pen metadata report precedes each DFT report.
452+
453+
* @param[in] reader The chunk of data allocated to the report.
454+
*/
455+
void parse_pen_metadata(Reader &reader)
456+
{
457+
m_pen_meta = reader.read<struct ipts_pen_metadata>();
458+
}
437459
};
438460

439461
} // namespace iptsd::ipts

src/ipts/protocol.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ struct [[gnu::packed]] ipts_heatmap_header {
157157
u32 size;
158158
};
159159

160+
struct [[gnu::packed]] ipts_pen_metadata {
161+
u32 group_counter;
162+
u8 seq_num;
163+
u8 data_type;
164+
u8 reserved[10]; // NOLINT(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
165+
};
166+
160167
struct [[gnu::packed]] ipts_pen_dft_window {
161168
u32 timestamp; // counting at approx 8MHz
162169
u8 num_rows;

0 commit comments

Comments
 (0)