mirror of
https://github.com/wled/WLED.git
synced 2025-07-24 19:26:40 +00:00
Serial improvements (can RX, canTX)
PinManager bugfix for unsigned long long
This commit is contained in:
parent
7f1ec4802d
commit
ac8f919304
7
wled00/data/settings_sync.htm
Executable file → Normal file
7
wled00/data/settings_sync.htm
Executable file → Normal file
@ -199,7 +199,7 @@ Realtime LED offset: <input name="WO" type="number" min="-255" max="255" require
|
|||||||
<div id="Alexa">
|
<div id="Alexa">
|
||||||
Emulate Alexa device: <input type="checkbox" name="AL"><br>
|
Emulate Alexa device: <input type="checkbox" name="AL"><br>
|
||||||
Alexa invocation name: <input type="text" name="AI" maxlength="32"><br>
|
Alexa invocation name: <input type="text" name="AI" maxlength="32"><br>
|
||||||
Also emulate devices to call the first <input name="AP" type="number" class="s" min="0" max="9" required> presets<br><br>
|
Also emulate devices to call the first <input name="AP" type="number" class="s" min="0" max="9"> presets<br><br>
|
||||||
</div>
|
</div>
|
||||||
<hr class="sml">
|
<hr class="sml">
|
||||||
<div class="warn">⚠ <b>MQTT and Hue sync all connect to external hosts!<br>
|
<div class="warn">⚠ <b>MQTT and Hue sync all connect to external hosts!<br>
|
||||||
@ -245,6 +245,10 @@ Hue Bridge IP:<br>
|
|||||||
Hue status: <span class="sip"> Disabled in this build </span>
|
Hue status: <span class="sip"> Disabled in this build </span>
|
||||||
</div>
|
</div>
|
||||||
<h3>Serial</h3>
|
<h3>Serial</h3>
|
||||||
|
<div id="NoSerial" class="hide">
|
||||||
|
<em class="warn">This firmware build does support Serial interface.<br></em>
|
||||||
|
</div>
|
||||||
|
<div id="Serial">
|
||||||
Baud rate:
|
Baud rate:
|
||||||
<select name=BD>
|
<select name=BD>
|
||||||
<option value=1152>115200</option>
|
<option value=1152>115200</option>
|
||||||
@ -257,6 +261,7 @@ Baud rate:
|
|||||||
<option value=15000>1500000</option>
|
<option value=15000>1500000</option>
|
||||||
</select><br>
|
</select><br>
|
||||||
<i>Keep at 115200 to use Improv. Some boards may not support high rates.</i>
|
<i>Keep at 115200 to use Improv. Some boards may not support high rates.</i>
|
||||||
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
|
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -714,9 +714,8 @@ void handleIR()
|
|||||||
if (strip.isUpdating() && timeDiff < 240) return; // be nice, but not too nice
|
if (strip.isUpdating() && timeDiff < 240) return; // be nice, but not too nice
|
||||||
irCheckedTime = currentTime;
|
irCheckedTime = currentTime;
|
||||||
if (irrecv->decode(&results)) {
|
if (irrecv->decode(&results)) {
|
||||||
if (results.value != 0) { // only print results if anything is received ( != 0 )
|
if (results.value != 0 && serialCanTX) { // only print results if anything is received ( != 0 )
|
||||||
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) // Serial TX pin (GPIO 1 on ESP32 and ESP8266)
|
Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value);
|
||||||
Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value);
|
|
||||||
}
|
}
|
||||||
decodeIR(results.value);
|
decodeIR(results.value);
|
||||||
irrecv->resume();
|
irrecv->resume();
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
#include "pin_manager.h"
|
#include "pin_manager.h"
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#ifdef bitRead
|
||||||
|
// Arduino variants assume 32 bit values
|
||||||
|
#undef bitRead
|
||||||
|
#undef bitSet
|
||||||
|
#undef bitClear
|
||||||
|
#define bitRead(var,bit) (((unsigned long long)(var)>>(bit))&0x1ULL)
|
||||||
|
#define bitSet(var,bit) ((var)|=(1ULL<<(bit)))
|
||||||
|
#define bitClear(var,bit) ((var)&=(~(1ULL<<(bit))))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
static void DebugPrintOwnerTag(PinOwner tag)
|
static void DebugPrintOwnerTag(PinOwner tag)
|
||||||
{
|
{
|
||||||
|
@ -87,7 +87,11 @@ class PinManagerClass {
|
|||||||
PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None };
|
PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PinManagerClass() : pinAlloc(0), i2cAllocCount(0), spiAllocCount(0) {}
|
PinManagerClass() : pinAlloc(0ULL), i2cAllocCount(0), spiAllocCount(0) {
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
ledcAlloc = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
// De-allocates a single pin
|
// De-allocates a single pin
|
||||||
bool deallocatePin(byte gpio, PinOwner tag);
|
bool deallocatePin(byte gpio, PinOwner tag);
|
||||||
// De-allocates multiple pins but only if all can be deallocated (PinOwner has to be specified)
|
// De-allocates multiple pins but only if all can be deallocated (PinOwner has to be specified)
|
||||||
|
@ -54,17 +54,19 @@ void WLED::loop()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
handleTime();
|
handleTime();
|
||||||
#ifndef WLED_DISABLE_INFRARED
|
#ifndef WLED_DISABLE_INFRARED
|
||||||
handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too
|
handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too
|
||||||
#endif
|
#endif
|
||||||
handleConnection();
|
handleConnection();
|
||||||
|
#ifdef WLED_ENABLE_ADALIGHT
|
||||||
handleSerial();
|
handleSerial();
|
||||||
|
#endif
|
||||||
handleImprovWifiScan();
|
handleImprovWifiScan();
|
||||||
handleNotifications();
|
handleNotifications();
|
||||||
handleTransitions();
|
handleTransitions();
|
||||||
#ifdef WLED_ENABLE_DMX
|
#ifdef WLED_ENABLE_DMX
|
||||||
handleDMX();
|
handleDMX();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
unsigned long usermodMillis = millis();
|
unsigned long usermodMillis = millis();
|
||||||
@ -476,10 +478,14 @@ void WLED::setup()
|
|||||||
WiFi.mode(WIFI_STA); // enable scanning
|
WiFi.mode(WIFI_STA); // enable scanning
|
||||||
findWiFi(true); // start scanning for available WiFi-s
|
findWiFi(true); // start scanning for available WiFi-s
|
||||||
|
|
||||||
|
// all GPIOs are allocated at this point
|
||||||
|
serialCanRX = !pinManager.isPinAllocated(hardwareRX); // Serial RX pin (GPIO 3 on ESP32 and ESP8266)
|
||||||
|
serialCanTX = !pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut; // Serial TX pin (GPIO 1 on ESP32 and ESP8266)
|
||||||
|
|
||||||
#ifdef WLED_ENABLE_ADALIGHT
|
#ifdef WLED_ENABLE_ADALIGHT
|
||||||
//Serial RX (Adalight, Improv, Serial JSON) only possible if GPIO3 unused
|
//Serial RX (Adalight, Improv, Serial JSON) only possible if GPIO3 unused
|
||||||
//Serial TX (Debug, Improv, Serial JSON) only possible if GPIO1 unused
|
//Serial TX (Debug, Improv, Serial JSON) only possible if GPIO1 unused
|
||||||
if (!pinManager.isPinAllocated(hardwareRX) && !pinManager.isPinAllocated(hardwareTX)) {
|
if (serialCanRX && serialCanTX) {
|
||||||
Serial.println(F("Ada"));
|
Serial.println(F("Ada"));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -491,10 +497,6 @@ void WLED::setup()
|
|||||||
if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6);
|
if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WLED_ENABLE_ADALIGHT
|
|
||||||
if (Serial.available() > 0 && Serial.peek() == 'I') handleImprovPacket();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_OTA
|
#ifndef WLED_DISABLE_OTA
|
||||||
if (aOtaEnabled) {
|
if (aOtaEnabled) {
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
@ -521,7 +523,7 @@ void WLED::setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WLED_ENABLE_ADALIGHT
|
#ifdef WLED_ENABLE_ADALIGHT
|
||||||
if (Serial.available() > 0 && Serial.peek() == 'I') handleImprovPacket();
|
if (serialCanRX && Serial.available() > 0 && Serial.peek() == 'I') handleImprovPacket();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// HTTP server page init
|
// HTTP server page init
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2409140
|
#define VERSION 2409170
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
@ -510,6 +510,8 @@ WLED_GLOBAL bool hueApplyColor _INIT(true);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
WLED_GLOBAL uint16_t serialBaud _INIT(1152); // serial baud rate, multiply by 100
|
WLED_GLOBAL uint16_t serialBaud _INIT(1152); // serial baud rate, multiply by 100
|
||||||
|
WLED_GLOBAL bool serialCanRX _INIT(false);
|
||||||
|
WLED_GLOBAL bool serialCanTX _INIT(false);
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_ESPNOW
|
#ifndef WLED_DISABLE_ESPNOW
|
||||||
WLED_GLOBAL bool enableESPNow _INIT(false); // global on/off for ESP-NOW
|
WLED_GLOBAL bool enableESPNow _INIT(false); // global on/off for ESP-NOW
|
||||||
|
@ -28,7 +28,7 @@ void updateBaudRate(uint32_t rate){
|
|||||||
if (rate100 == currentBaud || rate100 < 96) return;
|
if (rate100 == currentBaud || rate100 < 96) return;
|
||||||
currentBaud = rate100;
|
currentBaud = rate100;
|
||||||
|
|
||||||
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut){
|
if (serialCanTX){
|
||||||
Serial.print(F("Baud is now ")); Serial.println(rate);
|
Serial.print(F("Baud is now ")); Serial.println(rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ void updateBaudRate(uint32_t rate){
|
|||||||
|
|
||||||
// RGB LED data return as JSON array. Slow, but easy to use on the other end.
|
// RGB LED data return as JSON array. Slow, but easy to use on the other end.
|
||||||
void sendJSON(){
|
void sendJSON(){
|
||||||
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) {
|
if (serialCanTX) {
|
||||||
unsigned used = strip.getLengthTotal();
|
unsigned used = strip.getLengthTotal();
|
||||||
Serial.write('[');
|
Serial.write('[');
|
||||||
for (unsigned i=0; i<used; i++) {
|
for (unsigned i=0; i<used; i++) {
|
||||||
@ -51,7 +51,7 @@ void sendJSON(){
|
|||||||
|
|
||||||
// RGB LED data returned as bytes in TPM2 format. Faster, and slightly less easy to use on the other end.
|
// RGB LED data returned as bytes in TPM2 format. Faster, and slightly less easy to use on the other end.
|
||||||
void sendBytes(){
|
void sendBytes(){
|
||||||
if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) {
|
if (serialCanTX) {
|
||||||
Serial.write(0xC9); Serial.write(0xDA);
|
Serial.write(0xC9); Serial.write(0xDA);
|
||||||
unsigned used = strip.getLengthTotal();
|
unsigned used = strip.getLengthTotal();
|
||||||
unsigned len = used*3;
|
unsigned len = used*3;
|
||||||
@ -69,10 +69,8 @@ void sendBytes(){
|
|||||||
|
|
||||||
void handleSerial()
|
void handleSerial()
|
||||||
{
|
{
|
||||||
if (pinManager.isPinAllocated(hardwareRX)) return;
|
if (!(serialCanRX && Serial)) return; // arduino docs: `if (Serial)` indicates whether or not the USB CDC serial connection is open. For all non-USB CDC ports, this will always return true
|
||||||
if (!Serial) return; // arduino docs: `if (Serial)` indicates whether or not the USB CDC serial connection is open. For all non-USB CDC ports, this will always return true
|
|
||||||
|
|
||||||
#ifdef WLED_ENABLE_ADALIGHT
|
|
||||||
static auto state = AdaState::Header_A;
|
static auto state = AdaState::Header_A;
|
||||||
static uint16_t count = 0;
|
static uint16_t count = 0;
|
||||||
static uint16_t pixel = 0;
|
static uint16_t pixel = 0;
|
||||||
@ -86,54 +84,43 @@ void handleSerial()
|
|||||||
byte next = Serial.peek();
|
byte next = Serial.peek();
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AdaState::Header_A:
|
case AdaState::Header_A:
|
||||||
if (next == 'A') state = AdaState::Header_d;
|
if (next == 'A') { state = AdaState::Header_d; }
|
||||||
else if (next == 0xC9) { //TPM2 start byte
|
else if (next == 0xC9) { state = AdaState::TPM2_Header_Type; } //TPM2 start byte
|
||||||
state = AdaState::TPM2_Header_Type;
|
else if (next == 'I') { handleImprovPacket(); return; }
|
||||||
}
|
else if (next == 'v') { Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION); }
|
||||||
else if (next == 'I') {
|
else if (next == 0xB0) { updateBaudRate( 115200); }
|
||||||
handleImprovPacket();
|
else if (next == 0xB1) { updateBaudRate( 230400); }
|
||||||
return;
|
else if (next == 0xB2) { updateBaudRate( 460800); }
|
||||||
} else if (next == 'v') {
|
else if (next == 0xB3) { updateBaudRate( 500000); }
|
||||||
Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION);
|
else if (next == 0xB4) { updateBaudRate( 576000); }
|
||||||
|
else if (next == 0xB5) { updateBaudRate( 921600); }
|
||||||
} else if (next == 0xB0) {updateBaudRate( 115200);
|
else if (next == 0xB6) { updateBaudRate(1000000); }
|
||||||
} else if (next == 0xB1) {updateBaudRate( 230400);
|
else if (next == 0xB7) { updateBaudRate(1500000); }
|
||||||
} else if (next == 0xB2) {updateBaudRate( 460800);
|
else if (next == 'l') { sendJSON(); } // Send LED data as JSON Array
|
||||||
} else if (next == 0xB3) {updateBaudRate( 500000);
|
else if (next == 'L') { sendBytes(); } // Send LED data as TPM2 Data Packet
|
||||||
} else if (next == 0xB4) {updateBaudRate( 576000);
|
else if (next == 'o') { continuousSendLED = false; } // Disable Continuous Serial Streaming
|
||||||
} else if (next == 0xB5) {updateBaudRate( 921600);
|
else if (next == 'O') { continuousSendLED = true; } // Enable Continuous Serial Streaming
|
||||||
} else if (next == 0xB6) {updateBaudRate(1000000);
|
else if (next == '{') { //JSON API
|
||||||
} else if (next == 0xB7) {updateBaudRate(1500000);
|
|
||||||
|
|
||||||
} else if (next == 'l') {sendJSON(); // Send LED data as JSON Array
|
|
||||||
} else if (next == 'L') {sendBytes(); // Send LED data as TPM2 Data Packet
|
|
||||||
|
|
||||||
} else if (next == 'o') {continuousSendLED = false; // Disable Continuous Serial Streaming
|
|
||||||
} else if (next == 'O') {continuousSendLED = true; // Enable Continuous Serial Streaming
|
|
||||||
|
|
||||||
} else if (next == '{') { //JSON API
|
|
||||||
bool verboseResponse = false;
|
bool verboseResponse = false;
|
||||||
if (!requestJSONBufferLock(16)) {
|
if (!requestJSONBufferLock(16)) {
|
||||||
Serial.println(F("{\"error\":3}")); // ERR_NOBUF
|
Serial.printf_P(PSTR("{\"error\":%d}\n"), ERR_NOBUF);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.setTimeout(100);
|
Serial.setTimeout(100);
|
||||||
DeserializationError error = deserializeJson(*pDoc, Serial);
|
DeserializationError error = deserializeJson(*pDoc, Serial);
|
||||||
if (error) {
|
if (!error) {
|
||||||
releaseJSONBufferLock();
|
verboseResponse = deserializeState(pDoc->as<JsonObject>());
|
||||||
return;
|
//only send response if TX pin is unused for other purposes
|
||||||
}
|
if (verboseResponse && serialCanTX) {
|
||||||
verboseResponse = deserializeState(pDoc->as<JsonObject>());
|
pDoc->clear();
|
||||||
//only send response if TX pin is unused for other purposes
|
JsonObject state = pDoc->createNestedObject("state");
|
||||||
if (verboseResponse && (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut)) {
|
serializeState(state);
|
||||||
pDoc->clear();
|
JsonObject info = pDoc->createNestedObject("info");
|
||||||
JsonObject state = pDoc->createNestedObject("state");
|
serializeInfo(info);
|
||||||
serializeState(state);
|
|
||||||
JsonObject info = pDoc->createNestedObject("info");
|
|
||||||
serializeInfo(info);
|
|
||||||
|
|
||||||
serializeJson(*pDoc, Serial);
|
serializeJson(*pDoc, Serial);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
}
|
}
|
||||||
@ -199,11 +186,10 @@ void handleSerial()
|
|||||||
// All other received bytes will disable Continuous Serial Streaming
|
// All other received bytes will disable Continuous Serial Streaming
|
||||||
if (continuousSendLED && next != 'O'){
|
if (continuousSendLED && next != 'O'){
|
||||||
continuousSendLED = false;
|
continuousSendLED = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.read(); //discard the byte
|
Serial.read(); //discard the byte
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// If Continuous Serial Streaming is enabled, send new LED data as bytes
|
// If Continuous Serial Streaming is enabled, send new LED data as bytes
|
||||||
if (continuousSendLED && (lastUpdate != strip.getLastShow())){
|
if (continuousSendLED && (lastUpdate != strip.getLastShow())){
|
||||||
|
@ -571,6 +571,9 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
oappend(SET_F("toggle('Hue');")); // hide Hue Sync settings
|
oappend(SET_F("toggle('Hue');")); // hide Hue Sync settings
|
||||||
#endif
|
#endif
|
||||||
sappend('v',SET_F("BD"),serialBaud);
|
sappend('v',SET_F("BD"),serialBaud);
|
||||||
|
#ifndef WLED_ENABLE_ADALIGHT
|
||||||
|
oappend(SET_F("toggle('Serial);"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subPage == SUBPAGE_TIME)
|
if (subPage == SUBPAGE_TIME)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user