/*
 * bcode.h - barcode scanner input on the Workabout MX (integral laser).
 *
 * The Workabout MX integral laser is an UNDECODED (HHLC) scanner: it emits a
 * raw bar/space signal, not decoded ASCII. The hardware serial decoder in the
 * RS232/Barcode module only handles wands and wand-emulation scanners (the HC
 * guide lists "Undecoded Laser Scanner (HHLC)" as unsupported there), which is
 * why reading TTY:D directly yielded nothing even though the laser's own
 * good-read LED lit.
 *
 * The decode is instead done in software by a barcode decoder LDD. The SDK
 * ships several (\SIBOSDK\LIB): BAREAN (EAN/UPC), BARC39, BAR128, BARITF,
 * BARMPLES, BARRAW. Each registers the device "BAR:". For UPC we load BAREAN.
 *
 * Usage: bcodeLoad() once, then bcodeOpen() to get a channel, then read it.
 * The BAREAN.LDD file must be present on the device so p_loadldd can find it.
 */
#ifndef BCODE_H
#define BCODE_H

#include <plib.h>

/* Decoder LDD to load (BAREAN.LDD = EAN/UPC) and the device it registers.
   Full path: p_loadldd searches only the current path for a bare name, and the
   System screen's current path is not necessarily where SCAN.IMG lives. The
   .LDD extension is appended automatically. Change this if you move the file. */
#define BCODE_LDD "M:\\IMG\\BAREAN"
#define BCODE_DEV "BAR:"

/* Longest decoded barcode we handle (UPC-A is 12; headroom for EAN/supplements). */
#define BCODE_MAXLEN 24

/*
 * Load the UPC/EAN decoder LDD. Returns 0 if loaded, or a negative PLIB error.
 * E_FILE_EXIST (already loaded) is treated as success by callers.
 */
GLREF_C INT bcodeLoad(VOID);

/*
 * Open a channel to the barcode decoder device (BAR:). Stores it in *pChan.
 * Returns 0 on success or a negative PLIB error.
 */
GLREF_C INT bcodeOpen(VOID **pChan);

/* Close a channel opened by bcodeOpen. Safe to call with NULL. */
GLREF_C VOID bcodeClose(VOID *chan);

#endif /* BCODE_H */
