From 6561bb5a6cc41d642f77b14cc57f1eb418f0aebd Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 31 Oct 2022 11:11:09 +0100 Subject: [PATCH] add min/max to customization table #686 --- .../src/project/SettingsCustomization.tsx | 20 +++++++++++++++++-- src/emsdevice.cpp | 13 ++++++------ src/emsdevicevalue.cpp | 16 +++++++-------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/interface/src/project/SettingsCustomization.tsx b/interface/src/project/SettingsCustomization.tsx index 562c9faad..850054ad3 100644 --- a/interface/src/project/SettingsCustomization.tsx +++ b/interface/src/project/SettingsCustomization.tsx @@ -66,7 +66,7 @@ const SettingsCustomization: FC = () => { const entities_theme = useTheme({ Table: ` - --data-table-library_grid-template-columns: 120px repeat(1, minmax(0, 1fr)) 120px; + --data-table-library_grid-template-columns: 120px repeat(1, minmax(80px, 1fr)) 40px 40px 120px; `, BaseRow: ` font-size: 14px; @@ -75,6 +75,12 @@ const SettingsCustomization: FC = () => { } `, BaseCell: ` + &:nth-of-type(3) { + text-align: right; + } + &:nth-of-type(4) { + text-align: right; + } &:last-of-type { text-align: right; } @@ -122,6 +128,12 @@ const SettingsCustomization: FC = () => { &:nth-of-type(2) { padding: 8px; } + &:nth-of-type(3) { + padding-right: 4px; + } + &:nth-of-type(4) { + padding-right: 4px; + } &:last-of-type { padding-right: 8px; } @@ -446,6 +458,8 @@ const SettingsCustomization: FC = () => { {LL.NAME()} + min + max {LL.VALUE(0)} @@ -497,6 +511,8 @@ const SettingsCustomization: FC = () => { {formatName(de)} + {!(de.m & DeviceEntityMask.DV_READONLY) && (formatValue(de.mi))} + {!(de.m & DeviceEntityMask.DV_READONLY) && (formatValue(de.ma))} {formatValue(de.v)} ))} @@ -626,7 +642,7 @@ const SettingsCustomization: FC = () => { onChange={updateValue(setDeviceEntity)} /> - {typeof de.v === 'number' && de.w && ( + {typeof de.v === 'number' && de.w && !(de.m & DeviceEntityMask.DV_READONLY) && ( <> > 4; // send back the mask state. We're only interested in the high nibble obj["w"] = dv.has_cmd; // if writable - if (dv.has_cmd) { - // set the custom min and max values if there are any + if (dv.has_cmd && (obj["v"].is() || obj["v"].is())) { + // set the min and max values if there are any and if entity has a value int16_t dv_set_min; uint16_t dv_set_max; - if (dv.get_custom_min(dv_set_min)) { - obj["mi"] = fahrenheit ? (int)(dv_set_min * 1.8 + 32 * (fahrenheit - 1)) : dv_set_min; - } - if (dv.get_custom_max(dv_set_max)) { - obj["ma"] = fahrenheit ? (int)(dv_set_max * 1.8 + 32 * (fahrenheit - 1)) : dv_set_max; + if (dv.get_min_max(dv_set_min, dv_set_max)) { + char s[10]; + obj["mi"] = Helpers::render_value(s, dv_set_min, 0, fahrenheit); + obj["ma"] = Helpers::render_value(s, dv_set_max, 0, fahrenheit); } } } diff --git a/src/emsdevicevalue.cpp b/src/emsdevicevalue.cpp index dd15a653b..9fedd8c7a 100644 --- a/src/emsdevicevalue.cpp +++ b/src/emsdevicevalue.cpp @@ -287,13 +287,13 @@ bool DeviceValue::get_min_max(int16_t & dv_set_min, uint16_t & dv_set_max) { if (type == DeviceValueType::USHORT) { dv_set_min = Helpers::transformNumFloat(0, numeric_operator, fahrenheit); - dv_set_max = Helpers::transformNumFloat(EMS_VALUE_USHORT_NOTSET, numeric_operator, fahrenheit); + dv_set_max = Helpers::transformNumFloat(EMS_VALUE_USHORT_NOTSET - 1, numeric_operator, fahrenheit); return true; } if (type == DeviceValueType::SHORT) { - dv_set_min = Helpers::transformNumFloat(-EMS_VALUE_SHORT_NOTSET, numeric_operator, fahrenheit); - dv_set_max = Helpers::transformNumFloat(EMS_VALUE_SHORT_NOTSET, numeric_operator, fahrenheit); + dv_set_min = Helpers::transformNumFloat(-EMS_VALUE_SHORT_NOTSET + 1, numeric_operator, fahrenheit); + dv_set_max = Helpers::transformNumFloat(EMS_VALUE_SHORT_NOTSET - 1, numeric_operator, fahrenheit); return true; } @@ -301,7 +301,7 @@ bool DeviceValue::get_min_max(int16_t & dv_set_min, uint16_t & dv_set_max) { if (uom == DeviceValueUOM::PERCENT) { dv_set_max = 100; } else { - dv_set_max = Helpers::transformNumFloat(EMS_VALUE_UINT_NOTSET, numeric_operator, fahrenheit); + dv_set_max = Helpers::transformNumFloat(EMS_VALUE_UINT_NOTSET - 1, numeric_operator, fahrenheit); } return true; } @@ -311,19 +311,19 @@ bool DeviceValue::get_min_max(int16_t & dv_set_min, uint16_t & dv_set_max) { dv_set_min = -100; dv_set_max = 100; } else { - dv_set_min = Helpers::transformNumFloat(-EMS_VALUE_INT_NOTSET, numeric_operator, fahrenheit); - dv_set_max = Helpers::transformNumFloat(EMS_VALUE_INT_NOTSET, numeric_operator, fahrenheit); + dv_set_min = Helpers::transformNumFloat(-EMS_VALUE_INT_NOTSET + 1, numeric_operator, fahrenheit); + dv_set_max = Helpers::transformNumFloat(EMS_VALUE_INT_NOTSET - 1, numeric_operator, fahrenheit); } return true; } if (type == DeviceValueType::ULONG) { - dv_set_max = Helpers::transformNumFloat(EMS_VALUE_ULONG_NOTSET, numeric_operator); + dv_set_max = Helpers::transformNumFloat(EMS_VALUE_ULONG_NOTSET - 1, numeric_operator); return true; } if (type == DeviceValueType::TIME) { - dv_set_max = Helpers::transformNumFloat(EMS_VALUE_ULONG_NOTSET, numeric_operator); + dv_set_max = Helpers::transformNumFloat(EMS_VALUE_ULONG_NOTSET - 1, numeric_operator); return true; }