Crossfire LUA add missing support for PREC3 values (#7322)
This commit is contained in:
@@ -72,7 +72,7 @@ local function incrField(step)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
local min, max = 0, 0
|
local min, max = 0, 0
|
||||||
if field.type <= 5 then
|
if ((field.type <= 5) or (field.type == 8)) then
|
||||||
min = field.min
|
min = field.min
|
||||||
max = field.max
|
max = field.max
|
||||||
step = field.step * step
|
step = field.step * step
|
||||||
@@ -239,25 +239,21 @@ local function fieldFloatLoad(field, data, offset)
|
|||||||
field.default = fieldGetValue(data, offset+12, 4)
|
field.default = fieldGetValue(data, offset+12, 4)
|
||||||
fieldUnsignedToSigned(field, 4)
|
fieldUnsignedToSigned(field, 4)
|
||||||
field.prec = data[offset+16]
|
field.prec = data[offset+16]
|
||||||
if field.prec > 2 then
|
if field.prec > 3 then
|
||||||
field.prec = 2
|
field.prec = 3
|
||||||
end
|
end
|
||||||
field.step = fieldGetValue(data, offset+17, 4)
|
field.step = fieldGetValue(data, offset+17, 4)
|
||||||
field.unit, offset = fieldGetString(data, offset+21)
|
field.unit, offset = fieldGetString(data, offset+21)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function formatFloat(num, decimals)
|
||||||
|
local mult = 10^(decimals or 0)
|
||||||
|
local val = num / mult
|
||||||
|
return string.format("%." .. decimals .. "f", val)
|
||||||
|
end
|
||||||
|
|
||||||
local function fieldFloatDisplay(field, y, attr)
|
local function fieldFloatDisplay(field, y, attr)
|
||||||
local attrnum
|
lcd.drawText(140, y, formatFloat(field.value, field.prec) .. field.unit, attr)
|
||||||
if field.prec == 1 then
|
|
||||||
attrnum = LEFT + attr + PREC1
|
|
||||||
elseif field.prec == 2 then
|
|
||||||
attrnum = LEFT + attr + PREC2
|
|
||||||
else
|
|
||||||
attrnum = LEFT + attr
|
|
||||||
end
|
|
||||||
-- lcd.drawNumber(140, y, field.value, attrnum) -- NOTE: original code getLastPos not available in Horus
|
|
||||||
-- lcd.drawText(lcd.getLastPos(), y, field.unit, attr) -- NOTE: original code getLastPos not available in Horus
|
|
||||||
lcd.drawText(140, y, field.value .. field.unit, attr) -- NOTE: Concenated fields instead of get lastPos
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fieldFloatSave(field)
|
local function fieldFloatSave(field)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ local function incrField(step)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
local min, max = 0, 0
|
local min, max = 0, 0
|
||||||
if field.type <= 5 then
|
if ((field.type <= 5) or (field.type == 8)) then
|
||||||
min = field.min
|
min = field.min
|
||||||
max = field.max
|
max = field.max
|
||||||
step = field.step * step
|
step = field.step * step
|
||||||
@@ -238,23 +238,21 @@ local function fieldFloatLoad(field, data, offset)
|
|||||||
field.default = fieldGetValue(data, offset+12, 4)
|
field.default = fieldGetValue(data, offset+12, 4)
|
||||||
fieldUnsignedToSigned(field, 4)
|
fieldUnsignedToSigned(field, 4)
|
||||||
field.prec = data[offset+16]
|
field.prec = data[offset+16]
|
||||||
if field.prec > 2 then
|
if field.prec > 3 then
|
||||||
field.prec = 2
|
field.prec = 3
|
||||||
end
|
end
|
||||||
field.step = fieldGetValue(data, offset+17, 4)
|
field.step = fieldGetValue(data, offset+17, 4)
|
||||||
field.unit, offset = fieldGetString(data, offset+21)
|
field.unit, offset = fieldGetString(data, offset+21)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function formatFloat(num, decimals)
|
||||||
|
local mult = 10^(decimals or 0)
|
||||||
|
local val = num / mult
|
||||||
|
return string.format("%." .. decimals .. "f", val)
|
||||||
|
end
|
||||||
|
|
||||||
local function fieldFloatDisplay(field, y, attr)
|
local function fieldFloatDisplay(field, y, attr)
|
||||||
local attrnum
|
lcd.drawText(89, y, formatFloat(field.value, field.prec), LEFT + attr)
|
||||||
if field.prec == 1 then
|
|
||||||
attrnum = LEFT + attr + PREC1
|
|
||||||
elseif field.prec == 2 then
|
|
||||||
attrnum = LEFT + attr + PREC2
|
|
||||||
else
|
|
||||||
attrnum = LEFT + attr
|
|
||||||
end
|
|
||||||
lcd.drawNumber(89, y, field.value, attrnum)
|
|
||||||
lcd.drawText(lcd.getLastPos(), y, field.unit, attr)
|
lcd.drawText(lcd.getLastPos(), y, field.unit, attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ local function incrField(step)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
local min, max = 0, 0
|
local min, max = 0, 0
|
||||||
if field.type <= 5 then
|
if ((field.type <= 5) or (field.type == 8)) then
|
||||||
min = field.min
|
min = field.min
|
||||||
max = field.max
|
max = field.max
|
||||||
step = field.step * step
|
step = field.step * step
|
||||||
@@ -238,23 +238,21 @@ local function fieldFloatLoad(field, data, offset)
|
|||||||
field.default = fieldGetValue(data, offset+12, 4)
|
field.default = fieldGetValue(data, offset+12, 4)
|
||||||
fieldUnsignedToSigned(field, 4)
|
fieldUnsignedToSigned(field, 4)
|
||||||
field.prec = data[offset+16]
|
field.prec = data[offset+16]
|
||||||
if field.prec > 2 then
|
if field.prec > 3 then
|
||||||
field.prec = 2
|
field.prec = 3
|
||||||
end
|
end
|
||||||
field.step = fieldGetValue(data, offset+17, 4)
|
field.step = fieldGetValue(data, offset+17, 4)
|
||||||
field.unit, offset = fieldGetString(data, offset+21)
|
field.unit, offset = fieldGetString(data, offset+21)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function formatFloat(num, decimals)
|
||||||
|
local mult = 10^(decimals or 0)
|
||||||
|
local val = num / mult
|
||||||
|
return string.format("%." .. decimals .. "f", val)
|
||||||
|
end
|
||||||
|
|
||||||
local function fieldFloatDisplay(field, y, attr)
|
local function fieldFloatDisplay(field, y, attr)
|
||||||
local attrnum
|
lcd.drawText(140, y, formatFloat(field.value, field.prec), LEFT + attr)
|
||||||
if field.prec == 1 then
|
|
||||||
attrnum = LEFT + attr + PREC1
|
|
||||||
elseif field.prec == 2 then
|
|
||||||
attrnum = LEFT + attr + PREC2
|
|
||||||
else
|
|
||||||
attrnum = LEFT + attr
|
|
||||||
end
|
|
||||||
lcd.drawNumber(140, y, field.value, attrnum)
|
|
||||||
lcd.drawText(lcd.getLastPos(), y, field.unit, attr)
|
lcd.drawText(lcd.getLastPos(), y, field.unit, attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user