Skip to content

Commit

Permalink
Merge branch 'waveshare-screen'
Browse files Browse the repository at this point in the history
  • Loading branch information
21isenough committed Jul 8, 2020
2 parents 210fa4b + 3e24c6d commit 2275c79
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 78 deletions.
13 changes: 12 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import RPi.GPIO as GPIO

import config
import display
import lndrest
import lntxbot
import qr

import utils
import importlib

display_config = config.conf["atm"]["display"]
display = getattr(__import__("displays", fromlist=[display_config]), display_config)

led = "off"
logger = logging.getLogger("MAIN")

Expand All @@ -25,6 +28,8 @@ def softreset():
global led
config.SATS = 0
config.FIAT = 0
logger.info("%s Coin(s) and XX Bill(s) added", config.COINCOUNT)
config.COINCOUNT = 0
# Turn off button LED
GPIO.output(13, GPIO.LOW)
led = "off"
Expand Down Expand Up @@ -171,41 +176,47 @@ def coins_inserted():

if config.PULSES == 2:
config.FIAT += 0.02
config.COINCOUNT += 1
config.SATS = utils.get_sats()
config.SATSFEE = utils.get_sats_with_fee()
config.SATS -= config.SATSFEE
logger.info("2 cents added")
display.update_amount_screen()
if config.PULSES == 3:
config.FIAT += 0.05
config.COINCOUNT += 1
config.SATS = utils.get_sats()
config.SATSFEE = utils.get_sats_with_fee()
config.SATS -= config.SATSFEE
logger.info("5 cents added")
display.update_amount_screen()
if config.PULSES == 4:
config.FIAT += 0.1
config.COINCOUNT += 1
config.SATS = utils.get_sats()
config.SATSFEE = utils.get_sats_with_fee()
config.SATS -= config.SATSFEE
logger.info("10 cents added")
display.update_amount_screen()
if config.PULSES == 5:
config.FIAT += 0.2
config.COINCOUNT += 1
config.SATS = utils.get_sats()
config.SATSFEE = utils.get_sats_with_fee()
config.SATS -= config.SATSFEE
logger.info("20 cents added")
display.update_amount_screen()
if config.PULSES == 6:
config.FIAT += 0.5
config.COINCOUNT += 1
config.SATS = utils.get_sats()
config.SATSFEE = utils.get_sats_with_fee()
config.SATS -= config.SATSFEE
logger.info("50 cents added")
display.update_amount_screen()
if config.PULSES == 7:
config.FIAT += 1
config.COINCOUNT += 1
config.SATS = utils.get_sats()
config.SATS = utils.get_sats()
config.SATSFEE = utils.get_sats_with_fee()
Expand Down
12 changes: 11 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from shutil import copyfile

from papirus import Papirus
from waveshare_epd import epd2in13_V2

import utils

Expand All @@ -15,6 +16,9 @@
if not os.path.exists(ATM_data_dir):
os.makedirs(ATM_data_dir)

# Set to logging.DEBUG if more info needed
logging.disable(logging.DEBUG)

# Set to logging.DEBUG if more "requests" debugging info needed
logging.getLogger("requests").setLevel(logging.INFO)
logging.getLogger("urllib3.connectionpool").setLevel(logging.INFO)
Expand Down Expand Up @@ -115,7 +119,12 @@ def create_config(config_file=None):
WHITE = 1
BLACK = 0
PAPIRUSROT = 0
PAPIRUS = Papirus(rotation=PAPIRUSROT)
if "papirus" in conf["atm"]["display"]:
PAPIRUS = Papirus(rotation=PAPIRUSROT)

# Display - Waveshare 2.13 is 250 * 122 pixels
if "waveshare" in conf["atm"]["display"]:
WAVESHARE = epd2in13_V2.EPD()

# API URL for coingecko
COINGECKO_URL_BASE = "https://api.coingecko.com/api/v3/"
Expand All @@ -135,6 +144,7 @@ def create_config(config_file=None):
PULSES = 0
LASTPUSHES = 0
PUSHES = 0
COINCOUNT = 0

# Lists for different coin counting, not yet implemented
# COINLIST = []
Expand Down
Empty file added displays/__init__.py
Empty file.
72 changes: 72 additions & 0 deletions displays/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Text for update_startup_screen()
startup_screen_1 = "Welcome to the"
startup_screen_2 = "LightningATM"
startup_screen_3 = "- please insert coins -"

# Text for update_qr_request()
qr_request_1 = "Please scan"
qr_request_2 = "your invoice in"
qr_request_3 = "Scanning..."
qr_request_4 = "for "
qr_request_5 = " sats."

