Skip to content
Snippets Groups Projects
Commit cd5e396e authored by Václav Jelínek's avatar Václav Jelínek
Browse files

Center text, add battery constants

parent 21f5508f
No related branches found
No related tags found
1 merge request!12Major update of menu visuals and example programs
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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment