Cleaned up BCS2 code a bit; added scanner settings dialog code.
This commit is contained in:
parent
eca34f597a
commit
ebec983b9b
345
src/AppMain.c
345
src/AppMain.c
|
@ -35,6 +35,7 @@
|
|||
|
||||
#ifdef SCANLIB_BCS2
|
||||
#include "BCS2ScannerLib.h"
|
||||
#include "BCS2 Configuration Header.h"
|
||||
#endif
|
||||
|
||||
#ifdef SCANLIB_JANAM
|
||||
|
@ -87,7 +88,7 @@
|
|||
************************************************************/
|
||||
|
||||
#ifdef SCANLIB_BCS2
|
||||
UInt16 gBcs2RefNum = 0;
|
||||
UInt16 gBCS2RefNum = sysInvalidRefNum;
|
||||
#endif
|
||||
|
||||
#ifdef SCANLIB_JANAM
|
||||
|
@ -110,7 +111,7 @@ Boolean gBabbo = false;
|
|||
//UInt16 gNumRows = 11;
|
||||
//MemHandle gHandles[11][3];
|
||||
Int16 firstRecordIndex = -1;
|
||||
Boolean scanRecordsSelected[12];
|
||||
Boolean scanRecordsSelected[12] = {false};
|
||||
Int16 eventEnteredRow = -1;
|
||||
|
||||
// This handle serves the barcode field.
|
||||
|
@ -193,12 +194,14 @@ static Boolean TableHitTest(TablePtr table, Int16 screenX, Int16 screenY);
|
|||
static Int16 TableRowHitTest(TablePtr table, Int16 screenX, Int16 screenY);
|
||||
static void ClearScanRecordSelection();
|
||||
|
||||
static void* GetObjectPtr(UInt16 objectID);
|
||||
static void UpdateBarcode(Char* scancode);
|
||||
static void FocusBarcode();
|
||||
#ifdef SCANLIB_SYMBOL
|
||||
static void FetchScanData();
|
||||
#endif
|
||||
static void ProcessScan();
|
||||
static void StoreScanData();
|
||||
static void StoreScanRecord();
|
||||
static Boolean IsChecked(FormPtr form, UInt16 controlID);
|
||||
static void ShowQuantityForm(UInt16 triggerID, Boolean manual);
|
||||
|
||||
|
@ -209,10 +212,13 @@ static void AppendQuantityDigit(UInt16 digit);
|
|||
static void UpdateQuantityDisplay();
|
||||
static void QuantityFormAccept();
|
||||
|
||||
// Scanner Settings Form
|
||||
static Boolean ScannerSettingsFormHandleEvent(EventPtr event);
|
||||
|
||||
// Scanner-Specific
|
||||
#ifdef SCANLIB_BCS2
|
||||
static Boolean OpenBCS2Scanner();
|
||||
static void CloseBCS2Scanner();
|
||||
static Err OpenBCS2Scanner();
|
||||
static Err CloseBCS2Scanner();
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -228,11 +234,7 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
|
|||
|
||||
#ifdef SCANLIB_BCS2
|
||||
SysNotifyParamType* notifyParams = (SysNotifyParamType*) cmdPBP;
|
||||
Char * scancode;
|
||||
FormPtr form;
|
||||
FieldPtr barcode;
|
||||
MemHandle barcodeH;
|
||||
MemPtr barcodeP;
|
||||
Char* scancode;
|
||||
#endif
|
||||
|
||||
switch (cmd) {
|
||||
|
@ -246,33 +248,12 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
|
|||
#ifdef SCANLIB_BCS2
|
||||
case sysAppLaunchCmdNotify:
|
||||
if (notifyParams->notifyType == BCS2BarCodeReadyNotification) {
|
||||
|
||||
// Get pointer to scanned data.
|
||||
scancode = (Char*) notifyParams->notifyDetailsP + 1;
|
||||
|
||||
// Verify we got a good read from the scanner.
|
||||
if (StrCompareAscii(scancode, "NO READ") == 0) {
|
||||
scancode = (Char*) notifyParams->notifyDetailsP;
|
||||
if (StrCompare(scancode, "NO READ") == 0) {
|
||||
SndPlaySystemSound(sndWarning);
|
||||
|
||||
} else {
|
||||
SndPlaySystemSound(sndConfirmation);
|
||||
|
||||
form = FrmGetFormPtr(MainForm);
|
||||
barcode = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormBarcode));
|
||||
|
||||
barcodeH = FldGetTextHandle(barcode);
|
||||
FldSetTextHandle(barcode, NULL);
|
||||
if (! barcodeH) {
|
||||
barcodeH = MemHandleNew(15); // ugh
|
||||
}
|
||||
|
||||
barcodeP = MemHandleLock(barcodeH);
|
||||
StrCopy((Char*) barcodeP, scancode);
|
||||
MemHandleUnlock(barcodeH);
|
||||
|
||||
FldSetTextHandle(barcode, barcodeH);
|
||||
FldDrawField(barcode);
|
||||
|
||||
UpdateBarcode(scancode);
|
||||
ProcessScan();
|
||||
}
|
||||
}
|
||||
|
@ -380,7 +361,7 @@ static void AppEventLoop()
|
|||
// the event bubble up to the application handler instead. This is
|
||||
// possibly very bad form, but as of this writing I'm not sure how else
|
||||
// to accomplish using that button for a trigger.
|
||||
if (gBcs2RefNum && (event.eType == keyDownEvent) && (event.data.keyDown.chr == MzVCentreKey)) {
|
||||
if ((gBCS2RefNum != sysInvalidRefNum) && (event.eType == keyDownEvent) && (event.data.keyDown.chr == MzVCentreKey)) {
|
||||
defaultSysHandler = false;
|
||||
}
|
||||
#endif
|
||||
|
@ -427,6 +408,9 @@ static Boolean AppHandleEvent(EventPtr event)
|
|||
case QuantityForm:
|
||||
FrmSetEventHandler(form, QuantityFormHandleEvent);
|
||||
break;
|
||||
case ScannerSettingsForm:
|
||||
FrmSetEventHandler(form, ScannerSettingsFormHandleEvent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -576,8 +560,8 @@ static Boolean MainFormHandleEvent(EventPtr event)
|
|||
// On Meazura devices, the "center" hardware key is our scan
|
||||
// trigger. But we'll only trigger the scanner if the barcode
|
||||
// field has focus.
|
||||
if (gBcs2RefNum && (FrmGetFocus(form) == FrmGetObjectIndex(form, MainFormBarcode))) {
|
||||
BCS2LibTriggerOn(gBcs2RefNum);
|
||||
if ((gBCS2RefNum != sysInvalidRefNum) && (FrmGetFocus(form) == FrmGetObjectIndex(form, MainFormBarcode))) {
|
||||
BCS2LibTriggerOn(gBCS2RefNum);
|
||||
}
|
||||
handled = true;
|
||||
#endif
|
||||
|
@ -596,11 +580,11 @@ static Boolean MainFormHandleEvent(EventPtr event)
|
|||
/* if (GetCheckedValue(MainFormStopOnUnits)) { */
|
||||
/* SetFieldFocus(MainFormUnits); */
|
||||
/* } else { */
|
||||
/* StoreScanData(); */
|
||||
/* StoreScanRecord(); */
|
||||
/* } */
|
||||
/* *\/ */
|
||||
/* } else if (objId == MainFormUnits) { */
|
||||
/* StoreScanData(); */
|
||||
/* StoreScanRecord(); */
|
||||
/* } */
|
||||
|
||||
/* // Until I have more to go on, I'm assuming that if a handheld has */
|
||||
|
@ -608,9 +592,9 @@ static Boolean MainFormHandleEvent(EventPtr event)
|
|||
/* // "center" navigational (hardware) key should be used as the scan */
|
||||
/* // trigger. */
|
||||
/* } else if (event->data.keyDown.chr == MzVCentreKey) { */
|
||||
/* if (gBcs2RefNum) { */
|
||||
/* if (gBCS2RefNum) { */
|
||||
/* if (FrmGetFocus(form) == FrmGetObjectIndex(form, MainFormBarcode)) */
|
||||
/* BCS2LibTriggerOn(gBcs2RefNum); */
|
||||
/* BCS2LibTriggerOn(gBCS2RefNum); */
|
||||
/* } */
|
||||
|
||||
/* /\* */
|
||||
|
@ -679,11 +663,6 @@ static void MainFormInit(FormPtr form)
|
|||
TablePtr table;
|
||||
Int16 cols, col, rows, row;
|
||||
|
||||
// Clear row selection state.
|
||||
for (row = 0; row < 12; row++) {
|
||||
scanRecordsSelected[row] = false;
|
||||
}
|
||||
|
||||
table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords));
|
||||
TblHasScrollBar(table, true);
|
||||
|
||||
|
@ -789,6 +768,11 @@ static Boolean MainFormDoCommand(UInt16 command)
|
|||
handled = true;
|
||||
break;
|
||||
|
||||
case MainOptionsScannerSettings:
|
||||
FrmPopupForm(ScannerSettingsForm);
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case MainOptionsAboutRattail:
|
||||
form = FrmInitForm(AboutForm);
|
||||
FrmDoDialog(form);
|
||||
|
@ -1112,33 +1096,6 @@ static DmOpenRef OpenScanDatabase()
|
|||
}
|
||||
|
||||
|
||||
#ifdef SCANLIB_BCS2
|
||||
/************************************************************
|
||||
*
|
||||
* FUNCTION: CloseBCS2Scanner
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static void CloseBCS2Scanner()
|
||||
{
|
||||
LocalID dbId;
|
||||
|
||||
if (! gBcs2RefNum) {
|
||||
return;
|
||||
}
|
||||
|
||||
dbId = DmFindDatabase(cardNumber, appDbRattail);
|
||||
if (dbId) {
|
||||
SysNotifyUnregister(cardNumber, dbId, BCS2BarCodeReadyNotification,
|
||||
sysNotifyNormalPriority);
|
||||
}
|
||||
BCS2LibClose(gBcs2RefNum);
|
||||
SysLibRemove(gBcs2RefNum);
|
||||
gBcs2RefNum = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* FUNCTION: CreateScanDatabase
|
||||
|
@ -1192,13 +1149,45 @@ static Boolean IsChecked(FormPtr form, UInt16 controlID)
|
|||
*
|
||||
************************************************************/
|
||||
|
||||
/* static void *GetObjectPtr(UInt16 objectID) */
|
||||
/* { */
|
||||
/* FormPtr form; */
|
||||
static void* GetObjectPtr(UInt16 objectID)
|
||||
{
|
||||
FormPtr form;
|
||||
|
||||
/* form = FrmGetActiveForm(); */
|
||||
/* return FrmGetObjectPtr(form, FrmGetObjectIndex(form, objectID)); */
|
||||
/* } */
|
||||
form = FrmGetActiveForm();
|
||||
return FrmGetObjectPtr(form, FrmGetObjectIndex(form, objectID));
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* FUNCTION: UpdateBarcode
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static void UpdateBarcode(Char* scancode)
|
||||
{
|
||||
UInt16 size;
|
||||
FieldPtr barcode;
|
||||
MemHandle barcodeH;
|
||||
MemPtr barcodeP;
|
||||
|
||||
size = StrLen(scancode) + 1;
|
||||
barcode = GetObjectPtr(MainFormBarcode);
|
||||
|
||||
barcodeH = FldGetTextHandle(barcode);
|
||||
if (barcodeH == NULL) {
|
||||
barcodeH = MemHandleNew(size);
|
||||
} else if (MemHandleSize(barcodeH) < size) {
|
||||
MemHandleResize(barcodeH, size);
|
||||
}
|
||||
|
||||
barcodeP = MemHandleLock(barcodeH);
|
||||
MemMove(barcodeP, scancode, size);
|
||||
MemHandleUnlock(barcodeH);
|
||||
|
||||
FldSetTextHandle(barcode, barcodeH);
|
||||
FldDrawField(barcode);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
|
@ -1333,18 +1322,18 @@ static void ProcessScan()
|
|||
ShowQuantityForm(MainFormUnits, false);
|
||||
|
||||
} else {
|
||||
StoreScanData();
|
||||
StoreScanRecord();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* FUNCTION: StoreScanData
|
||||
* FUNCTION: StoreScanRecord
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static void StoreScanData()
|
||||
static void StoreScanRecord()
|
||||
{
|
||||
FormPtr form;
|
||||
ControlPtr ctrl;
|
||||
|
@ -1383,7 +1372,7 @@ static void StoreScanData()
|
|||
FocusBarcode();
|
||||
}
|
||||
|
||||
/* static void StoreScanData() */
|
||||
/* static void StoreScanRecord() */
|
||||
/* { */
|
||||
/* FormPtr form; */
|
||||
/* FieldPtr barcode; */
|
||||
|
@ -1536,65 +1525,83 @@ static Boolean OpenBabboScanner()
|
|||
*
|
||||
************************************************************/
|
||||
|
||||
static Boolean OpenBCS2Scanner()
|
||||
static Err OpenBCS2Scanner()
|
||||
{
|
||||
Err err;
|
||||
LocalID dbId;
|
||||
LocalID dbID;
|
||||
|
||||
err = SysLibLoad('libr', 'BcAp', &gBcs2RefNum);
|
||||
if (err) {
|
||||
switch (err) {
|
||||
case sysErrLibNotFound:
|
||||
SysFatalAlert("BCS2 library not found!");
|
||||
break;
|
||||
case sysErrNoFreeRAM:
|
||||
SysFatalAlert("Out of memory (RAM)!");
|
||||
break;
|
||||
case sysErrNoFreeLibSlots:
|
||||
SysFatalAlert("No free library slots!");
|
||||
break;
|
||||
default:
|
||||
SysFatalAlert("BCS2 library load failed!");
|
||||
break;
|
||||
}
|
||||
gBcs2RefNum = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
err = BCS2LibOpen(gBcs2RefNum);
|
||||
if (err) {
|
||||
switch (err) {
|
||||
case errBCS2MemoryError:
|
||||
SysFatalAlert("BCS2 threw memory error");
|
||||
break;
|
||||
default:
|
||||
SysFatalAlert("BCS2 library open failed!");
|
||||
break;
|
||||
}
|
||||
SysLibRemove(gBcs2RefNum);
|
||||
gBcs2RefNum = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
dbId = DmFindDatabase(cardNumber, appDbRattail);
|
||||
if (! dbId) {
|
||||
SysFatalAlert("Find database failed!");
|
||||
SysLibRemove(gBcs2RefNum);
|
||||
gBcs2RefNum = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
err = SysNotifyRegister(cardNumber, dbId,
|
||||
BCS2BarCodeReadyNotification, NULL,
|
||||
sysNotifyNormalPriority, NULL);
|
||||
// Find the loaded BCS2 library, or attempt to load it.
|
||||
if (SysLibFind(BCS2LibName, &gBCS2RefNum) != errNone) {
|
||||
err = SysLibLoad(BCS2LibTypeID, BCS2LibCreatorID, &gBCS2RefNum);
|
||||
if (err != errNone) {
|
||||
SysFatalAlert("Notify registration failed!");
|
||||
SysLibRemove(gBcs2RefNum);
|
||||
gBcs2RefNum = 0;
|
||||
return false;
|
||||
SysFatalAlert("BCS2 library not found!");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
// Open the BCS2 library.
|
||||
err = BCS2LibOpen(gBCS2RefNum);
|
||||
if (err != 0) {
|
||||
SysFatalAlert("BCS2 library could not be opened!");
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Find the Rattail database.
|
||||
dbID = DmFindDatabase(cardNumber, appDbRattail);
|
||||
if (dbID == 0) {
|
||||
err = DmGetLastErr();
|
||||
SysFatalAlert("Rattail application database not found!");
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Register for barcode ready notification.
|
||||
err = SysNotifyRegister(cardNumber, dbID, BCS2BarCodeReadyNotification, NULL, sysNotifyNormalPriority, NULL);
|
||||
if (err != errNone) {
|
||||
SysFatalAlert("Registering for barcode ready notification failed!");
|
||||
goto error;
|
||||
}
|
||||
|
||||
return errNone;
|
||||
|
||||
error:
|
||||
if (dbID != 0) {
|
||||
SysNotifyUnregister(cardNumber, dbID, BCS2BarCodeReadyNotification, sysNotifyNormalPriority);
|
||||
}
|
||||
if (gBCS2RefNum != sysInvalidRefNum) {
|
||||
SysLibRemove(gBCS2RefNum);
|
||||
gBCS2RefNum = sysInvalidRefNum;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* FUNCTION: CloseBCS2Scanner
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static Err CloseBCS2Scanner()
|
||||
{
|
||||
Err err = errNone;
|
||||
LocalID dbID;
|
||||
|
||||
dbID = DmFindDatabase(cardNumber, appDbRattail);
|
||||
if (dbID != 0) {
|
||||
SysNotifyUnregister(cardNumber, dbID, BCS2BarCodeReadyNotification, sysNotifyNormalPriority);
|
||||
}
|
||||
|
||||
if (gBCS2RefNum != sysInvalidRefNum) {
|
||||
err = BCS2LibClose(gBCS2RefNum);
|
||||
if (err == errNone) {
|
||||
err = SysLibRemove(gBCS2RefNum);
|
||||
if (err == errNone) {
|
||||
gBCS2RefNum = sysInvalidRefNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1864,11 +1871,11 @@ static void QuantityFormAccept()
|
|||
if (IsChecked(form, MainFormStopOnUnits)) {
|
||||
ShowQuantityForm(MainFormUnits, false);
|
||||
} else {
|
||||
StoreScanData();
|
||||
StoreScanRecord();
|
||||
}
|
||||
|
||||
} else if (gQuantityTriggerID == MainFormUnits) {
|
||||
StoreScanData();
|
||||
StoreScanRecord();
|
||||
}
|
||||
|
||||
#ifdef SCANLIB_SYMBOLY
|
||||
|
@ -1877,3 +1884,65 @@ static void QuantityFormAccept()
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* FUNCTION: ScannerSettingsFormHandleEvent
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static Boolean ScannerSettingsFormHandleEvent(EventPtr event)
|
||||
{
|
||||
Boolean handled = false;
|
||||
FormPtr form;
|
||||
Char settings[7] = {0};
|
||||
|
||||
switch (event->eType) {
|
||||
|
||||
case frmOpenEvent:
|
||||
form = FrmGetActiveForm();
|
||||
FrmDrawForm(form);
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case ctlSelectEvent:
|
||||
switch (event->data.ctlSelect.controlID) {
|
||||
|
||||
case ScannerSettingsResetScanner:
|
||||
BCS2LibReset(gBCS2RefNum);
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case ScannerSettingsSetFactoryDefaults:
|
||||
BCS2LibSetToFactoryDefaults(gBCS2RefNum);
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case ScannerSettingsPushRattailSettings:
|
||||
/* BCS2LibChangeSettings(gBCS2RefNum, BCS2ManualTrigger, 3); */
|
||||
/* BCS2LibChangeSettings(gBCS2RefNum, BSC2EnableNOREAD, 3); */
|
||||
/* BCS2LibChangeSettings(gBCS2RefNum, "R40R34", 6); */
|
||||
|
||||
StrCopy(settings, BCS2ManualTrigger);
|
||||
StrCat(settings, BSC2EnableNOREAD);
|
||||
BCS2LibChangeSettings(gBCS2RefNum, settings, StrLen(settings));
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case ScannerSettingsDone:
|
||||
FrmReturnToForm(MainForm);
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue