TouchBreaker


TouchBreaker is a new way to control your factory connected with bundled cables. With TouchBreaker you can set up 12 different breakers that are displayed and controlled through a touchscreen for easy on/off toggling.



List of features:
Ability to set labels for breakers
Breaker labels are the same color as the wire color they are assigned to.
Each breaker is numbered so you know which breaker to edit.
Colors are listed to help prevent spelling mistakes (the program will not work if the spelling is wrong)
Easy to use setup
Easy to use breaker editor

setup:
1. Place a monitor 2 blocks tall and 3 blocks wide
2. Save the program as startup

You can download touchBreaker using my Package Downloader and typing: package elrond1369 touchBreaker startup
or you can copy this code directly.
startup:
Spoiler

if fs.exists("/config")==false then
term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1,1)
print("Welcome to touchBreaker first time setup")
print("")
print("Enter ouput side")
output = io.read()
print("Enter monitor side")
monitor = io.read()
fs.makeDir("config")
fs.makeDir("dev")
file = io.open("config/output.dat","w")
file:write(output) file:close()
file=io.open("config/monitor.dat","w")
file:write(monitor) file:close()
curDev = 1
while curDev ~= 13 do
file = io.open("/dev/"..curDev..".dat","w")
file:write() file:close()
curDev = curDev + 1
end
end
selected = 0
file = io.open("/config/monitor.dat","r")
monitor = file:read() file:close()
monitor = peripheral.wrap(monitor)
file = io.open("/config/output.dat","r")
output = file:read() file:close()
term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1,1)
print("Welcome to touchBreaker")
print("")
print("Press any char to chage a breaker...")
term.redirect(monitor)
repeat

term.setBackgroundColor(colors.black)
term.setBackgroundColor(colors.black)
term.clear()
devCount = 13
curDev = 1
x=1
while curDev ~= devCount do
  if curDev % 2 == 0 then
   b = 15
   y = 28
  else
   b = 1
   y = 13
  end
  file = io.open("/dev/"..curDev..".dat","r")
  name = file:read()
  if name ~=nil then
   color=file:read() stat = file:read()
   term.setCursorPos(b,x)
   term.setBackgroundColor(colors.black)
   term.setTextColor(colors[color])
   print(name)
   term.setCursorPos(y,x)
   if tonumber(stat)==0 then
	term.setBackgroundColor(colors.red)
   else
	term.setBackgroundColor(colors.lime)
	selected = colors.combine(selected, colors[color])
	rs.setBundledOutput(output,selected)
   end
   term.setTextColor(colors.white)
   print(curDev)
  end
  file:close()
  if curDev % 2 == 0 then
   x=x+2
  end
  curDev = curDev + 1
end
repeat
  event, pram, x, y = os.pullEvent()
until event=="monitor_touch" or event=="char"
if event == "char" then
  term.restore()
  print("Enter slot # 1-12")
  repeat
   slot = tonumber(io.read())
   if slot<1 or slot>12 then
	print("Slot # out of range")
   end
  until slot>0 and slot<13
  print("Enter device name. Leave blank to disable")
  repeat
   name = io.read()
   if string.len(name)>12 then
	print("Name too long")
   end
  until string.len(name)<13
  if name == "" then
   file = io.open("/dev/"..slot..".dat","r")
   file:read() color=file:read() file:close()
   selected = colors.subtract(selected, colors[color])
   rs.setBundledOutput(output,selected)
   file = io.open("/dev/"..slot..".dat","w")
   file:write() file:close()
  else
   print("Enter wire color. Valid colors are:")
   print("white orange magenta lightBlue yellow lime pink gray lightGray cyan purple blue brown green red")
   color = io.read()
   file = io.open("/dev/"..slot..".dat","w")
   file:write(name.."\n"..color.."\n0") file:close()
  end
  term.setBackgroundColor(colors.blue)
  term.clear()
  term.setCursorPos(1,1)
  print("Welcome to touchBreaker")
  print("")
  print("Press any char to chage a breaker...")
  term.redirect(monitor)
end
if event=="monitor_touch"  then
  if x==13 then
   number = y
  end
  if x==28 then
   number = y+1
  end
if x==13 or x==28 then
  file = io.open("/dev/"..number..".dat","r")
  name = file:read()
  if name~=nil then
   color=file:read()
   stat=tonumber(file:read())
   file:close()
   if stat==0 then
	stat=1
   else
	stat=0
	selected = colors.subtract(selected, colors[color])
	rs.setBundledOutput(output,selected)
   end
   file=io.open("/dev/"..number..".dat","w")
   file:write(name.."\n"..color.."\n"..stat)
   file:close()
  end
end
end
until a =="waffles"