mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
ESP32: Experimental BT support, enable with #define SERIAL_BT_COMMANDS
This commit is contained in:
parent
2f9c8faa77
commit
9dabf14aa3
|
@ -1 +1 @@
|
|||
#define GITHUB_SHA "PORTX-HAL-20220823"
|
||||
#define GITHUB_SHA "PORTX-HAL-20220828"
|
||||
|
|
|
@ -24,6 +24,18 @@
|
|||
#include "DCCEXParser.h"
|
||||
#include "StringFormatter.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef SERIAL_BT_COMMANDS
|
||||
#include <BluetoothSerial.h>
|
||||
//#include <BleSerial.h>
|
||||
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
||||
#error No Bluetooth library available
|
||||
#endif //ENABLED
|
||||
BluetoothSerial SerialBT;
|
||||
//BleSerial SerialBT;
|
||||
#endif //COMMANDS
|
||||
#endif //ESP32
|
||||
|
||||
SerialManager * SerialManager::first=NULL;
|
||||
|
||||
SerialManager::SerialManager(Stream * myserial) {
|
||||
|
@ -51,6 +63,17 @@ void SerialManager::init() {
|
|||
Serial1.begin(115200);
|
||||
new SerialManager(&Serial1);
|
||||
#endif
|
||||
#ifdef SERIAL_BT_COMMANDS
|
||||
{
|
||||
uint64_t chipid = ESP.getEfuseMac();
|
||||
char idstr[16] = {0};
|
||||
snprintf(idstr, 15, "DCCEX-%08X",
|
||||
__builtin_bswap32((uint32_t)(chipid>>16)));
|
||||
SerialBT.begin(idstr);
|
||||
new SerialManager(&SerialBT);
|
||||
delay(1000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SerialManager::broadcast(char * stringBuffer) {
|
||||
|
|
|
@ -115,6 +115,10 @@ bool WifiESP::setup(const char *SSid,
|
|||
bool wifiUp = false;
|
||||
uint8_t tries = 40;
|
||||
|
||||
//#ifdef SERIAL_BT_COMMANDS
|
||||
//return false;
|
||||
//#endif
|
||||
|
||||
// tests
|
||||
// enableCoreWDT(1);
|
||||
// disableCoreWDT(0);
|
||||
|
@ -135,7 +139,11 @@ bool WifiESP::setup(const char *SSid,
|
|||
|
||||
if (haveSSID && havePassword) {
|
||||
WiFi.mode(WIFI_STA);
|
||||
#ifdef SERIAL_BT_COMMANDS
|
||||
WiFi.setSleep(true);
|
||||
#else
|
||||
WiFi.setSleep(false);
|
||||
#endif
|
||||
WiFi.setAutoReconnect(true);
|
||||
WiFi.begin(SSid, password);
|
||||
while (WiFi.status() != WL_CONNECTED && tries) {
|
||||
|
@ -178,7 +186,11 @@ bool WifiESP::setup(const char *SSid,
|
|||
strPass.concat(strMac);
|
||||
|
||||
WiFi.mode(WIFI_AP);
|
||||
#ifdef SERIAL_BT_COMMANDS
|
||||
WiFi.setSleep(true);
|
||||
#else
|
||||
WiFi.setSleep(false);
|
||||
#endif
|
||||
if (WiFi.softAP(strSSID.c_str(),
|
||||
havePassword ? password : strPass.c_str(),
|
||||
channel, false, 8)) {
|
||||
|
@ -319,14 +331,19 @@ void WifiESP::loop() {
|
|||
}
|
||||
} else if (!APmode) { // in STA mode but not connected any more
|
||||
// kick it again
|
||||
DIAG(F("Wifi aborted with error %s. Kicking Wifi!"), wlStatus <= 6 ? wlerror[wlStatus] : "UNKNOWN");
|
||||
esp_wifi_start();
|
||||
esp_wifi_connect();
|
||||
uint8_t tries=40;
|
||||
while (WiFi.status() != WL_CONNECTED && tries) {
|
||||
Serial.print('.');
|
||||
tries--;
|
||||
delay(500);
|
||||
if (wlStatus <= 6) {
|
||||
DIAG(F("Wifi aborted with error %s. Kicking Wifi!"), wlerror[wlStatus]);
|
||||
esp_wifi_start();
|
||||
esp_wifi_connect();
|
||||
uint8_t tries=40;
|
||||
while (WiFi.status() != WL_CONNECTED && tries) {
|
||||
Serial.print('.');
|
||||
tries--;
|
||||
delay(500);
|
||||
}
|
||||
} else {
|
||||
// all well, probably
|
||||
//DIAG(F("Running BT"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user