2023-02-06 02:23:00 +01:00
|
|
|
#include <WiFi.h>
|
|
|
|
#include <ESPDateTime.h>
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "U8g2lib.h"
|
|
|
|
#include "logos.h"
|
|
|
|
#include "utils.h"
|
2023-02-10 01:25:54 +01:00
|
|
|
#include "vars.h"
|
2023-02-06 02:23:00 +01:00
|
|
|
|
|
|
|
void drawCurvedLineV(U8G2 u8g2, int xStart, int yStart, int vert, int horiz) {
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.drawVLine(xStart, yStart + 1, vert);
|
|
|
|
u8g2.drawVLine(xStart + 1, yStart, vert);
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.drawHLine(xStart, yStart + vert, horiz);
|
|
|
|
u8g2.drawHLine(xStart + 1, yStart + vert + 1, horiz);
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawCurvedLine(U8G2 u8g2, int xStart, int yStart, int horiz, int vert) {
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.drawHLine(xStart, yStart, horiz);
|
|
|
|
u8g2.drawHLine(xStart, yStart + 1, horiz);
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.drawVLine(xStart + horiz, yStart, vert);
|
|
|
|
u8g2.drawVLine(xStart + horiz + 1, yStart + 1, vert);
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawLogoAfraPay(U8G2 u8g2) {
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.setFontMode(1);
|
|
|
|
u8g2.setFontDirection(0);
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
int xOffset = 12;
|
|
|
|
int yOffset = 23;
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.setFont(u8g2_font_maniac_tr);
|
|
|
|
u8g2.drawStr(xOffset, yOffset, "AfRA");
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.setFont(u8g2_font_tenthinguys_tr);
|
|
|
|
u8g2.drawStr(xOffset + 73, yOffset + 3, "pay");
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
// uncomment to verify distance to screen gap is equal on both sides
|
|
|
|
//u8g2.drawHLine(0, yOffset-12, xOffset);
|
|
|
|
//u8g2.drawHLine(127-xOffset-1, yOffset, xOffset);
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
drawCurvedLineV(u8g2, xOffset + 69, yOffset, 7, 32);
|
|
|
|
drawCurvedLine(u8g2, xOffset + 73, yOffset - 8, 28, 15);
|
|
|
|
u8g2.drawPixel(xOffset + 101, yOffset + 7);
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawLogoBitmap(U8G2 u8g2, int width, int height, unsigned char bits[], int yOffset = 0) {
|
2023-02-08 16:42:47 +01:00
|
|
|
int offset = (128 - width) / 2;
|
|
|
|
u8g2.drawXBM(offset, yOffset, width, height, bits);
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawLogo(U8G2 u8g2, e_logo logo) {
|
2023-02-08 16:42:47 +01:00
|
|
|
switch (logo) {
|
|
|
|
case LOGO_AFRAPAY:
|
|
|
|
drawLogoAfraPay(u8g2);
|
|
|
|
break;
|
|
|
|
case LOGO_CONTACTLESS:
|
|
|
|
drawLogoBitmap(u8g2, contactless_width, contactless_height, contactless_bits);
|
|
|
|
break;
|
|
|
|
case LOGO_MATECARD:
|
|
|
|
drawLogoBitmap(u8g2, matecard_width, matecard_height, matecard_bits, 5);
|
|
|
|
u8g2.setFont(u8g2_font_bpixeldouble_tr);
|
|
|
|
u8g2.drawStr((126 - u8g2.getStrWidth("matecard")) / 2, 57, "matecard");
|
|
|
|
break;
|
|
|
|
case LOGO_PENDING:
|
|
|
|
drawLogoBitmap(u8g2, pending_width, pending_height, pending_bits, 5);
|
|
|
|
break;
|
|
|
|
case LOGO_SUCCESS:
|
|
|
|
drawLogoBitmap(u8g2, success_width, success_height, success_bits, 5);
|
|
|
|
break;
|
|
|
|
case LOGO_FAILURE:
|
|
|
|
drawLogoBitmap(u8g2, failure_width, failure_height, failure_bits, 5);
|
|
|
|
break;
|
|
|
|
}
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
2023-02-10 03:09:50 +01:00
|
|
|
void drawStatusText(U8G2 u8g2, const String& status, const String& statusRightAligned = "") {
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.setFont(u8g2_font_bpixel_te);
|
|
|
|
u8g2.drawUTF8(0, 61, status.c_str());
|
2023-02-06 02:23:00 +01:00
|
|
|
|
2023-02-08 16:42:47 +01:00
|
|
|
if (!statusRightAligned.isEmpty()) {
|
|
|
|
int textWidth = u8g2.getUTF8Width(statusRightAligned.c_str());
|
|
|
|
u8g2.drawUTF8(126 - textWidth, 61, statusRightAligned.c_str());
|
|
|
|
}
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
2023-02-10 03:09:50 +01:00
|
|
|
void drawFullScreenText(U8G2 u8g2, const String& textTop, const String& textBottom) {
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.setFont(u8g2_font_chargen_92_tr);
|
|
|
|
u8g2.drawUTF8((127-u8g2.getUTF8Width(textTop.c_str()))/2, 13, textTop.c_str());
|
|
|
|
u8g2.setFont(u8g2_font_maniac_te);
|
|
|
|
u8g2.drawUTF8((127-u8g2.getUTF8Width(textBottom.c_str()))/2, 45, textBottom.c_str());
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
2023-02-10 03:09:50 +01:00
|
|
|
void updateOLED(U8G2 u8g2, e_state state, const String& statusText, const String& statusTextRightAligned = "") {
|
2023-02-08 16:42:47 +01:00
|
|
|
u8g2.clearBuffer();
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case STATE_IDLE:
|
|
|
|
drawLogo(u8g2, LOGO_AFRAPAY);
|
|
|
|
break;
|
|
|
|
case STATE_TRANSACT_CARDSCAN:
|
|
|
|
case STATE_BALANCE_CARDSCAN:
|
2023-04-20 15:42:55 +02:00
|
|
|
case STATE_LINK_CARD_SCAN:
|
|
|
|
case STATE_LINK_CARD_RESCAN:
|
2023-02-08 16:42:47 +01:00
|
|
|
drawLogo(u8g2, LOGO_CONTACTLESS);
|
|
|
|
break;
|
|
|
|
case STATE_RESULT_SUCCESS:
|
|
|
|
drawLogo(u8g2, LOGO_SUCCESS);
|
|
|
|
break;
|
|
|
|
case STATE_RESULT_FAILURE:
|
|
|
|
drawLogo(u8g2, LOGO_FAILURE);
|
|
|
|
break;
|
|
|
|
case STATE_RESULT_DISPLAY:
|
|
|
|
drawFullScreenText(u8g2, splitString(statusText, ':', 0), splitString(statusText, ':', 1) + "€");
|
|
|
|
drawStatusText(u8g2, splitString(statusText, ':', 2), statusTextRightAligned);
|
|
|
|
u8g2.sendBuffer();
|
|
|
|
return;
|
|
|
|
case STATE_TRANSACT_VERIFY:
|
|
|
|
case STATE_BALANCE_VERIFY:
|
|
|
|
case STATE_LINK_VERIFY:
|
|
|
|
drawLogo(u8g2, LOGO_PENDING);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawStatusText(u8g2, statusText, statusTextRightAligned);
|
|
|
|
u8g2.sendBuffer();
|
2023-02-06 02:23:00 +01:00
|
|
|
}
|
|
|
|
|
2023-02-10 03:09:50 +01:00
|
|
|
void updateOLED(const U8G2& u8g2, e_state state) {
|
2023-02-08 16:42:47 +01:00
|
|
|
String time = DateTime.format(DateFormatter::TIME_ONLY);
|
2023-02-10 02:18:02 +01:00
|
|
|
if (!digitalRead(PIN_INTERRUPT_CANCEL) || millis()%20000 < 10000)
|
2023-04-21 21:42:16 +02:00
|
|
|
updateOLED(u8g2, state, time, AFRAPAY_GIT_COMMIT);
|
2023-02-10 01:25:54 +01:00
|
|
|
else
|
|
|
|
updateOLED(u8g2, state, time, WiFi.localIP().toString());
|
2023-02-08 16:42:47 +01:00
|
|
|
}
|