Added udp cloud options and ledstrip fixes
This commit is contained in:
@ -123,6 +123,8 @@ struct CanReceiveRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_
|
||||
#ifdef FEATURE_CLOUD
|
||||
struct CloudCollectRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.cloudCollectRate; } };
|
||||
struct CloudSendRateAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.cloudSendRate; } };
|
||||
struct UdpCloudSendIntervalAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.boardcomputerHardware.timersSettings.udpSendRateMs; } };
|
||||
struct UdpCloudEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.cloudSettings.udpCloudEnabled; } };
|
||||
#endif
|
||||
|
||||
struct DefaultModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return settings.defaultMode.modelMode; } };
|
||||
@ -171,7 +173,7 @@ struct LedsStVOFrontLengthAccessor : public RefAccessorSaveSettings<int16_t> { i
|
||||
struct EnableLedstripStVOFrontlight : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.ledstrip.stvoFrontEnable; } };
|
||||
struct AnimationMultiplierAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.animationMultiplier; } };
|
||||
struct LedstripBrightnessAccessor : public RefAccessorSaveSettings<uint8_t> { uint8_t &getRef() const override { return settings.ledstrip.brightness; } };
|
||||
struct LedstripEnableBlinkAnimation : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.ledstrip.enableAnimBlink; } };
|
||||
struct LedstripEnableBlinkAnimationAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.ledstrip.enableAnimBlink; } };
|
||||
struct LedstripOtaAnimationAccessor : public RefAccessorSaveSettings<OtaAnimationModes> { OtaAnimationModes &getRef() const override { return settings.ledstrip.otaMode; } };
|
||||
#endif
|
||||
|
||||
|
@ -50,6 +50,14 @@ using CloudSendRateChangeDisplay = espgui::makeComponent<
|
||||
espgui::BackActionInterface<espgui::SwitchScreenAction<CloudSettingsMenu>>,
|
||||
espgui::SwitchScreenAction<CloudSettingsMenu>
|
||||
>;
|
||||
|
||||
using UdpCloudSendRateChangeDisplay = espgui::makeComponent<
|
||||
espgui::ChangeValueDisplay<int16_t>,
|
||||
espgui::StaticText<TEXT_UDPSENDRATE>,
|
||||
UdpCloudSendIntervalAccessor,
|
||||
espgui::BackActionInterface<espgui::SwitchScreenAction<CloudSettingsMenu>>,
|
||||
espgui::SwitchScreenAction<CloudSettingsMenu>
|
||||
>;
|
||||
} // namespace
|
||||
|
||||
using namespace espgui;
|
||||
@ -57,6 +65,7 @@ using namespace espgui;
|
||||
CloudSettingsMenu::CloudSettingsMenu()
|
||||
{
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CLOUDENABLED>, ToggleBoolAction, CheckboxIcon, CloudEnabledAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UDPCLOUDENABLED>, ToggleBoolAction, CheckboxIcon, UdpCloudEnabledAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CLOUDTRANSMITTIMEOUT>, SwitchScreenAction<CloudTransmitTimeoutChangeScreen>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, CloudCreatedText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, CloudStartedText, DisabledColor, DummyAction>>();
|
||||
@ -64,6 +73,7 @@ CloudSettingsMenu::CloudSettingsMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, CloudBufferLengthText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CLOUDCOLLECTRATE>, SwitchScreenAction<CloudCollectRateChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CLOUDSENDRATE>, SwitchScreenAction<CloudSendRateChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UDPSENDRATE>, SwitchScreenAction<UdpCloudSendRateChangeDisplay>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace {
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKLEFT>, LedstripAnimationBlinkLeftAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKRIGHT>, LedstripAnimationBlinkRightAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKBOTH>, LedstripAnimationBlinkBothAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIP_EN_BLINK_ANIM>, ToggleBoolAction, CheckboxIcon, LedstripEnableBlinkAnimation>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIP_EN_BLINK_ANIM>, ToggleBoolAction, CheckboxIcon, LedstripEnableBlinkAnimationAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
};
|
||||
|
@ -213,7 +213,7 @@ void updateLedStrip()
|
||||
|
||||
void showAnimation()
|
||||
{
|
||||
if (settings.ledstrip.enableLedAnimation && !simplified && (!asyncOtaTaskStarted || settings.ledstrip.otaMode != OtaAnimationModes::None))
|
||||
if (settings.ledstrip.enableLedAnimation && !simplified && !(asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None))
|
||||
{
|
||||
if (animation_type == LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW) showDefaultLedstrip();
|
||||
else if (animation_type == LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW) showBetterRainbow();
|
||||
|
@ -449,7 +449,8 @@ extern "C" void app_main()
|
||||
#endif
|
||||
calculateStatistics();
|
||||
#ifdef FEATURE_CLOUD
|
||||
sendUdpCloudPacket();
|
||||
if (settings.cloudSettings.udpCloudEnabled)
|
||||
sendUdpCloudPacket();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +147,7 @@ constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings
|
||||
#ifdef FEATURE_CLOUD
|
||||
.cloudCollectRate = 100,
|
||||
.cloudSendRate = 1,
|
||||
.udpSendRateMs = 65,
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -175,6 +176,7 @@ constexpr Settings::CloudSettings defaultCloudSettings {
|
||||
.cloudEnabled = false,
|
||||
.cloudTransmitTimeout = 10,
|
||||
.udpUid = 0,
|
||||
.udpCloudEnabled = false,
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -113,6 +113,7 @@ struct Settings
|
||||
#ifdef FEATURE_CLOUD
|
||||
int16_t cloudCollectRate;
|
||||
int16_t cloudSendRate;
|
||||
int16_t udpSendRateMs;
|
||||
#endif
|
||||
} timersSettings;
|
||||
} boardcomputerHardware;
|
||||
@ -122,6 +123,7 @@ struct Settings
|
||||
bool cloudEnabled;
|
||||
int16_t cloudTransmitTimeout; // in ms
|
||||
uint32_t udpUid;
|
||||
bool udpCloudEnabled;
|
||||
} cloudSettings;
|
||||
#endif
|
||||
|
||||
@ -282,12 +284,14 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
||||
#ifdef FEATURE_CLOUD
|
||||
callable("cloudCollectRat", boardcomputerHardware.timersSettings.cloudCollectRate);
|
||||
callable("cloudSendRate", boardcomputerHardware.timersSettings.cloudSendRate);
|
||||
callable("udpSendRate", boardcomputerHardware.timersSettings.udpSendRateMs);
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_CLOUD
|
||||
callable("cloudEnabled", cloudSettings.cloudEnabled);
|
||||
callable("clodTransmTmout", cloudSettings.cloudTransmitTimeout);
|
||||
callable("cloudUDPUid", cloudSettings.udpUid);
|
||||
callable("enUdpCloud", cloudSettings.udpCloudEnabled);
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_LEDSTRIP
|
||||
|
@ -48,10 +48,12 @@ constexpr char TEXT_BLEENABLED[] = "BLE enabled";
|
||||
#ifdef FEATURE_CLOUD
|
||||
//CloudSettingsMenu
|
||||
constexpr char TEXT_CLOUDSETTINGS[] = "Cloud settings";
|
||||
constexpr char TEXT_CLOUDENABLED[] = "Cloud enabled";
|
||||
constexpr char TEXT_CLOUDENABLED[] = "Tcp Cloud enabled";
|
||||
constexpr char TEXT_UDPCLOUDENABLED[] = "Udp Cloud enabled";
|
||||
constexpr char TEXT_CLOUDTRANSMITTIMEOUT[] = "Transmit timeout";
|
||||
constexpr char TEXT_CLOUDCOLLECTRATE[] = "Cloud collect rate";
|
||||
constexpr char TEXT_CLOUDSENDRATE[] = "Cloud send rate";
|
||||
constexpr char TEXT_UDPSENDRATE[] = "Udp send rate";
|
||||
//constexpr char TEXT_BACK[] = "Back";
|
||||
#endif
|
||||
|
||||
|
@ -4,6 +4,11 @@ constexpr const char * const TAG = "bobbycloud";
|
||||
// 3rd party includes
|
||||
#include <ArduinoJson.h>
|
||||
#include <FastLED.h>
|
||||
#ifdef FEATURE_OTA
|
||||
#include <espcppmacros.h>
|
||||
#include <espstrutils.h>
|
||||
#include <esp_ota_ops.h>
|
||||
#endif
|
||||
|
||||
// local includes
|
||||
#include "udpcloud.h"
|
||||
@ -19,6 +24,8 @@ constexpr const char * const TAG = "bobbycloud";
|
||||
#include "drivingstatistics.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
// Little "flash" on statusdisplay when udp stuff is happening
|
||||
bool visualSendUdpPacket;
|
||||
|
||||
espchrono::millis_clock::time_point timestampLastFailed;
|
||||
|
||||
@ -115,6 +122,14 @@ std::string buildUdpCloudJson()
|
||||
doc["wN"] = drivingStatistics.wh_used;
|
||||
doc["wL"] = getRemainingWattHours();
|
||||
doc["kmL"] = getRemainingWattHours() / settings.battery.watthoursPerKilometer;
|
||||
//#ifdef FEATURE_OTA
|
||||
// if (const esp_app_desc_t *app_desc = esp_ota_get_app_description())
|
||||
// {
|
||||
// doc["ver"] = espcpputils::toHexString({app_desc->app_elf_sha256, 8});
|
||||
// }
|
||||
//#else
|
||||
// doc["ver"] = "-";
|
||||
//#endif
|
||||
|
||||
serializeJson(doc, buf);
|
||||
return buf;
|
||||
@ -122,17 +137,22 @@ std::string buildUdpCloudJson()
|
||||
|
||||
void sendUdpCloudPacket()
|
||||
{
|
||||
EVERY_N_MILLIS(30) {
|
||||
EVERY_N_MILLIS(settings.boardcomputerHardware.timersSettings.udpSendRateMs) {
|
||||
if (espchrono::ago(timestampLastFailed) < 3s)
|
||||
{
|
||||
visualSendUdpPacket = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (stringSettings.udpCloudUrl.empty())
|
||||
{
|
||||
visualSendUdpPacket = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED)
|
||||
{
|
||||
visualSendUdpPacket = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -149,12 +169,14 @@ void sendUdpCloudPacket()
|
||||
ESP_LOGE(TAG, "dns_gethostbyname() failed because: %i", res);
|
||||
}
|
||||
timestampLastFailed = espchrono::millis_clock::now();
|
||||
visualSendUdpPacket = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (udpCloudIp.type != IPADDR_TYPE_V4)
|
||||
{
|
||||
ESP_LOGE(TAG, "unsupported ip type: %hhu", udpCloudIp.type);
|
||||
visualSendUdpPacket = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -173,6 +195,7 @@ void sendUdpCloudPacket()
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "now: %s", buf.c_str());
|
||||
visualSendUdpPacket = !visualSendUdpPacket;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
// Little "flash" on statusdisplay when udp stuff is happening
|
||||
extern bool visualSendUdpPacket;
|
||||
|
||||
void spamUdpBroadcast();
|
||||
std::string buildUdpCloudJson();
|
||||
void sendUdpCloudPacket();
|
||||
|
Reference in New Issue
Block a user