From da881c1fec46e713bc7d5bcb30b92b7acae66f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Benito=20Lamata?= Date: Sun, 17 Sep 2023 11:38:53 +0200 Subject: [PATCH] Better ack handling --- DMI/window/menu.cpp | 2 ++ DMI/window/window.cpp | 2 +- EVC/DMI/acks.cpp | 13 +++++-------- EVC/DMI/acks.h | 1 + EVC/DMI/windows.cpp | 23 +++++++++++++---------- EVC/TrainSubsystems/brake.cpp | 3 ++- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/DMI/window/menu.cpp b/DMI/window/menu.cpp index ff9ef5ce..833e2515 100644 --- a/DMI/window/menu.cpp +++ b/DMI/window/menu.cpp @@ -90,6 +90,8 @@ void menu::setLayout() { if (labels[i] != nullptr) addToLayout(labels[i], new RelativeAlignment(nullptr, 334, 100+24*i, 0)); } + extern Component ackButton; + addToLayout(&ackButton, new RelativeAlignment(nullptr, 600, 348, 0)); } else { diff --git a/DMI/window/window.cpp b/DMI/window/window.cpp index d652e6d9..a3f44869 100755 --- a/DMI/window/window.cpp +++ b/DMI/window/window.cpp @@ -13,7 +13,7 @@ #include "platform_runtime.h" bool isInside(Component *comp, float x, float y) { - if (componentAck != nullptr && comp != componentAck && comp != &ackButton) return false; + //if (componentAck != nullptr && comp != componentAck && comp != &ackButton) return false; return (comp->x-comp->touch_left)x + comp->sx + comp->touch_right)>x && (comp->y-comp->touch_up)y + comp->sy+comp->touch_down)>y; } diff --git a/EVC/DMI/acks.cpp b/EVC/DMI/acks.cpp index dcb9c1eb..f4e3808e 100644 --- a/EVC/DMI/acks.cpp +++ b/EVC/DMI/acks.cpp @@ -25,15 +25,12 @@ void update_acks() } if (ack_required && active_dialog != dialog_sequence::StartUp) { if (active_dialog != dialog_sequence::None) { - if (active_dialog == dialog_sequence::NTCData) { - for (auto &kvp : installed_stms) { - auto *stm = kvp.second; - if (stm->data_entry == stm_object::data_entry_state::Driver) - stm->data_entry = stm_object::data_entry_state::Active; - } + std::string active = active_window_dmi["active"]; + if (active != "menu_main" && active != "menu_override" && active != "menu_spec" && + active != "menu_settings" && active != "menu_radio" && active != "menu_ntc") { + close_window(); + last_ack_time = get_milliseconds(); } - active_dialog = dialog_sequence::None; - last_ack_time = get_milliseconds(); } if (get_milliseconds() > last_ack_time + 1000) ack_allowed = true; diff --git a/EVC/DMI/acks.h b/EVC/DMI/acks.h index 9b640356..f0c68ff9 100644 --- a/EVC/DMI/acks.h +++ b/EVC/DMI/acks.h @@ -8,4 +8,5 @@ */ #pragma once extern bool ack_allowed; +extern bool ack_required; void update_acks(); \ No newline at end of file diff --git a/EVC/DMI/windows.cpp b/EVC/DMI/windows.cpp index eda750f6..bb3ae32d 100644 --- a/EVC/DMI/windows.cpp +++ b/EVC/DMI/windows.cpp @@ -783,6 +783,11 @@ void update_dmi_windows() } enabled_buttons["EndDataEntry"] = active_dialog_step != "S1" && active_dialog_step != "S4"; } + if (ack_required) { + for (auto &kvp : enabled_buttons) { + kvp.second = false; + } + } std::string active = active_window_dmi["active"]; if (active == "menu_main" && !active_window_dmi.contains("hour_glass")) { json &enabled = active_window_dmi["enabled"]; @@ -826,11 +831,12 @@ void update_dmi_windows() } if (active_dialog != dialog_sequence::None && active_dialog != dialog_sequence::StartUp && (!som_active || som_status != S1)) { extern bool traindata_applied; + bool close = false; if ((active == "trn_window" && !enabled_buttons["Train Running Number"]) || (active == "driver_window" && !enabled_buttons["Driver ID"]) || (active == "level_window" && !enabled_buttons["Level"]) || ((active == "train_data_validation_window" || active == "train_data_window" || active == "fixed_train_data_validation_window" || active == "fixed_train_data_window") && !enabled_buttons["Train Data"])) { - active_dialog_step = "S1"; + close = true; if ((active == "fixed_train_data_window" || active == "fixed_train_data_validation_window" || active == "train_data_window" || active == "train_data_validation_window") && V_est != 0) { traindata_applied = true; trigger_brake_reason(1); @@ -838,33 +844,30 @@ void update_dmi_windows() } if ((active == "rbc_data_window" && !enabled_buttons["Enter RBC data"]) || (active == "radio_network_window" && !enabled_buttons["Radio Network ID"]) ) { - active_dialog_step = "S5-1"; + close = true; } if ((active == "language_window" && !enabled_buttons["Language"]) || (active == "volume_window" && !enabled_buttons["Volume"]) || (active == "brightness_window" && !enabled_buttons["Brightness"]) ) { - active_dialog_step = "S1"; + close = true; } if ((active == "adhesion_window" && !enabled_buttons["Adhesion"]) || (active == "sr_data_window" && !enabled_buttons["SRspeed"]) ) { - active_dialog_step = "S1"; + close = true; if (active == "sr_data_window" && V_est != 0) { traindata_applied = true; trigger_brake_reason(1); } } if ((active == "ntc_data_window" || active == "ntc_data_validation_window") && !enabled_buttons[active_window_dmi["ntc"]]) { - for (auto &kvp : installed_stms) { - auto *stm = kvp.second; - if (stm->data_entry == stm_object::data_entry_state::Driver) - stm->data_entry = stm_object::data_entry_state::Active; - } - active_dialog_step = "S2"; + close = true; if (V_est != 0) { traindata_applied = true; trigger_brake_reason(1); } } + if (close) + close_window(); } } void close_window() diff --git a/EVC/TrainSubsystems/brake.cpp b/EVC/TrainSubsystems/brake.cpp index 8c432a9b..f755fa15 100644 --- a/EVC/TrainSubsystems/brake.cpp +++ b/EVC/TrainSubsystems/brake.cpp @@ -128,7 +128,8 @@ void handle_brake_command() } } } - if ((prevEB || prevSB) && !EB_command && !SB_command) send_command("playSinfo",""); + extern bool any_button_pressed; + if ((prevEB || prevSB) && !EB_command && !SB_command && !any_button_pressed) send_command("playSinfo",""); prevEB = EB_command; prevSB = SB_command; } \ No newline at end of file