Refactor
This commit is contained in:
parent
de2a3ec163
commit
7b487bc137
|
@ -15,13 +15,24 @@
|
|||
#include "utils.h"
|
||||
#include "oled.h"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
|
||||
|
||||
//MFRC522 pinout (front) 3V3 RST GND IRQ MISO MOSI SCK SDA
|
||||
//MFRC522 pinout (rear) SDA SCK MOSI MISO IRQ GND RST 3V3
|
||||
#define HSPI_MISO 12
|
||||
#define HSPI_MOSI 13
|
||||
#define HSPI_SCLK 14
|
||||
#define HSPI_SS 15
|
||||
#define HSPI_RST 16
|
||||
|
||||
#define BUZZER_PIN 26
|
||||
#define PIN_BUZZER 19
|
||||
//#define PIN_OLED_SDA 21
|
||||
//#define PIN_OLED_SCL 22
|
||||
#define PIN_INTERRUPT_TRANSACT 26
|
||||
#define PIN_INTERRUPT_BALANCE 25
|
||||
#define PIN_INTERRUPT_LINK 33
|
||||
#define PIN_INTERRUPT_CANCEL 32
|
||||
|
||||
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
|
||||
MFRC522 mfrc522(HSPI_SS, HSPI_RST);
|
||||
|
@ -39,6 +50,7 @@ String lastStatusText = "";
|
|||
unsigned long timer = 0;
|
||||
|
||||
void IRAM_ATTR TransactInterruptHandler() {
|
||||
Serial.println("transact interrupt hit");
|
||||
if (state != STATE_IDLE) {
|
||||
return;
|
||||
}
|
||||
|
@ -47,6 +59,7 @@ void IRAM_ATTR TransactInterruptHandler() {
|
|||
}
|
||||
|
||||
void IRAM_ATTR LinkInterruptHandler() {
|
||||
Serial.println("link interrupt hit");
|
||||
if (state != STATE_IDLE) {
|
||||
return;
|
||||
}
|
||||
|
@ -55,6 +68,7 @@ void IRAM_ATTR LinkInterruptHandler() {
|
|||
}
|
||||
|
||||
void IRAM_ATTR BalanceInterruptHandler() {
|
||||
Serial.println("balance interrupt hit");
|
||||
if (state != STATE_IDLE) {
|
||||
return;
|
||||
}
|
||||
|
@ -83,17 +97,19 @@ void setup() {
|
|||
apiUrl = WiFiSettings.string("AfRApay.Web API", "http://192.168.50.170:5296");
|
||||
WiFiSettings.connect();
|
||||
mfrc522.PCD_Init();
|
||||
mfrc522.PCD_DumpVersionToSerial();
|
||||
DateTime.setTimeZone(TZ_Europe_Berlin);
|
||||
DateTime.begin();
|
||||
updateOLED(u8g2, state);
|
||||
|
||||
ledcSetup(0, 5000, 12);
|
||||
pinMode(25, INPUT_PULLUP);
|
||||
pinMode(32, INPUT_PULLUP);
|
||||
pinMode(33, INPUT_PULLUP);
|
||||
attachInterrupt(25, BalanceInterruptHandler, FALLING);
|
||||
attachInterrupt(32, LinkInterruptHandler, FALLING);
|
||||
attachInterrupt(33, TransactInterruptHandler, FALLING);
|
||||
pinMode(PIN_INTERRUPT_TRANSACT, INPUT_PULLUP);
|
||||
pinMode(PIN_INTERRUPT_BALANCE, INPUT_PULLUP);
|
||||
pinMode(PIN_INTERRUPT_CANCEL, INPUT_PULLUP);
|
||||
pinMode(PIN_INTERRUPT_LINK, INPUT_PULLUP);
|
||||
attachInterrupt(PIN_INTERRUPT_TRANSACT, TransactInterruptHandler, FALLING);
|
||||
attachInterrupt(PIN_INTERRUPT_BALANCE, BalanceInterruptHandler, FALLING);
|
||||
attachInterrupt(PIN_INTERRUPT_LINK, LinkInterruptHandler, FALLING);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -124,17 +140,17 @@ void loop() {
|
|||
break;
|
||||
case STATE_TRANSACT_VERIFY:
|
||||
updateOLED(u8g2, state, lastStatusText);
|
||||
tone(BUZZER_PIN, NOTE_A5, 25);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 150);
|
||||
tone(PIN_BUZZER, NOTE_A5, 25);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 150);
|
||||
lastStatusText = cardTransaction(wifi, http, apiUrl, scannedCardId, "1.50");
|
||||
if (lastStatusText.startsWith("S:")) {
|
||||
tone(BUZZER_PIN, NOTE_C7, 650);
|
||||
tone(PIN_BUZZER, NOTE_C7, 650);
|
||||
lastStatusText += "€";
|
||||
state = STATE_RESULT_SUCCESS;
|
||||
} else {
|
||||
tone(BUZZER_PIN, NOTE_CS5, 100);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 25);
|
||||
tone(BUZZER_PIN, NOTE_CS5, 400);
|
||||
tone(PIN_BUZZER, NOTE_CS5, 100);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 25);
|
||||
tone(PIN_BUZZER, NOTE_CS5, 400);
|
||||
state = STATE_RESULT_FAILURE;
|
||||
}
|
||||
lastStatusText = lastStatusText.substring(2);
|
||||
|
@ -155,18 +171,18 @@ void loop() {
|
|||
break;
|
||||
case STATE_LINK_VERIFY:
|
||||
updateOLED(u8g2, state, lastStatusText);
|
||||
tone(BUZZER_PIN, NOTE_A5, 25);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 150);
|
||||
tone(PIN_BUZZER, NOTE_A5, 25);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 150);
|
||||
lastStatusText = cardLink(wifi, http, apiUrl, scannedCardId);
|
||||
if (lastStatusText.startsWith("S:")) {
|
||||
tone(BUZZER_PIN, NOTE_C6, 100);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 10);
|
||||
tone(BUZZER_PIN, NOTE_C6, 100);
|
||||
tone(PIN_BUZZER, NOTE_C6, 100);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 10);
|
||||
tone(PIN_BUZZER, NOTE_C6, 100);
|
||||
state = STATE_RESULT_SUCCESS;
|
||||
} else {
|
||||
tone(BUZZER_PIN, NOTE_CS5, 100);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 25);
|
||||
tone(BUZZER_PIN, NOTE_CS5, 400);
|
||||
tone(PIN_BUZZER, NOTE_CS5, 100);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 25);
|
||||
tone(PIN_BUZZER, NOTE_CS5, 400);
|
||||
state = STATE_RESULT_FAILURE;
|
||||
}
|
||||
lastStatusText = lastStatusText.substring(2);
|
||||
|
@ -187,16 +203,16 @@ void loop() {
|
|||
break;
|
||||
case STATE_BALANCE_VERIFY:
|
||||
updateOLED(u8g2, state, lastStatusText);
|
||||
tone(BUZZER_PIN, NOTE_A5, 25);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 150);
|
||||
tone(PIN_BUZZER, NOTE_A5, 25);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 150);
|
||||
lastStatusText = cardBalance(wifi, http, apiUrl, scannedCardId);
|
||||
if (lastStatusText.startsWith("S:")) {
|
||||
lastStatusText = lastStatusText + ":Card #" + scannedCardId;
|
||||
state = STATE_RESULT_DISPLAY;
|
||||
} else {
|
||||
tone(BUZZER_PIN, NOTE_CS5, 100);
|
||||
tone(BUZZER_PIN, NOTE_NONE, 25);
|
||||
tone(BUZZER_PIN, NOTE_CS5, 400);
|
||||
tone(PIN_BUZZER, NOTE_CS5, 100);
|
||||
tone(PIN_BUZZER, NOTE_NONE, 25);
|
||||
tone(PIN_BUZZER, NOTE_CS5, 400);
|
||||
state = STATE_RESULT_FAILURE;
|
||||
}
|
||||
lastStatusText = lastStatusText.substring(2);
|
||||
|
@ -211,4 +227,5 @@ void loop() {
|
|||
}
|
||||
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
#pragma clang diagnostic pop
|
Loading…
Reference in a new issue