Skip to content

Commit b139aaa

Browse files
authored
Merge pull request #211 from LeeLeahy2/wifi-profile
WiFi Config: Enable modification of profileName and profileNumber
2 parents 3ce6f75 + 3a45d8c commit b139aaa

File tree

5 files changed

+101
-14
lines changed

5 files changed

+101
-14
lines changed

Firmware/RTK_Surveyor/AP-Config/index.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,39 @@ <h2>
8787
<div align="center" class="small">
8888
<span id="rtkFirmwareVersion" style="display:inline;">RTK Firmware: v0.0</span> <br>
8989
<span id="zedFirmwareVersion" style="display:inline;">ZED-F9P Firmware: v0.0</span> <br>
90-
<span id="profileName" style="display:inline;">Profile Name: Default</span>
9190
</div>
9291
</div>
9392

9493
<hr class="mt-0">
9594
<div style="margin-top:20px;">
95+
96+
<!-- --------- Profile Config --------- -->
97+
<div class="d-grid gap-2">
98+
<button class="btn btn-primary mt-3 toggle-btn" id="profileConfig" type="button" data-toggle="collapse"
99+
data-target="#collapseProfileConfig" aria-expanded="false" aria-controls="collapseProfileConfig">
100+
Profile Configuration <i id="profileCaret" class="caret-icon bi icon-caret-down"></i>
101+
</button>
102+
</div>
103+
<div class="collapse mb-2" id="collapseProfileConfig">
104+
<div class="card card-body">
105+
<div class="form-group row">
106+
<label for="profileNumber" class="box-margin20 col-sm-3 col-4 col-form-label">Profile Number</label>
107+
<div class="col-sm-8 col-7">
108+
<input type="number" class="form-control mb-2" id="profileNumber">
109+
<p id="profileNumberError" class="inlineError"></p>
110+
</div>
111+
</div>
112+
113+
<div class="form-group row">
114+
<label for="profileName" class="box-margin20 col-sm-3 col-4 col-form-label">Profile Name</label>
115+
<div class="col-sm-8 col-7">
116+
<input type="text" class="form-control" id="profileName">
117+
<p id="profileNameError" class="inlineError"></p>
118+
</div>
119+
</div>
120+
</div>
121+
</div>
122+
96123
<!-- --------- GNSS Config --------- -->
97124
<div class="d-grid gap-2">
98125
<button class="btn btn-primary toggle-btn" type="button" data-toggle="collapse"

