📄 cashterminal.c
字号:
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2007 SEGGER Microcontroller Systeme GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V4.14 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : CashTerminal.c
Purpose : Cash Terminal Demo
---------------------------END-OF-HEADER------------------------------
*/
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "GUI.h"
#include "WM.h"
#include "BUTTON.h"
#include "EDIT.h"
#include "TEXT.h"
#include "SLIDER.h"
/* Global data */
extern GUI_CONST_STORAGE GUI_BITMAP bmSeggerLogo;
extern GUI_CONST_STORAGE GUI_BITMAP bmSeggerLogoLarge;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_AmericanExpress;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_Cirrus;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_ECCard;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_GeldKarte;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_Maestro;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_MasterCard;
extern GUI_CONST_STORAGE GUI_BITMAP bmLogo_VisaCard;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontAA4_24;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontAA2_32;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontAA4_32;
/*********************************************************************
*
* Defines, configurables
*
**********************************************************************
*/
#define BUTTON_CLICK_SPEED 600
#define BUTTON_CLICK_DELAY 750
#define DEFAULT_WIDGET_EFFECT (&WIDGET_Effect_3D2L)
#define MAIN_BKCOLOR 0xD0D0D0
#define MAIN_TEXTCOLOR 0x000000
#define MAIN_FONT (&GUI_FontAA2_32)
#define MAIN_BORDER 10
#define MAIN_TITLE_HEIGHT 67
#define MAIN_LOGO_BITMAP (&bmSeggerLogo)
#define MAIN_LOGO_OFFSET_X 0
#define MAIN_LOGO_OFFSET_Y 0
#define FRAME_BKCOLOR 0xB0B0B0
#define FRAME_TEXTCOLOR 0x000000
#define FRAME_FONT (&GUI_FontAA4_32)
#define FRAME_EFFECT (&WIDGET_Effect_3D2L)
#define FRAME_BORDER FRAME_EFFECT->EffectSize
#define FRAME_WIDTH (640 - (FRAME_BORDER * 2) - (MAIN_BORDER * 2))
#define FRAME_HEIGHT (480 - (FRAME_BORDER * 2) - (MAIN_BORDER + MAIN_TITLE_HEIGHT))
#define FRAME_BUTTON_BKCOLOR0 0xB8B8B8 /* Unpressed */
#define FRAME_BUTTON_BKCOLOR1 0xE0E0E0 /* Pressed */
#define FRAME_BUTTON_BKCOLOR2 0xC0C0C0 /* Disabled */
#define FRAME_BUTTON_COLOR0 0x000000 /* Unpressed */
#define FRAME_BUTTON_COLOR1 0x000000 /* Pressed */
#define FRAME_BUTTON_FONT (&GUI_FontAA4_24)
#define FRAME_BUTTON_EFFECT (&WIDGET_Effect_3D2L)
#define LOGO_FRAME_OFFSET_Y 15
#define LOGO_FRAME_SIZE_X 116
#define LOGO_FRAME_SIZE_Y 92
#define LOGO_FRAME_DIST_X 4
#define LOGO_FRAME_BKCOLOR 0xFFFFFF
#define LOGO_FRAME_EFFECT (&WIDGET_Effect_3D2L)
#define NUMPAD_BKCOLOR GUI_LIGHTGRAY
#define NUMPAD_EFFECT (&WIDGET_Effect_3D2L)
#define NUMPAD_BORDER 9
#define NUMPAD_PIN 1685
#define NUMPAD_BUTTON_BKCOLOR0 0xB8B8B8 /* Unpressed */
#define NUMPAD_BUTTON_BKCOLOR1 0xE0E0E0 /* Pressed */
#define NUMPAD_BUTTON_BKCOLOR2 0xC0C0C0 /* Disabled */
#define NUMPAD_BUTTON_COLOR0 0x700000 /* Unpressed */
#define NUMPAD_BUTTON_COLOR1 0x700000 /* Pressed */
#define NUMPAD_BUTTON_RED0 0x0060FF /* Unpressed */
#define NUMPAD_BUTTON_RED1 0x0030E8 /* Pressed */
#define NUMPAD_BUTTON_YELLOW0 0x00F0FF /* Unpressed */
#define NUMPAD_BUTTON_YELLOW1 0x00B0D0 /* Pressed */
#define NUMPAD_BUTTON_GREEN0 0x00B040 /* Unpressed */
#define NUMPAD_BUTTON_GREEN1 0x00D000 /* Pressed */
#define NUMPAD_BUTTON_FONT (&GUI_Font16B_1)
#define NUMPAD_BUTTON_EFFECT (&WIDGET_Effect_3D1L)
#define NUMPAD_BUTTON_WIDTH 40
#define NUMPAD_BUTTON_HEIGHT 32
#define NUMPAD_BUTTON_DIST_X 7
#define NUMPAD_BUTTON_DIST_Y 7
/*********************************************************************
*
* Defines, constants
*
**********************************************************************
*/
#define NUMPAD_ID_0 (GUI_ID_USER + 0)
#define NUMPAD_ID_1 (GUI_ID_USER + 1)
#define NUMPAD_ID_2 (GUI_ID_USER + 2)
#define NUMPAD_ID_3 (GUI_ID_USER + 3)
#define NUMPAD_ID_4 (GUI_ID_USER + 4)
#define NUMPAD_ID_5 (GUI_ID_USER + 5)
#define NUMPAD_ID_6 (GUI_ID_USER + 6)
#define NUMPAD_ID_7 (GUI_ID_USER + 7)
#define NUMPAD_ID_8 (GUI_ID_USER + 8)
#define NUMPAD_ID_9 (GUI_ID_USER + 9)
#define NUMPAD_ID_X (GUI_ID_USER + 10)
#define NUMPAD_ID_Y (GUI_ID_USER + 11)
#define NUMPAD_ID_A (GUI_ID_USER + 12)
#define NUMPAD_ID_B (GUI_ID_USER + 13)
#define NUMPAD_ID_C (GUI_ID_USER + 14)
#define NUMPAD_ID_D (GUI_ID_USER + 15)
#define MSG_CARD_INSERTED (WM_USER + 0)
#define MSG_CARD_REMOVED (WM_USER + 1)
#define MSG_MONEY_REMOVED (WM_USER + 2)
#define MSG_PIN_CHANGED (WM_USER + 3)
#define MSG_PIN_OK (WM_USER + 4)
#define MSG_PIN_CANCEL (WM_USER + 5)
#define MSG_PIN_ERROR (WM_USER + 6)
#define LANG_GER 0
#define LANG_ENG 1
#define TEXT_ID_ABBRUCH 1
#define TEXT_ID_KORREKTUR 2
#define TEXT_ID_BESTAETIGEN 3
#define TEXT_ID_PIN_EINGEBEN 4
#define TEXT_ID_KARTE_EINFUEHREN 5
#define TEXT_ID_GELD_ABHEBEN 6
#define TEXT_ID_KONTOSTAND_ANSEHEN 7
#define TEXT_ID_AUSWAHL_TREFFEN 8
#define TEXT_ID_ANDERER_BETRAG 9
#define TEXT_ID_BITTE_GEDULD 10
#define TEXT_ID_KARTE_ENTNEHMEN 11
#define TEXT_ID_GELD_ENTNEHMEN 12
#define TEXT_ID_VIELEN_DANK 13
#define TEXT_ID_GELDAUTOMAT 14
#define TEXT_ID_KONTOSTAND 15
#define TEXT_ID_AUSWAHL_BETRAG 16
#define TEXT_ID_FALSCHE_PIN 17
#define TEXT_ID_BETRAG_EINGEBEN 18
/*********************************************************************
*
* Types
*
**********************************************************************
*/
typedef struct {
int x;
int y;
int Pressed;
int Duration;
} PID_EVENT;
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static PID_EVENT _aPID_Events[] = {
{ 320, 315, 1, 500 }, /* Language */
{ 320, 315, 0, 2500 },
{ 320, 260, 1, 0 }, /* Insert card */
{ 320, 260, 0, 4000 },
{ 210, 315, 1, 300 }, /* PIN */
{ 210, 315, 0, 300 },
{ 255, 315, 1, 300 },
{ 255, 315, 0, 300 },
{ 300, 315, 1, 300 },
{ 300, 315, 0, 300 },
{ 210, 350, 1, 300 },
{ 210, 350, 0, 1500 }, /* Confirm */
{ 400, 430, 1, 500 },
{ 400, 430, 0, 1500 }, /* Draw money */
{ 320, 260, 1, 500 },
{ 320, 260, 0, 2500 }, /* Amount */
{ 160, 415, 1, 500 },
{ 160, 415, 0, 2500 },
{ 320, 260, 1, 3000 },
{ 320, 260, 0, 500 },
{ 320, 260, 1, 3000 },
{ 320, 260, 0, 100 },
{ 320, 260, 1, 3000 },
{ 320, 260, 0, 100 },
{ 320, 260, 1, 3000 },
{ 320, 260, 0, 100 },
};
static const char * _aLang[][2] = {
{ "Abbruch",
"Cancel"
},
{ "Korrektur",
"Correction"
},
{ "Best鋞igen",
"Confirm"
},
{ "Bitte geben Sie Ihre Geheimzahl ein:",
"Please enter your PIN:"
},
{ "Bitte f黨ren Sie Ihre Karte ein",
"Please insert your card"
},
{ "Geld abheben",
"Draw money"
},
{ "Kontostand ansehen",
"View account balance"
},
{ "Bitte treffen Sie Ihre Auswahl",
"Please select..."
},
{ "Anderer Betrag",
"Different amount"
},
{ "Bitte haben Sie etwas Geduld.\nIhr Geld wird ausgezahlt.",
"Please wait until your transaction\nis being processed."
},
{ "Bitte entnehmen Sie Ihre Karte",
"Please you take your card"
},
{ "Bitte entnehmen Sie Ihr Geld",
"Transaction completed.\nPlease take your money"
},
{ "Vielen Dank f黵\nIhren Besuch",
"Thank you for\nusing"
},
{ "Geldautomat",
"ATM"
},
{ "Ihr Saldo betr鋑t: 1234.56 EUR",
"Your balance amount is: -1234.56 EUR"
},
{ "Bitte treffen Sie Ihre Auswahl",
"Please select amount"
},
{ "Falsche PIN. Mindestens 4 Ziffern",
"Wrong PIN. At least 4 digits"
},
{ "Bitte geben Sie den Betrag ein",
"Please enter amount"
},
};
static WM_HWIN _hLastFrame;
static WM_HWIN _hNumPad;
static unsigned _PIN_Value;
static unsigned _PIN_Digits;
static unsigned _Break;
static unsigned _Language;
static WM_HWIN _hTitle;
/*********************************************************************
*
* Static code, helpers
*
**********************************************************************
*/
/*********************************************************************
*
* _GetLang
*/
static const char * _GetLang(unsigned Index) {
const char * p;
p = NULL;
Index--;
if ((Index < GUI_COUNTOF(_aLang)) && (_Language < GUI_COUNTOF(_aLang[0]))) {
p = _aLang[Index][_Language];
}
return p;
}
/*********************************************************************
*
* Static code, draw down/up rect
*
**********************************************************************
*/
/*********************************************************************
*
* _DrawDownRectEx
*/
static void _DrawDownRectEx(const WIDGET_EFFECT* pEffect, const GUI_RECT* pRect) {
WM_LOCK();
pEffect->pfDrawDownRect(pRect);
WM_UNLOCK();
}
/*********************************************************************
*
* _DrawDownRect
*/
static void _DrawDownRect(const WIDGET_EFFECT* pEffect, int x0, int y0, int x1, int y1) {
GUI_RECT r;
r.x0 = x0;
r.y0 = y0;
r.x1 = x1;
r.y1 = y1;
_DrawDownRectEx(pEffect, &r);
}
/*********************************************************************
*
* _DrawUpRectEx
*/
static void _DrawUpRectEx(const WIDGET_EFFECT* pEffect, const GUI_RECT* pRect) {
WM_LOCK();
pEffect->pfDrawUpRect(pRect);
WM_UNLOCK();
}
/*********************************************************************
*
* Static code, frame functions
*
**********************************************************************
*/
/*********************************************************************
*
* _PaintFrame
*/
static void _PaintFrame(void) {
GUI_RECT r;
WM_GetClientRect(&r);
GUI_SetBkColor(FRAME_BKCOLOR);
GUI_SetColor(FRAME_TEXTCOLOR);
GUI_SetFont(FRAME_FONT);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_ClearRectEx(&r);
}
/*********************************************************************
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -