Skip to content

Commit ec5d0e3

Browse files
committed
[Cleanup] Move more plugin code to use FormSelectorOptions class
1 parent bcea8ef commit ec5d0e3

11 files changed

+90
-93
lines changed

src/_P168_VEML6030_7700.ino

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,8 @@ boolean Plugin_168(uint8_t function, struct EventStruct *event, String& string)
114114
VEML_LUX_CORRECTED_NOWAIT,
115115
};
116116
constexpr size_t optionCount = NR_ELEMENTS(readMethodOptions);
117-
addFormSelector(F("Lux Read-method"),
118-
F("rmth"),
119-
optionCount,
120-
readMethod,
121-
readMethodOptions,
122-
P168_READLUX_MODE);
117+
FormSelectorOptions selector(optionCount, readMethod, readMethodOptions);
118+
selector.addFormSelector(F("Lux Read-method"), F("rmth"), P168_READLUX_MODE);
123119
addFormNote(F("For 'Auto' Read-method, the Gain factor and Integration time settings are ignored."));
124120
}
125121
{
@@ -136,21 +132,17 @@ boolean Plugin_168(uint8_t function, struct EventStruct *event, String& string)
136132
0b11,
137133
};
138134
constexpr size_t optionCount = NR_ELEMENTS(alsGainOptions);
139-
addFormSelector(F("Gain factor"),
140-
F("gain"),
141-
optionCount,
142-
alsGain,
143-
alsGainOptions,
144-
P168_ALS_GAIN);
135+
FormSelectorOptions selector(optionCount, alsGain, alsGainOptions);
136+
selector.addFormSelector(F("Gain factor"), F("gain"), P168_ALS_GAIN);
145137
}
146138
{
147139
const __FlashStringHelper *alsIntegration[] = {
148-
F("25 ms"),
149-
F("50 ms"),
150-
F("100 ms"),
151-
F("200 ms"),
152-
F("400 ms"),
153-
F("800 ms"),
140+
F("25"),
141+
F("50"),
142+
F("100"),
143+
F("200"),
144+
F("400"),
145+
F("800"),
154146
};
155147
const int alsIntegrationOptions[] = {
156148
0b1100,
@@ -161,12 +153,9 @@ boolean Plugin_168(uint8_t function, struct EventStruct *event, String& string)
161153
0b0011,
162154
};
163155
constexpr size_t optionCount = NR_ELEMENTS(alsIntegrationOptions);
164-
addFormSelector(F("Integration time"),
165-
F("int"),
166-
optionCount,
167-
alsIntegration,
168-
alsIntegrationOptions,
169-
P168_ALS_INTEGRATION);
156+
FormSelectorOptions selector(optionCount, alsIntegration, alsIntegrationOptions);
157+
selector.addFormSelector(F("Integration time"), F("int"), P168_ALS_INTEGRATION);
158+
addUnit(F("ms"));
170159
}
171160
addFormSeparator(2);
172161
{
@@ -185,12 +174,8 @@ boolean Plugin_168(uint8_t function, struct EventStruct *event, String& string)
185174
static_cast<int>(P168_power_save_mode_e::Mode4),
186175
};
187176
constexpr size_t optionCount = NR_ELEMENTS(psmModeOptions);
188-
addFormSelector(F("Power Save Mode"),
189-
F("psm"),
190-
optionCount,
191-
psmMode,
192-
psmModeOptions,
193-
P168_PSM_MODE);
177+
FormSelectorOptions selector(optionCount, psmMode, psmModeOptions);
178+
selector.addFormSelector(F("Power Save Mode"), F("psm"), P168_PSM_MODE);
194179
}
195180

196181
success = true;

