Fixed crash when pressing buttons
This commit is contained in:
@ -6,9 +6,7 @@
|
||||
// local includes
|
||||
#include "newsettings.h"
|
||||
#include "settingsutils.h"
|
||||
#include "modes/defaultmode.h"
|
||||
#include "ledstripdefines.h"
|
||||
#include "ledstrip.h"
|
||||
|
||||
#include "bobbyquickactions.h"
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <ArduinoJson.h>
|
||||
#include <esphttpdutils.h>
|
||||
#include <espwifistack.h>
|
||||
#include <fmt/core.h>
|
||||
#include <menudisplay.h>
|
||||
@ -876,7 +875,7 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
||||
std::string id = doc["id"];
|
||||
doc.clear();
|
||||
ESP_LOGI(TAG, "popup: %s, id: %s", text.c_str(), id.c_str());
|
||||
BobbyErrorHandler{}.errorOccured(std::move(text));
|
||||
BobbyErrorHandler{}.errorOccurred(std::move(text));
|
||||
|
||||
if (id.empty())
|
||||
return;
|
||||
@ -985,7 +984,7 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
||||
}
|
||||
else if (type == "rawBtnPrssd")
|
||||
{
|
||||
uint8_t button;
|
||||
int8_t button;
|
||||
JsonVariant btn_id = doc["btn"];
|
||||
if (btn_id.isNull())
|
||||
{
|
||||
@ -1009,12 +1008,11 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
||||
return;
|
||||
}
|
||||
|
||||
espgui::currentDisplay->rawButtonPressed(button);
|
||||
espgui::currentDisplay->rawButtonReleased(button);
|
||||
rawButtonRequest = button;
|
||||
}
|
||||
else if (type == "btnPressed")
|
||||
{
|
||||
espgui::Button button;
|
||||
int8_t button;
|
||||
JsonVariant btn_id = doc["btn"];
|
||||
if (btn_id.isNull())
|
||||
{
|
||||
@ -1022,9 +1020,9 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto parsed = cpputils::fromString<std::underlying_type_t<espgui::Button>>(btn_id.as<std::string>()))
|
||||
if (auto parsed = cpputils::fromString<decltype(button)>(btn_id.as<std::string>()))
|
||||
{
|
||||
button = espgui::Button(*parsed);
|
||||
button = *parsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1038,8 +1036,7 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
||||
return;
|
||||
}
|
||||
|
||||
espgui::currentDisplay->buttonPressed(button);
|
||||
espgui::currentDisplay->buttonReleased(button);
|
||||
buttonRequest = button;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace {
|
||||
|
||||
class MainMenu : public bobbygui::MenuDisplayWithTime
|
||||
{
|
||||
using Base = espgui::MenuDisplay;
|
||||
using Base = bobbygui::MenuDisplayWithTime;
|
||||
|
||||
public:
|
||||
MainMenu();
|
||||
|
@ -39,6 +39,9 @@ bool simplified =
|
||||
ProfileSettings profileSettings;
|
||||
SettingsPersister settingsPersister;
|
||||
|
||||
std::atomic<int8_t> rawButtonRequest;
|
||||
std::atomic<int8_t> buttonRequest;
|
||||
|
||||
Controllers controllers;
|
||||
|
||||
#ifdef FEATURE_BLUETOOTH
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
// system includes
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
@ -25,11 +26,11 @@
|
||||
// local includes
|
||||
#include "controller.h"
|
||||
#include "display.h"
|
||||
#include "modeinterface.h"
|
||||
#include "profilesettings.h"
|
||||
#include "newsettings.h"
|
||||
#include "settingspersister.h"
|
||||
#include "macros_bobbycar.h"
|
||||
#include "modeinterface.h"
|
||||
#include "newsettings.h"
|
||||
#include "profilesettings.h"
|
||||
#include "settingspersister.h"
|
||||
|
||||
extern std::optional<int16_t> raw_gas, raw_brems;
|
||||
extern std::optional<float> gas, brems;
|
||||
@ -66,6 +67,9 @@ extern bool simplified;
|
||||
extern ProfileSettings profileSettings;
|
||||
extern SettingsPersister settingsPersister;
|
||||
|
||||
extern std::atomic<int8_t> rawButtonRequest;
|
||||
extern std::atomic<int8_t> buttonRequest;
|
||||
|
||||
class Controllers : public std::array<Controller, 2>
|
||||
{
|
||||
public:
|
||||
|
@ -7,7 +7,6 @@
|
||||
// local includes
|
||||
#include "esptexthelpers.h"
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include "icons/logo.h"
|
||||
|
||||
using namespace espgui;
|
||||
@ -42,6 +41,21 @@ void updateDisplay()
|
||||
changeScreenCallback();
|
||||
changeScreenCallback = {};
|
||||
}
|
||||
|
||||
if (const int8_t rawButton = rawButtonRequest.load(); rawButton != -1 && currentDisplay)
|
||||
{
|
||||
currentDisplay->rawButtonPressed(rawButton);
|
||||
currentDisplay->rawButtonReleased(rawButton);
|
||||
rawButtonRequest = -1;
|
||||
}
|
||||
|
||||
if (const int8_t button = buttonRequest.load(); button != -1 && currentDisplay)
|
||||
{
|
||||
const auto btn = espgui::Button(button);
|
||||
currentDisplay->buttonPressed(btn);
|
||||
currentDisplay->buttonReleased(btn);
|
||||
buttonRequest = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void redrawDisplay()
|
||||
|
@ -23,8 +23,9 @@
|
||||
|
||||
// local includes
|
||||
#include "bobbybuttons.h"
|
||||
#include "webserver_lock.h"
|
||||
#include "globals.h"
|
||||
#include "newsettings.h"
|
||||
#include "webserver_lock.h"
|
||||
|
||||
using esphttpdutils::HtmlTag;
|
||||
using namespace std::chrono_literals;
|
||||
@ -297,7 +298,7 @@ esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req)
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error());
|
||||
}
|
||||
|
||||
uint8_t button;
|
||||
int8_t button;
|
||||
constexpr const std::string_view buttonParamName{"button"};
|
||||
|
||||
{
|
||||
@ -335,15 +336,7 @@ esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req)
|
||||
}
|
||||
}
|
||||
|
||||
if (!espgui::currentDisplay)
|
||||
{
|
||||
constexpr const std::string_view msg = "espgui::currentDisplay is null";
|
||||
ESP_LOGW(TAG, "%.*s", msg.size(), msg.data());
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||
}
|
||||
|
||||
espgui::currentDisplay->rawButtonPressed(button);
|
||||
espgui::currentDisplay->rawButtonReleased(button);
|
||||
rawButtonRequest.store(button);
|
||||
|
||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||
@ -362,7 +355,7 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error());
|
||||
}
|
||||
|
||||
espgui::Button button;
|
||||
int8_t button;
|
||||
constexpr const std::string_view buttonParamName{"button"};
|
||||
|
||||
{
|
||||
@ -388,9 +381,9 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
||||
|
||||
std::string_view value{valueBuf};
|
||||
|
||||
if (auto parsed = cpputils::fromString<std::underlying_type_t<espgui::Button>>(value))
|
||||
if (auto parsed = cpputils::fromString<int8_t>(value))
|
||||
{
|
||||
button = espgui::Button(*parsed);
|
||||
button = *parsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -400,15 +393,7 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
||||
}
|
||||
}
|
||||
|
||||
if (!espgui::currentDisplay)
|
||||
{
|
||||
constexpr const std::string_view msg = "espgui::currentDisplay is null";
|
||||
ESP_LOGW(TAG, "%.*s", msg.size(), msg.data());
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg);
|
||||
}
|
||||
|
||||
espgui::currentDisplay->buttonPressed(button);
|
||||
espgui::currentDisplay->buttonReleased(button);
|
||||
buttonRequest.store(button);
|
||||
|
||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud");
|
||||
|
Reference in New Issue
Block a user