Apply ble remote control command also in default driving mode
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
// local includes
|
||||
#include "ledstrip.h"
|
||||
#include "globals.h"
|
||||
#include "modes/defaultmode.h"
|
||||
#include "modes/remotecontrolmode.h"
|
||||
#include "utils.h"
|
||||
#include "newsettings.h"
|
||||
@ -246,12 +247,14 @@ void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
||||
|
||||
if (!simplified)
|
||||
{
|
||||
modes::remoteControlMode.setCommand(RemoteCommand{
|
||||
RemoteCommand cmd {
|
||||
.frontLeft = doc[isInverted ? "fr":"fl"].as<int16_t>(),
|
||||
.frontRight = doc[isInverted ? "fl":"fr"].as<int16_t>(),
|
||||
.backLeft = doc["bl"].as<int16_t>(),
|
||||
.backRight = doc["br"].as<int16_t>()
|
||||
});
|
||||
};
|
||||
modes::defaultMode.setRemoteCommand(cmd);
|
||||
modes::remoteControlMode.setRemoteCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +273,7 @@ void WirelessSettingsCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
||||
|
||||
if (write_type == "wifi") {
|
||||
const int index = doc["wifi_index"].as<int>();
|
||||
ESP_LOGI(TAG, "[ble_config]: Set wifi%i: WiFi-SSID: %s, WiFi-Password: ***", doc["wifi_index"].as<int>(), doc["wifi_ssid"].as<const char*>());
|
||||
ESP_LOGI(TAG, "Set wifi%i: WiFi-SSID: %s, WiFi-Password: ***", doc["wifi_index"].as<int>(), doc["wifi_ssid"].as<const char*>());
|
||||
configs.write_config(configs.wifi_configs[index].ssid, doc["wifi_ssid"].as<std::string>());
|
||||
configs.write_config(configs.wifi_configs[index].key, doc["wifi_pass"].as<std::string>());
|
||||
} else {
|
||||
@ -283,7 +286,7 @@ void WiFiListCallbacks::onRead(NimBLECharacteristic *pCharacteristic)
|
||||
{
|
||||
StaticJsonDocument<768> responseDoc;
|
||||
auto wifiArray = responseDoc.createNestedArray("wifis");
|
||||
ESP_LOGI(TAG, "[ble_wifilist] Got request for listing wifi ssids.");
|
||||
ESP_LOGI(TAG, "Got request for listing wifi ssids.");
|
||||
for (const auto &wifi : configs.wifi_configs)
|
||||
{
|
||||
wifiArray.add(wifi.ssid.value());
|
||||
|
@ -13,3 +13,10 @@ extern BLECharacteristic *getwifilist;
|
||||
void initBle();
|
||||
|
||||
void handleBle();
|
||||
|
||||
struct RemoteCommand {
|
||||
int16_t frontLeft{};
|
||||
int16_t frontRight{};
|
||||
int16_t backLeft{};
|
||||
int16_t backRight{};
|
||||
};
|
||||
|
@ -260,4 +260,18 @@ void DefaultMode::update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_remoteCommand && espchrono::ago(m_timestamp) < 500ms)
|
||||
{
|
||||
controllers.front.command.left.pwm += m_remoteCommand->frontLeft;
|
||||
controllers.front.command.right.pwm += m_remoteCommand->frontRight;
|
||||
controllers.back.command.left.pwm += m_remoteCommand->backLeft;
|
||||
controllers.back.command.left.pwm += m_remoteCommand->backRight;
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultMode::setRemoteCommand(const RemoteCommand &command)
|
||||
{
|
||||
m_remoteCommand = command;
|
||||
m_timestamp = espchrono::millis_clock::now();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "modeinterface.h"
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include "ble_bobby.h"
|
||||
|
||||
class DefaultMode : public ModeInterface
|
||||
{
|
||||
@ -25,9 +26,14 @@ public:
|
||||
bool waitForGasLoslass{false};
|
||||
bool waitForBremsLoslass{false};
|
||||
|
||||
void setRemoteCommand(const RemoteCommand &command);
|
||||
|
||||
private:
|
||||
espchrono::millis_clock::time_point m_lastTime{espchrono::millis_clock::now()};
|
||||
float m_lastPwm{0};
|
||||
|
||||
std::optional<RemoteCommand> m_remoteCommand;
|
||||
espchrono::millis_clock::time_point m_timestamp;
|
||||
};
|
||||
|
||||
namespace modes {
|
||||
|
@ -44,7 +44,7 @@ void RemoteControlMode::update()
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteControlMode::setCommand(const RemoteCommand &command)
|
||||
void RemoteControlMode::setRemoteCommand(const RemoteCommand &command)
|
||||
{
|
||||
m_remoteCommand = command;
|
||||
m_timestamp = espchrono::millis_clock::now();
|
||||
|
@ -10,13 +10,7 @@
|
||||
// local includes
|
||||
#include "bobbycar-common.h"
|
||||
#include "modeinterface.h"
|
||||
|
||||
struct RemoteCommand {
|
||||
int16_t frontLeft{};
|
||||
int16_t frontRight{};
|
||||
int16_t backLeft{};
|
||||
int16_t backRight{};
|
||||
};
|
||||
#include "ble_bobby.h"
|
||||
|
||||
class RemoteControlMode : public ModeInterface
|
||||
{
|
||||
@ -27,8 +21,9 @@ public:
|
||||
|
||||
const char *displayName() const override { return "RemoteControl"; }
|
||||
|
||||
void setCommand(const RemoteCommand &command);
|
||||
void setRemoteCommand(const RemoteCommand &command);
|
||||
|
||||
private:
|
||||
std::optional<RemoteCommand> m_remoteCommand;
|
||||
espchrono::millis_clock::time_point m_timestamp;
|
||||
};
|
||||
|
Reference in New Issue
Block a user