src/_P169_AS3935_LightningDetector.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,11 @@ boolean Plugin_169(uint8_t function, struct EventStruct *event, String& string)
127127
AS3935MI::AS3935_MNL_9,
128128
AS3935MI::AS3935_MNL_16 };
129129
constexpr size_t optionCount = NR_ELEMENTS(optionValues);
130-
addFormSelector(F("Lightning Threshold"),
131-
P169_LIGHTNING_THRESHOLD_LABEL,
132-
optionCount,
133-
options,
134-
optionValues,
135-
P169_LIGHTNING_THRESHOLD);
130+
FormSelectorOptions selector(optionCount, options, optionValues);
131+
selector.addFormSelector(
132+
F("Lightning Threshold"),
133+
P169_LIGHTNING_THRESHOLD_LABEL,
134+
P169_LIGHTNING_THRESHOLD);
136135
addFormNote(F("Minimum number of lightning strikes in the last 15 minutes"));
137136
}
138137
{
@@ -159,8 +158,9 @@ boolean Plugin_169(uint8_t function, struct EventStruct *event, String& string)
159158
18
160159
};
161160
constexpr size_t optionCount = NR_ELEMENTS(optionValues);
162-
addFormSelector(F("AFE Gain Min"), P169_AFE_GAIN_LOW_LABEL, optionCount, options, optionValues, P169_AFE_GAIN_LOW);
163-
addFormSelector(F("AFE Gain Max"), P169_AFE_GAIN_HIGH_LABEL, optionCount, options, optionValues, P169_AFE_GAIN_HIGH);
161+
FormSelectorOptions selector(optionCount, options, optionValues);
162+
selector.addFormSelector(F("AFE Gain Min"), P169_AFE_GAIN_LOW_LABEL, P169_AFE_GAIN_LOW);
163+
selector.addFormSelector(F("AFE Gain Max"), P169_AFE_GAIN_HIGH_LABEL, P169_AFE_GAIN_HIGH);
164164
addFormNote(F("Lower and upper limit for the Analog Frond-End auto gain to use."));
165165
}
166166

src/src/PluginStructs/P002_data_struct.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ void P002_data_struct::webformLoad(struct EventStruct *event)
154154
P002_ADC_0db
155155
};
156156
constexpr int nrOptions = NR_ELEMENTS(outputOptionValues);
157-
addFormSelector(F("Attenuation"), F("attn"), nrOptions, outputOptions, outputOptionValues, P002_ATTENUATION);
157+
FormSelectorOptions selector(nrOptions, outputOptions, outputOptionValues);
158+
selector.addFormSelector(F("Attenuation"), F("attn"), P002_ATTENUATION);
158159
}
159160

160161
# endif // ifdef ESP32
@@ -175,7 +176,8 @@ void P002_data_struct::webformLoad(struct EventStruct *event)
175176
# endif // ifndef LIMIT_BUILD_SIZE
176177
};
177178
constexpr int nrOptions = NR_ELEMENTS(outputOptionValues);
178-
addFormSelector(F("Oversampling"), F("oversampling"), nrOptions, outputOptions, outputOptionValues, P002_OVERSAMPLING);
179+
FormSelectorOptions selector(nrOptions, outputOptions, outputOptionValues);
180+
selector.addFormSelector(F("Oversampling"), F("oversampling"), P002_OVERSAMPLING);
179181
}
180182

181183
# ifdef ESP32

src/src/PluginStructs/P025_data_struct.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ bool P025_data_struct::webformLoad(struct EventStruct *event)
326326
};
327327

328328
constexpr size_t ADS1115_PGA_OPTIONS = NR_ELEMENTS(pgaOptions);
329-
addFormSelector(F("Gain"), F("gain"), ADS1115_PGA_OPTIONS, pgaOptions, nullptr, P025_GAIN);
329+
FormSelectorOptions selector(ADS1115_PGA_OPTIONS, pgaOptions);
330+
selector.addFormSelector(F("Gain"), F("gain"), P025_GAIN);
330331
addFormNote(F("Do not apply more than VDD + 0.3 V to the analog inputs of the device."));
331332
}
332333
{
@@ -341,8 +342,8 @@ bool P025_data_struct::webformLoad(struct EventStruct *event)
341342
F("860 / 3300"),
342343
};
343344
constexpr size_t NR_OPTIONS = NR_ELEMENTS(P025_SPSOptions);
344-
345-
addFormSelector(F("Sample Rate"), F("sps"), NR_OPTIONS, P025_SPSOptions, nullptr, p025_variousBits.getSampleRate());
345+
FormSelectorOptions selector(NR_OPTIONS, P025_SPSOptions);
346+
selector.addFormSelector(F("Sample Rate"), F("sps"), p025_variousBits.getSampleRate());
346347
addUnit(F("SPS"));
347348
addFormNote(F("Lower values for ADS1115, higher values for ADS1015"));
348349

src/src/PluginStructs/P073_data_struct.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ void P073_display_output_selector(const __FlashStringHelper *id, int16_t value)
115115
P073_DISP_CLOCK12,
116116
P073_DISP_DATE,
117117
};
118-
119-
addFormSelector(F("Display Output"), id, NR_ELEMENTS(disploutOptions), displout, disploutOptions, value);
118+
FormSelectorOptions selector(NR_ELEMENTS(disploutOptions), displout, disploutOptions);
119+
selector.addFormSelector(F("Display Output"), id, value);
120120
}
121121

