Difference between revisions of "Talk:Digiline Jumpdrive controller"

From Pandorabox
Jump to navigation Jump to search
(Luac and touchscreen usage modernization, draft for review)
 
(Real Coordinates background info added.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Draft of modernized version for comments, before making version 1.2 out of it, any comments? (some spaces eaten by copypaste)
+
Draft of modernized version for comments, before making version 1.2 out of it, any comments?
  
-- version 1.1.huhhila.1
+
<syntaxhighlight lang="Lua">
 +
-- version 1.1.huhhila.2
  
 
mem.factor = mem.factor or 1
 
mem.factor = mem.factor or 1
Line 7: Line 8:
 
-- TODO actually use converted coordinates in table
 
-- TODO actually use converted coordinates in table
 
local function c(v)
 
local function c(v)
return (v + 0)*5/4 + 3/8
+
  return (v + 0)*5/4 + 3/8
 
end
 
end
  
 
local function c1(t)
 
local function c1(t)
local r = {}
+
  local r = {}
for k, v in pairs(t) do
+
  for k, v in pairs(t) do
r[k] = (k == "X" or k == "Y") and c(v) or k == "H" and v*2*15/13*0.35 or v
+
    r[k] = (k == "X" or k == "Y") and c(v) or k == "H" and v*2*15/13*0.35 or v
end
+
  end
return r
+
  return r
 
end
 
end
  
 
local function convert(t)
 
local function convert(t)
local r = {}
+
  local r = {}
for _, v in ipairs(t) do
+
  for _, v in ipairs(t) do
table.insert(r, c1(v))
+
    table.insert(r, c1(v))
end
+
  end
return r
+
  return r
 
end
 
end
  
 
local function draw_touch()
 
local function draw_touch()
digiline_send("touch", convert({
+
digiline_send("touch", convert({
{ command = "set", locked = true, real_coordinates = true, width = (10-1)*5/4+3/4+1, height = (8-1)*5/4+3/4+1 },
+
  { command = "set", locked = true, real_coordinates = true, width = (10-1)*5/4+3/4+1, height = (8-1)*5/4+3/4+1 },
{ command = "clear" },
+
  { command = "clear" },
  
{ command = "add", element="button_exit", name="xplus", label="X+", X=0, Y=0, W=4, H=1 },
+
  { command = "add", element="button_exit", name="xplus",   label="X+", X=0, Y=0, W=4, H=1 },
{ command = "add", element="button_exit", name="xminus", label="X-", X=0, Y=1, W=4, H=1 },
+
  { command = "add", element="button_exit", name="xminus", label="X-", X=0, Y=1, W=4, H=1 },
{ command = "add", element="button_exit", name="yplus", label="Y+", X=0, Y=2, W=4, H=1 },
+
  { command = "add", element="button_exit", name="yplus",   label="Y+", X=0, Y=2, W=4, H=1 },
{ command = "add", element="button_exit", name="yminus", label="Y-", X=0, Y=3, W=4, H=1 },
+
  { command = "add", element="button_exit", name="yminus", label="Y-", X=0, Y=3, W=4, H=1 },
{ command = "add", element="button_exit", name="zplus", label="Z+", X=0, Y=4, W=4, H=1 },
+
  { command = "add", element="button_exit", name="zplus",   label="Z+", X=0, Y=4, W=4, H=1 },
{ command = "add", element="button_exit", name="zminus", label="Z-", X=0, Y=5, W=4, H=1 },
+
  { command = "add", element="button_exit", name="zminus", label="Z-", X=0, Y=5, W=4, H=1 },
  
{ command = "add", element="button", name="factorplus", label="Factor+", X=0, Y=6, W=4, H=1 },
+
  { command = "add", element="button", name="factorplus", label="Factor+",   X=0, Y=6, W=4, H=1 },
{ command = "add", element="button", name="factorminus", label="Factor-", X=0, Y=7, W=4, H=1 },
+
  { command = "add", element="button", name="factorminus", label="Factor-", X=0, Y=7, W=4, H=1 },
{ command = "add", element="label", label="Factor: " .. mem.factor, X=4, Y=6.5 },
+
  { command = "add", element="label", label="Factor: " .. mem.factor, X=4, Y=6.5 },
  
{ command = "add", element="button_exit", name="sethome", label="Set home", X=4, Y=0, W=4, H=1 },
+
  { command = "add", element="button_exit", name="sethome", label="Set home", X=4, Y=0, W=4, H=1 },
{ command = "add", element="button_exit", name="gohome", label="Go home", X=4, Y=1, W=4, H=1 },
+
  { command = "add", element="button_exit", name="gohome",   label="Go home",   X=4, Y=1, W=4, H=1 },
  
{ command = "add", element="button_exit", name="lock", label="Lock", X=4, Y=5, W=4, H=1 }}))
+
  { command = "add", element="button_exit", name="lock", label="Lock", X=4, Y=5, W=4, H=1 }}))
 
end
 
end
  
 
local function update_touch()
 
local function update_touch()
digiline_send("touch", { command = "replace", index = 9,
+
  digiline_send("touch", { command = "replace", index = 9,
element = "label", label = "Factor: " .. mem.factor, X = 5.375, Y = 8.5 })
+
    element = "label", label = "Factor: " .. mem.factor, X = 5.375, Y = 8.5 })
 
end
 
end
  
 
if event.type == "program" then
 
if event.type == "program" then
draw_touch()
+
draw_touch()
 
end
 
end
  
 
if event.type == "digiline" and event.channel == "touch" then
 
if event.type == "digiline" and event.channel == "touch" then
mem.touch_event = event.msg
+
mem.touch_event = event.msg
digiline_send("jumpdrive", {command="get"})
+
digiline_send("jumpdrive", {command="get"})
 
end
 
end
  
 
if event.type == "digiline" and event.channel == "jumpdrive" and event.msg.target then
 
if event.type == "digiline" and event.channel == "jumpdrive" and event.msg.target then
local jump = false
+
local jump = false
local increment = ((event.msg.radius*2)+1)*mem.factor
+
local increment = ((event.msg.radius*2)+1)*mem.factor
if mem.touch_event.lock then
+
if mem.touch_event.lock then
digiline_send("touch", { command = "clear" })
+
  digiline_send("touch", { command = "clear" })
 +
 
 +
elseif mem.touch_event.sethome then
 +
  mem.home = event.msg.position
  
elseif mem.touch_event.sethome then
+
elseif mem.touch_event.gohome and mem.home then
mem.home = event.msg.position
+
  digiline_send("jumpdrive", {command="set", x = mem.home.x, y = mem.home.y, z = mem.home.z})
 +
  jump = true
  
elseif mem.touch_event.gohome and mem.home then
+
elseif mem.touch_event.yplus then
digiline_send("jumpdrive", {command="set", {x = mem.home.x, y = mem.home.y, z = mem.home.z}})
+
  digiline_send("jumpdrive", {command="set", key="y", value=event.msg.target.y+increment})
jump = true
+
  jump = true
  
elseif mem.touch_event.yplus then
+
elseif mem.touch_event.yminus then
digiline_send("jumpdrive", {command="set", key="y", value=event.msg.target.y+increment})
+
  digiline_send("jumpdrive", {command="set", key="y", value=event.msg.target.y-increment})
jump = true
+
  jump = true
  
elseif mem.touch_event.yminus then
+
elseif mem.touch_event.xplus then
digiline_send("jumpdrive", {command="set", key="y", value=event.msg.target.y-increment})
+
  digiline_send("jumpdrive", {command="set", key="x", value=event.msg.target.x+increment})
jump = true
+
  jump = true
  
elseif mem.touch_event.xplus then
+
elseif mem.touch_event.xminus then
digiline_send("jumpdrive", {command="set", key="x", value=event.msg.target.x+increment})
+
  digiline_send("jumpdrive", {command="set", key="x", value=event.msg.target.x-increment})
jump = true
+
  jump = true
  
elseif mem.touch_event.xminus then
+
elseif mem.touch_event.zplus then
digiline_send("jumpdrive", {command="set", key="x", value=event.msg.target.x-increment})
+
  digiline_send("jumpdrive", {command="set", key="z", value=event.msg.target.z+increment})
jump = true
+
  jump = true
  
elseif mem.touch_event.zplus then
+
elseif mem.touch_event.zminus then
digiline_send("jumpdrive", {command="set", key="z", value=event.msg.target.z+increment})
+
  digiline_send("jumpdrive", {command="set", key="z", value=event.msg.target.z-increment})
jump = true
+
  jump = true
  
elseif mem.touch_event.zminus then
+
elseif mem.touch_event.factorplus then
digiline_send("jumpdrive", {command="set", key="z", value=event.msg.target.z-increment})
+
  mem.factor = mem.factor + 1
jump = true
+
  update_touch()
  
elseif mem.touch_event.factorplus then
+
elseif mem.touch_event.factorminus then
mem.factor = mem.factor + 1
+
  mem.factor = mem.factor - 1
update_touch()
+
  if mem.factor < 1 then
 +
  mem.factor = 1
 +
  end
 +
  update_touch()
  
elseif mem.touch_event.factorminus then
+
end
mem.factor = mem.factor - 1
+
 
if mem.factor < 1 then
+
if jump then
mem.factor = 1
+
  digiline_send("jumpdrive", {command="jump"})
 +
end
 
end
 
end
update_touch()
+
</syntaxhighlight>
  
end
+
<[[User:SwissalpS]]> Some more comments explaining what the convert function is about and why it is needed, would make understanding the formulas like "v*2*15/13*0.35" better.
  
if jump then
+
<[[User:Huhhila]]> That particular formula is taken from https://minetest.gitlab.io/minetest/formspec/#migrating-to-real-coordinates and results in the following:
digiline_send("jumpdrive", {command="jump"})
+
<syntaxhighlight lang="Lua">
end
+
converted = {
end
+
{
 +
command = "set",
 +
height = 10.5,
 +
real_coordinates = true,
 +
locked = true,
 +
width = 13
 +
},
 +
{
 +
command = "clear"
 +
},
 +
{
 +
label = "X+",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 0.375,
 +
name = "xplus",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "X-",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 1.625,
 +
name = "xminus",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Y+",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 2.875,
 +
name = "yplus",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Y-",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 4.125,
 +
name = "yminus",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Z+",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 5.375,
 +
name = "zplus",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Z-",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 6.625,
 +
name = "zminus",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Factor+",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 7.875,
 +
name = "factorplus",
 +
H = 0.80769230769231,
 +
element = "button"
 +
},
 +
{
 +
label = "Factor-",
 +
X = 0.375,
 +
command = "add",
 +
W = 4,
 +
Y = 9.125,
 +
name = "factorminus",
 +
H = 0.80769230769231,
 +
element = "button"
 +
},
 +
{
 +
label = "Factor: 1",
 +
X = 5.375,
 +
command = "add",
 +
Y = 8.5,
 +
element = "label"
 +
},
 +
{
 +
label = "Set home",
 +
X = 5.375,
 +
command = "add",
 +
W = 4,
 +
Y = 0.375,
 +
name = "sethome",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Go home",
 +
X = 5.375,
 +
command = "add",
 +
W = 4,
 +
Y = 1.625,
 +
name = "gohome",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
},
 +
{
 +
label = "Lock",
 +
X = 5.375,
 +
command = "add",
 +
W = 4,
 +
Y = 6.625,
 +
name = "lock",
 +
H = 0.80769230769231,
 +
element = "button_exit"
 +
}
 +
}
 +
</syntaxhighlight>
 +
For example code related to jumpdrive digiline control such conversion is somewhat offtopic, and should be moved to another more touchscreen-focused page. But @[[User:BuckarooBanzai]], was the original layout of the UI significant / does preserving it matter?

Latest revision as of 13:23, 12 June 2022

Draft of modernized version for comments, before making version 1.2 out of it, any comments?

-- version 1.1.huhhila.2

mem.factor = mem.factor or 1

-- TODO actually use converted coordinates in table
local function c(v)
  return (v + 0)*5/4 + 3/8
end

local function c1(t)
  local r = {}
  for k, v in pairs(t) do
    r[k] = (k == "X" or k == "Y") and c(v) or k == "H" and v*2*15/13*0.35 or v
  end
  return r
end

local function convert(t)
  local r = {}
  for _, v in ipairs(t) do
    table.insert(r, c1(v))
  end
  return r
end

local function draw_touch()
 digiline_send("touch", convert({
  { command = "set", locked = true, real_coordinates = true, width = (10-1)*5/4+3/4+1, height = (8-1)*5/4+3/4+1 },
  { command = "clear" },

  { command = "add", element="button_exit",  name="xplus",   label="X+",  X=0, Y=0, W=4, H=1 },
  { command = "add", element="button_exit",  name="xminus",  label="X-",  X=0, Y=1, W=4, H=1 },
  { command = "add", element="button_exit",  name="yplus",   label="Y+",  X=0, Y=2, W=4, H=1 },
  { command = "add", element="button_exit",  name="yminus",  label="Y-",  X=0, Y=3, W=4, H=1 },
  { command = "add", element="button_exit",  name="zplus",   label="Z+",  X=0, Y=4, W=4, H=1 },
  { command = "add", element="button_exit",  name="zminus",  label="Z-",  X=0, Y=5, W=4, H=1 },

  { command = "add", element="button",  name="factorplus",  label="Factor+",   X=0, Y=6, W=4, H=1 },
  { command = "add", element="button",  name="factorminus",  label="Factor-",  X=0, Y=7, W=4, H=1 },
  { command = "add", element="label",  label="Factor: " .. mem.factor,  X=4, Y=6.5 },

  { command = "add", element="button_exit",  name="sethome",  label="Set home",  X=4, Y=0, W=4, H=1 },
  { command = "add", element="button_exit",  name="gohome",   label="Go home",   X=4, Y=1, W=4, H=1 },

  { command = "add", element="button_exit",  name="lock",  label="Lock",  X=4, Y=5, W=4, H=1 }}))
end

local function update_touch()
  digiline_send("touch", { command = "replace", index = 9,
    element = "label", label = "Factor: " .. mem.factor, X = 5.375, Y = 8.5 })
end

if event.type == "program" then
 draw_touch()
end

if event.type == "digiline" and event.channel == "touch" then
 mem.touch_event = event.msg
 digiline_send("jumpdrive",  {command="get"})
end

if event.type == "digiline" and event.channel == "jumpdrive" and event.msg.target then
 local jump = false
 local increment = ((event.msg.radius*2)+1)*mem.factor
 if mem.touch_event.lock then
  digiline_send("touch", { command = "clear" })

 elseif mem.touch_event.sethome then
  mem.home = event.msg.position

 elseif mem.touch_event.gohome and mem.home then
  digiline_send("jumpdrive", {command="set", x = mem.home.x, y = mem.home.y, z = mem.home.z})
  jump = true

 elseif mem.touch_event.yplus then
  digiline_send("jumpdrive", {command="set", key="y", value=event.msg.target.y+increment})
  jump = true

 elseif mem.touch_event.yminus then
  digiline_send("jumpdrive", {command="set", key="y", value=event.msg.target.y-increment})
  jump = true

 elseif mem.touch_event.xplus then
  digiline_send("jumpdrive", {command="set", key="x", value=event.msg.target.x+increment})
  jump = true

 elseif mem.touch_event.xminus then
  digiline_send("jumpdrive", {command="set", key="x", value=event.msg.target.x-increment})
  jump = true

 elseif mem.touch_event.zplus then
  digiline_send("jumpdrive", {command="set", key="z", value=event.msg.target.z+increment})
  jump = true

 elseif mem.touch_event.zminus then
  digiline_send("jumpdrive", {command="set", key="z", value=event.msg.target.z-increment})
  jump = true

 elseif mem.touch_event.factorplus then
  mem.factor = mem.factor + 1
  update_touch()

 elseif mem.touch_event.factorminus then
  mem.factor = mem.factor - 1
  if mem.factor < 1 then
   mem.factor = 1
  end
  update_touch()

 end

 if jump then
  digiline_send("jumpdrive", {command="jump"})
 end
end

<User:SwissalpS> Some more comments explaining what the convert function is about and why it is needed, would make understanding the formulas like "v*2*15/13*0.35" better.

<User:Huhhila> That particular formula is taken from https://minetest.gitlab.io/minetest/formspec/#migrating-to-real-coordinates and results in the following:

converted = {
		{
			command = "set",
			height = 10.5,
			real_coordinates = true,
			locked = true,
			width = 13
		},
		{
			command = "clear"
		},
		{
			label = "X+",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 0.375,
			name = "xplus",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "X-",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 1.625,
			name = "xminus",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Y+",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 2.875,
			name = "yplus",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Y-",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 4.125,
			name = "yminus",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Z+",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 5.375,
			name = "zplus",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Z-",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 6.625,
			name = "zminus",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Factor+",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 7.875,
			name = "factorplus",
			H = 0.80769230769231,
			element = "button"
		},
		{
			label = "Factor-",
			X = 0.375,
			command = "add",
			W = 4,
			Y = 9.125,
			name = "factorminus",
			H = 0.80769230769231,
			element = "button"
		},
		{
			label = "Factor: 1",
			X = 5.375,
			command = "add",
			Y = 8.5,
			element = "label"
		},
		{
			label = "Set home",
			X = 5.375,
			command = "add",
			W = 4,
			Y = 0.375,
			name = "sethome",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Go home",
			X = 5.375,
			command = "add",
			W = 4,
			Y = 1.625,
			name = "gohome",
			H = 0.80769230769231,
			element = "button_exit"
		},
		{
			label = "Lock",
			X = 5.375,
			command = "add",
			W = 4,
			Y = 6.625,
			name = "lock",
			H = 0.80769230769231,
			element = "button_exit"
		}
	}

For example code related to jumpdrive digiline control such conversion is somewhat offtopic, and should be moved to another more touchscreen-focused page. But @User:BuckarooBanzai, was the original layout of the UI significant / does preserving it matter?