# Text for update_qr_failed()
qr_failed_1 = "Scan failed."
qr_failed_2 = "Try again."

# Text for update_payout_screen()
payout_screen_1 = " sats"
payout_screen_2 = "on the way!"

# text for update_payment_failed()
payment_failed_1 = "Payment failed!"
payment_failed_2 = "Please contact"
payment_failed_3 = "operator."

# Text for update_thankyou_screen()
thankyou_screen_1 = "Enjoy your new"
thankyou_screen_2 = "satoshis!!"
thankyou_screen_3 = "#bitcoin #lightning"

# Text for update_nocoin_screen()
nocoin_screen_1 = "No coins added!"
nocoin_screen_2 = "Please add"
nocoin_screen_3 = "coins first"

# Text for update_lnurl_generation()
lnurl_generation_1 = "Generating"
lnurl_generation_2 = "QR code to scan"

# Text for update_shutdown_screen()
shutdown_screen_1 = "ATM turned off!"
shutdown_screen_2 = "Please contact"
shutdown_screen_3 = "operator."

# Text for update_wallet_scan()
wallet_scan_1 = "Please scan"
wallet_scan_2 = "your wallet"
wallet_scan_3 = "credentials."

# Text for update_lntxbot_balance()
lntxbot_balance_1 = "Success!!"
lntxbot_balance_2 = "Your current balance:"
lntxbot_balance_3 = " sats"

# Text for update_btcpay_lnd()
btcpay_lnd_1 = "Success!!"
btcpay_lnd_2 = "Successfuly scanned"
btcpay_lnd_3 = "BTCPay LND Wallet."

# Text for draw_lnurl_qr()
lnurl_qr_1 = "Scan to"
lnurl_qr_2 = "receive"

# Text for update_amount_screen()
amount_screen_1 = " sats"
amount_screen_2 = "Rate"
amount_screen_3 = "= "
amount_screen_4 = " sats/"
amount_screen_5 = "Fee"
amount_screen_6 = "= "
amount_screen_7 = "% ("
amount_screen_8 = " sats)"
59 changes: 29 additions & 30 deletions display.py → displays/papiruszero2in.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import config
import utils

from displays import messages

from PIL import Image, ImageFont, ImageDraw


Expand Down Expand Up @@ -98,12 +100,7 @@ def update_qr_failed():
draw.rectangle(
(2, 2, width - 2, height - 2), fill=config.WHITE, outline=config.BLACK
)
draw.text(
(25, 10),
"Scanning...",
fill=config.BLACK,
font=utils.create_font("freemono", 20),
)

draw.text(
(25, 30),
"Scan failed.",
Expand Down Expand Up @@ -366,6 +363,32 @@ def update_btcpay_lnd():
time.sleep(3)


def draw_lnurl_qr(qr_img):
"""Draw a lnurl qr code on the e-ink screen
"""
image, width, height, draw = init_screen(color=config.BLACK)

qr_img = qr_img.resize((96, 96), resample=0)

draw = ImageDraw.Draw(image)
draw.bitmap((0, 0), qr_img, fill=config.WHITE)
draw.text(
(110, 25),
"Scan to",
fill=config.WHITE,
font=utils.create_font("freemonobold", 16),
)
draw.text(
(110, 45),
"receive",
fill=config.WHITE,
font=utils.create_font("freemonobold", 16),
)

config.PAPIRUS.display(image)
config.PAPIRUS.update()


def update_amount_screen():
"""Update the amount screen to reflect new coins inserted
"""
Expand Down Expand Up @@ -423,30 +446,6 @@ def update_blank_screen():
config.PAPIRUS.update()


def menu_screen():
image, width, height, draw = init_screen(color=config.WHITE)

draw.rectangle(
(2, 2, width - 2, height - 2), fill=config.WHITE, outline=config.BLACK
)
draw.text(
(20, 16), "►", fill=config.BLACK, font=utils.create_font("freemono", 20),
)
draw.text(
(40, 20), "Menu 1", fill=config.BLACK, font=utils.create_font("freemono", 20),
)
draw.text(
(40, 40), "Menu 2", fill=config.BLACK, font=utils.create_font("freemono", 20),
)

config.PAPIRUS.display(image)
config.PAPIRUS.partial_update()

while config.PUSHES <= 2:
print(config.PUSHES)
time.sleep(2)


def init_screen(color):
"""Prepare the screen for drawing and return the draw variables
"""
Expand Down
Loading

0 comments on commit 2275c79

Please sign in to comment.