mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
add steps to web input of numbers, #329
This commit is contained in:
@@ -244,6 +244,7 @@ const DashboardData: FC = () => {
|
||||
sx={{ width: '30ch' }}
|
||||
type={deviceValue.u ? 'number' : 'text'}
|
||||
onChange={updateValue(setDeviceValue)}
|
||||
inputProps={{ step: deviceValue.s }}
|
||||
InputProps={{
|
||||
startAdornment: <InputAdornment position="start">{DeviceValueUOM_s[deviceValue.u]}</InputAdornment>
|
||||
}}
|
||||
|
||||
@@ -132,6 +132,7 @@ export interface DeviceValue {
|
||||
c: string; // command
|
||||
l: string[]; // list
|
||||
h?: string; // help text
|
||||
s?: string; // steps for up/down
|
||||
}
|
||||
|
||||
export interface DeviceData {
|
||||
|
||||
@@ -731,17 +731,28 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
||||
l.add(read_flash_string(dv.options[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dv.type == DeviceValueType::BOOL) {
|
||||
} else if (dv.type == DeviceValueType::BOOL) {
|
||||
JsonArray l = obj.createNestedArray("l");
|
||||
l.add("off");
|
||||
l.add("on");
|
||||
}
|
||||
// add command help template
|
||||
if ((dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) && dv.options_size == 1) {
|
||||
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
|
||||
if (dv.options_size == 1) {
|
||||
obj["h"] = dv.options[0];
|
||||
}
|
||||
}
|
||||
// add steps to numeric values with divider/multiplier
|
||||
else {
|
||||
int8_t divider = (dv.options_size == 1) ? Helpers::atoint(read_flash_string(dv.options[0]).c_str()) : 0;
|
||||
char s[10];
|
||||
if (divider > 0) {
|
||||
obj["s"] = Helpers::render_value(s, (float)1 / divider, 1);
|
||||
} else if (divider < 0) {
|
||||
obj["s"] = Helpers::render_value(s, (-1) * divider, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user