From cd5e396e8919e0030432d97e45962da288ef99b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=A1clav=20Jel=C3=ADnek?= <jelinva4@fel.cvut.cz>
Date: Thu, 17 Oct 2024 16:05:56 +0200
Subject: [PATCH] Center text, add battery constants

---
 lib/menu_display.py | 23 ++++++++++++-----------
 lib/robot_consts.py |  5 ++++-
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/lib/menu_display.py b/lib/menu_display.py
index 676eae0..b302f05 100644
--- a/lib/menu_display.py
+++ b/lib/menu_display.py
@@ -1,5 +1,6 @@
 import micropython
 
+from lib.robot_consts import BAT_VOLTAGE_MAX, BAT_VOLTAGE_MIN
 
 DISPLAY_TITLE_POS = 18
 DISPLAY_PROG_POS = 42
@@ -21,7 +22,7 @@ class Menu:
 # Fill fr
 # amebuffer with battery voltage
 def display_fill_battery(robot, bat_voltage):
-    bat_percentage = int((bat_voltage - 6.4) / (8.4 - 6.4) * 20) * 5
+    bat_percentage = int((bat_voltage - BAT_VOLTAGE_MIN) / (BAT_VOLTAGE_MAX - BAT_VOLTAGE_MIN) * 20) * 5 # Round to 5
     bat_percentage = 100 if bat_percentage > 100 else 0 if bat_percentage < 0 else bat_percentage
 
     robot.display.line(0, 13, 128, 13, 1)
@@ -70,7 +71,7 @@ def display_fill_bt_pin(robot, pin, connecting):
 def display_fill_mot_test(robot, current_motor_test):
     robot.display.fill(0)
     robot.display.centered_text('< Motor test >', DISPLAY_TITLE_POS, 1)
-    robot.display.centered_text('M{}'.format(current_motor_test+1), DISPLAY_PROG_POS, 1)
+    robot.display.centered_text(f'M{current_motor_test+1}', DISPLAY_PROG_POS, 1)
     display_fill_arrows(robot)
 
 # Fill framebuffer with sensor test menu
@@ -81,7 +82,7 @@ def display_fill_sen_test(robot, current_sen_test, sensor_test_menu, sensor_test
         robot.display.centered_text(sensor_test_name, DISPLAY_PROG_POS, 1)
     else:
         robot.display.centered_text('< Sensor port', DISPLAY_TITLE_POS, 1)
-        robot.display.centered_text('S{}'.format(current_sen_test+1), DISPLAY_PROG_POS, 1)
+        robot.display.centered_text(f'S{current_sen_test+1}', DISPLAY_PROG_POS, 1)
     display_fill_arrows(robot)
 
 # Fill framebuffer with cube test menu
@@ -98,24 +99,24 @@ def display_fill_arrows(robot):
 def display_fill_fw_version(robot, fw_version):
     robot.display.fill(0)
     robot.display.centered_text("< Firmware >", DISPLAY_TITLE_POS, 1)
-    robot.display.centered_text("Open-Cube", DISPLAY_PROG_POS-4, 1)
-    robot.display.centered_text(fw_version, DISPLAY_PROG_POS+4, 1)
+    robot.display.centered_text("Open-Cube", DISPLAY_PROG_POS-10, 1)
+    robot.display.centered_text(fw_version, DISPLAY_PROG_POS, 1)
 
 # Show program error on display
 def display_show_error(robot):
     robot.display.fill(0)
-    robot.display.text('Program', 35, 20, 1)
-    robot.display.text('error!', 40, 30, 1)
+    robot.display.centered_text('Program', 20, 1)
+    robot.display.centered_text('error!', 30, 1)
     robot.display.show()
 
 def display_show_startup(robot):
     robot.display.fill(0)
-    robot.display.text('Turning', 35, 20, 1)
-    robot.display.text('on', 40, 30, 1)
+    robot.display.centered_text('Turning', 20, 1)
+    robot.display.centered_text('on', 30, 1)
     robot.display.show()
 
 def display_show_program(robot):
     robot.display.fill(0)
-    robot.display.text('Program', 35, 20, 1)
-    robot.display.text('running', 40, 30, 1)
+    robot.display.centered_text('Program', 20, 1)
+    robot.display.centered_text('running', 30, 1)
     robot.display.show()
\ No newline at end of file
diff --git a/lib/robot_consts.py b/lib/robot_consts.py
index 4509665..ae4fdea 100644
--- a/lib/robot_consts.py
+++ b/lib/robot_consts.py
@@ -72,8 +72,11 @@ class Color:
     WHITE: Color = const(6)
     BROWN: Color = const(7)
 
-BAT_VOLTAGE_TURNOFF = 6.3			# Volts
+
 BAT_MEASURE_PERIOD = const(1000)	# ms
+BAT_VOLTAGE_MAX = 8.4
+BAT_VOLTAGE_MIN = 6.2
+BAT_VOLTAGE_TURNOFF = (BAT_VOLTAGE_MIN+0.1)			# Volts
 
 PCF_CHECK_PERIOD = const(50)		# ms
 
-- 
GitLab