Fixed crash when pressing buttons
This commit is contained in:
@ -6,9 +6,7 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
#include "settingsutils.h"
|
#include "settingsutils.h"
|
||||||
#include "modes/defaultmode.h"
|
|
||||||
#include "ledstripdefines.h"
|
#include "ledstripdefines.h"
|
||||||
#include "ledstrip.h"
|
|
||||||
|
|
||||||
#include "bobbyquickactions.h"
|
#include "bobbyquickactions.h"
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <esphttpdutils.h>
|
|
||||||
#include <espwifistack.h>
|
#include <espwifistack.h>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <menudisplay.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"];
|
std::string id = doc["id"];
|
||||||
doc.clear();
|
doc.clear();
|
||||||
ESP_LOGI(TAG, "popup: %s, id: %s", text.c_str(), id.c_str());
|
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())
|
if (id.empty())
|
||||||
return;
|
return;
|
||||||
@ -985,7 +984,7 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
|||||||
}
|
}
|
||||||
else if (type == "rawBtnPrssd")
|
else if (type == "rawBtnPrssd")
|
||||||
{
|
{
|
||||||
uint8_t button;
|
int8_t button;
|
||||||
JsonVariant btn_id = doc["btn"];
|
JsonVariant btn_id = doc["btn"];
|
||||||
if (btn_id.isNull())
|
if (btn_id.isNull())
|
||||||
{
|
{
|
||||||
@ -1009,12 +1008,11 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
espgui::currentDisplay->rawButtonPressed(button);
|
rawButtonRequest = button;
|
||||||
espgui::currentDisplay->rawButtonReleased(button);
|
|
||||||
}
|
}
|
||||||
else if (type == "btnPressed")
|
else if (type == "btnPressed")
|
||||||
{
|
{
|
||||||
espgui::Button button;
|
int8_t button;
|
||||||
JsonVariant btn_id = doc["btn"];
|
JsonVariant btn_id = doc["btn"];
|
||||||
if (btn_id.isNull())
|
if (btn_id.isNull())
|
||||||
{
|
{
|
||||||
@ -1022,9 +1020,9 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
|||||||
return;
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -1038,8 +1036,7 @@ void cloudEventHandler(void *event_handler_arg, esp_event_base_t event_base, int
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
espgui::currentDisplay->buttonPressed(button);
|
buttonRequest = button;
|
||||||
espgui::currentDisplay->buttonReleased(button);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ namespace {
|
|||||||
|
|
||||||
class MainMenu : public bobbygui::MenuDisplayWithTime
|
class MainMenu : public bobbygui::MenuDisplayWithTime
|
||||||
{
|
{
|
||||||
using Base = espgui::MenuDisplay;
|
using Base = bobbygui::MenuDisplayWithTime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainMenu();
|
MainMenu();
|
||||||
|
@ -39,6 +39,9 @@ bool simplified =
|
|||||||
ProfileSettings profileSettings;
|
ProfileSettings profileSettings;
|
||||||
SettingsPersister settingsPersister;
|
SettingsPersister settingsPersister;
|
||||||
|
|
||||||
|
std::atomic<int8_t> rawButtonRequest;
|
||||||
|
std::atomic<int8_t> buttonRequest;
|
||||||
|
|
||||||
Controllers controllers;
|
Controllers controllers;
|
||||||
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// system includes
|
// system includes
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@ -25,11 +26,11 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "modeinterface.h"
|
|
||||||
#include "profilesettings.h"
|
|
||||||
#include "newsettings.h"
|
|
||||||
#include "settingspersister.h"
|
|
||||||
#include "macros_bobbycar.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<int16_t> raw_gas, raw_brems;
|
||||||
extern std::optional<float> gas, brems;
|
extern std::optional<float> gas, brems;
|
||||||
@ -66,6 +67,9 @@ extern bool simplified;
|
|||||||
extern ProfileSettings profileSettings;
|
extern ProfileSettings profileSettings;
|
||||||
extern SettingsPersister settingsPersister;
|
extern SettingsPersister settingsPersister;
|
||||||
|
|
||||||
|
extern std::atomic<int8_t> rawButtonRequest;
|
||||||
|
extern std::atomic<int8_t> buttonRequest;
|
||||||
|
|
||||||
class Controllers : public std::array<Controller, 2>
|
class Controllers : public std::array<Controller, 2>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "esptexthelpers.h"
|
#include "esptexthelpers.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "icons/logo.h"
|
#include "icons/logo.h"
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
@ -42,6 +41,21 @@ void updateDisplay()
|
|||||||
changeScreenCallback();
|
changeScreenCallback();
|
||||||
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()
|
void redrawDisplay()
|
||||||
|
@ -23,8 +23,9 @@
|
|||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "bobbybuttons.h"
|
#include "bobbybuttons.h"
|
||||||
#include "webserver_lock.h"
|
#include "globals.h"
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
|
#include "webserver_lock.h"
|
||||||
|
|
||||||
using esphttpdutils::HtmlTag;
|
using esphttpdutils::HtmlTag;
|
||||||
using namespace std::chrono_literals;
|
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());
|
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"};
|
constexpr const std::string_view buttonParamName{"button"};
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -335,15 +336,7 @@ esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!espgui::currentDisplay)
|
rawButtonRequest.store(button);
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
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");
|
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());
|
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"};
|
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};
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -400,15 +393,7 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!espgui::currentDisplay)
|
buttonRequest.store(button);
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/")
|
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");
|
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