FuncKB.c .
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FUNCKEY_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <string.h>
#include <ctype.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XLCD.h"
#include "XTimer.h"
#include "XTask.h"
#include "XParser.h"
#include "XDisplay.h"
#include "XKeyboard.h"
#include "Function.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#if defined(PS2_MODEL) || defined(USB_HOST_MODEL)
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
STATIC CHAR InputPrompt[DSP_LINE_CHARS + 1];
STATIC CHAR InputData[1024];
STATIC BOOL InputNumber;
STATIC BOOL InputInsert;
STATIC BOOL InputMask;
STATIC INT InputCursor;
STATIC INT InputLocation;
STATIC INT InputLimit;
STATIC BOOL CloseFuncKB;
STATIC XCALLBACK callbackKB;
STATIC TASK(MenuTask, arg)
{
#if defined(MENU_TSPL_3) || defined(MENU_TSPL_4)
KeyboardMenu();
#endif
if (arg) *(BOOL *)arg = FALSE;
TaskExit();
}
STATIC TASK(MenuFileFlashTask, arg)
{
#if defined(MENU_TSPL_3) || defined(MENU_TSPL_4)
KeyboardFlashListMenu();
#endif
if (arg) *(BOOL *)arg = FALSE;
TaskExit();
}
STATIC VOID RxFuncKB(VOID)
{
_PrintCfg *pKeybCfg = GrabPrintConfig();
USHORT key;
CHAR data;
if ((key = KeyboardOut()) == 0)
return;
switch (key)
{
case SCAN_KEY_F1:
if (IsMotion() || CheckJobLock() || GetJobErrorState())
break;
if (GetDisplayStatus() != DIS_READY)
break;
CloseFuncKB = TRUE;
TaskCreate(MenuTask, &CloseFuncKB, TASK_MENU_STACK);
break;
case SCAN_KEY_F2:
if (IsMotion() || CheckJobLock() || GetJobErrorState())
break;
if (GetDisplayStatus() != DIS_READY)
break;
CloseFuncKB = TRUE;
TaskCreate(MenuFileFlashTask, &CloseFuncKB, TASK_MENU_STACK);
break;
case SCAN_KEY_CTRL_DEL:
pKeybCfg->IgnoreAutoRun = TRUE;
case SCAN_KEY_CTRL_C:
if (IsMotorEnable())
break;
PrinterReboot();
break;
case SCAN_KEY_ENTER:
UserDataIn(CR_CHAR);
UserDataIn(LF_CHAR);
break;
default:
data = key & 0xFF;
if (data == 0)
break;
UserDataIn(data);
break;
}
}
STATIC VOID InputFuncKB(VOID)
{
_PrintCfg *pKeybCfg = GrabPrintConfig();
USHORT key;
CHAR data;
INT i;
if (IsMotion() || CheckJobLock() || GetJobErrorState())
return;
if ((key = KeyboardOut()) == 0)
return;
if (InputMask)
{
InputMask = FALSE;
switch (key)
{
case SCAN_KEY_ESC:
case SCAN_KEY_DEL:
case SCAN_KEY_BACKSPACE:
memset(InputData, 0, sizeof(InputData));
case SCAN_KEY_HOME:
case SCAN_KEY_LEFT:
InputCursor = InputLocation = 0;
break;
case SCAN_KEY_ENTER:
for (i = 0; i < strlen(InputData); i++)
UserDataIn(InputData[i]);
UserDataIn(CR_CHAR);
break;
case SCAN_KEY_INSERT:
InputInsert = !InputInsert;
break;
case SCAN_KEY_CTRL_DEL:
pKeybCfg->IgnoreAutoRun = TRUE;
case SCAN_KEY_CTRL_C:
PrinterReboot();
break;
default:
data = key & 0xFF;
if (data == 0)
break;
if (InputNumber && !isdigit(data) && data != '.' && data != '-')
break;
memset(InputData, 0, sizeof(InputData));
InputCursor = InputLocation = 1;
InputData[0] = data;
break;
}
}
else
{
switch (key)
{
case SCAN_KEY_HOME:
InputCursor = InputLocation = 0;
break;
case SCAN_KEY_END:
InputCursor = InputLocation = strlen(InputData);
if (InputCursor > DSP_LINE_CHARS - 1)
InputCursor = DSP_LINE_CHARS - 1;
break;
case SCAN_KEY_RIGHT:
InputLocation++;
if (InputLocation > strlen(InputData))
InputLocation = strlen(InputData);
InputCursor++;
if (InputCursor > strlen(InputData))
InputCursor = strlen(InputData);
if (InputCursor > DSP_LINE_CHARS - 1)
InputCursor = DSP_LINE_CHARS - 1;
break;
case SCAN_KEY_LEFT:
InputLocation--;
if (InputLocation < 0)
InputLocation = 0;
InputCursor--;
if (InputCursor < 0)
InputCursor = 0;
break;
case SCAN_KEY_DEL:
if (InputLocation != strlen(InputData))
strcpy(InputData + InputLocation, InputData + InputLocation + 1);
break;
case SCAN_KEY_BACKSPACE:
if (InputLocation)
strcpy(InputData + InputLocation - 1, InputData + InputLocation);
InputLocation--;
if (InputLocation < 0)
InputLocation = 0;
InputCursor--;
if (InputCursor < 0)
InputCursor = 0;
break;
case SCAN_KEY_ESC:
InputCursor = InputLocation = 0;
memset(InputData, 0, sizeof(InputData));
break;
case SCAN_KEY_ENTER:
for (i = 0; i < strlen(InputData); i++)
UserDataIn(InputData[i]);
UserDataIn(CR_CHAR);
break;
case SCAN_KEY_INSERT:
InputInsert = !InputInsert;
break;
case SCAN_KEY_CTRL_DEL:
pKeybCfg->IgnoreAutoRun = TRUE;
case SCAN_KEY_CTRL_C:
PrinterReboot();
break;
default:
data = key & 0xFF;
if (data == 0)
break;
if (InputLocation >= InputLimit || InputLocation >= sizeof(InputData) - 1)
break;
if (InputNumber && !isdigit(data) && data != '.' && data != '-')
break;
if (InputNumber && data == '.' && strchr(InputData, '.'))
break;
if (InputNumber && data == '-' && strchr(InputData, '-'))
break;
if (InputLocation == strlen(InputData))
InputData[InputLocation + 1] = '\0';
else if (InputInsert)
{
if (strlen(InputData) >= InputLimit ||
strlen(InputData) >= sizeof(InputData) - 1)
break;
memmove(InputData + InputLocation + 1,
InputData + InputLocation, strlen(InputData + InputLocation));
}
InputData[InputLocation++] = data;
InputCursor++;
if (InputCursor > DSP_LINE_CHARS - 1)
InputCursor = DSP_LINE_CHARS - 1;
break;
}
}
SetDisplayInputFunc(
InputPrompt,
InputData + InputLocation - InputCursor,
InputNumber,
InputCursor,
InputInsert ? 0 : 1,
TRUE);
}
STATIC VOID KeyboardFunc(VOID)
{
if (callbackKB && CloseFuncKB == FALSE)
callbackKB();
}
VOID InitialFuncKB(VOID)
{
memset(InputPrompt, 0, sizeof(InputPrompt));
memset(InputData, 0, sizeof(InputData));
CloseFuncKB = FALSE;
callbackKB = RxFuncKB;
StartPeriodFunc(KeyboardFunc);
}
VOID EntryInputKB(CHAR *prompt, CHAR *data, BOOL number, INT limit)
{
if (KeyboardReady == FALSE)
return;
strncpy(InputPrompt, prompt, sizeof(InputPrompt) - 1);
strncpy(InputData, data, sizeof(InputData) - 1);
InputNumber = number;
InputInsert = TRUE;
InputMask = TRUE;
InputCursor = InputLocation = strlen(InputData);
if (InputCursor > DSP_LINE_CHARS - 1)
InputCursor = DSP_LINE_CHARS - 1;
InputLimit = (limit > 0) ? (limit) : (sizeof(InputData) - 1);
while (IsMotion() || CheckJobLock() || GetJobErrorState())
NutSleep(10);
SetDisplayInputFunc(
InputPrompt,
InputData,
InputNumber,
0,
MIN(InputLocation, DSP_LINE_CHARS),
FALSE);
callbackKB = InputFuncKB;
}
VOID LeaveInputKB(VOID)
{
ClrDisplayStatus(DIS_INPUT_FUNC);
callbackKB = RxFuncKB;
}
#endif
FuncKey.c /
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FUNCKEY_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#include <string.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XLED.h"
#include "XKey.h"
#include "XBuzzer.h"
#include "XTimer.h"
#include "XTask.h"
#include "XVarBank.h"
#include "XRTC.h"
#include "XProFile.h"
#include "XFuseFlash.h"
#include "XParser.h"
#include "XDisplay.h"
#include "XKeyboard.h"
#include "Function.h"
//#include "XPrintBack.h"
extern VOID ClrPaperErrCnt(VOID); // ch_20220411
// ch_20220428
STATIC UCHAR taskBusy = 0;
VOID SetTaskStatus(VOID) {
taskBusy = 1;
}
VOID ResetTaskStatus(VOID) {
taskBusy = 0;
}
UCHAR ReturnTaskStatus(VOID) {
return taskBusy;
}
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
STATIC VOID KeyFuncFormFeed(INT);
STATIC VOID KeyFuncPauseFeed(INT);
STATIC VOID KeyFuncCal(VOID); // ch_20211209
STATIC VOID KeyFunPrintSelfTest(VOID); // ch_20211217
STATIC VOID KeyFuncPause(INT);
STATIC VOID KeyFuncMenu(INT);
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
#if defined(TTP245_PCB) || defined(TTP245P_PCB) || defined(TTP245C_PCB) || defined(TDP225_PCB)
STATIC CONST KEYFUNC DefaultKeyFunc[KEY_TOTAL] =
{
KeyFuncPauseFeed,
_NULL,
_NULL,
_NULL,
_NULL,
_NULL,
};
#elif defined(T045_PCB) ||defined(T40_PCB)
#if defined(XP300B)
STATIC CONST KEYFUNC DefaultKeyFunc[KEY_TOTAL] =
{
KeyFuncPause,
KeyFuncPauseFeed,
_NULL,
_NULL,
_NULL,
_NULL,
};
#else
STATIC CONST KEYFUNC DefaultKeyFunc[KEY_TOTAL] =
{
KeyFuncPauseFeed, //单击按键执行
// KeyFuncPause,
KeyFunPrintSelfTest,
KeyFuncCal,
// KeyFunPrintSelfTest,
// _NULL,
_NULL,
_NULL,
_NULL,
};
#endif
#endif
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
STATIC FUNCARG KeyFuncArg[KEY_TOTAL];
STATIC INT FeedTimes;
STATIC INT FeedFexKey;
STATIC BOOL FeedState = FALSE; // ch_20211215
// ch_20211220
STATIC UCHAR powerOnDone = 0;
UCHAR PowerOnStatus(VOID)
{
return powerOnDone;
}
STATIC TASK(MenuTask, arg)
{
#if defined(MENU_TSPL_1) || defined(MENU_TSPL_2) || defined(MENU_TSPL_3)
MainMenu();
#endif
if (arg) *(BOOL *)arg = FALSE;
TaskExit();
}
STATIC TASK(PauseMenu, arg)
{
#if defined(LCD_MODEL) && defined(MENU_TSPL_3)
ClrDisplayStatus(DIS_PAUSE);
JobMenu();
SetDisplayStatus(DIS_PAUSE);
#endif
if (arg) *(BOOL *)arg = FALSE;
TaskExit();
}
STATIC TASK(PrintTask, arg)
{
INT Quantity = ((FUNCARG *)arg)->Number;
#if defined(TSPL)
TsplPrintFunc(Quantity);
#endif
TaskExit();
}
STATIC TASK(CutTask, arg)
{
CutPaper();
TaskExit();
}
STATIC TASK(ResetAlarm, arg)
{
INT Key = *(INT *)arg;
StopKeyFunc();
#ifdef DEBUG_PRNT
sysprintf("EnableBuzzer TASK\r\n");
#endif
EnableBuzzer(3, 300000); // 5 minutes
while (CheckKeyPin(Key)){}
DisableBuzzer();
PrinterReboot();
TaskExit();
}
STATIC VOID DecFeedTimes(VOID)
{
FeedTimes -= 1;
}
STATIC VOID FeedFaxPaper(VOID)
{
_PrintCfg *pKeyCfg = GrabPrintConfig();
if (FeedTimes > 1){}
else if (CheckKeyPin(FeedFexKey))
{
FeedTimes += 1;
MotorMove((LONG)MM_DOT * 3, pKeyCfg, MOTOR_FORWARD, DecFeedTimes);
}
else if (!CheckKeyPin(FeedFexKey))
CancelPeriodFunc(FeedFaxPaper);
}
STATIC VOID BackFeedFaxPaper(VOID)
{
_PrintCfg *pKeyCfg = GrabPrintConfig();
if (FeedTimes > 1){}
else if (CheckKeyPin(FeedFexKey))
{
FeedTimes += 1;
MotorMove((LONG)MM_DOT * 3, pKeyCfg, MOTOR_BACKWARD, DecFeedTimes);
}
else if (!CheckKeyPin(FeedFexKey))
CancelPeriodFunc(BackFeedFaxPaper);
}
STATIC VOID ClrFeedState(VOID)
{
FeedState = FALSE;
}
STATIC VOID KeyFuncFeed(INT Key)
{
sysprintf("Key..1\n");
if (!IsMotion() && !CheckJobLock())
{
FeedTimes = 0;
FeedFexKey = Key;
ResetHeadPosition();
StartPeriodFunc(FeedFaxPaper);
}
}
STATIC VOID KeyFuncBackFeed(INT Key)
{
sysprintf("Key..2\n");
if (!IsMotion() && !CheckJobLock())
{
FeedTimes = 0;
FeedFexKey = Key;
ResetHeadPosition();
StartPeriodFunc(BackFeedFaxPaper);
}
}
STATIC VOID KeyFuncFormFeed(INT Key)
{
_PrintCfg *pKeyCfg = GrabPrintConfig();
sysprintf("Key..3\n");
if (!IsMotion() && !CheckJobLock())
{
if (pKeyCfg->SensorMode == CONTINUE_MODE_T ||
pKeyCfg->SensorMode == CONTINUE_MODE_R ||
pKeyCfg->SensorMode == FEED_CONTINUE_MODE)
{
if (pKeyCfg->FeedLength)
{
ResetHeadPosition();
MotorMove(pKeyCfg->FeedLength, pKeyCfg, MOTOR_FORWARD, _NULL);
}
else
{
#if defined(TSPL_VER_1)
FeedTimes = 0;
FeedFexKey = Key;
ResetHeadPosition();
StartPeriodFunc(FeedFaxPaper);
#else
FeedBatch(1, pKeyCfg, TRUE, _NULL);
#endif
}
}
else
FeedBatch(1, pKeyCfg, TRUE, _NULL);
}
}
/
STATIC VOID KeyFuncPauseFeed(INT Key) //单击按键执行
{
_PrintCfg *pKeyCfg = GrabPrintConfig();
_ePolyLEDStat LEDState = 0; // ch_20220609
//sysprintf("FeedLen%d\n", pKeyCfg->FeedLength); // ch_20220411
#ifdef DEBUG_PRNT
sysprintf("KeyFuncPauseFeed()...\n"); // ch_20211209
#endif
if (FeedState)
return;
#ifdef DEBUG_PRNT
sysprintf("FeedState = %d\n", FeedState); // ch_20211209
#endif
if (!CheckJobLock())
{
#ifdef DEBUG_PRNT
sysprintf("(!CheckJobLock()) = TRUE\n"); // ch_20211211
#endif
if (!IsMotion())
{
#ifdef DEBUG_PRNT
sysprintf("(!IsMotion()) = TRUE\n"); // ch_20211211
sysprintf("pKeyCfg->SensorMode = %d\tpKeyCfg->FeedLength = %d\n", pKeyCfg->SensorMode, pKeyCfg->FeedLength); // ch_20211211
#endif
if (pKeyCfg->SensorMode == CONTINUE_MODE_T ||
pKeyCfg->SensorMode == CONTINUE_MODE_R ||
pKeyCfg->SensorMode == FEED_CONTINUE_MODE)
{
#ifdef DEBUG_PRNT
sysprintf("CONTINOUS mode ...\n"); // ch_20211211
#endif
// if (!pKeyCfg->FeedLength) // ch_20211215
pKeyCfg->FeedLength = 160; // ch_20211211
if (pKeyCfg->FeedLength)
{
ResetHeadPosition();
MotorMove(pKeyCfg->FeedLength, pKeyCfg, MOTOR_FORWARD, ClrFeedState);
}
else
FeedBatch(1, pKeyCfg, TRUE, ClrFeedState);
}
else
{
#ifdef DEBUG_PRNT
sysprintf("Other mode ...\n"); // ch_20211211
#endif
//pKeyCfg->FeedLength = 160; // ch_20220321
FeedBatch(1, pKeyCfg, TRUE, ClrFeedState);
}
FeedState = TRUE;
}
else if (!GetJobErrorState())
{
StopJobManager();
#if defined(MONO_LED)
StartPeriodFunc(FlashLED2);
#elif defined(POLY_LED)
///
// ch_20220609
//sysprintf("K_P_0\n");
LEDState = GetLEDStat();
//sysprintf("LED_S_%d\n", LEDState);
if (LED_FLASH_RED_BLUE == LEDState)
CancelPeriodFunc(FlashBlueRedLED);
else if (LED_FLASH_RED_BLUE_FAST == LEDState)
CancelPeriodFunc(FlashBlueRedLEDFast);
SetLEDStat(LED_FLASH_BLUE);
///
StartPeriodFunc(FlashGreenLED);
#endif
#if defined(LCD_MODEL)
SetDisplayStatus(DIS_PAUSE);
#endif
}
}
else
PrinterStart();
}
// ch_20211209
STATIC TASK(FuncTest, arg)
{
#ifdef DEBUG_PRNT
sysprintf("Exec FuncTest()...\n");
#endif
TaskExit();
}
// ch_20211209
STATIC VOID KeyFuncCal(VOID) //双击定标进来执行
{
_PrintCfg *pPrintCfg = GrabPrintConfig();
_ePolyLEDStat LEDState = 0; // ch_20220608
#ifdef DEBUG_PRNT
sysprintf("Enter KeyFuncCal()...\n"); // ch_20211209
#endif
if (!CheckJobLock())
{
if (!IsMotion())
{
SetCalStatPowerOn(); // ch_20220414
// pPrintCfg->SensorMode = CONTINUE_MODE_T;
// DetectSensorInten(pPrintCfg, TRUE, FALSE, 0, 0);
Calibration(pPrintCfg, TRUE, 0, 0);
// DetectSensorInten(pPrintCfg, TRUE, TRUE, 0, 0);
pPrintCfg->IgnoreAutoRun = TRUE;
}
// ch_20220609
// else if (!GetJobErrorState())
// {
// StopJobManager();
//
//#if defined(MONO_LED)
// StartPeriodFunc(FlashLED2);
//#elif defined(POLY_LED)
// ///
// // ch_20220609
// LEDState = GetLEDStat();
// if (LED_FLASH_RED_BLUE == LEDState)
// CancelPeriodFunc(FlashBlueRedLED);
// else if (LED_FLASH_RED_BLUE_FAST == LEDState)
// CancelPeriodFunc(FlashBlueRedLEDFast);
// SetLEDStat(LED_FLASH_BLUE);
// ///
// StartPeriodFunc(FlashGreenLED);
//#endif
//
//#if defined(LCD_MODEL)
// SetDisplayStatus(DIS_PAUSE);
//#endif
// }
}
// else // ch_20220609
// PrinterStart(); // ch_20220609
}
// ch_20211230
STATIC TASK(PrintSelfTest, arg)
{
REPORT *Report;
_ePolyLEDStat LEDState = 0; // ch_20220608
if (!CheckJobLock())
{
if (!IsMotion())
{
WaitWorkJobEnd(); // ch_20220427
#ifdef DEBUG_PRNT
sysprintf("Start Self-test...\n"); // ch_20211217
sysprintf("Memory %u free\n", (unsigned int)NutHeapAvailable()); // ch_20211220
#endif
// StartPeriodFunc(FlashTimesRedLED); // ch_20220427
//sysprintf("Get to HERE!\n"); // ch_20220427
Report = SelfTestReport(NULL, FALSE, OUTPUT_LABEL);
Report = BtConfigReport(Report, FALSE, OUTPUT_LABEL);
Report = FileReport(Report, FALSE, OUTPUT_LABEL);
// Report = SelfTestReport(NULL, FALSE, OUTPUT_RS232);
// Report = BtConfigReport(Report, FALSE, OUTPUT_RS232);
// Report = FileReport(Report, FALSE, OUTPUT_RS232);
DumpText(Report);
// PrintImageLabel(1, 1);
// sysDisableWatchDogTimer(); // ch_20220427
#ifdef DEBUG_PRNT
sysprintf("End\n"); // ch_20220427
#endif
}
else if (!GetJobErrorState())
{
StopJobManager();
#if defined(MONO_LED)
StartPeriodFunc(FlashLED2);
#elif defined(POLY_LED)
///
// ch_20220609
LEDState = GetLEDStat();
if (LED_FLASH_RED_BLUE == LEDState)
CancelPeriodFunc(FlashBlueRedLED);
else if (LED_FLASH_RED_BLUE_FAST == LEDState)
CancelPeriodFunc(FlashBlueRedLEDFast);
SetLEDStat(LED_FLASH_BLUE);
///
StartPeriodFunc(FlashGreenLED);
#endif
#if defined(LCD_MODEL)
SetDisplayStatus(DIS_PAUSE);
#endif
}
}
ResetTaskStatus(); // ch_20220428
TaskExit();
}
// ch_20211230
VOID KeyFunPrintSelfTest(VOID)
{
while (ReturnTaskStatus()); // ch_20220428
StartPeriodFunc(FlashTimesRedLED); // ch_20220427
SetTaskStatus(); // ch_20220428
TaskCreate(PrintSelfTest, 0, TASK_SELFTEST_STACK);
}
STATIC VOID KeyFuncPause(INT Key)
{
if (CheckJobLock())
PrinterStart();
else
PrinterPause();
}
STATIC VOID KeyFuncMenu(INT Key)
{
STATIC BOOL CreateMenu = FALSE;
if (CreateMenu)
return;
if (!IsMotion() && !CheckJobLock() && !GetJobErrorState())
{
CreateMenu = TRUE;
TaskCreate(MenuTask, &CreateMenu, TASK_MENU_STACK);
}
#if defined(MENU_TSPL_3)
else if (IsMotion() && CheckJobLock() && !GetJobErrorState())
{
CreateMenu = TRUE;
TaskCreate(PauseMenu, &CreateMenu, TASK_MENU_STACK);
}
#endif
}
STATIC VOID KeyFuncPrint(INT Key)
{
if (!IsMotion() && !CheckJobLock() && !GetJobErrorState())
TaskCreate(PrintTask, (VOID *)&KeyFuncArg[Key], TASK_PRINT_STACK);
}
STATIC VOID KeyFuncCut(INT Key)
{
if (!IsMotion() && !CheckJobLock() && !GetJobErrorState())
TaskCreate(CutTask, 0, TASK_CUT_STACK);
}
STATIC VOID KeyFuncInput(INT Key)
{
BYTE *data = (BYTE *)KeyFuncArg[Key].String;
while (*data != 0)
UserDataIn(*data++);
// UserDataIn(CR_CHAR);
}
STATIC VOID KeyFuncLongReset(INT Key)
{
STATIC CONST INT KeyArg[KEY_TOTAL] = { 0, 1, 2, 3, 4, 5 };
if (CheckJobLock() && !GetJobErrorState())
TaskCreate(ResetAlarm, (VOID *)&KeyArg[Key], TASK_RESET_STACK);
}
VOID InitialFuncKey(VOID)
{
_PrintCfg *pKeyCfg = GrabPrintConfig();
INT Key;
ClrFeedState();
for (Key = 0; Key < KEY_TOTAL; Key++)
KeyFuncSetting(Key, &pKeyCfg->KeySetting[Key]);
}
/
VOID KeyFuncSetting(INT Key, _KeySetting *KeySetting)
{
#ifdef DEBUG_PRNT
sysprintf("Enter KeyFuncSetting() to set Key %d\n", Key); // ch_20211210
#endif
if (KeySetting->FuncID == KEY_FUNC_OFF)
ClrKeyFunc(Key);
if (KeySetting->FuncID == KEY_FUNC_DEFAULT)
SetKeyFunc(Key, DefaultKeyFunc[Key]);
if (KeySetting->FuncID == KEY_FUNC_MENU)
SetKeyFunc(Key, KeyFuncMenu);
if (KeySetting->FuncID == KEY_FUNC_PAUSE)
SetKeyFunc(Key, KeyFuncPause);
if (KeySetting->FuncID == KEY_FUNC_FEED)
SetKeyFunc(Key, KeyFuncFeed);
if (KeySetting->FuncID == KEY_FUNC_BACKFEED)
SetKeyFunc(Key, KeyFuncBackFeed);
if (KeySetting->FuncID == KEY_FUNC_FORMFEED)
SetKeyFunc(Key, KeyFuncFormFeed);
if (KeySetting->FuncID == KEY_FUNC_PRINT)
SetKeyFunc(Key, KeyFuncPrint);
if (KeySetting->FuncID == KEY_FUNC_CUT)
SetKeyFunc(Key, KeyFuncCut);
if (KeySetting->FuncID == KEY_FUNC_INPUT)
SetKeyFunc(Key, KeyFuncInput);
KeyFuncArg[Key] = KeySetting->Argument;
}
#if defined(TTP245P_PCB) ||defined(T045_PCB) ||defined(T40_PCB)
VOID CheckPowerOnKey(VOID)
{
_PrintCfg *pPwrKeyCfg = GrabPrintConfig();
REPORT *Report;
FLOAT data;
INT part;
#if defined(LCD_MODEL)
CONST STATIC CHAR *Msg[5] =
{
"Calibrate ",
"Self Test ",
"Initialize ",
"Bline Detect ",
"Gap Detect ",
};
#endif
// ch_20211229
// CONST STATIC _ePolyLED Light[5][2] =
// {
// { HID_LED_RED, HID_LED_DARK },
// { HID_LED_ORANGE, HID_LED_DARK },
// { HID_LED_GREEN, HID_LED_DARK },
// { HID_LED_GREEN, HID_LED_ORANGE },
// { HID_LED_RED, HID_LED_ORANGE },
// };
CONST STATIC _ePolyLED Light[12/*6*/][2] = // ch_20220509 : changed to 12 from 6.
{
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK },
{ HID_LED_RED, HID_LED_DARK }
};
//#ifdef DEBUG_PRNT
//sysprintf("Enter CheckPowerOnKey()_0...\n"); // ch_20211208
//#endif
part = 0;
while (CheckKeyPin(FEED_KEY))
{
#if defined(LCD_MODEL)
ShowLCDString(0, 0, (CHAR *)Msg[part/10], 0);
#endif
switch ( part )
{
case 0 :
if (GetProfileInt("AUTODETECT KEY CLOSE 1", &data) == FALSE)
data=0;
if ((BOOL)data == TRUE)
part=10;
else
break;
case 10 :
if (GetProfileInt("SELFTEST KEY CLOSE 2", &data) == FALSE)
data=0;
if ((BOOL)data == TRUE)
part=20;
else
break;
case 20 :
if (GetProfileInt("INITIALPRINTER KEY CLOSE 3", &data) == FALSE)
data=0;
if ((BOOL)data == TRUE)
part=30;
else
break;
case 30 :
if (GetProfileInt("BLINEDETECT KEY CLOSE 4", &data) == FALSE)
data=0;
if ((BOOL)data == TRUE)
part=40;
else
break;
case 40 :
if (GetProfileInt("GAPDETECT KEY CLOSE 5", &data) == FALSE)
data=0;
if ((BOOL)data == TRUE)
part=50;
else
break;
case 50 :
if (GetProfileInt("IGNORE AUTO KEY CLOSE 6", &data) == FALSE)
data=0;
if ((BOOL)data == TRUE)
part=60;
}
#ifdef DEBUG_PRNT
sysprintf("key part %d\r\n",part);
#endif
// ch_20220509
// if(part>59)
// {
ShowLED(HID_LED_GREEN); // ch_20220119
// ShowLED(HID_LED_RED); // ch_20220119
// break;
// }
if (!(part%3)) // ch_20211229
ShowLED(Light[part/10][part&1]);
delay_msec(300);
// if (++part >= 50) // ch_20220509
part++; // ch_20220509
if (part >= 130) // ch_20220509
{
pPwrKeyCfg->IgnoreAutoRun = TRUE;
break;
}
// ch_20211230
if (14 == part)
{
EnableBuzzer(8, 500);
while (CheckBuzzerStatus());
}
// ch_20220509
if (100 == part) {
EnableBuzzer(8, 100);
while (CheckBuzzerStatus());
delay_msec(50);
EnableBuzzer(8, 100);
while (CheckBuzzerStatus());
delay_msec(50);
EnableBuzzer(8, 100);
while (CheckBuzzerStatus());
delay_msec(50);
EnableBuzzer(8, 100);
while (CheckBuzzerStatus());
delay_msec(50);
}
}
powerOnDone = 1; // ch_20211220
#ifdef DEBUG_PRNT
sysprintf("Enter CheckPowerOnKey()_0...\n"); // ch_20211208
sysprintf("powerOnDone = %d\n", powerOnDone); // ch_20211208
#endif
GetKey(FEED_KEY);
// ShowLED(HID_LED_GREEN); // ch_20220119
// ch_20220509
if (part >= 130) {
}
else if (part >= 100) {
spiFlashEraseAll();
DelayTime(50000000);
ProcessorReset();
}
else if (part >= 14) {
#if defined(LCD_MODEL)
SetDisplayStatus(DIS_INITIAL);
#endif
if (GetProfileInt("FILES KEEP", &data) == FALSE)
data = 1;
if ((BOOL)data == FALSE)
DeleteFile(FLASH_DEVICE, "*");
InitialDefaultVar();
pPwrKeyCfg->IgnoreAutoRun = TRUE;
PrinterReboot();
#if defined(LCD_MODEL)
ClrDisplayStatus(DIS_INITIAL);
#endif
}
else if (0 == part) {
if (GetProfileInt("GOHOME", &data) == FALSE)
data = 0;
if ((BOOL)data == TRUE)
PaperHome(pPwrKeyCfg);
#if defined(ZPL2)
Zpl2MediaPowerUp();
#endif
}
// ch_20220509
// if (part == 0)
// {
// if (GetProfileInt("GOHOME", &data) == FALSE)
// data = 0;
// if ((BOOL)data == TRUE)
// PaperHome(pPwrKeyCfg);
//
//#if defined(ZPL2)
// Zpl2MediaPowerUp();
//#endif
// }
// ch_20211229
// // Ribbon intension
// else if (part < 10)
// {
//#if defined(LCD_MODEL)
// SetDisplayStatus(DIS_CALIBRATION);
//#endif
//
//#if defined(RIBBON_MODEL)
// CheckRibbonExists(TRUE, TRUE);
//#endif
//
//#ifdef DEBUG_PRNT
//sysprintf("pPwrKeyCfg->SensorMode = %d\n", pPwrKeyCfg->SensorMode); // ch_20211211
//sysprintf("pPwrKeyCfg-AutoSensorRef = %d\n", pPwrKeyCfg->AutoSensorRef); // ch_20211211
//sysprintf("pPwrKeyCfg->ContinuousRef = %d\n", pPwrKeyCfg->ContinuousRef); // ch_20211211
//sysprintf("pPwrKeyCfg->ContinuePaperFeed = %d\n", pPwrKeyCfg->ContinuePaperFeed); // ch_20211211
//sysprintf("pPwrKeyCfg->FeedLength = %d\n", pPwrKeyCfg->FeedLength); // ch_20211211
//sysprintf("pPwrKeyCfg->ContinuousInten = %d\n", pPwrKeyCfg->ContinuousInten); // ch_20211211
//#endif
//
// DetectSensorInten(pPwrKeyCfg, TRUE, FALSE, 0, 0);
// pPwrKeyCfg->IgnoreAutoRun = TRUE;
//
//#if defined(LCD_MODEL)
// ClrDisplayStatus(DIS_CALIBRATION);
//#endif
// }
// Self test and Dump page mode
// ch_20211230 : comment
else if (part < 20) // ch_20211229
// else if ((part >= 4) && (part < 20)) // ch_20211229
// {
//#if defined(LCD_MODEL)
// SetDisplayStatus(DIS_SELFTEST);
//#endif
//
// StartPeriodFunc(FlashTimesRedLED); // ch_20211229
//
//#ifdef DEBUG_PRNT
//sysprintf("Enter CheckPowerOnKey()_1...\n"); // ch_20211208
//#endif
//
// if (DetectSensorInten(pPwrKeyCfg, TRUE, FALSE, 0, 0))
// {
// Report = SelfTestReport(NULL, FALSE, OUTPUT_LABEL);
//#if defined(NUTNET)
// if (GetThreadByName("ethernet"))
// Report = IpConfigReport(Report, FALSE, OUTPUT_LABEL);
//#endif
// Report = BtConfigReport(Report, FALSE, OUTPUT_LABEL);
// Report = FileReport(Report, FALSE, OUTPUT_LABEL);
// DumpText(Report);
// }
// pPwrKeyCfg->IgnoreAutoRun = TRUE;
//
//#ifdef DEBUG_PRNT
//sysprintf("Leave CheckPowerOnKey()_1...\n"); // ch_20211208
//#endif
//
//#if defined(LCD_MODEL)
// ClrDisplayStatus(DIS_SELFTEST);
//#endif
// }
// Initial factory reset
else if (part < 30) // ch_20211229
// ch_20220509 : commented.
// else if (part >= 14) // ch_20211230
// {
//#if defined(LCD_MODEL)
// SetDisplayStatus(DIS_INITIAL);
//#endif
// if (GetProfileInt("FILES KEEP", &data) == FALSE)
// data = 1;
// if ((BOOL)data == FALSE)
// DeleteFile(FLASH_DEVICE, "*");
//
// InitialDefaultVar();
// pPwrKeyCfg->IgnoreAutoRun = TRUE;
// PrinterReboot();
//
//#if defined(LCD_MODEL)
// ClrDisplayStatus(DIS_INITIAL);
//#endif
// }
// ch_20211229
// // Bline intension
// else if (part < 40)
// {
//#if defined(LCD_MODEL)
// SetDisplayStatus(DIS_CALIBRATION);
//#endif
//
//#ifdef DEBUG_PRNT
//sysprintf("Enter CheckPowerOnKey()_2...\n"); // ch_20211208
//#endif
//
// pPwrKeyCfg->SensorMode = BLINE_MODE;
// DetectSensorInten(pPwrKeyCfg, TRUE, FALSE, 0, 0);
// pPwrKeyCfg->IgnoreAutoRun = TRUE;
//
//#if defined(LCD_MODEL)
// ClrDisplayStatus(DIS_CALIBRATION);
//#endif
// }
//
// // Gap intension
// else if (part < 50)
// {
//#if defined(LCD_MODEL)
// SetDisplayStatus(DIS_CALIBRATION);
//#endif
//
//#ifdef DEBUG_PRNT
//sysprintf("Enter CheckPowerOnKey()_3...\n"); // ch_20211208
//#endif
//
// pPwrKeyCfg->SensorMode = GAP_MODE;
// DetectSensorInten(pPwrKeyCfg, TRUE, FALSE, 0, 0);
// pPwrKeyCfg->IgnoreAutoRun = TRUE;
//
//#if defined(LCD_MODEL)
// ClrDisplayStatus(DIS_CALIBRATION);
//#endif
// }
#ifdef DEBUG_PRNT
sysprintf("Leave CheckPowerOnKey()_0...\n"); // ch_20211221
#endif
}
#endif
extern void UsbRxDataIn(UINT8 data);
void PowerOnFeed(void){
#ifdef DEBUG_PRNT
sysprintf("Enter PowerOnFeed()...\n"); // ch_20211216
#endif
#if 0
BYTE *Data = "SPEED 2\r\nBLINEDETECT\r\n";
do{
UsbRxDataIn(*Data++);
}while(*Data != 0);
#else
KeyFuncPauseFeed(FEED_KEY);
#endif
}
FuncMedia.c //
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FUNCMEDIA_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XADC.h"
#include "XLED.h"
#include "XKey.h"
#include "XTimer.h"
#include "XDisplay.h"
#include "XParser.h"
#include "Function.h"
#include "XProFile.h"
#include "XVarBank.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define DETECT_SAMPLE 16
#define DETECT_PAPER_STEP (MM_DOT * 2)
#define DETECT_GAP_SHIFT (MM_DOT / 2)
#define DETECT_GAP_STEP (MM_DOT / 4)
#define DETECT_GAP_DEC (GAP_SENSOR_SCALE >> 5)
#define DETECT_REF (FLOAT)0.3
#if defined(AT91SAM9260)
#define DETECT_DELAY_TIME 50000
#define SCALE_DELAY_TIME 1280000
#elif defined(SH7040)
#define DETECT_DELAY_TIME 10000
#define SCALE_DELAY_TIME 256000
#elif defined(N3290)
#define DETECT_DELAY_TIME 50000
#define SCALE_DELAY_TIME 1280000
#endif
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
VOID PaperHome(_PrintCfg *pPrtCfg)
{
_PrintRecord *pHomeRec;
_WorkJob WorkJob;
_eSensorType SnrType;
FLOAT fGapBlineSize;
WORD NextPaperDis;
LONG MoveLength;
SHORT state;
BYTE Inten;
WORD Ref;
INT Signal;
FLOAT fData=0;
WaitWorkJobEnd();
sysprintf("PaperHome---\r\n");
ConfigToWorkJob(&WorkJob, pPrtCfg);
if (WorkJob.SensorMode == GAP_MODE)
{
SnrType = GAP_SENSOR;
Inten = WorkJob.GapInten;
Ref = WorkJob.GapRef;
fGapBlineSize = WorkJob.fGapSize;
}
else if (WorkJob.SensorMode == BLINE_MODE)
{
SnrType = BLINE_SENSOR;
Inten = WorkJob.BlineInten;
Ref = WorkJob.BlineRef;
fGapBlineSize = WorkJob.fBlineSize;
}
else
return;
pHomeRec = GrabPrintRecord();
ResetHeadPosition();
MotorMove(0, pPrtCfg, MOTOR_FORWARD, _NULL);
WaitWorkJobEnd();
MoveLength = pHomeRec->DotMilage;
MotorMove((LONG)WorkJob.fLabelSize * 2, pPrtCfg, MOTOR_FORWARD, _NULL);
EnableSensor(SnrType, Inten, pPrtCfg->RibbonFlag, Ref);
state = FALSE;
while (IsMotion())
{
//if(IsCarriageOpen() && pPrtCfg->CarriageOpen)
DelayTime(DETECT_DELAY_TIME);
Signal = GetSensorSignal(SnrType);
if (GetSensorPosition(SnrType, Signal) == POSITION_ON_GAP_BLINE)
break;
}
while (IsMotion())
{
DelayTime(DETECT_DELAY_TIME);
Signal = GetSensorSignal(SnrType);
if (GetSensorPosition(SnrType, Signal) == POSITION_ON_PAPER)
{
state = TRUE;
StopMotor();
break;
}
}
DisableSensor(SnrType);
if (state == FALSE)
{
if(GetProfileInt("PAPER HOME TO CONTINUE",&fData)&&(fData==1))
{
DetectContinuousInten(pPrtCfg);
pPrtCfg->SensorMode = CONTINUE_MODE_T;
}
return;
}
NextPaperDis = GetNextPaperDis(&WorkJob);
MoveLength = pHomeRec->DotMilage - MoveLength;
if (MoveLength > (LONG)(WorkJob.fLabelSize + fGapBlineSize) - NextPaperDis)
MotorMove((LONG)(WorkJob.fLabelSize * 2) - NextPaperDis, pPrtCfg, MOTOR_BACKWARD, _NULL);
else
MotorMove((LONG)(WorkJob.fLabelSize) - NextPaperDis, pPrtCfg, MOTOR_BACKWARD, _NULL);
}
#if defined(DIVIDE_INTENSION)
BOOL DetectSensorInten(_PrintCfg *pPrtCfg, BOOL setsize, BOOL autodetect, INT prepaper, INT pregapbline)
{
_CalResult *pCalResult;
WORD LabelSize;
#ifdef DEBUG_PRNT
sysprintf("Enter DetectSensorInten()...\n"); // ch_20211208
#endif
#if defined(TTP243PP_PCB)
pPrtCfg->SensorMode = GAP_MODE;
#endif
if(ProfileLimit("NO BLINE MODE")==1)
pPrtCfg->SensorMode = GAP_MODE;
#ifdef DEBUG_PRNT
sysprintf("pPrtCfg->SensorMode = %d\tautodetect = %d\tprepaper = %d\tpregapbline = %d\n",
pPrtCfg->SensorMode, autodetect, prepaper, pregapbline); // ch_20211211
#endif
Calibration(pPrtCfg, autodetect, prepaper, pregapbline);
WaitWorkJobEnd();
pCalResult = GrabCalibrationResult();
if (pCalResult->Finish)
{
pPrtCfg->GapInten = pCalResult->GapInten;
pPrtCfg->BlineInten = pCalResult->BlineInten;
pPrtCfg->ContinuousInten = pCalResult->ContinuousInten;
pPrtCfg->GapRef = pCalResult->GapRef;
pPrtCfg->BlineRef = pCalResult->BlineRef;
pPrtCfg->ContinuousRef = pCalResult->ContinuousRef;
if (setsize)
{
pPrtCfg->SensorMode = pCalResult->SensorMode;
pPrtCfg->fPaperSize = pCalResult->fPaperSize;
pPrtCfg->fGapSize = pCalResult->fGapSize;
pPrtCfg->fBlineSize = pCalResult->fBlineSize;
LabelSize = (WORD)CalculateLabelSize(pPrtCfg);
ReallocImageBuffer(&sImageBuffer, LabelSize);
InitialCalibration();
}
#ifdef DEBUG_PRNT
sysprintf("Leave DetectSensorInten()...\n"); // ch_20211208
#endif
return TRUE;
}
#ifdef DEBUG_PRNT
sysprintf("Leave DetectSensorInten()...\n"); // ch_20211208
#endif
return FALSE;
}
#elif defined(PWM_INTENSION)
STATIC SHORT SampleMaxNotThrough(_PrintCfg *pPrtCfg, INT Step)
{
SHORT SampleBuf[DETECT_SAMPLE];
SHORT OrderBuf[DETECT_SAMPLE];
SHORT Inten;
SHORT i, j, k;
for (i = 0; i < DETECT_SAMPLE; i++)
{
MotorMove(Step, pPrtCfg, MOTOR_FORWARD, _NULL);
while (IsMotion()){}
EnableSensor(GAP_SENSOR, GAP_SENSOR_SCALE - 1, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(DETECT_DELAY_TIME);
for (Inten = GAP_SENSOR_SCALE - 1; Inten > 0; Inten--)
{
EnableSensor(GAP_SENSOR, Inten, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(SCALE_DELAY_TIME / GAP_SENSOR_SCALE);
if (GetSensorSignal(GAP_SENSOR) == SENSOR_UNDETECTED) // if not through
break;
}
SampleBuf[i] = Inten;
}
DisableSensor(GAP_SENSOR);
// Sort array in descending order.
for (i = 0; i < DETECT_SAMPLE; i++)
{
OrderBuf[i] = 0;
for (j = 0; j < DETECT_SAMPLE; j++)
{
if (OrderBuf[i] < SampleBuf[j])
{
OrderBuf[i] = SampleBuf[j];
k = j;
}
}
SampleBuf[k] = 0;
}
// Pick some samples to get an average for "Inten".
Inten = (OrderBuf[1] + OrderBuf[2] + OrderBuf[3] + OrderBuf[4]) >> 2;
if (OrderBuf[1] >= (GAP_SENSOR_SCALE - 1))
Inten -= (Inten >> 2);
return Inten;
}
STATIC SHORT SampleMinThrough(_PrintCfg *pPrtCfg, INT Step)
{
SHORT SampleBuf[DETECT_SAMPLE];
SHORT OrderBuf[DETECT_SAMPLE];
SHORT Inten;
SHORT i, j, k;
for (i = 0; i < DETECT_SAMPLE; i++)
{
MotorMove(Step, pPrtCfg, MOTOR_FORWARD, _NULL);
while (IsMotion()){}
EnableSensor(GAP_SENSOR, 0, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(DETECT_DELAY_TIME);
for (Inten = 0; Inten < GAP_SENSOR_SCALE; Inten++)
{
EnableSensor(GAP_SENSOR, Inten, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(SCALE_DELAY_TIME / GAP_SENSOR_SCALE);
if (GetSensorSignal(GAP_SENSOR) == SENSOR_DETECTED) // if through
break;
}
SampleBuf[i] = Inten;
}
DisableSensor(GAP_SENSOR);
// Sort array in ascending order.
for (i = 0; i < DETECT_SAMPLE; i++)
{
OrderBuf[i] = GAP_SENSOR_SCALE;
for (j = 0; j < DETECT_SAMPLE; j++)
{
if (OrderBuf[i] > SampleBuf[j])
{
OrderBuf[i] = SampleBuf[j];
k = j;
}
}
SampleBuf[k] = GAP_SENSOR_SCALE;
}
// Pick some samples to get an average for "Inten".
Inten = (OrderBuf[1] + OrderBuf[2] + OrderBuf[3] + OrderBuf[4]) >> 2;
return Inten;
}
BOOL DetectGapInten(_PrintCfg *pPrtCfg, BOOL Position)
{
_PrintCfg IntenCfg;
WORD DetectLength;
SHORT Max, Min ,Inten;
SHORT state;
INT Signal;
WaitWorkJobEnd();
ResetHeadPosition();
DetectLength = pPrtCfg->LimitFeed;
IntenCfg = *pPrtCfg;
if (GetGapSensorReverse())
{
Min = SampleMinThrough(&IntenCfg, DETECT_PAPER_STEP);
Inten = Min + DETECT_GAP_DEC;
}
else
{
Max = SampleMaxNotThrough(&IntenCfg, DETECT_PAPER_STEP);
Inten = Max - DETECT_GAP_DEC;
}
MotorMove(DetectLength, &IntenCfg, MOTOR_FORWARD, _NULL);
state = FALSE;
while (IsMotion())
{
EnableSensor(GAP_SENSOR, DETECT_GAP_DEC, IntenCfg.RibbonFlag, HALF_AD_SCALE);
DelayTime(DETECT_DELAY_TIME);
EnableSensor(GAP_SENSOR, Inten, IntenCfg.RibbonFlag, HALF_AD_SCALE);
DelayTime(DETECT_DELAY_TIME);
Signal = GetSensorSignal(GAP_SENSOR);
if (GetSensorPosition(GAP_SENSOR, Signal) == POSITION_ON_PAPER)
break;
}
EnableSensor(GAP_SENSOR, Inten, IntenCfg.RibbonFlag, HALF_AD_SCALE);
while (IsMotion())
{
DelayTime(DETECT_DELAY_TIME);
Signal = GetSensorSignal(GAP_SENSOR);
if (GetSensorPosition(GAP_SENSOR, Signal) == POSITION_ON_GAP_BLINE)
{
state = TRUE;
StopMotor();
break;
}
}
DisableSensor(GAP_SENSOR);
if (state == FALSE)
{
DetectContinuousInten(pPrtCfg);
pPrtCfg->SensorMode = CONTINUE_MODE_T;
return FALSE;
}
MotorMove(DETECT_GAP_SHIFT, &IntenCfg, MOTOR_FORWARD, _NULL);
if (GetGapSensorReverse())
Max = SampleMaxNotThrough(&IntenCfg, DETECT_GAP_STEP);
else
Min = SampleMinThrough(&IntenCfg, DETECT_GAP_STEP);
if ((Max - Min) < DETECT_GAP_DEC)
{
DetectContinuousInten(pPrtCfg);
pPrtCfg->SensorMode = CONTINUE_MODE_T;
return FALSE;
}
Inten = (Max - Min) * DETECT_REF + Min;
IntenCfg.GapInten = Inten;
IntenCfg.PrintOutMode = OFF_MODE;
if (IntenCfg.SensorMode != GAP_MODE)
{
IntenCfg.SensorMode = GAP_MODE;
IntenCfg.fPaperSize = DetectLength;
IntenCfg.fGapSize = TPH_DPI;
}
if (Position)
FeedBatch(1, &IntenCfg, FALSE, _NULL);
pPrtCfg->SensorMode = IntenCfg.SensorMode;
pPrtCfg->GapInten = IntenCfg.GapInten;
return TRUE;
}
#endif
BOOL DetectContinuousInten(_PrintCfg *pPrtCfg)
{
SHORT Inten;
WORD Value;
WaitWorkJobEnd();
EnableSensor(GAP_SENSOR, GAP_SENSOR_SCALE - 1, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(DETECT_DELAY_TIME);
for (Inten = GAP_SENSOR_SCALE - 1; Inten > 1; Inten--)
{
EnableSensor(GAP_SENSOR, Inten, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(SCALE_DELAY_TIME * 2 / GAP_SENSOR_SCALE);
#if defined(ANALOG_MEDIA)
StartADConvert(GAP_SENSOR_AD);
Value = ReadAD(GAP_SENSOR_AD);
#if defined(GAP_LEVEL_UP)
if (Value < GAP_LIMIT)
break;
#elif defined(GAP_LEVEL_DOWN)
if (Value > GAP_LIMIT)
break;
#endif
#else
if (GetSensorSignal(GAP_SENSOR) == SENSOR_UNDETECTED) // if not through
break;
#endif
}
DisableSensor(GAP_SENSOR);
#if defined(ANALOG_MEDIA)
pPrtCfg->ContinuousInten = (Inten + 1) >> 1;
pPrtCfg->ContinuousRef = (Value + GAP_LIMIT) >> 1;
#elif defined(DIVIDE_INTENSION)
pPrtCfg->ContinuousInten = (Inten + 2) >> 1;
#elif defined(PWM_INTENSION)
pPrtCfg->ContinuousInten = (Inten + 60) >> 1;
#endif
return TRUE;
}
#if defined(ANALOG_MEDIA)
BOOL DetectContinuousIntenBm(_PrintCfg *pPrtCfg)
{
SHORT Inten;
WORD Value;
WaitWorkJobEnd();
EnableSensor(BLINE_SENSOR, 1, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(DETECT_DELAY_TIME);
for (Inten = 1; Inten < BLINE_SENSOR_SCALE - 1; Inten++)
{
EnableSensor(BLINE_SENSOR, Inten, pPrtCfg->RibbonFlag, HALF_AD_SCALE);
DelayTime(SCALE_DELAY_TIME * 2 / BLINE_SENSOR_SCALE);
StartADConvert(BLINE_SENSOR_AD);
Value = ReadAD(BLINE_SENSOR_AD);
debug_printf("6");
#if defined(BLINE_LEVEL_UP)
if (Value < BLINE_LIMIT)
break;
#elif defined(BLINE_LEVEL_DOWN)
if (Value > BLINE_LIMIT)
break;
#endif
}
DisableSensor(BLINE_SENSOR);
pPrtCfg->ContinuousInten = (Inten + BLINE_SENSOR_SCALE) >> 1;
pPrtCfg->ContinuousRef = (Value + BLINE_LIMIT) >> 1;
return TRUE;
}
#endif
BOOL DetectLabelSize(_PrintCfg *pPrtCfg, LONG Quantity, _ePrintOutMode OutMode)
{
_PrintCfg GetLenCfg;
WORD JobError;
WORD LabelSize;
WORD PaperSize;
WORD GapBmSize;
WORD DetectLength;
#ifdef DEBUG_PRNT
sysprintf("Enter DetectLabelSize()\n");
#endif
if (pPrtCfg->SensorMode != GAP_MODE && pPrtCfg->SensorMode != BLINE_MODE)
return FALSE;
DetectLength = pPrtCfg->LimitFeed;
GetLenCfg = *pPrtCfg;
GetLenCfg.fPaperSize = DetectLength;
GetLenCfg.fGapSize = TPH_DPI;
GetLenCfg.fBlineSize = TPH_DPI;
GetLenCfg.PrintOutMode = OFF_MODE;
FeedBatch(Quantity, &GetLenCfg, FALSE, _NULL);
while (IsMotion())
{
if (GetJobState() == JOB_ERROR)
{
SetJobState(JOB_NULL);
SetJobMonitor(MONITOR_IDLE);
StartKeyFunc(TRUE);
#if defined(LCD_MODEL)
JobError = GetJobErrorState();
if (JobError & ERROR_PAPER_JAM)
ClrDisplayStatus(DIS_PAPER_JAM);
if (JobError & ERROR_PAPER_EMPTY)
ClrDisplayStatus(DIS_PAPER_EMPTY);
if (JobError & ERROR_RIBBON_JAM || JobError & ERROR_RIBBON_EMPTY)
ClrDisplayStatus(DIS_RIBBON_EMPTY);
if (JobError & ERROR_CUTTER)
ClrDisplayStatus(DIS_CUTTER_ERROR);
#endif
ClrJobErrorState(ERROR_JOB_ALL_STATE);
#if defined(MONO_LED)
CancelPeriodFunc(FlashLED3);
ShowLED(HID_LED_IDLE, HID_LED_ON, HID_LED_OFF);
#elif defined(POLY_LED)
// CancelPeriodFunc(FlashRedLED); // ch_20211221
CancelPeriodFunc(FlashBlueRedLED); // ch_20211221
ShowLED(HID_LED_GREEN);
#endif
break;
}
}
PaperSize = GetPaperLength();
GapBmSize = GetGapBmLength();
if (PaperSize < (MM_DOT * 3) || GapBmSize < MM_DOT)
{
DetectContinuousInten(pPrtCfg);
pPrtCfg->SensorMode = CONTINUE_MODE_T;
}
else
{
pPrtCfg->fPaperSize = PaperSize;
if (pPrtCfg->SensorMode == GAP_MODE)
pPrtCfg->fGapSize = GapBmSize;
else if (pPrtCfg->SensorMode == BLINE_MODE)
pPrtCfg->fBlineSize = GapBmSize;
}
LabelSize = (WORD)CalculateLabelSize(pPrtCfg);
ReallocImageBuffer(&sImageBuffer, LabelSize);
InitialCalibration();
if (OutMode != OFF_MODE)
{
GetLenCfg = *pPrtCfg;
GetLenCfg.PrintOutMode = OutMode;
if (OutMode == CUTTER_MODE)
GetLenCfg.CutterPieces = 1;
ResetHeadPosition();
FeedBatch(1, &GetLenCfg, TRUE, _NULL);
}
return TRUE;
}
FuncType.h /
#ifndef FUNCTYPE_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FUNCTYPE_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
/* None */
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
#define KEY_FUNC_OFF 0 // Disable the key function
#define KEY_FUNC_DEFAULT 1
#define KEY_FUNC_MENU 2
#define KEY_FUNC_PAUSE 3
#define KEY_FUNC_FEED 4
#define KEY_FUNC_BACKFEED 5
#define KEY_FUNC_FORMFEED 6
#define KEY_FUNC_PRINT 7
#define KEY_FUNC_CUT 8
#define KEY_FUNC_INPUT 9
#define GPI_FUNC_OFF 0 // Disable the GPIO input function
#define GPI_FUNC_PAUSE 1
#define GPI_FUNC_PAUSE_ON 2
#define GPI_FUNC_PAUSE_OFF 3
#define GPI_FUNC_REPRINT 4
#define GPI_FUNC_REPRINT_ON 5
#define GPI_FUNC_REPRINT_OFF 6
#define GPI_FUNC_PRINT 7
#define GPI_FUNC_FEED 8
#define GPI_FUNC_BACKFEED 9
#define GPI_FUNC_FORMFEED 10
#define GPI_FUNC_CUT 11
#define GPI_FUNC_INPUT 12
#define GPO_FUNC_OFF 0 // Disable the GPIO output function
#define GPO_FUNC_PAUSE 1
#define GPO_FUNC_REPRINT 2
#define GPO_FUNC_TAKELABEL 3
#define GPO_FUNC_IDLE 4
#define GPO_FUNC_FAULT 5
#define GPO_FUNC_FAULT_PAPER 6
#define GPO_FUNC_FAULT_RIBBON 7
#define GPO_FUNC_FAULT_CARRIAGE 8
#define GPO_FUNC_FAULT_CUTTER 9
#define GPO_FUNC_FAULT_MEMORY 10
#define GPO_FUNC_FAULT_OVERHEAT 11
#define GPI_CH1 0
#define GPI_CH2 1
#define GPI_CH3 2
#define GPI_CH4 3
#define GPI_TOTAL 4
#define GPO_CH1 0
#define GPO_CH2 1
#define GPO_CH3 2
#define GPO_CH4 3
#define GPO_CH5 4
#define GPO_CH6 5
#define GPO_CH7 6
#define GPO_TOTAL 7
#define ITEM_IP_ADDRESS 0
#define ITEM_SUBNET_MASK 1
#define ITEM_GATEWAY 2
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
typedef union
{
INT Number;
CHAR String[16];
} FUNCARG;
typedef struct
{
INT FuncID; // Function ID
FUNCARG Argument; // Function argument
}_KeySetting;
typedef struct
{
INT Signal; // Signal type
INT Pulse; // Pulse width
INT FuncID; // Function ID
FUNCARG Argument; // Function argument
}_GPISetting;
typedef struct
{
INT Signal; // Signal type
INT TrueDelay; // Delay time when function condition "true"
INT TruePulse; // Pulse width when function condition "true"
INT FalseDelay; // Delay time when function condition "false"
INT FalsePulse; // Pulse width when function condition "false"
INT FuncID; // Function ID
}_GPOSetting;
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif