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

Make esp menu reset smoother

parent 498289aa
No related branches found
No related tags found
1 merge request!12Major update of menu visuals and example programs
......@@ -249,7 +249,6 @@ class Esp:
response = self.repeat_cmd(Esp.COM_BT_PIN, 50)
self.cmd_stop()
return response
utime.sleep(0.6)
else:
return None
......@@ -269,6 +268,12 @@ class Esp:
self.cmd_stop()
utime.sleep(0.6)
return response
def set_name_nonblocking(self, name: str, timeout=50):
self.cmd_start()
response = self.repeat_str(Esp.COM_NAME, name, timeout)
self.cmd_stop()
return response
def set_password(self, password: str, timeout=50):
self.cmd_start()
......@@ -297,6 +302,7 @@ class Esp:
self.flush()
self.esp_mode = self.esp_mode_prev
self.pcf_buttons.set_pin(8, True)
utime.sleep(0.01)
def timeout(self):
self.not_responding += 1
......
......@@ -85,7 +85,7 @@ def main():
robot.display.centered_text(f'{pin:06d}', 20, 1)
robot.display.centered_text('?', 30, 1)
robot.display.text('no', 10, 44, 1)
robot.display.centered_text('ok', 90,44, 1)
robot.display.centered_text('ok', 44, 1)
# Fill framebuffer with motor test menu
def display_fill_mot_test(robot, current_motor_test):
......@@ -228,7 +228,7 @@ def main():
bt_pair = False
bt_connecting = False
button_values = robot.buttons.pressed()
esp_reset = False
display_show_startup(robot)
# Get a list of user programs
......@@ -258,22 +258,26 @@ def main():
# Loop that shows display, controls menu and starts user programs
while(True):
# Connect to and reset ESP32 to BT mode if it is not running
if not robot.esp.running() and counter % 20 == 0:
robot.esp.reset_non_blocking()
if robot.esp.running() and counter == 1000:
robot.esp.set_name(esp_default_name,100)
if not robot.esp.running() and counter % 10 == 0:
s = utime.ticks_ms()
robot.esp.reset(200)
print("ESP32 reset time: ", utime.ticks_ms() - s)
esp_reset_counter = counter
if robot.esp.running() and counter - esp_reset_counter == 10:
robot.esp.set_name_nonblocking(esp_default_name, 100)
print("ESP BT name: ", esp_default_name)
bat_voltage = robot.battery.voltage() # Get current battery voltage
button_values = robot.buttons.pressed() # Get buttons state
# Move menu accordingly to pressed buttons
menu_move_v, menu_move_h, menu_debounce, ok_pressed = buttons(robot,
button_values, robot_state,
menu_move_v, menu_move_h,
menu_debounce)
# Check if buttons were pressed and move menu accordingly
if not bt_pair:
menu_move_v, menu_move_h, menu_debounce, ok_pressed = buttons(robot,
button_values, robot_state,
menu_move_v, menu_move_h,
menu_debounce)
# Check if buttons were pressed and move menu accordingly
if menu_debounce == 0:
if sensor_test_menu == Menu.SEN_TEST_PORT:
if menu_move_v != 0:
......@@ -312,9 +316,11 @@ def main():
if ok_pressed:
robot.esp.send_pair()
bt_connecting = True
elif button_values[Button.LEFT]:
menu_debounce = 1
elif menu_move_h == -1:
rejected_pin = pin
robot.esp.send_cancel()
menu_debounce = 1
elif current_menu == Menu.MOT_TEST:
chosen_motor_port = menu_list[current_menu]
......
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