rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
touch_merge.c File Reference

The glass's contacts and a touch injector's, merged (touch_merge.h). More...

#include "touch_merge.h"
#include <string.h>

Functions

static int clamp_count (int n)
 n held to 0..TOUCH_MAX_POINTS.
static bool same_point (const touch_point_t *a, const touch_point_t *b)
 The same contact at the same place and strength.
void touch_merge_reset (touch_merge_t *m)
 Forget both sets: no contacts, the injector attached at 0ms.
void touch_merge_attach (touch_merge_t *m, uint32_t now_ms)
 Reset, with the injector attached and answering at now_ms.
void touch_merge_start (touch_merge_t *m, bool answered, uint32_t now_ms)
 The start-up look for the injector.
bool touch_merge_attached (const touch_merge_t *m)
 Whether the injector is attached: false once detached, until a probe.
bool touch_merge_expire (touch_merge_t *m, uint32_t now_ms)
 Detach the injector when its last good read is TOUCH_MERGE_DETACH_MS or more old. Detaching drops its contacts.
bool touch_merge_probe_due (const touch_merge_t *m, uint32_t now_ms)
 Whether a detached injector is due to be probed: TOUCH_MERGE_PROBE_MS after the detach and after every probe. Never for an absent one.
bool touch_merge_probe (touch_merge_t *m, bool answered, uint32_t now_ms)
 A detached injector was probed.
static void recut (touch_merge_t *m)
 Decide which injected contacts the frame has room for.
void touch_merge_glass (touch_merge_t *m, const touch_point_t *pts, int n)
 The glass reported a new contact set (0 points when every finger lifted). Injected contacts the frame no longer has room for are cut.
bool touch_merge_inject_due (const touch_merge_t *m, uint32_t now_ms)
 Whether the injector is due to be asked: on every poll while it answers, and every TOUCH_MERGE_RETRY_MS once it has failed TOUCH_MERGE_FAIL_DROP times in a row.
static bool frames_differ (const touch_point_t *a, int na, const touch_point_t *b, int nb)
 Whether two merged sets differ.
bool touch_merge_inject (touch_merge_t *m, const touch_point_t *pts, int n, bool fresh, uint32_t now_ms)
 The injector answered at now_ms.
bool touch_merge_inject_failed (touch_merge_t *m, uint32_t now_ms)
 An injector read failed.
int touch_merge_frame (const touch_merge_t *m, touch_point_t *out, int max)
 The merged set: the glass's contacts, then the injector's that are not cut, TOUCH_MAX_POINTS at most.
int touch_merge_mark_cut (const touch_merge_t *m, touch_event_t *evts, int n)
 Mark the UP of every cut injected contact TOUCH_FLAG_NO_TAP.
bool touch_merge_is_injector (const char *product_id)
 Whether product_id is the touch injector's.
touch_role_t touch_merge_role (uint16_t addr, bool glass_found, const char *product_id)
 The role of a controller that answered as a GT911 at start-up.
touch_map_t touch_merge_role_map (touch_role_t role, const touch_map_t *glass, const touch_map_t *inject, bool turned)
 The map for one report of a controller with role role.

Detailed Description

The glass's contacts and a touch injector's, merged (touch_merge.h).

SPDX-License-Identifier: MIT

Function Documentation

◆ recut()

void recut ( touch_merge_t * m)
static

Decide which injected contacts the frame has room for.

The room is what the glass leaves. A contact shown before keeps its place before a new one gets any, in report order; a cut one stays cut.

Parameters
mThe merge.

◆ touch_merge_attach()

void touch_merge_attach ( touch_merge_t * m,
uint32_t now_ms )

Reset, with the injector attached and answering at now_ms.

Parameters
mThe merge.
now_msThe clock.

◆ touch_merge_attached()

bool touch_merge_attached ( const touch_merge_t * m)

Whether the injector is attached: false once detached, until a probe.

Parameters
mThe merge.
Returns
Whether it is attached.

◆ touch_merge_expire()

bool touch_merge_expire ( touch_merge_t * m,
uint32_t now_ms )

Detach the injector when its last good read is TOUCH_MERGE_DETACH_MS or more old. Detaching drops its contacts.

Parameters
mThe merge.
now_msThe clock.
Returns
True when this call detached it.

◆ touch_merge_frame()

int touch_merge_frame ( const touch_merge_t * m,
touch_point_t * out,
int max )

The merged set: the glass's contacts, then the injector's that are not cut, TOUCH_MAX_POINTS at most.

Parameters
mThe merge.
outWhere the set goes.
maxThe room in out.
Returns
The number written.

◆ touch_merge_glass()

void touch_merge_glass ( touch_merge_t * m,
const touch_point_t * pts,
int n )

The glass reported a new contact set (0 points when every finger lifted). Injected contacts the frame no longer has room for are cut.

