Add deposit functionality
This commit is contained in:
parent
49c26b7ed4
commit
15215f02d0
|
@ -36,10 +36,13 @@ Reader* scannedCardReader;
|
||||||
String scannedCardId = "";
|
String scannedCardId = "";
|
||||||
String lastStatusText = "";
|
String lastStatusText = "";
|
||||||
|
|
||||||
int transactionAmount = 150;
|
bool deposit = false;
|
||||||
String transactionAmountDecimal = "1.50";
|
int transactionAmountIndex = 0;
|
||||||
|
int transactionAmountsDebit[] = {-150, -200};
|
||||||
|
int transactionAmountsCredit[] = {+100, +200, +500, +1000};
|
||||||
|
|
||||||
volatile bool toggleTransactionAmount = false;
|
volatile bool toggleTransactionAmountDebit = false;
|
||||||
|
volatile bool toggleTransactionAmountCredit = false;
|
||||||
volatile bool interruptFired = false;
|
volatile bool interruptFired = false;
|
||||||
unsigned long timer = 0;
|
unsigned long timer = 0;
|
||||||
|
|
||||||
|
@ -81,6 +84,9 @@ void IRAM_ATTR LinkInterruptHandler() {
|
||||||
else if (state == STATE_LINK_CARD_SCAN) {
|
else if (state == STATE_LINK_CARD_SCAN) {
|
||||||
PN532Reader::toggleMode = true;
|
PN532Reader::toggleMode = true;
|
||||||
}
|
}
|
||||||
|
else if (state == STATE_TRANSACT_CARDSCAN) {
|
||||||
|
toggleTransactionAmountCredit = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +104,7 @@ void IRAM_ATTR BalanceInterruptHandler() {
|
||||||
PN532Reader::toggleMode = true;
|
PN532Reader::toggleMode = true;
|
||||||
}
|
}
|
||||||
else if (state == STATE_TRANSACT_CARDSCAN) {
|
else if (state == STATE_TRANSACT_CARDSCAN) {
|
||||||
toggleTransactionAmount = true;
|
toggleTransactionAmountDebit = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
|
@ -111,6 +117,42 @@ void IRAM_ATTR CancelInterruptHandler() {
|
||||||
state = STATE_IDLE;
|
state = STATE_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetTransactionAmount() {
|
||||||
|
if (deposit)
|
||||||
|
return transactionAmountsCredit[transactionAmountIndex];
|
||||||
|
else
|
||||||
|
return transactionAmountsDebit[transactionAmountIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
String GetDisplayTransactionAmount() {
|
||||||
|
String result = "";
|
||||||
|
int total = abs(GetTransactionAmount());
|
||||||
|
int cents = total % 100;
|
||||||
|
|
||||||
|
if (PN532Reader::mode == PN532_MIFARE_ISO14443A) {
|
||||||
|
if (deposit)
|
||||||
|
result += "Deposit: ";
|
||||||
|
|
||||||
|
result += total / 100;
|
||||||
|
result += ".";
|
||||||
|
result += cents;
|
||||||
|
|
||||||
|
if (cents < 10)
|
||||||
|
result += "0";
|
||||||
|
|
||||||
|
result += "€";
|
||||||
|
}
|
||||||
|
else { // TOKYO MODE
|
||||||
|
if (deposit)
|
||||||
|
result += "Deposit: ";
|
||||||
|
|
||||||
|
result += "¥";
|
||||||
|
result += total;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool cooldownCheck(long timeout) {
|
bool cooldownCheck(long timeout) {
|
||||||
if (millis() - timer > timeout) {
|
if (millis() - timer > timeout) {
|
||||||
state = STATE_IDLE;
|
state = STATE_IDLE;
|
||||||
|
@ -215,20 +257,37 @@ void loop() {
|
||||||
if (PN532Reader::mode != PN532_MIFARE_ISO14443A)
|
if (PN532Reader::mode != PN532_MIFARE_ISO14443A)
|
||||||
PN532Reader::mode = PN532_MIFARE_ISO14443A;
|
PN532Reader::mode = PN532_MIFARE_ISO14443A;
|
||||||
|
|
||||||
|
if (deposit == true)
|
||||||
|
deposit = false;
|
||||||
|
|
||||||
|
if (transactionAmountIndex != 0)
|
||||||
|
transactionAmountIndex = 0;
|
||||||
|
|
||||||
oled.updateOLED(state);
|
oled.updateOLED(state);
|
||||||
break;
|
break;
|
||||||
case STATE_TRANSACT_CARDSCAN:
|
case STATE_TRANSACT_CARDSCAN:
|
||||||
if (toggleTransactionAmount && millis() - timer > 250) {
|
if (toggleTransactionAmountDebit) {
|
||||||
if (transactionAmount == 150) {
|
if (millis() - timer > 250) {
|
||||||
transactionAmount = 200;
|
if (deposit) {
|
||||||
transactionAmountDecimal = "2.00";
|
deposit = false;
|
||||||
|
transactionAmountIndex = -1;
|
||||||
|
}
|
||||||
|
transactionAmountIndex = ++transactionAmountIndex % 2;
|
||||||
|
timer = millis();
|
||||||
}
|
}
|
||||||
else {
|
toggleTransactionAmountDebit = false;
|
||||||
transactionAmount = 150;
|
}
|
||||||
transactionAmountDecimal = "1.50";
|
|
||||||
|
if (toggleTransactionAmountCredit) {
|
||||||
|
if (millis() - timer > 250) {
|
||||||
|
if (!deposit) {
|
||||||
|
deposit = true;
|
||||||
|
transactionAmountIndex = -1;
|
||||||
|
}
|
||||||
|
transactionAmountIndex = ++transactionAmountIndex % 4;
|
||||||
|
timer = millis();
|
||||||
}
|
}
|
||||||
toggleTransactionAmount = false;
|
toggleTransactionAmountCredit = false;
|
||||||
timer = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Reader* reader : readers) {
|
for (Reader* reader : readers) {
|
||||||
|
@ -241,12 +300,9 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cooldownCheck(scanTimeout)) {
|
if (!cooldownCheck(scanTimeout))
|
||||||
if (PN532Reader::mode == PN532_MIFARE_ISO14443A)
|
oled.updateOLED(state, GetDisplayTransactionAmount(), String(cooldownSecondsRemaining(scanTimeout, timer)));
|
||||||
oled.updateOLED(state, transactionAmountDecimal + String("€"), String(cooldownSecondsRemaining(scanTimeout, timer)));
|
|
||||||
else
|
|
||||||
oled.updateOLED(state, String("¥") + transactionAmount, String(cooldownSecondsRemaining(scanTimeout, timer)));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case STATE_TRANSACT_VERIFY:
|
case STATE_TRANSACT_VERIFY:
|
||||||
oled.updateOLED(state, lastStatusText);
|
oled.updateOLED(state, lastStatusText);
|
||||||
|
@ -259,7 +315,7 @@ void loop() {
|
||||||
tone(PIN_BUZZER, NOTE_NONE, 150);
|
tone(PIN_BUZZER, NOTE_NONE, 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastStatusText = cardTransaction(wifi, http, apiUrl, scannedCardId, String("-") + transactionAmount);
|
lastStatusText = cardTransaction(wifi, http, apiUrl, scannedCardId, String(GetTransactionAmount()));
|
||||||
if (lastStatusText.startsWith("S:")) {
|
if (lastStatusText.startsWith("S:")) {
|
||||||
tone(PIN_BUZZER, NOTE_C7, 650);
|
tone(PIN_BUZZER, NOTE_C7, 650);
|
||||||
state = STATE_RESULT_SUCCESS;
|
state = STATE_RESULT_SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue