Difference between revisions of "Talk:Digiline Jumpdrive controller"

From Pandorabox
Jump to navigation Jump to search
m (+syntaxhighlight)
m (spaces)
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?
  
 
<syntaxhighlight lang="Lua">
 
<syntaxhighlight lang="Lua">
Line 8: 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
+
elseif mem.touch_event.sethome then
mem.home = event.msg.position
+
  mem.home = event.msg.position
  
elseif mem.touch_event.gohome and mem.home then
+
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}})
+
  digiline_send("jumpdrive", {command="set", {x = mem.home.x, y = mem.home.y, z = mem.home.z}})
jump = true
+
  jump = true
  
elseif mem.touch_event.yplus then
+
elseif mem.touch_event.yplus 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.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.xplus then
+
elseif mem.touch_event.xplus 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.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.zplus then
+
elseif mem.touch_event.zplus 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.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.factorplus then
+
elseif mem.touch_event.factorplus then
mem.factor = mem.factor + 1
+
  mem.factor = mem.factor + 1
update_touch()
+
  update_touch()
  
elseif mem.touch_event.factorminus then
+
elseif mem.touch_event.factorminus then
mem.factor = mem.factor - 1
+
  mem.factor = mem.factor - 1
if mem.factor < 1 then
+
  if mem.factor < 1 then
mem.factor = 1
+
  mem.factor = 1
end
+
  end
update_touch()
+
  update_touch()
  
end
+
end
  
if jump then
+
if jump then
digiline_send("jumpdrive", {command="jump"})
+
  digiline_send("jumpdrive", {command="jump"})
end
+
end
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 18:58, 28 April 2022

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

-- version 1.1.huhhila.1

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