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
5 changes: 4 additions & 1 deletion HORUS/SD/SCRIPTS/TOOLS/Yaapu Maps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ local menuItems = {
{"map type:", 1, "MAPT", 1, { "", "", "", "" }, { "", "", "", "" } },
{"map grid lines:", 1, "MAPG", 1, { "yes", "no" }, { true, false } },
{"map trail dots:", 0, "MAPTD", 10, 5, 50,nil,0,1 },
{"emulated wheel channel:", 0, "ZTC", 0, 0, 32,nil,0,1 },
{"zoom channel type:", 1, "ZCT", 1, { "emulated wheel", "potentiometer" }, { 1, 2 } },
{"zoom channel:", 0, "ZTC", 0, 0, 32,nil,0,1 },
{"emulated wheel delay in seconds:", 0, "ZDMS", 1, 0, 50,"sec",PREC1, 1 },
{"map zoom level default value:", 0, "MAPZ", -2, -2, 17,nil,0,1 },
{"map zoom level min value:", 0, "MAPmZ", -2, -2, 17,nil,0,1 },
Expand Down Expand Up @@ -193,6 +194,8 @@ local function applyConfigValues(conf)
conf.mapZoomMin = getMenuItemByName(menuItems,"MAPmZ")
conf.mapZoomMax = getMenuItemByName(menuItems,"MAPMZ")

conf.zoomChannelType = getMenuItemByName(menuItems,"ZCT")

local chInfo = getFieldInfo("ch"..getMenuItemByName(menuItems,"ZTC"))
conf.mapWheelChannelId = (chInfo == nil and -1 or chInfo['id'])

Expand Down
74 changes: 58 additions & 16 deletions HORUS/SD/WIDGETS/YaapuMaps/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -861,32 +861,74 @@ function utils.checkHomeResetChannel(widget)
end
end

function filterZoom(t)
local out = {}
local counter = 1

for k, v in pairs(t) do
if v == true then
out[counter] = k
counter = counter + 1
end
end
table.sort(out)
return out
end

function tableCount(t)
local counter = 1
for _ in pairs(t) do counter = counter + 1 end
return counter
end

function math_clamp(x, min, max)
return math.max(math.min(x, max), min)
end

function utils.getMapZoomLevel(widget,conf,status,customSensors)
local chValue = getValue(conf.mapWheelChannelId)
local newZoom = status.mapZoomLevel == nil and conf.mapZoomLevel or status.mapZoomLevel
local zoomLevels = nil
if customSensors ~= nil then
zoomLevels = customSensors.zoomLevels
end
if conf.mapWheelChannelId > -1 then
-- SW up (increase zoom detail)
if chValue < -600 then
if conf.mapProvider == 1 then
return utils.decZoomLevel(conf,status,zoomLevels)
else
return utils.incZoomLevel(conf,status,zoomLevels)
end

if conf.zoomChannelType == 2 then
-- do magic here
local normChValue = chValue + 1024

if (zoomLevels == nil) then
-- no custom zoom levels set using the default -2 to 16 zoom levels
local sizePerChannel = 2048 / 19
return math_clamp(math.floor((normChValue / sizePerChannel))-2, -2, 16)
else
-- no custom zoom levels set using the default -2 to 16 zoom levels
local filtered = filterZoom(zoomLevels)
local sizePerChannel = 2048 / (tableCount(filtered) - 1)
local tableSize = tableCount(filtered) - 1
return filtered[math_clamp(math.floor(normChValue / sizePerChannel) + 1, 1, tableSize)]
end
-- SW down (decrease zoom detail)
if chValue > 600 then
if conf.mapProvider == 1 then
return utils.incZoomLevel(conf,status,zoomLevels)
else
return utils.decZoomLevel(conf,status,zoomLevels)
else
if conf.mapWheelChannelId > -1 then
-- SW up (increase zoom detail)
if chValue < -600 then
if conf.mapProvider == 1 then
return utils.decZoomLevel(conf,status,zoomLevels)
else
return utils.incZoomLevel(conf,status,zoomLevels)
end
end
-- SW down (decrease zoom detail)
if chValue > 600 then
if conf.mapProvider == 1 then
return utils.incZoomLevel(conf,status,zoomLevels)
else
return utils.decZoomLevel(conf,status,zoomLevels)
end
end
-- switch is idle, force timer expire
zoomDelayStart = getTime() - conf.mapWheelChannelDelay*10
end
-- switch is idle, force timer expire
zoomDelayStart = getTime() - conf.mapWheelChannelDelay*10
end
return status.mapZoomLevel
end
Expand Down
5 changes: 4 additions & 1 deletion HORUS/SD/WIDGETS/YaapuMaps/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ local menuItems = {
{"map type:", 1, "MAPT", 1, { "", "", "", "" }, { "", "", "", "" } },
{"map grid lines:", 1, "MAPG", 1, { "yes", "no" }, { true, false } },
{"map trail dots:", 0, "MAPTD", 10, 5, 50,nil,0,1 },
{"emulated wheel channel:", 0, "ZTC", 0, 0, 32,nil,0,1 },
{"zoom channel type:", 1, "ZCT", 1, { "emulated wheel", "potentiometer" }, { 1, 2 } },
{"zoom channel:", 0, "ZTC", 0, 0, 32,nil,0,1 },
{"emulated wheel delay in seconds:", 0, "ZDMS", 1, 0, 50,"sec",PREC1, 1 },
{"map zoom level default value:", 0, "MAPZ", -2, -2, 17,nil,0,1 },
{"map zoom level min value:", 0, "MAPmZ", -2, -2, 17,nil,0,1 },
Expand Down Expand Up @@ -193,6 +194,8 @@ local function applyConfigValues(conf)
conf.mapZoomMin = getMenuItemByName(menuItems,"MAPmZ")
conf.mapZoomMax = getMenuItemByName(menuItems,"MAPMZ")

conf.zoomChannelType = getMenuItemByName(menuItems,"ZCT")

local chInfo = getFieldInfo("ch"..getMenuItemByName(menuItems,"ZTC"))
conf.mapWheelChannelId = (chInfo == nil and -1 or chInfo['id'])

Expand Down