Difference between revisions of "Digiline Jumpdrive controller"

From Pandorabox
Jump to navigation Jump to search
(Created page with " === Overview === Simple digiline jumpdrive controller Features: * Allows for step-jumping into all 6 directions * Sethome / go-home button * Lock button === Lua Contro...")
 
 
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:
  
 
=== Lua Controller ===
 
=== Lua Controller ===
 +
 +
Version history:
 +
* 1.0 initial code [[User:BuckarooBanzai]]
 +
* 1.1 "factor" variable to jump further
  
 
<syntaxhighlight lang="Lua">
 
<syntaxhighlight lang="Lua">
-- version 1.0
+
-- version 1.1
  
if event.type == "program" then
+
mem.factor = mem.factor or 1
 +
 
 +
local function update_touch()
 
  digiline_send("touch", { command = "clear" })
 
  digiline_send("touch", { command = "clear" })
  
Line 23: Line 29:
 
  digiline_send("touch", {  command = "addbutton_exit",  name="zplus",  label="Z+",  X=0, Y=4, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="zplus",  label="Z+",  X=0, Y=4, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="zminus",  label="Z-",  X=0, Y=5, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="zminus",  label="Z-",  X=0, Y=5, W=4, H=1 })
 +
 +
digiline_send("touch", {  command = "addbutton_exit",  name="factorplus",  label="Factor+",  X=0, Y=6, W=4, H=1 })
 +
digiline_send("touch", {  command = "addbutton_exit",  name="factorminus",  label="Factor-",  X=0, Y=7, W=4, H=1 })
 +
digiline_send("touch", {  command = "addlabel",  label="Factor: " .. mem.factor,  X=4, Y=6.5 })
 +
 
  digiline_send("touch", {  command = "addbutton_exit",  name="sethome",  label="Set home",  X=4, Y=0, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="sethome",  label="Set home",  X=4, Y=0, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="gohome",  label="Go home",  X=4, Y=1, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="gohome",  label="Go home",  X=4, Y=1, W=4, H=1 })
 +
 
  digiline_send("touch", {  command = "addbutton_exit",  name="lock",  label="Lock",  X=4, Y=5, W=4, H=1 })
 
  digiline_send("touch", {  command = "addbutton_exit",  name="lock",  label="Lock",  X=4, Y=5, W=4, H=1 })
 +
end
 +
 +
if event.type == "program" then
 +
update_touch()
 
end
 
end
  
Line 35: Line 51:
 
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
+
  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" })
Line 71: Line 87:
 
   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
 +
  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
 
  end
Line 89: Line 116:
  
 
[[Category:Tutorial]]
 
[[Category:Tutorial]]
 +
[[Category:Digiline]]
 +
[[Category:Spaceship design]]

Latest revision as of 20:22, 12 December 2019

Overview

Simple digiline jumpdrive controller

Features:

  • Allows for step-jumping into all 6 directions
  • Sethome / go-home button
  • Lock button

Lua Controller

Version history:

-- version 1.1

mem.factor = mem.factor or 1

local function update_touch()
 digiline_send("touch", { command = "clear" })

 digiline_send("touch", {  command = "addbutton_exit",  name="xplus",  label="X+",  X=0, Y=0, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="xminus",  label="X-",  X=0, Y=1, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="yplus",  label="Y+",  X=0, Y=2, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="yminus",  label="Y-",  X=0, Y=3, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="zplus",  label="Z+",  X=0, Y=4, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="zminus",  label="Z-",  X=0, Y=5, W=4, H=1 })

 digiline_send("touch", {  command = "addbutton_exit",  name="factorplus",  label="Factor+",  X=0, Y=6, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="factorminus",  label="Factor-",  X=0, Y=7, W=4, H=1 })
 digiline_send("touch", {  command = "addlabel",  label="Factor: " .. mem.factor,  X=4, Y=6.5 })

 digiline_send("touch", {  command = "addbutton_exit",  name="sethome",  label="Set home",  X=4, Y=0, W=4, H=1 })
 digiline_send("touch", {  command = "addbutton_exit",  name="gohome",  label="Go home",  X=4, Y=1, W=4, H=1 })

 digiline_send("touch", {  command = "addbutton_exit",  name="lock",  label="Lock",  X=4, Y=5, W=4, H=1 })
end

if event.type == "program" then
 update_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", key="x", value=mem.home.x})
  digiline_send("jumpdrive", {command="set", key="y", value=mem.home.y})
  digiline_send("jumpdrive", {command="set", key="z", value=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

Setup