122122
# ifdef P073_EXTRA_FONTS
@@ -127,8 +127,8 @@ void P073_font_selector(const __FlashStringHelper *id, int16_t value) {
127127
F("Siekoo with uppercase 'CHNORUX'"),
128128
F("dSEG7"),
129129
};
130-
131-
addFormSelector(F("Font set"), id, NR_ELEMENTS(fontset), fontset, nullptr, value);
130+
FormSelectorOptions selector(NR_ELEMENTS(fontset), fontset);
131+
selector.addFormSelector(F("Font set"), id, value);
132132
addFormNote(F("Check documentation for examples of the font sets."));
133133
}
134134

src/src/PluginStructs/P104_data_struct.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,12 +1890,11 @@ bool P104_data_struct::webform_load(struct EventStruct *event) {
18901890
static_cast<int>(MD_MAX72XX::moduleType_t::DR0CR1RR1_HW),
18911891
static_cast<int>(MD_MAX72XX::moduleType_t::DR1CR0RR1_HW)
18921892
};
1893-
addFormSelector(F("Hardware type"),
1894-
F("hardware"),
1895-
P104_hardwareTypeCount,
1896-
hardwareTypes,
1897-
hardwareOptions,
1898-
P104_CONFIG_HARDWARETYPE);
1893+
FormSelectorOptions selector(
1894+
P104_hardwareTypeCount,
1895+
hardwareTypes,
1896+
hardwareOptions);
1897+
selector.addFormSelector(F("Hardware type"), F("hardware"), P104_CONFIG_HARDWARETYPE);
18991898
# ifdef P104_ADD_SETTINGS_NOTES
19001899
addFormNote(F("DR = Digits as Rows, CR = Column Reversed, RR = Row Reversed; 0 = no, 1 = yes."));
19011900
# endif // ifdef P104_ADD_SETTINGS_NOTES
@@ -1929,10 +1928,9 @@ bool P104_data_struct::webform_load(struct EventStruct *event) {
19291928
P104_DATE_FORMAT_US,
19301929
P104_DATE_FORMAT_JP
19311930
};
1932-
addFormSelector(F("Date format"), F("datefmt"),
1933-
3,
1934-
dateFormats, dateFormatOptions,
1935-
get4BitFromUL(P104_CONFIG_DATETIME, P104_CONFIG_DATETIME_FORMAT));
1931+
FormSelectorOptions selector(3, dateFormats, dateFormatOptions);
1932+
selector.addFormSelector(F("Date format"), F("datefmt"),
1933+
get4BitFromUL(P104_CONFIG_DATETIME, P104_CONFIG_DATETIME_FORMAT));
19361934
}
19371935
{ // Date separator
19381936
const __FlashStringHelper *dateSeparators[] = {
@@ -1947,10 +1945,9 @@ bool P104_data_struct::webform_load(struct EventStruct *event) {
19471945
P104_DATE_SEPARATOR_DASH,
19481946
P104_DATE_SEPARATOR_DOT
19491947
};
1950-
addFormSelector(F("Date separator"), F("datesep"),
1951-
4,
1952-
dateSeparators, dateSeparatorOptions,
1953-
get4BitFromUL(P104_CONFIG_DATETIME, P104_CONFIG_DATETIME_SEP_CHAR));
1948+
FormSelectorOptions selector(4, dateSeparators, dateSeparatorOptions);
1949+
selector.addFormSelector(F("Date separator"), F("datesep"),
1950+
get4BitFromUL(P104_CONFIG_DATETIME, P104_CONFIG_DATETIME_SEP_CHAR));
19541951

19551952
addFormCheckBox(F("Year uses 4 digits"), F("year4dgt"), bitRead(P104_CONFIG_DATETIME, P104_CONFIG_DATETIME_YEAR4DGT));
19561953
}
@@ -1974,24 +1971,27 @@ bool P104_data_struct::webform_load(struct EventStruct *event) {
19741971
# endif // ifdef P104_USE_ZONE_ORDERING
19751972
" will save and reload the page.");
19761973
# endif // if defined(P104_USE_TOOLTIPS) || defined(P104_ADD_SETTINGS_NOTES)
1977-
addFormSelector(F("Zones"), F("zonecnt"), P104_MAX_ZONES, zonesList, zonesOptions, nullptr, P104_CONFIG_ZONE_COUNT, true
1978-
# ifdef P104_USE_TOOLTIPS
1979-
, zonetip
1980-
# endif // ifdef P104_USE_TOOLTIPS
1981-
);
1974+
1975+
FormSelectorOptions selector(P104_MAX_ZONES, zonesList, zonesOptions);
1976+
selector.reloadonchange = true;
1977+
# ifdef P104_USE_TOOLTIPS
1978+
selector.tooltip = zonetip;
1979+
#endif
1980+
selector.addFormSelector(F("Zones"), F("zonecnt"), P104_CONFIG_ZONE_COUNT);
19821981

19831982
# ifdef P104_USE_ZONE_ORDERING
19841983
const String orderTypes[] = {
19851984
F("Numeric order (1..n)"),
19861985
F("Display order (n..1)")
19871986
};
19881987
const int orderOptions[] = { 0, 1 };
1989-
addFormSelector(F("Zone order"), F("zoneorder"), 2, orderTypes, orderOptions, nullptr,
1990-
bitRead(P104_CONFIG_FLAGS, P104_CONFIG_FLAG_ZONE_ORDER) ? 1 : 0, true
1991-
# ifdef P104_USE_TOOLTIPS
1992-
, zonetip
1993-
# endif // ifdef P104_USE_TOOLTIPS
1994-
);
1988+
FormSelectorOptions selector_zoneordering(2, orderTypes, orderOptions);
1989+
selector.reloadonchange = true;
1990+
# ifdef P104_USE_TOOLTIPS
1991+
selector.tooltip = zonetip;
1992+
#endif
1993+
selector_zoneordering.addFormSelector(F("Zone order"), F("zoneorder"),
1994+
bitRead(P104_CONFIG_FLAGS, P104_CONFIG_FLAG_ZONE_ORDER) ? 1 : 0);
19951995
# endif // ifdef P104_USE_ZONE_ORDERING
19961996
# ifdef P104_ADD_SETTINGS_NOTES
19971997
addFormNote(zonetip);

src/src/PluginStructs/P120_data_struct.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ bool P120_data_struct::plugin_webform_loadOutputSelector(struct EventStruct *eve
519519
const int values[] = { 0,
520520
1 };
521521
const int choice = bitRead(P120_CONFIG_FLAGS1, P120_FLAGS1_ANGLE_IN_RAD);
522-
addFormSelector(F("Angle Units"), F("angle_rad"), 2, options, values, choice);
522+
FormSelectorOptions selector(2, options, values);
523+
selector.addFormSelector(F("Angle Units"), F("angle_rad"), choice);
523524
}
524525
return true;
525526
}
@@ -533,8 +534,9 @@ bool P120_data_struct::plugin_webform_load(struct EventStruct *event) {
533534
F("8g"),
534535
F("16g (default)") };
535536
int rangeValues[] = { P120_RANGE_2G, P120_RANGE_4G, P120_RANGE_8G, P120_RANGE_16G };
536-
addFormSelector(F("Range"), F("range"), 4, rangeOptions, rangeValues,
537-
get2BitFromUL(P120_CONFIG_FLAGS1, P120_FLAGS1_RANGE));
537+
FormSelectorOptions selector(4, rangeOptions, rangeValues);
538+
selector.addFormSelector(F("Range"), F("range"),
539+
get2BitFromUL(P120_CONFIG_FLAGS1, P120_FLAGS1_RANGE));
538540
}
539541

540542
// Axis selection
@@ -627,7 +629,8 @@ bool P120_data_struct::plugin_webform_load(struct EventStruct *event) {
627629
F("10"),
628630
F("50") };
629631
int frequencyValues[] = { P120_FREQUENCY_10, P120_FREQUENCY_50 };
630-
addFormSelector(F("Measuring frequency"), F("frequency"), 2, frequencyOptions, frequencyValues, P120_FREQUENCY);
632+
FormSelectorOptions selector( 2, frequencyOptions, frequencyValues);
633+
selector.addFormSelector(F("Measuring frequency"), F("frequency"), P120_FREQUENCY);
631634
addUnit(F("Hz"));
632635
addFormNote(F("Values X/Y/Z are updated 1x per second, Controller updates &amp; Value-events are based on 'Interval' setting."));
633636
}

src/src/PluginStructs/P148_data_struct.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ void P148_data_struct::MonitorTaskValue_t::webformLoad(int index) const {
158158
static_cast<int>(P148_data_struct::Tm1621UnitOfMeasure::kWh_Watt)
159159
};
160160
constexpr size_t nrElements = sizeof(optionValues) / sizeof(optionValues[0]);
161-
162-
addFormSelector(
161+
FormSelectorOptions selector(nrElements, options, optionValues);
162+
selector.addFormSelector(
163163
F("Unit Symbols"), concat(F("punit"), index),
164-
nrElements, options, optionValues, static_cast<int>(unit));
164+
static_cast<int>(unit));
165165
} else {
166166
const __FlashStringHelper *options[] = {
167167
F("None"),
@@ -177,9 +177,10 @@ void P148_data_struct::MonitorTaskValue_t::webformLoad(int index) const {
177177
};
178178
constexpr size_t nrElements = sizeof(optionValues) / sizeof(optionValues[0]);
179179

180-
addFormSelector(
180+
FormSelectorOptions selector(nrElements, options, optionValues);
181+
selector.addFormSelector(
181182
F("Unit Symbols"), concat(F("punit"), index),
182-
nrElements, options, optionValues, static_cast<int>(unit));
183+
static_cast<int>(unit));
183184
}
184185
} else {
185186
addFormCheckBox(F("Clear Line"), concat(F("pshowname"), index), showname);

src/src/PluginStructs/P165_data_struct.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ bool P165_data_struct::plugin_webform_load(struct EventStruct *event) {
201201
{
202202
const __FlashStringHelper *stripOptions[] = { F("GRB"), F("GRBW") };
203203
const int stripOptionValues[] = { P165_STRIP_TYPE_RGB, P165_STRIP_TYPE_RGBW };
204-
addFormSelector(F("Strip Type"), F("stripe"), NR_ELEMENTS(stripOptionValues), stripOptions, stripOptionValues, P165_CONFIG_STRIP_TYPE);
204+
FormSelectorOptions selector(NR_ELEMENTS(stripOptionValues), stripOptions, stripOptionValues);
205+
selector.addFormSelector(F("Strip Type"), F("stripe"), P165_CONFIG_STRIP_TYPE);
205206
}
206207

207208
if ((0 == P165_CONFIG_DEF_BRIGHT) && (0 == P165_CONFIG_MAX_BRIGHT)) {
@@ -234,8 +235,8 @@ bool P165_data_struct::plugin_webform_load(struct EventStruct *event) {
234235
P165_DISP_CLOCK12,
235236
P165_DISP_DATE,
236237
};
237-
addFormSelector(F("Display Output"), F("dspout"), NR_ELEMENTS(disploutOptions),
238-
displout, disploutOptions, P165_CONFIG_OUTPUTTYPE);
238+
FormSelectorOptions selector(NR_ELEMENTS(disploutOptions), displout, disploutOptions);
239+
addFormSelector(F("Display Output"), F("dspout"), P165_CONFIG_OUTPUTTYPE);
239240
# endif // if P165_FEATURE_P073
240241

241242
int dgtCount = 0;
@@ -283,13 +284,12 @@ bool P165_data_struct::plugin_webform_load(struct EventStruct *event) {
283284
? EMPTY_STRING
284285
: AdaGFXrgb565ToWebColor(P165_CONFIG_FG_COLOR);
285286

286-
addFormSelector(F("Number of Groups *"),
287-
F("grps"),
288-
NR_ELEMENTS(digitOptionValues),
289-
digitOptions,
290-
digitOptionValues,
291-
grpCount,
292-
true);
287+
FormSelectorOptions selector(
288+
NR_ELEMENTS(digitOptionValues),
289+
digitOptions,
290+
digitOptionValues);
291+
selector.reloadonchange = true;
292+
selector.addFormSelector(F("Number of Groups *"), F("grps"), grpCount);
293293

294294
AdaGFXFormForeAndBackColors(F("fgcolor"),
295295
P165_CONFIG_FG_COLOR,

src/src/WebServer/Markup_Forms.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ void addFormSeparatorCharInput(const __FlashStringHelper *rowLabel,
427427
charList[i + 1] = charset[i];
428428
charOpts[i + 1] = static_cast<int>(charset[i]);
429429
}
430-
addFormSelector(rowLabel, id, len, charList, charOpts, value);
430+
FormSelectorOptions selector(len, charList, charOpts);
431+
selector.addFormSelector(rowLabel, id, value);
431432

432433
if (!String(additionalText).isEmpty()) {
433434
addUnit(additionalText);
@@ -506,6 +507,7 @@ void addFormSelectorI2C(const String& id,
506507
addSelector_Foot();
507508
}
508509

510+
/*
509511
void addFormSelector(const __FlashStringHelper * label,
510512
const __FlashStringHelper * id,
511513
int optionCount,
@@ -620,6 +622,7 @@ void addFormSelector(const String & label,
620622
#endif
621623
selector.addFormSelector(label, id, selectedIndex);
622624
}
625+
*/
623626

624627
void addFormSelector_YesNo(const __FlashStringHelper * label,
625628
const __FlashStringHelper * id,

0 commit comments

Comments
 (0)