Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.luac
*.zip
.DS_Store
1 change: 1 addition & 0 deletions i18n/cs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
FontSizeIndex = "Velikost písma",
Source = "Zdroj",
SourceMissed = "žádný zdroj",
SourceReset = "%s Reset",
BackgroundColor = "Barva pozadí",
StateDown = "Dole",
StateMiddle = "Střed",
Expand Down
1 change: 1 addition & 0 deletions i18n/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
FontSizeIndex = "Schriftgröße",
Source = "Quelle",
SourceMissed = "keine Quelle",
SourceReset = "%s zurücksetzen",
BackgroundColor = "Hintergrundfarbe",
StateDown = "Unten",
StateMiddle = "Mitte",
Expand Down
1 change: 1 addition & 0 deletions i18n/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
FontSizeIndex = "Font size",
Source = "Source",
SourceMissed = "no source",
SourceReset = "Reset %s",
BackgroundColor = "Background color",
StateDown = "Down",
StateMiddle = "Middle",
Expand Down
1 change: 1 addition & 0 deletions i18n/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
FontSizeIndex = "Tamaño de fuente",
Source = "Fuente",
SourceMissed = "sin fuente",
SourceReset = "Reiniciar %s",
BackgroundColor = "Color de fondo",
StateDown = "Abajo",
StateMiddle = "Medio",
Expand Down
1 change: 1 addition & 0 deletions i18n/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
FontSizeIndex = "Taille de police",
Source = "Source",
SourceMissed = "aucune source",
SourceReset = "Réinitialiser %s",
BackgroundColor = "Couleur de fond",
StateDown = "Bas",
StateMiddle = "Milieu",
Expand Down
1 change: 1 addition & 0 deletions i18n/it.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ return {
FontSizeIndex = "Dimensione carattere",
Source = "Sorgente",
SourceMissed = "nessuna sorgente",
SourceReset = "%s ReImposta",
BackgroundColor = "Colore sfondo",
StateDown = "Giù",
StateMiddle = "Centro",
Expand Down
19 changes: 11 additions & 8 deletions lib/w_paint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ local wPaint = {
LINE_CENTERED = 2, -- align middle (vertical centered)
LINE_BOTTOM = 3, -- align bottom

-- Transparency Box offset (to show that widget has the Focus)
TRANSPARENCY_X_OFFSET = 1, -- left and right offset
TRANSPARENCY_Y_OFFSET = 1, -- top and bottom offset
} -- library structure

-- required libraries
Expand Down Expand Up @@ -77,26 +80,26 @@ function wPaint.text(text, fontSize, horizontalAlign, verticalAlign, shiftLine)
_, textHeight = lcd.getTextSize("")

if verticalAlign == wPaint.LINE_TOP then -- align top
textPosY = wPaint.FREE_ABOVE + wPaint.titleHeight
textPosY = wPaint.TRANSPARENCY_Y_OFFSET + wPaint.FREE_ABOVE + wPaint.titleHeight
elseif verticalAlign == wPaint.LINE_BOTTOM then -- align bottom
textPosY = (widget.height - textHeight - wPaint.footerHeight - wPaint.FREE_BELOW)
textPosY = (widget.height - textHeight - wPaint.footerHeight - wPaint.FREE_BELOW - wPaint.TRANSPARENCY_Y_OFFSET)
else -- align centered (default)
-- textPosY = wPaint.FREE_ABOVE +
-- ((widget.height - wPaint.titleHeight - wPaint.FREE_ABOVE - wPaint.footerHeight - wPaint.FREE_BELOW) / 2 - textHeight / 2) +
-- wPaint.titleHeight

local boxTop = wPaint.titleHeight + wPaint.FREE_ABOVE
local boxHeight = widget.height - wPaint.FREE_BELOW - wPaint.footerHeight - boxTop
local boxTop = wPaint.titleHeight + wPaint.FREE_ABOVE + wPaint.TRANSPARENCY_Y_OFFSET
local boxHeight = widget.height - wPaint.FREE_BELOW - wPaint.footerHeight - wPaint.TRANSPARENCY_Y_OFFSET - boxTop
local boxMiddle = boxTop + boxHeight / 2
textPosY = boxMiddle - textHeight / 2
end

textPosY = textPosY + (shiftLine * textHeight) -- shift line

if horizontalAlign == TEXT_LEFT then
lcd.drawText(wPaint.FREE_LEFT, textPosY, text, TEXT_LEFT)
lcd.drawText(wPaint.FREE_LEFT + wPaint.TRANSPARENCY_X_OFFSET, textPosY, text, TEXT_LEFT)
elseif horizontalAlign == TEXT_RIGHT then
lcd.drawText(widget.width - wPaint.FREE_RIGHT, textPosY, text, TEXT_RIGHT)
lcd.drawText(widget.width - wPaint.FREE_RIGHT - wPaint.TRANSPARENCY_X_OFFSET, textPosY, text, TEXT_RIGHT)
else
lcd.drawText((widget.width / 2), textPosY, text, TEXT_CENTERED)
end
Expand All @@ -116,7 +119,7 @@ function wPaint.title(titleText, titleBGColor, titleTxColor)
titleHeight = wPaint.FREE_ABOVE + titleHeight + wPaint.FREE_BELOW

lcd.color(titleBGColor)
lcd.drawFilledRectangle(0, 0, widget.width, titleHeight)
lcd.drawFilledRectangle(wPaint.TRANSPARENCY_X_OFFSET, wPaint.TRANSPARENCY_Y_OFFSET, widget.width - (2 * wPaint.TRANSPARENCY_X_OFFSET), titleHeight - wPaint.TRANSPARENCY_Y_OFFSET)

--- draw title text
lcd.color(titleTxColor)
Expand All @@ -141,7 +144,7 @@ function wPaint.footer(footerText, footerBGColor, footerTxColor)
if footerBGColor ~= nil then
footerHeight = wPaint.FREE_ABOVE + footerHeight
lcd.color(footerBGColor)
lcd.drawFilledRectangle(0, widget.height - footerHeight, widget.width, widget.height)
lcd.drawFilledRectangle(wPaint.TRANSPARENCY_X_OFFSET, widget.height - footerHeight - (2 * wPaint.TRANSPARENCY_Y_OFFSET), widget.width - (2 * wPaint.TRANSPARENCY_X_OFFSET), widget.height - (2 * wPaint.TRANSPARENCY_Y_OFFSET))
end
--- draw footer text
lcd.color(footerTxColor)
Expand Down
88 changes: 82 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ local function paint(widget)

-- paint background
lcd.color(widget:getStateBgColor())
lcd.drawFilledRectangle(0, 0, widget.width, widget.height)
lcd.drawFilledRectangle(wPaint.TRANSPARENCY_X_OFFSET, wPaint.TRANSPARENCY_Y_OFFSET, widget.width - (2 * wPaint.TRANSPARENCY_X_OFFSET), widget.height - (2 * wPaint.TRANSPARENCY_Y_OFFSET))

-- paint title (must be before paint state text or debug information)
paintTitle()
Expand All @@ -295,7 +295,7 @@ local function paint(widget)
local function paintSourceMissed()
local debug = wHelper.Debug:new(widget.no, "paintSourceMissed"):info()
lcd.color(COLOR_BLACK)
lcd.drawFilledRectangle(0, 0, widget.width, widget.height)
lcd.drawFilledRectangle(wPaint.TRANSPARENCY_X_OFFSET, wPaint.TRANSPARENCY_Y_OFFSET, widget.width - (2 * wPaint.TRANSPARENCY_X_OFFSET), widget.height - (2 * wPaint.TRANSPARENCY_Y_OFFSET))

--- paint title
paintTitle()
Expand Down Expand Up @@ -356,12 +356,68 @@ local function configure(widget)
updateLanguage(widget) -- check if system language has changed
wConfig.init({ form = form, widget = widget, STR = STR })

-- Source
wConfig.addSourceField("source")
-- Source and thresholds
local function sourcePrecision(source)
local precision = THRESHOLD_PRECISION
if wHelper.existSource(source) and source.decimals and source:decimals()~=nil then
precision = source:decimals()
end
return precision
end
local function sourceFactorInt(x, source) -- adjust on source change
local precision = sourcePrecision(source)
local factor = 10 ^ precision
return math.floor(x * factor + 0.5) -- convert & round to nearest factor integer
end
local function sourceFactorFloat(x, source) -- adjust on source change
local precision = sourcePrecision(source)
local factor = 10 ^ precision
return math.floor(x + 0.5) / factor -- reconvert & round to nearest factor float
end
local function updateFieldRange(field, source)
local precision = sourcePrecision(source)
local min = -THRESHOLD_RANGE
local max = THRESHOLD_RANGE
if wHelper.existSource(source) then
if source.minimum and source:minimum()~=nil then
min = source:minimum()
end
if source.maximum and source:maximum()~=nil then
max = source:maximum()
end
end
if field then
field:decimals(precision)
field:minimum(sourceFactorInt(min, source))
field:maximum(sourceFactorInt(max, source))
end
end

line = wConfig.addLine(wHelper.capitalizeFirstLetter("source"))
local thresholdDownField
local thresholdUpField
local sourceField = form.addSourceField(line, nil, function() return widget["source"] end,
function(value)
widget["source"] = value
updateFieldRange(thresholdDownField, value)
updateFieldRange(thresholdUpField, value)
end)

-- thresholds
wConfig.addNumberField("thresholdDown", -THRESHOLD_RANGE, THRESHOLD_RANGE, THRESHOLD_PRECISION)
wConfig.addNumberField("thresholdUp", -THRESHOLD_RANGE, THRESHOLD_RANGE, THRESHOLD_PRECISION)

line = wConfig.addLine(wHelper.capitalizeFirstLetter("thresholdDown"))
thresholdDownField = form.addNumberField(line, nil, 0, 0, -- min max adjusted in updateFieldRangeForSource
function() return sourceFactorInt(widget["thresholdDown"], widget.source) end,
function(value) widget["thresholdDown"] = sourceFactorFloat(value, widget.source) end
)
updateFieldRange(thresholdDownField, widget.source)

line = wConfig.addLine(wHelper.capitalizeFirstLetter("thresholdUp"))
thresholdUpField = form.addNumberField(line, nil, 0, 0, -- min max adjusted in updateFieldRangeForSource
function() return sourceFactorInt(widget["thresholdUp"], widget.source) end,
function(value) widget["thresholdUp"] = sourceFactorFloat(value, widget.source) end
)
updateFieldRange(thresholdUpField, widget.source)

-- Font size
wConfig.addChoiceField("fontSizeIndex", FONT_SIZE_SELECTION)
Expand Down Expand Up @@ -499,6 +555,25 @@ local function read(widget)
wStorage.read("debugMode")
end

local function menu(widget)
local CATEGORY_LUA = 29
if wHelper.existSource(widget.source) and widget.source.reset then
local category = widget.source:category()
if
category == CATEGORY_TIMER or
category == CATEGORY_TELEMETRY_SENSOR or
category == CATEGORY_LUA
then
return {
{string.format(STR("SourceReset"), widget.source:name()),
function()
widget.source:reset()
end},
}
end
end
return {}
end
------------------------------------------------------------------------------------------------------------------------
--- Initialize the widget (register it in the system).
local function init()
Expand All @@ -512,6 +587,7 @@ local function init()
configure = configure,
read = read,
write = write,
menu=menu,
title = false
})
end
Expand Down