-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,587 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
|
||
|
||
#include <TFT_eSPI.h> | ||
#include "qrcode.h" | ||
#include <Keypad.h> | ||
|
||
//keypad stuff | ||
String key_val; | ||
TFT_eSPI tft = TFT_eSPI(); | ||
|
||
void screen_splash() | ||
{ | ||
tft.drawBitmap(0, 0, (uint8_t *)SplashDIY_map, 160, 128, TFT_WHITE); | ||
|
||
} | ||
|
||
void screen_input_sats(String fiat, int nosats) | ||
{ | ||
tft.setTextSize(1); | ||
tft.setTextColor(TFT_RED, TFT_BLACK); | ||
tft.setCursor(25, 40); | ||
tft.println(fiat); | ||
tft.setTextColor(TFT_GREEN, TFT_BLACK); | ||
tft.setCursor(30, 57); | ||
tft.println(String(nosats)); | ||
} | ||
|
||
void screen_qrdisplay(String XXX) | ||
{ | ||
tft.fillScreen(TFT_WHITE); | ||
XXX.toUpperCase(); | ||
const char* addr = XXX.c_str(); | ||
Serial.println(addr); | ||
int qrSize = 12; | ||
int sizes[17] = { 14, 26, 42, 62, 84, 106, 122, 152, 180, 213, 251, 287, 331, 362, 412, 480, 504 }; | ||
int len = String(addr).length(); | ||
for(int i=0; i<17; i++){ | ||
if(sizes[i] > len){ | ||
qrSize = i+1; | ||
break; | ||
} | ||
} | ||
QRCode qrcode; | ||
uint8_t qrcodeData[qrcode_getBufferSize(qrSize)]; | ||
qrcode_initText(&qrcode, qrcodeData, qrSize-1, ECC_LOW, addr); | ||
Serial.println(qrSize -1); | ||
|
||
float scale = 2; | ||
|
||
for (uint8_t y = 0; y < qrcode.size; y++) { | ||
for (uint8_t x = 0; x < qrcode.size; x++) { | ||
if(qrcode_getModule(&qrcode, x, y)){ | ||
tft.drawRect(15+2+scale*x, 2+scale*y, scale, scale, TFT_BLACK); | ||
} | ||
else{ | ||
tft.drawRect(15+2+scale*x, 2+scale*y, scale, scale, TFT_WHITE); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void screen_wifi_check() | ||
{ | ||
tft.fillScreen(TFT_BLACK); | ||
tft.setCursor(25, 40); | ||
tft.setTextSize(1); | ||
tft.setTextColor(TFT_RED); | ||
tft.println("WIFI NOT CONNECTED"); | ||
} | ||
|
||
void screen_refresh() | ||
{ | ||
tft.fillScreen(TFT_BLACK); | ||
tft.setCursor(0, 0); | ||
tft.setTextColor(TFT_WHITE); | ||
} | ||
|
||
void screen_page_input() | ||
{ | ||
tft.fillScreen(TFT_BLACK); | ||
tft.setTextColor(TFT_WHITE); | ||
tft.setTextSize(1); | ||
tft.setCursor(0, 17); | ||
tft.println("AMOUNT THEN #"); | ||
tft.println(""); | ||
tft.println(""); | ||
tft.println(on_currency.substring(3) + ": "); | ||
tft.println(""); | ||
tft.println("SATS: "); | ||
tft.println(""); | ||
tft.println(""); | ||
tft.setTextSize(1); | ||
tft.setCursor(30, 110); | ||
tft.println("TO RESET PRESS *"); | ||
} | ||
|
||
void screen_page_processing() | ||
{ | ||
tft.fillScreen(TFT_BLACK); | ||
tft.setCursor(20, 40); | ||
tft.setTextSize(2); | ||
tft.setTextColor(TFT_WHITE); | ||
tft.println("PROCESSING"); | ||
} | ||
|
||
void screen_complete() | ||
{ | ||
tft.fillScreen(TFT_BLACK); | ||
tft.setCursor(30, 40); | ||
tft.setTextSize(2); | ||
tft.setTextColor(TFT_GREEN); | ||
tft.println("COMPLETE"); | ||
delay(1000); | ||
} | ||
|
||
void screen_cancel() | ||
{ | ||
tft.fillScreen(TFT_BLACK); | ||
tft.setCursor(23, 40); | ||
tft.setTextSize(2); | ||
tft.setTextColor(TFT_RED); | ||
tft.println("CANCELLED"); | ||
delay(1000); | ||
} | ||
|
||
|
||
//Set keypad | ||
const byte rows = 4; //four rows | ||
const byte cols = 3; //three columns | ||
char keys[rows][cols] = { | ||
{'1','2','3'}, | ||
{'4','5','6'}, | ||
{'7','8','9'}, | ||
{'*','0','#'} | ||
}; | ||
byte rowPins[rows] = {12, 14, 27, 26}; //connect to the row pinouts of the keypad | ||
byte colPins[cols] = {25, 33, 32}; //connect to the column pinouts of the keypad | ||
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols ); | ||
|
||
|
||
void get_keypad(){ | ||
|
||
key_val = keypad.getKey(); | ||
uint8_t key = 1; | ||
if(key != 0) { | ||
if(key >= 0x20 && key < 0x7F) { // ASCII String | ||
if (isdigit((char)key)){ | ||
key_val = ((char)key); | ||
} | ||
else { | ||
key_val = ""; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* LNPay Payment Connector | ||
* | ||
* @author Tim Kijewski <[email protected]> | ||
* | ||
*/ | ||
|
||
#include <ArduinoJson.h> | ||
#include <WiFiClientSecure.h> | ||
#include <HTTPClient.h> | ||
|
||
#include "PaymentConnector.h" | ||
|
||
|
||
//API Setup | ||
String api_key = "3zB1DPk2bFwiocmjOasLJA4Tpfc2jUDB"; // Public API key...Can be found here: https://lnpay.co/dashboard/integrations | ||
String wallet_key = "wi_ghDiaaRxecSHGcV8JrmITOtb"; // Invoice key...Can be found here: https://lnpay.co/dashboard/advanced-wallets | ||
|
||
|
||
//Endpoint Setup | ||
String api_endpoint = "https://lnpay.co/v1"; | ||
String invoice_create_endpoint = "/wallet/" + wallet_key + "/invoice"; | ||
String invoice_check_endpoint = "/lntx/{{tx_id}}?fields=settled"; //append LNTX ID to the end (e.g. /user/lntx/lntx_mfEKSse22) | ||
|
||
//HTTP client | ||
HTTPClient http; | ||
|
||
|
||
//Constructor | ||
PaymentConnector::PaymentConnector (String currency_pair) { | ||
_currency_pair = currency_pair; | ||
} | ||
|
||
|
||
/** | ||
* PaymentConnector::createRequest | ||
* | ||
* @param String method - GET,POST | ||
* @param String path - REST path to be appended to api_endpoint | ||
* @param String data - string of data for POST requests | ||
* | ||
* @return String - response data from request | ||
* | ||
*/ | ||
String PaymentConnector::createRequest(String method,String path, String data) | ||
{ | ||
String payload; | ||
int httpCode; | ||
|
||
Serial.println("PaymentConnector::createRequest BEGIN-------"); | ||
Serial.println("METHOD:" + method); | ||
Serial.println("URL:" + api_endpoint + path); | ||
Serial.println("DATA:" + data); | ||
|
||
http.begin(api_endpoint + path); //Getting fancy to response size | ||
http.addHeader("Content-Type","application/json"); | ||
http.addHeader("X-Api-Key",api_key); | ||
|
||
if (method.equals("POST")) | ||
httpCode = http.POST(data); //Make the request | ||
else if (method.equals("GET")) { | ||
httpCode = http.GET(); //Make the request | ||
} else { | ||
Serial.println("This HTTP method usage is not defined"); | ||
} | ||
|
||
if (httpCode > 0) { //Check for the returning code | ||
payload = http.getString(); | ||
Serial.println("RESPONSE:" + payload); | ||
} else { | ||
Serial.println("Error on HTTP request"); | ||
} | ||
http.end(); //Free the resources | ||
Serial.println("PaymentConnector::createRequest END--------"); | ||
|
||
return payload; | ||
} | ||
|
||
/** | ||
* PaymentConnector::createInvoice | ||
* | ||
* @param int num_satoshis - number of satoshis for invoice | ||
* @param String memo - Memo for invoice | ||
* | ||
* @return createInvoiceResponse - object containing both a payment_request AND an ID for lookup | ||
* | ||
*/ | ||
|
||
createInvoiceResponse PaymentConnector::createInvoice(int num_satoshis, String memo) { | ||
String toPost = "{ \"num_satoshis\" : " + (String) num_satoshis +", \"memo\" :\""+ memo + String(random(1,1000)) + "\"}"; | ||
|
||
String payload = PaymentConnector::createRequest((String)"POST",invoice_create_endpoint,toPost); | ||
|
||
const size_t capacity = JSON_OBJECT_SIZE(2) + 500; | ||
DynamicJsonDocument doc(capacity); | ||
deserializeJson(doc, payload); | ||
Serial.println(payload); | ||
|
||
const char* payment_request = doc["payment_request"]; | ||
const char* id = doc["id"]; | ||
String payreq = (String) payment_request; | ||
String lntx_id = (String) id; | ||
Serial.println(payreq); | ||
Serial.println(lntx_id); | ||
|
||
createInvoiceResponse cir; | ||
|
||
cir.payment_request = payreq; | ||
cir.payment_id = lntx_id; | ||
|
||
return cir; | ||
} | ||
|
||
/** | ||
* PaymentConnector::checkIfPaymentIsSettled | ||
* | ||
* @param String id - provided from the PaymentConnector::createInvoice call to check if settled | ||
* | ||
* @return int - 1 or 0 depending on settled | ||
* | ||
*/ | ||
|
||
int PaymentConnector::checkIfPaymentIsSettled(String id) { | ||
invoice_check_endpoint.replace("{{tx_id}}",id); | ||
String payloadd = PaymentConnector::createRequest((String)"GET",invoice_check_endpoint); | ||
delay(1500); | ||
|
||
StaticJsonDocument<200> doc; | ||
DeserializationError error = deserializeJson(doc, payloadd); | ||
int Settled = doc["settled"]; | ||
|
||
if (Settled == 1){ | ||
return 1; | ||
} else{ | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.