Firmware/RTK_Surveyor/AP-Config/src/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ function parseIncoming(msg) {
8282
|| id.includes("sdUsedSpace")
8383
|| id.includes("rtkFirmwareVersion")
8484
|| id.includes("zedFirmwareVersion")
85-
|| id.includes("profileName")
8685
|| id.includes("hardwareID")
8786
|| id.includes("daysRemaining")
8887
) {
@@ -123,6 +122,8 @@ function parseIncoming(msg) {
123122
//console.log("Settings loaded");
124123

125124
//Force element updates
125+
ge("profileNumber").dispatchEvent(new CustomEvent('change'));
126+
ge("profileName").dispatchEvent(new CustomEvent('change'));
126127
ge("measurementRateHz").dispatchEvent(new CustomEvent('change'));
127128
ge("baseTypeSurveyIn").dispatchEvent(new CustomEvent('change'));
128129
ge("baseTypeFixed").dispatchEvent(new CustomEvent('change'));
@@ -195,6 +196,7 @@ function collapseSection(section, caret) {
195196

196197
function validateFields() {
197198
//Collapse all sections
199+
collapseSection("collapseProfileConfig", "profileCaret");
198200
collapseSection("collapseGNSSConfig", "gnssCaret");
199201
collapseSection("collapseGNSSConfigMsg", "gnssMsgCaret");
200202
collapseSection("collapseBaseConfig", "baseCaret");
@@ -205,6 +207,10 @@ function validateFields() {
205207

206208
errorCount = 0;
207209

210+
//Profile Config
211+
checkElementValue("profileNumber", 1, 4, "Must be between 1 and 4", "collapseProfileConfig");
212+
checkElementString("profileName", 1, 49, "Must be 1 to 49 characters", "collapseProfileConfig");
213+
208214
//GNSS Config
209215
checkElementValue("measurementRateHz", 0.00012, 10, "Must be between 0.00012 and 10Hz", "collapseGNSSConfig");
210216
checkConstellations();

Firmware/RTK_Surveyor/Form.ino

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,8 @@ void createSettingsString(char* settingsCSV)
405405
stringRecord(settingsCSV, "enableExternalHardwareEventLogging", settings.enableExternalHardwareEventLogging);
406406

407407
//Profiles
408-
char apProfileName[50];
409-
sprintf(apProfileName, "Profile Name: %s", settings.profileName);
410-
stringRecord(settingsCSV, "profileName", apProfileName);
408+
stringRecord(settingsCSV, "profileNumber", profileNumber + 1);
409+
stringRecord(settingsCSV, "profileName", profileNames[profileNumber]);
411410

412411
//New settings not yet integrated
413412
//...
@@ -423,6 +422,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
423422
{
424423
#ifdef COMPILE_AP
425424
char* ptr;
425+
int newProfileNumber;
426426
double settingValue = strtod(settingValueStr, &ptr);
427427

428428
bool settingValueBool = false;
@@ -486,7 +486,23 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
486486
else if (strcmp(settingName, "enableExternalHardwareEventLogging") == 0)
487487
settings.enableExternalHardwareEventLogging = settingValueBool;
488488
else if (strcmp(settingName, "profileName") == 0)
489+
{
489490
strcpy(settings.profileName, settingValueStr);
491+
strcpy(profileNames[profileNumber], settingValueStr);
492+
}
493+
else if (strcmp(settingName, "profileNumber") == 0)
494+
{
495+
if ((sscanf(settingValueStr, "%d", &newProfileNumber) == 1)
496+
&& (newProfileNumber >= 1) && (newProfileNumber <= MAX_PROFILE_COUNT)
497+
&& (profileNumber != newProfileNumber))
498+
{
499+
profileNumber = newProfileNumber - 1;
500+
501+
//Switch to a new profile
502+
setSettingsFileName();
503+
recordProfileNumber(profileNumber);
504+
}
505+
}
490506

491507
else if (strcmp(settingName, "enableNtripServer") == 0)
492508
settings.enableNtripServer = settingValueBool;

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ void loadSettings()
3535
Serial.printf("Profile '%s' loaded\n\r", profileNames[profileNumber]);
3636
}
3737

38+
//Set the settingsFileName used many places
39+
void setSettingsFileName()
40+
{
41+
sprintf(settingsFileName, "/%s_Settings_%d.txt", platformFilePrefix, profileNumber);
42+
}
43+
3844
//Load only LFS settings without recording
3945
//Used at very first boot to test for resetCounter
4046
void loadSettingsPartial()
@@ -43,7 +49,7 @@ void loadSettingsPartial()
4349
loadProfileNumber();
4450

4551
//Set the settingsFileName used many places
46-
sprintf(settingsFileName, "/%s_Settings_%d.txt", platformFilePrefix, profileNumber);
52+
setSettingsFileName();
4753

4854
loadSystemSettingsFromFileLFS(settingsFileName, &settings);
4955
}
@@ -911,9 +917,8 @@ void loadProfileNumber()
911917
if (!fileProfileNumber)
912918
{
913919
log_d("profileNumber.txt not found");
914-
profileNumber = 0;
915920
settings.updateZEDSettings = true; //Force module update
916-
recordProfileNumber(profileNumber); //Record profile
921+
recordProfileNumber(0); //Record profile
917922
}
918923
else
919924
{
@@ -925,24 +930,24 @@ void loadProfileNumber()
925930
if (profileNumber >= MAX_PROFILE_COUNT)
926931
{
927932
log_d("ProfileNumber invalid. Going to zero.");
928-
profileNumber = 0;
929933
settings.updateZEDSettings = true; //Force module update
930-
recordProfileNumber(profileNumber); //Record profile
934+
recordProfileNumber(0); //Record profile
931935
}
932936

933937
log_d("Using profile #%d", profileNumber);
934938
}
935939

936940
//Record the given profile number as well as a config bool
937-
void recordProfileNumber(uint8_t profileNumber)
941+
void recordProfileNumber(uint8_t newProfileNumber)
938942
{
943+
profileNumber = newProfileNumber;
939944
File fileProfileNumber = LittleFS.open("/profileNumber.txt", FILE_WRITE);
940945
if (!fileProfileNumber)
941946
{
942947
log_d("profileNumber.txt failed to open");
943948
return;
944949
}
945-
fileProfileNumber.write(profileNumber);
950+
fileProfileNumber.write(newProfileNumber);
946951
fileProfileNumber.close();
947952
}
948953

Firmware/RTK_Surveyor/form.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ function parseIncoming(msg) {
105105
|| id.includes("sdUsedSpace")
106106
|| id.includes("rtkFirmwareVersion")
107107
|| id.includes("zedFirmwareVersion")
108-
|| id.includes("profileName")
109108
|| id.includes("hardwareID")
110109
|| id.includes("daysRemaining")
111110
) {
@@ -146,6 +145,8 @@ function parseIncoming(msg) {
146145
//console.log("Settings loaded");
147146

148147
//Force element updates
148+
ge("profileNumber").dispatchEvent(new CustomEvent('change'));
149+
ge("profileName").dispatchEvent(new CustomEvent('change'));
149150
ge("measurementRateHz").dispatchEvent(new CustomEvent('change'));
150151
ge("baseTypeSurveyIn").dispatchEvent(new CustomEvent('change'));
151152
ge("baseTypeFixed").dispatchEvent(new CustomEvent('change'));
@@ -218,6 +219,7 @@ function collapseSection(section, caret) {
218219

219220
function validateFields() {
220221
//Collapse all sections
222+
collapseSection("collapseProfileConfig", "profileCaret");
221223
collapseSection("collapseGNSSConfig", "gnssCaret");
222224
collapseSection("collapseGNSSConfigMsg", "gnssMsgCaret");
223225
collapseSection("collapseBaseConfig", "baseCaret");
@@ -228,6 +230,10 @@ function validateFields() {
228230

229231
errorCount = 0;
230232

233+
//Profile Config
234+
checkElementValue("profileNumber", 1, 4, "Must be between 1 and 4", "collapseProfileConfig");
235+
checkElementString("profileName", 1, 49, "Must be 1 to 49 characters", "collapseProfileConfig");
236+
231237
//GNSS Config
232238
checkElementValue("measurementRateHz", 0.00012, 10, "Must be between 0.00012 and 10Hz", "collapseGNSSConfig");
233239
checkConstellations();
@@ -860,12 +866,39 @@ static const char *index_html = R"=====(
860866
<div align="center" class="small">
861867
<span id="rtkFirmwareVersion" style="display:inline;">RTK Firmware: v0.0</span> <br>
862868
<span id="zedFirmwareVersion" style="display:inline;">ZED-F9P Firmware: v0.0</span> <br>
863-
<span id="profileName" style="display:inline;">Profile Name: Default</span>
864869
</div>
865870
</div>
866871

867872
<hr class="mt-0">
868873
<div style="margin-top:20px;">
874+
875+
<!-- --------- Profile Config --------- -->
876+
<div class="d-grid gap-2">
877+
<button class="btn btn-primary mt-3 toggle-btn" id="profileConfig" type="button" data-toggle="collapse"
878+
data-target="#collapseProfileConfig" aria-expanded="false" aria-controls="collapseProfileConfig">
879+
Profile Configuration <i id="profileCaret" class="caret-icon bi icon-caret-down"></i>
880+
</button>
881+
</div>
882+
<div class="collapse mb-2" id="collapseProfileConfig">
883+
<div class="card card-body">
884+
<div class="form-group row">
885+
<label for="profileNumber" class="box-margin20 col-sm-3 col-4 col-form-label">Profile Number</label>
886+
<div class="col-sm-8 col-7">
887+
<input type="number" class="form-control mb-2" id="profileNumber">
888+
<p id="profileNumberError" class="inlineError"></p>
889+
</div>
890+
</div>
891+
892+
<div class="form-group row">
893+
<label for="profileName" class="box-margin20 col-sm-3 col-4 col-form-label">Profile Name</label>
894+
<div class="col-sm-8 col-7">
895+
<input type="text" class="form-control" id="profileName">
896+
<p id="profileNameError" class="inlineError"></p>
897+
</div>
898+
</div>
899+
</div>
900+
</div>
901+
869902
<!-- --------- GNSS Config --------- -->
870903
<div class="d-grid gap-2">
871904
<button class="btn btn-primary toggle-btn" type="button" data-toggle="collapse"

0 commit comments

Comments
 (0)