Skip to content

Commit

Permalink
Baud rate setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Feb 1, 2022
1 parent 3228688 commit 00dbdc2
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 9 deletions.
6 changes: 6 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
rlyMde = !relay["rev"];
}

CJSON(serialBaud, hw[F("baud")]);
if (serialBaud < 96 || serialBaud > 15000) serialBaud = 1152;
updateBaudRate(serialBaud *100);

//int hw_status_pin = hw[F("status")]["pin"]; // -1

JsonObject light = doc[F("light")];
Expand Down Expand Up @@ -630,6 +634,8 @@ void serializeConfig() {
hw_relay["pin"] = rlyPin;
hw_relay["rev"] = !rlyMde;

hw[F("baud")] = serialBaud;

//JsonObject hw_status = hw.createNestedObject("status");
//hw_status["pin"] = -1;

Expand Down
16 changes: 15 additions & 1 deletion wled00/data/settings_sync.htm
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,21 @@ <h3>Philips Hue</h3>
<input name="H3" type="number" class="s" min="0" max="255" ><br>
<b>Press the pushlink button on the bridge, after that save this page!</b><br>
(when first connecting)<br>
Hue status: <span class="sip"> Disabled in this build </span><hr>
Hue status: <span class="sip"> Disabled in this build </span>
<h3>Serial</h3>
Baud rate:
<select name=BD>
<option value=1152>115200</option>
<option value=2304>230400</option>
<option value=4608>460800</option>
<option value=5000>500000</option>
<option value=5760>576000</option>
<option value=9216>921600</option>
<option value=10000>1000000</option>
<option value=15000>1500000</option>
</select><br>
<i>Keep at 115200 to use Improv. Some boards may not support high rates.</i>
<hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>
</body>
Expand Down
1 change: 1 addition & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void clearEEPROM();

//wled_serial.cpp
void handleSerial();
void updateBaudRate(uint32_t rate);

//wled_server.cpp
bool isIp(String str);
Expand Down
10 changes: 8 additions & 2 deletions wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,14 @@ class="s" min="0" max="255"> . <input name="H2" type="number" class="s" min="0"
max="255"> . <input name="H3" type="number" class="s" min="0" max="255"><br><b>
Press the pushlink button on the bridge, after that save this page!</b><br>
(when first connecting)<br>Hue status: <span class="sip">Disabled in this build
</span><hr><button type="button" onclick="B()">Back</button><button
type="submit">Save</button></form></body></html>)=====";
</span><h3>Serial</h3>Baud rate: <select name="BD"><option value="1152">115200
</option><option value="2304">230400</option><option value="4608">460800
</option><option value="5000">500000</option><option value="5760">576000
</option><option value="9216">921600</option><option value="10000">1000000
</option><option value="15000">1500000</option></select><br><i>
Keep at 115200 to use Improv. Some boards may not support high rates.</i><hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save
</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_time.htm, do not edit!!
Expand Down
4 changes: 4 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
hueStoreAllowed = true;
reconnectHue();
#endif

t = request->arg(F("BD")).toInt();
if (t >= 96 && t <= 15000) serialBaud = t;
updateBaudRate(serialBaud *100);
}

//TIME
Expand Down
10 changes: 6 additions & 4 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,13 @@ WLED_GLOBAL bool hueApplyBri _INIT(true);
WLED_GLOBAL bool hueApplyColor _INIT(true);
#endif

WLED_GLOBAL uint16_t serialBaud _INIT(1152); // serial baud rate, multiply by 100

// Time CONFIG
WLED_GLOBAL bool ntpEnabled _INIT(false); // get internet time. Only required if you use clock overlays or time-activated macros
WLED_GLOBAL bool useAMPM _INIT(false); // 12h/24h clock format
WLED_GLOBAL byte currentTimezone _INIT(0); // Timezone ID. Refer to timezones array in wled10_ntp.ino
WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC before timzone calculation
WLED_GLOBAL bool ntpEnabled _INIT(false); // get internet time. Only required if you use clock overlays or time-activated macros
WLED_GLOBAL bool useAMPM _INIT(false); // 12h/24h clock format
WLED_GLOBAL byte currentTimezone _INIT(0); // Timezone ID. Refer to timezones array in wled10_ntp.ino
WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC before timzone calculation

WLED_GLOBAL byte overlayDefault _INIT(0); // 0: no overlay 1: analog clock 2: single-digit clock 3: cronixie
WLED_GLOBAL byte overlayMin _INIT(0), overlayMax _INIT(DEFAULT_LED_COUNT - 1); // boundaries of overlay mode
Expand Down
4 changes: 2 additions & 2 deletions wled00/wled_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ enum class AdaState {

uint16_t currentBaud = 1152; //default baudrate 115200 (divided by 100)

void updateBaudRate(int rate){
void updateBaudRate(uint32_t rate){
uint16_t rate100 = rate/100;
if (rate100 == currentBaud) return;
if (rate100 == currentBaud || rate100 < 96) return;
currentBaud = rate100;

if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){
Expand Down
1 change: 1 addition & 0 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ void getSettingsJS(byte subPage, char* dest)

sappends('m',SET_F("(\"sip\")[0]"),hueErrorString);
#endif
sappend('v',SET_F("BD"),serialBaud);
}

if (subPage == 5)
Expand Down

0 comments on commit 00dbdc2

Please sign in to comment.