Parameters
mThe merge.
ptsThe points, in panel pixels.
nHow many; a count outside 0..TOUCH_MAX_POINTS is clamped.

◆ touch_merge_inject()

bool touch_merge_inject ( touch_merge_t * m,
const touch_point_t * pts,
int n,
bool fresh,
uint32_t now_ms )

The injector answered at now_ms.

A contact it reports keeps its cut by track id; a new one is cut when the frame has no room for it. A cut contact the injector lifts is forgotten, and its id is free again.

Parameters
mThe merge.
ptsThe points, in panel pixels; not read when fresh is false.
nHow many.
freshFalse when it had no new report.
now_msThe clock.
Returns
True when the merged set changed.

◆ touch_merge_inject_due()

bool touch_merge_inject_due ( const touch_merge_t * m,
uint32_t now_ms )

Whether the injector is due to be asked: on every poll while it answers, and every TOUCH_MERGE_RETRY_MS once it has failed TOUCH_MERGE_FAIL_DROP times in a row.

Parameters
mThe merge.
now_msThe clock.
Returns
Whether to read it.

◆ touch_merge_inject_failed()

bool touch_merge_inject_failed ( touch_merge_t * m,
uint32_t now_ms )

An injector read failed.

Parameters
mThe merge.
now_msThe clock.
Returns
True when this failure dropped injected contacts, which changes the merged set.

◆ touch_merge_is_injector()

bool touch_merge_is_injector ( const char * product_id)

Whether product_id is the touch injector's.

Parameters
product_idThe 4 bytes read at 0x8140; NULL is not the injector.
Returns
True for TOUCH_MERGE_INJECT_PRODUCT exactly.

◆ touch_merge_mark_cut()

int touch_merge_mark_cut ( const touch_merge_t * m,
touch_event_t * evts,
int n )

Mark the UP of every cut injected contact TOUCH_FLAG_NO_TAP.

Called on the tracker's events for the frame touch_merge_frame() gave. A contact cut to make room for the glass's did not lift; its UP ends the press as TOUCH_FLAG_NO_TAP says. Every other event is left as it is.

Parameters
mThe merge.
evtsThe events.
nHow many.
Returns
How many UPs were marked.

◆ touch_merge_probe()

bool touch_merge_probe ( touch_merge_t * m,
bool answered,
uint32_t now_ms )

A detached injector was probed.

Parameters
mThe merge.
answeredTrue when it answered as a GT911.
now_msThe clock.
Returns
True when this re-attached it.

◆ touch_merge_probe_due()

bool touch_merge_probe_due ( const touch_merge_t * m,
uint32_t now_ms )

Whether a detached injector is due to be probed: TOUCH_MERGE_PROBE_MS after the detach and after every probe. Never for an absent one.

Parameters
mThe merge.
now_msThe clock.
Returns
Whether to probe.

◆ touch_merge_reset()

void touch_merge_reset ( touch_merge_t * m)

Forget both sets: no contacts, the injector attached at 0ms.

Parameters
mThe merge; NULL does nothing.

◆ touch_merge_role()

touch_role_t touch_merge_role ( uint16_t addr,
bool glass_found,
const char * product_id )

The role of a controller that answered as a GT911 at start-up.

  • At TOUCH_MERGE_GLASS_ADDR: the glass, whatever its product ID.
  • At TOUCH_MERGE_INJECT_ADDR with TOUCH_MERGE_INJECT_PRODUCT: the injector, beside a glass at 0x5D or alone.
  • At TOUCH_MERGE_INJECT_ADDR with any other product ID: the glass when nothing answered at 0x5D (glass_found false); not read when the glass answered at 0x5D, so 0x5D wins.
  • At any other address: not read.
Parameters
addrThe address it answered at.
glass_foundWhether a glass answered at TOUCH_MERGE_GLASS_ADDR before it.
product_idIts 4-byte product ID; NULL when the read failed.
Returns
Its role.

◆ touch_merge_role_map()

touch_map_t touch_merge_role_map ( touch_role_t role,
const touch_map_t * glass,
const touch_map_t * inject,
bool turned )

The map for one report of a controller with role role.

Parameters
roleIts role.
glassThe glass's map: its resolution, mirrors and rotation.
injectThe injector's map (logical pixels).
turnedWhether the turned picture is on the glass (gfx_turn_shown()); false again after the turn falls back.
Returns
glass turned by turned for TOUCH_ROLE_GLASS; inject, never turned, for TOUCH_ROLE_INJECTOR; a zeroed map for TOUCH_ROLE_NONE or a NULL map.

◆ touch_merge_start()

void touch_merge_start ( touch_merge_t * m,
bool answered,
uint32_t now_ms )

The start-up look for the injector.

An answer is touch_merge_attach(). No answer makes the injector absent until the next start: nothing in this header attaches, reads or probes it, and touch_merge_attached() stays false.

Parameters
mThe merge.
answeredTrue when 0x14 answered as a GT911.
now_msThe clock.