if(menu_config == 1):
# Display the selection (options) menu.
img.draw_rectangle(0, 0, 128, 30, fill=1, color =(0,0,0))
img.draw_string(int((128-16*len("Add Cart"))/2), 3, "Add Cart", color=(0,255,0), scale=2)
img.draw_rectangle(0, 130, 128, 160, fill=1, color =(0,0,0))
img.draw_string(int((128-16*len("Remove"))/2), 135, "Remove", color=(255,0,0), scale=2)
lcd.display(img)
print("Selection Menu Activated!")
while(menu_config == 1):
j_x, sw = readJoystick()
# Add the detected product to the database table.
if(j_x > 3):
cart_choice = "add"
print("Selected Cart Option: " + cart_choice)
img.draw_rectangle(0, 0, 128, 30, fill=1, color =(0,255,0))
img.draw_string(int((128-16*len("Add Cart"))/2), 3, "Add Cart", color=(255,255,255), scale=2)
img.draw_rectangle(0, 130, 128, 160, fill=1, color =(0,0,0))
img.draw_string(int((128-16*len("Remove"))/2), 135, "Remove", color=(255,0,0), scale=2)
lcd.display(img)
adjustColor((0,1,0))
sleep(1)
# Remove the detected product from the database table.
if(j_x < 2):
cart_choice = "remove"
print("Selected Cart Option: " + cart_choice)
img.draw_rectangle(0, 0, 128, 30, fill=1, color =(0,0,0))
img.draw_string(int((128-16*len("Add Cart"))/2), 3, "Add Cart", color=(0,255,0), scale=2)
img.draw_rectangle(0, 130, 128, 160, fill=1, color =(255,0,0))
img.draw_string(int((128-16*len("Remove"))/2), 135, "Remove", color=(255,255,255), scale=2)
adjustColor((1,0,0))
lcd.display(img)
sleep(1)
# Send the generated query (command), including the selected option (cart choice) and
# the detected product's details, to the web application via Beetle ESP32-C3.
if(sw == 0):
query = "&"+cart_choice+"=OK&product_id="+products[detected_product]["id"]+"&product_name="+products[detected_product]["name"]+"&product_price="+products[detected_product]["price"]
print("\nQuery: " + query + "\n")
img.draw_rectangle(0, int(160/4), 128, int(160/2), fill=1, color =(0,0,255))
img.draw_string(int((128-16*len("Query"))/2), int((160/2)-28), "Query", color=(255,255,255), scale=2)
img.draw_string(int((128-16*len("Sent!"))/2), int((160/2)+8), "Sent!", color=(255,255,255), scale=2)
lcd.display(img)
uart.write(query)
adjustColor((0,0,1))
sleep(5)
adjustColor((0,0,0))
# Close the selection menu after transferring the product information and the selected option to the web application via Beetle ESP32-C3.
menu_config = 0
# Clear the detected label and the selected option (cart choice).
detected_product = 0
cart_choice = "EMPTY"