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

The touch injector's commands and gestures (injector.h): the line parser, up to INJ_CONTACTS contacts at once, and the frames that carry them to the panel. More...

#include "injector.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

Data Structures

struct  field_t
 A numeric field: its name in err range and its maximum. More...
struct  plan_t
 Where the notes and the message of the tab shown go. More...

Macros

#define MAX_TOKENS   7
 Tokens a line may hold: swipe's five numbers, its id= and itself.
#define N_IDS   ((unsigned)(INJ_ID_MAX + 1u))
 Ids from 0 to INJ_ID_MAX: the size of injector_t.c.
#define ID_NONE   (-1)
 No id= on the line.
#define ID_BAD   (-2)
 A bad id=; the error is replied.

Functions

static void reply (injector_t *in, const char *fmt,...)
 Queue one reply line; a full queue drops its oldest.
bool injector_take_reply (injector_t *in, char *out, size_t n)
 The oldest reply.
const char * inj_gesture_name (inj_gesture_t g)
 The gesture's word.
void injector_init (injector_t *in)
 Reset: LISTEN, no contacts, no replies.
static bool live (const inj_contact_t *c)
 A tap, hold or swipe under way, not yet released.
static bool pressing (const inj_contact_t *c)
 A gesture under way whose contact the panel has down.
static unsigned in_use (const injector_t *in)
 Contact ids in use: gestures under way and lifts not yet read.
static void contact_end (inj_contact_t *c)
 The id is free again; the last point stays for status.
static void release_contact (inj_contact_t *c)
 A gesture under way stops.
static void fail_all (injector_t *in, const char *why)
 Every contact ends: each gesture under way gets fail why.
static bool parse_int (const char *s, long *out)
 A decimal integer, with an optional minus sign.
static bool field (injector_t *in, const char *cmd, const char *tok, const field_t *f, long *out)
 Parse tok against f; on failure the error is replied.
static int take_id (injector_t *in, const char *cmd, char **tok, int *ntok)
 Take an id=N off the end of the line.
static void cmd_gesture (injector_t *in, inj_gesture_t kind, char **tok, int ntok)
 tap, hold and swipe: the checks they share, then the start.
static void cmd_status (injector_t *in, uint32_t now_ms)
 status: the state, the bus counts and contact 0.
static void cmd_contacts (injector_t *in, int ntok)
 contacts: every id in use, its gesture, down and point.
static void cmd_wiring (injector_t *in, int ntok)
 wiring: ask the glue to listen, in LISTEN only.
static void cmd_confirm (injector_t *in, char **tok, int ntok)
 confirm scl=GP5: go ACTIVE after an ok verdict.
static void cmd_release (injector_t *in, char **tok, int ntok)
 release [id=N]: one contact, or every one without id=.
static void run_line (injector_t *in, char *line, uint32_t now_ms)
 Split one line into tokens and run its command.
void injector_input (injector_t *in, const char *bytes, size_t n, uint32_t now_ms)
 Bytes from the host. A full line runs at once.
bool injector_take_wiring (injector_t *in)
 True once after wiring: the glue starts listening to the lines.
void injector_wiring_done (injector_t *in, const inj_line_result_t *r)
 The glue's 500ms of listening, classified.
bool injector_take_attach (injector_t *in)
 True once after confirm: the glue attaches the I2C target.
void injector_host_closed (injector_t *in)
 The host closed the port (DTR, data terminal ready, fell).
static uint16_t lerp (uint16_t a, uint16_t b, uint32_t num, uint32_t den)
 The point num / den of the way from a to b.
static long labs_ (long v)
 The magnitude of v.
static bool swipe_point (const inj_contact_t *c, uint32_t now_ms, uint16_t *x, uint16_t *y)
 Where a swipe's next frame puts its contact at now_ms.
static void finish (injector_t *in, inj_contact_t *c, uint32_t now_ms)
 The lift of contact c was read: done, unless it was released.
static void frame_read (injector_t *in, uint32_t now_ms)
 The panel acknowledged the frame out at now_ms.
static plan_t plan (const inj_contact_t *c, uint32_t now_ms)
 Plan contact c's part in a frame published at now_ms.
