from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
from flow import ezdata
import unit
setScreenColor(0x222222)
rfid0 = unit.get(unit.RFID, unit.PAHUB0)
light0 = unit.get(unit.LIGHT, unit.PORTB)
env21 = unit.get(unit.ENV2, unit.PAHUB1)
mac = None
Data_send = None
stock = None
transactions = None
sold = None
quantity = None
wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()
wifiCfg.autoConnect(lcdShow=False)
price = M5TextBox(179, 109, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
title0 = M5Title(title="paymentSystem", x=3, fgcolor=0xFFFFFF, bgcolor=0xff0047)
label3 = M5TextBox(66, 109, "Total Price:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
stock_lbl = M5TextBox(117, 27, "stock_lbl", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(0, 77, "Transactions:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
sales_lbl = M5TextBox(142, 82, "sales_lbl", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(0, 22, "Stock left:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label6 = M5TextBox(9, 112, "Internal Temp:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label7 = M5TextBox(52, 134, "Lighting:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
lighting = M5TextBox(115, 134, "lighting", lcd.FONT_Default, 0xFFFFFF, rotate=0)
temp = M5TextBox(267, 112, "temp", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label8 = M5TextBox(0, 49, "Stock sold:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
sold_lbl = M5TextBox(124, 54, "sold_lbl", lcd.FONT_Default, 0xFFFFFF, rotate=0)
scan = M5TextBox(41, 160, "Please scan to pay", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label2 = M5TextBox(41, 214, "Back", lcd.FONT_Default, 0xFFFFFF, rotate=0)
from numbers import Number
# Describe this function...
def stats_hide():
global mac, Data_send, stock, transactions, sold, quantity
label1.hide()
label5.hide()
sold_lbl.setPosition(x=999)
stock_lbl.setPosition(x=999)
sales_lbl.setPosition(x=999)
label2.setPosition(x=999)
label6.setPosition(x=999)
label7.hide()
label8.hide()
lighting.setPosition(x=999)
temp.setPosition(x=999)
# Describe this function...
def stats_show():
global mac, Data_send, stock, transactions, sold, quantity
label1.show()
label5.show()
stock_lbl.setText(str(stock))
sales_lbl.setText(str(transactions))
sold_lbl.setText(str(sold))
sold_lbl.setPosition(x=120)
sales_lbl.setPosition(x=142)
stock_lbl.setPosition(x=120)
label2.setPosition(x=41)
label6.setPosition(x=10)
label7.show()
label8.show()
lighting.setPosition(x=115)
temp.setPosition(x=115)
lcd.setBrightness(100)
while not (btnA.isPressed()):
lighting.setText(str(light0.analogValue))
temp.setText(str(env21.temperature))
# Describe this function...
def payment_hide():
global mac, Data_send, stock, transactions, sold, quantity
label3.hide()
scan.hide()
price.hide()
label2.setPosition(x=999)
lcd.setBrightness(0)
# Describe this function...
def payment_show():
global mac, Data_send, stock, transactions, sold, quantity
label3.show()
scan.show()
price.show()
label2.setPosition(x=41)
lcd.setBrightness(100)
def recv_cb(_):
global mac,Data_send,stock,transactions,sold,quantity
mac, _, Data_send = espnow.recv_data(encoder='str')
payment_show()
scan.setText('Please scan to pay')
price.setText(str(Data_send))
while not (btnA.isPressed()):
if rfid0.isCardOn():
espnow.add_peer('98:f4:ab:6b:a3:85', id=2)
espnow.send(id=2, data=str('test'))
scan.setText('Payment successful!')
speaker.tone(800, 200)
transactions = (transactions if isinstance(transactions, Number) else 0) + 1
ezdata.setData('m4kkE3iXSzN01jLI6QN0D9bytn23prU5', 'transactions', transactions)
quantity = float((float(Data_send) / 2.5))
stock = (stock if isinstance(stock, Number) else 0) + int((quantity * -1))
sold = (sold if isinstance(sold, Number) else 0) + int(quantity)
ezdata.setData('m4kkE3iXSzN01jLI6QN0D9bytn23prU5', 'stock_sold', sold)
break
payment_hide()
pass
espnow.recv_cb(recv_cb)
def buttonB_wasPressed():
global mac, Data_send, stock, transactions, sold, quantity
payment_hide()
stats_show()
pass
btnB.wasPressed(buttonB_wasPressed)
def buttonA_wasPressed():
global mac, Data_send, stock, transactions, sold, quantity
payment_hide()
stats_hide()
pass
btnA.wasPressed(buttonA_wasPressed)
lcd.setBrightness(100)
stock = 10
transactions = int((ezdata.getData('m4kkE3iXSzN01jLI6QN0D9bytn23prU5', 'transactions')))
sold = int((ezdata.getData('m4kkE3iXSzN01jLI6QN0D9bytn23prU5', 'stock_sold')))
payment_hide()
stats_hide()
quantity = 0
Comments