mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +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' }}
|
sx={{ width: '30ch' }}
|
||||||
type={deviceValue.u ? 'number' : 'text'}
|
type={deviceValue.u ? 'number' : 'text'}
|
||||||
onChange={updateValue(setDeviceValue)}
|
onChange={updateValue(setDeviceValue)}
|
||||||
|
inputProps={{ step: deviceValue.s }}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: <InputAdornment position="start">{DeviceValueUOM_s[deviceValue.u]}</InputAdornment>
|
startAdornment: <InputAdornment position="start">{DeviceValueUOM_s[deviceValue.u]}</InputAdornment>
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ export interface DeviceValue {
|
|||||||
c: string; // command
|
c: string; // command
|
||||||
l: string[]; // list
|
l: string[]; // list
|
||||||
h?: string; // help text
|
h?: string; // help text
|
||||||
|
s?: string; // steps for up/down
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeviceData {
|
export interface DeviceData {
|
||||||
|
|||||||
@@ -731,15 +731,26 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
|||||||
l.add(read_flash_string(dv.options[i]));
|
l.add(read_flash_string(dv.options[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (dv.type == DeviceValueType::BOOL) {
|
||||||
if (dv.type == DeviceValueType::BOOL) {
|
|
||||||
JsonArray l = obj.createNestedArray("l");
|
JsonArray l = obj.createNestedArray("l");
|
||||||
l.add("off");
|
l.add("off");
|
||||||
l.add("on");
|
l.add("on");
|
||||||
}
|
}
|
||||||
// add command help template
|
// 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) {
|
||||||
obj["h"] = dv.options[0];
|
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