static void publish_next (injector_t *in, uint32_t now_ms)
 Publish the next frame when a contact needs one.
static bool any_down (const injector_t *in)
 A gesture under way has a contact the panel was given.
void injector_poll (injector_t *in, uint32_t now_ms)
 Move the gestures on: frames, acknowledges, timeouts. Call often.
inj_led_t injector_led (const injector_t *in, uint32_t now_ms)
 What the status LED shows at now_ms.

Variables

static const field_t k_x = { "x", (long)INJ_RES_X - 1 }
 x
static const field_t k_y = { "y", (long)INJ_RES_Y - 1 }
 y
static const field_t k_ms = { "ms", (long)INJ_MS_MAX }
 ms

Detailed Description

The touch injector's commands and gestures (injector.h): the line parser, up to INJ_CONTACTS contacts at once, and the frames that carry them to the panel.

SPDX-License-Identifier: MIT

Function Documentation

◆ inj_gesture_name()

const char * inj_gesture_name ( inj_gesture_t g)

The gesture's word.

Parameters
gThe gesture.
Returns
tap, hold, swipe, release, or idle.

◆ injector_host_closed()

void injector_host_closed ( injector_t * in)

The host closed the port (DTR, data terminal ready, fell).

Every contact that is down is released; nothing is replied.

Parameters
inThe injector.

◆ injector_init()

void injector_init ( injector_t * in)

Reset: LISTEN, no contacts, no replies.

Parameters
inThe injector.

◆ injector_input()

void injector_input ( injector_t * in,
const char * bytes,
size_t n,
uint32_t now_ms )

Bytes from the host. A full line runs at once.

Parameters
inThe injector.
bytesThe bytes.
nHow many.
now_msThe clock.

◆ injector_led()

inj_led_t injector_led ( const injector_t * in,
uint32_t now_ms )

What the status LED shows at now_ms.

Parameters
inThe injector.
now_msThe clock.
Returns
The colour.

◆ injector_poll()

void injector_poll ( injector_t * in,
uint32_t now_ms )

Move the gestures on: frames, acknowledges, timeouts. Call often.

Parameters
inThe injector.
now_msThe clock.

◆ injector_take_attach()

bool injector_take_attach ( injector_t * in)

True once after confirm: the glue attaches the I2C target.

Parameters
inThe injector.
Returns
Whether to attach.

◆ injector_take_reply()

bool injector_take_reply ( injector_t * in,
char * out,
size_t n )

The oldest reply.

Parameters
inThe injector.
outWhere it goes.
nThe size of out.
Returns
False when there is none.

◆ injector_take_wiring()

bool injector_take_wiring ( injector_t * in)

True once after wiring: the glue starts listening to the lines.

Parameters
inThe injector.
Returns
Whether to start.

◆ injector_wiring_done()

void injector_wiring_done ( injector_t * in,
const inj_line_result_t * r )

The glue's 500ms of listening, classified.

Parameters
inThe injector.
rThe verdict.

◆ parse_int()

bool parse_int ( const char * s,
long * out )
static

A decimal integer, with an optional minus sign.

Ten digits or more read as out of range rather than as a syntax error.

Parameters
sThe text.
outThe value.
Returns
False on anything else.

◆ release_contact()

void release_contact ( inj_contact_t * c)
static

A gesture under way stops.

A contact the panel may have seen down gets its lift in a frame, with no reply of its own. One never published needs none, and no frame is withdrawn for it: a frame out carries only contacts put down before.

Parameters
cThe contact.

◆ swipe_point()

bool swipe_point ( const inj_contact_t * c,
uint32_t now_ms,
uint16_t * x,
uint16_t * y )
static

Where a swipe's next frame puts its contact at now_ms.

Parameters
cThe swipe.
now_msThe clock.
xThe column.
yThe row.
Returns
Whether the 100px step limit shortened this step.

◆ take_id()

int take_id ( injector_t * in,
const char * cmd,
char ** tok,
int * ntok )
static

Take an id=N off the end of the line.

Parameters
inThe injector, for the error reply.
cmdThe command, for err syntax.
tokThe tokens.
ntokTheir count; one less when an id= was taken.
Returns
The id, ID_NONE when the line has none, ID_BAD after an error.