From 4e3027d2916114c38ca83674c97bf9f0c90fa71a Mon Sep 17 00:00:00 2001
From: moon2 <moon2protonmail@protonmail.com>
Date: Fri, 19 May 2023 21:45:53 +0200
Subject: [PATCH] refactored payload adjusted to new api

---
 .../{cap_touch_demo.py => harmonic_demo.py}   |  0
 python_payload/main.py                        | 39 +++++++------------
 python_payload/utils.py                       |  4 +-
 3 files changed, 16 insertions(+), 27 deletions(-)
 rename python_payload/{cap_touch_demo.py => harmonic_demo.py} (100%)

diff --git a/python_payload/cap_touch_demo.py b/python_payload/harmonic_demo.py
similarity index 100%
rename from python_payload/cap_touch_demo.py
rename to python_payload/harmonic_demo.py
diff --git a/python_payload/main.py b/python_payload/main.py
index 92aa3c6cad..1bbeed1cff 100644
--- a/python_payload/main.py
+++ b/python_payload/main.py
@@ -1,40 +1,29 @@
-from machine import Pin
 from hardware import *
 import utils
 import time
-import cap_touch_demo
+import harmonic_demo
 import melodic_demo
 
 MODULES = [
-    cap_touch_demo,
+    harmonic_demo,
     melodic_demo,
 ]
 
-BOOTSEL_PIN = Pin(0, Pin.IN)
-VOL_UP_PIN = Pin(35, Pin.IN, Pin.PULL_UP)
-VOL_DOWN_PIN = Pin(37, Pin.IN, Pin.PULL_UP)
-
 CURRENT_APP_RUN = None
 VOLUME = 0
 
 SELECT_TEXT = [
-    " ##  #### #    ####  ##  ##### #",
-    "#  # #    #    #    #  #   #   #",
-    "#    #    #    #    #      #   #",
-    " ##  #### #    #### #      #   #",
-    "   # #    #    #    #      #   #",
-    "#  # #    #    #    #  #   #    ",
-    " ##  #### #### ####  ##    #   #",
+    " ##  #### #    ####  ##  #####          ",
+    "#  # #    #    #    #  #   #        ##" ,
+    "#    #    #    #    #      #     #    #",
+    " ##  #### #    #### #      #         #" ,
+    "   # #    #    #    #      #     #    #",
+    "#  # #    #    #    #  #   #        ## ",
+    " ##  #### #### ####  ##    #            ",
 ]
 
 BACKGROUND_COLOR = 0
 
-# pin numbers
-# right side: left 37, down 0, right 35
-# left side: left 7, down 6, right 5
-# NOTE: All except for 0 should be initialized with Pin.PULL_UP
-# 0 (bootsel) probably not but idk? never tried
-
 def run_menu():
     global CURRENT_APP_RUN
     display_fill(BACKGROUND_COLOR)
@@ -95,16 +84,16 @@ def main():
     set_global_volume_dB(VOLUME)
 
     while True:
-        if(BOOTSEL_PIN.value() == 0):
+        if(get_button(0) == 2):
             if CURRENT_APP_RUN == run_menu:
                 captouch_autocalib()
             else:
                 CURRENT_APP_RUN = run_menu
                 foreground_menu()
-        if(VOL_UP_PIN.value() == 0):
-            set_rel_volume(+3)
-        if(VOL_DOWN_PIN.value() == 0):
-            set_rel_volume(-3)
+        if(get_button(0) == 1):
+            set_rel_volume(+1)
+        if(get_button(0) == -1):
+            set_rel_volume(-1)
         CURRENT_APP_RUN()
 
 main()
diff --git a/python_payload/utils.py b/python_payload/utils.py
index 52b2b00f50..88ca4d3ba3 100644
--- a/python_payload/utils.py
+++ b/python_payload/utils.py
@@ -11,8 +11,8 @@ def clear_all_leds():
     update_leds()
 
 def draw_text_big(text, x, y):
-    ypos = 120+int(len(text)/2) + int(y)
-    xpos = 120+int(len(text[0])/2) + int(x)
+    ypos = 120+int(len(text)) + int(y)
+    xpos = 120+int(len(text[0])) + int(x)
     for l, line in enumerate(text):
         for p, pixel in enumerate(line):
             if(pixel == '#'):
-- 
GitLab