Advertisement
cyber_Ahn

BigReactor Control automatic search in network

Aug 25th, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.75 KB | None | 0 0
  1. --BigReactor Info Control
  2. --automatic search in network
  3. --for max 4 Reactors
  4.  
  5. local hw = {}
  6. local hwB = {}
  7. local change_type
  8. --load API
  9. shell.run("delete caAPI")
  10. shell.run("pastebin get EDLdR1nF caAPI")
  11. os.loadAPI("caAPI")
  12. --set monitor
  13. function set_monitor()
  14. local monitor_number = caAPI.get_hardware("monitor")
  15. local found = fs.exists("config/monitor.cfg")
  16. if found == true then
  17. file = fs.open("config/monitor.cfg","r")
  18. local fileData = {}
  19. local line = file.readLine()
  20. repeat
  21. table.insert(fileData,line)
  22. line = file.readLine()
  23. until line == nil
  24. file.close()
  25. monitor_number = fileData[1]
  26. end
  27. mon = peripheral.wrap(monitor_number)
  28. end
  29.  
  30. --search reactores and turbines
  31. function search()
  32. local periList = peripheral.getNames()
  33. for i = 1, #periList do
  34. if peripheral.getType(periList[i]) == "BigReactors-Reactor" then
  35. table.insert(hw,periList[i])
  36. end
  37. end
  38. local periList = peripheral.getNames()
  39. for i = 1, #periList do
  40. if peripheral.getType(periList[i]) == "BigReactors-Turbine" then
  41. table.insert(hwB,periList[i])
  42. end
  43. end
  44. end
  45.  
  46. --draw screen
  47. function draw_screen()
  48. mon.setTextColor(1)
  49. mon.setBackgroundColor(colors.black)
  50. mon.clear()
  51. mon.setCursorPos(2,1)
  52. mon.setTextColor(colors.blue)
  53. num = #hw
  54. numB = #hwB
  55. mon.write("Reactor Control Screen")
  56. mon.setCursorPos(2,2)
  57. mon.write("Found "..num.." Reactors and "..numB.." Turbines")
  58. mon.setCursorPos(50,1)
  59. mon.setBackgroundColor(colors.red)
  60. mon.setTextColor(colors.black)
  61. mon.write("X")
  62. line = 3
  63. for i = 1, #hw do
  64. mon.setCursorPos(2,line)
  65. mon.setBackgroundColor(colors.black)
  66. mon.setTextColor(colors.red)
  67. mon.write("Reactor Port:"..hw[i])
  68. mon.setTextColor(colors.black)
  69. reactor = peripheral.wrap(hw[i])
  70. line = line + 1
  71. mon.setCursorPos(2,line)
  72. stat = reactor.getActive()
  73. if stat == false then
  74. mon.setBackgroundColor(colors.green)
  75. mon.write("Turn On")
  76. else
  77. mon.setBackgroundColor(colors.red)
  78. mon.write("Turn Off")
  79. end
  80. line = line + 1
  81. mon.setBackgroundColor(colors.black)
  82. mon.setTextColor(colors.green)
  83. mon.setCursorPos(2,line)
  84. mon.write("Set Rod:")
  85. mon.write(reactor.getControlRodLevel(0),"%")
  86. mon.write("%")
  87. mon.setBackgroundColor(colors.red)
  88. mon.setTextColor(colors.black)
  89. mon.setCursorPos(20,line)
  90. mon.write("0%")
  91. mon.setCursorPos(24,line)
  92. mon.write("50%")
  93. mon.setCursorPos(29,line)
  94. mon.write("100%")
  95. line = line + 2
  96. end
  97. change_type = line
  98. for i = 1, #hwB do
  99. mon.setCursorPos(2,line)
  100. mon.setBackgroundColor(colors.black)
  101. mon.setTextColor(colors.red)
  102. mon.write("Reactor Port:"..hwB[i])
  103. mon.setTextColor(colors.black)
  104. turbine = peripheral.wrap(hwB[i])
  105. line = line + 1
  106. mon.setCursorPos(2,line)
  107. stat = turbine.getActive()
  108. if stat == false then
  109. mon.setBackgroundColor(colors.green)
  110. mon.write("Turn On")
  111. else
  112. mon.setBackgroundColor(colors.red)
  113. mon.write("Turn Off")
  114. end
  115. line = line + 2
  116. end
  117. mon.setBackgroundColor(colors.black)
  118. mon.setTextColor(colors.white)
  119. touch()
  120. end
  121.  
  122. --touch
  123. function touch()
  124. local ix = true
  125. while ix == true do
  126. event, side, x, y = os.pullEvent()
  127. if event == "monitor_touch" then
  128. if x == 50 and y == 1 then
  129. ix = false
  130. shell.run("clear")
  131. end
  132. if y == 4 then
  133. ix = false
  134. if y > change_type then
  135. if (y - change_type) == 1  then
  136. num = 1
  137. end
  138. if (y - change_type) > 5  then
  139. num = 2
  140. end
  141. if (y - change_type) > 10  then
  142. num = 3
  143. end
  144. if (y - change_type) > 15  then
  145. num = 4
  146. end
  147. if hwB[num] ~= nil then
  148. turbine = peripheral.wrap(hwB[num])
  149. stat = turbine.getActive()
  150. if stat == false then
  151. turbine.setActive(true)
  152. else
  153. turbine.setActive(false)
  154. end
  155. end
  156. else
  157. num  = 1
  158. if hw[num] ~= nil then
  159. reactor = peripheral.wrap(hw[num])
  160. stat = reactor.getActive()
  161. if stat == false then
  162. reactor.setActive(true)
  163. else
  164. reactor.setActive(false)
  165. end
  166. end
  167. end
  168. draw_screen()
  169. end
  170. if y == 8 then
  171. ix = false
  172. if y > change_type then
  173. if (y - change_type) == 1  then
  174. num = 1
  175. end
  176. if (y - change_type) > 5  then
  177. num = 2
  178. end
  179. if (y - change_type) > 10  then
  180. num = 3
  181. end
  182. if (y - change_type) > 15  then
  183. num = 4
  184. end
  185. if hwB[num] ~= nil then
  186. turbine = peripheral.wrap(hwB[num])
  187. stat = turbine.getActive()
  188. if stat == false then
  189. turbine.setActive(true)
  190. else
  191. turbine.setActive(false)
  192. end
  193. end
  194. else
  195. num  = 2
  196. if hw[num] ~= nil then
  197. reactor = peripheral.wrap(hw[num])
  198. stat = reactor.getActive()
  199. if stat == false then
  200. reactor.setActive(true)
  201. else
  202. reactor.setActive(false)
  203. end
  204. end
  205. end
  206. draw_screen()
  207. end
  208. if y == 12 then
  209. ix = false
  210. if y > change_type then
  211. if (y - change_type) == 1  then
  212. num = 1
  213. end
  214. if (y - change_type) > 5  then
  215. num = 2
  216. end
  217. if (y - change_type) > 10  then
  218. num = 3
  219. end
  220. if (y - change_type) > 15  then
  221. num = 4
  222. end
  223. if hwB[num] ~= nil then
  224. turbine = peripheral.wrap(hwB[num])
  225. stat = turbine.getActive()
  226. if stat == false then
  227. turbine.setActive(true)
  228. else
  229. turbine.setActive(false)
  230. end
  231. end
  232. else
  233. num  = 3
  234. if hw[num] ~= nil then
  235. reactor = peripheral.wrap(hw[num])
  236. stat = reactor.getActive()
  237. if stat == false then
  238. reactor.setActive(true)
  239. else
  240. reactor.setActive(false)
  241. end
  242. end
  243. end
  244. draw_screen()
  245. end
  246. if y == 16 then
  247. ix = false
  248. if y > change_type then
  249. if (y - change_type) == 1  then
  250. num = 1
  251. end
  252. if (y - change_type) > 5  then
  253. num = 2
  254. end
  255. if (y - change_type) > 10  then
  256. num = 3
  257. end
  258. if (y - change_type) > 15  then
  259. num = 4
  260. end
  261. if hwB[num] ~= nil then
  262. turbine = peripheral.wrap(hwB[num])
  263. stat = turbine.getActive()
  264. if stat == false then
  265. turbine.setActive(true)
  266. else
  267. turbine.setActive(false)
  268. end
  269. end
  270. else
  271. num  = 4
  272. if hw[num] ~= nil then
  273. reactor = peripheral.wrap(hw[num])
  274. stat = reactor.getActive()
  275. if stat == false then
  276. reactor.setActive(true)
  277. else
  278. reactor.setActive(false)
  279. end
  280. end
  281. end
  282. draw_screen()
  283. end
  284. if y == 5 and x > 19 and x < 24 then
  285. ix = false
  286. num  = 1
  287. if hw[num] ~= nil then
  288. reactor = peripheral.wrap(hw[num])
  289. reactor.setAllControlRodLevels(0)
  290. end
  291. draw_screen()
  292. end
  293. if y == 5 and x > 23 and x < 29 then
  294. ix = false
  295. num  = 1
  296. if hw[num] ~= nil then
  297. reactor = peripheral.wrap(hw[num])
  298. reactor.setAllControlRodLevels(50)
  299. end
  300. draw_screen()
  301. end
  302. if y == 5 and x > 28 and x < 33 then
  303. ix = false
  304. num  = 1
  305. if hw[num] ~= nil then
  306. reactor = peripheral.wrap(hw[num])
  307. reactor.setAllControlRodLevels(100)
  308. end
  309. draw_screen()
  310. end
  311. if y == 9 and x > 19 and x < 24 then
  312. ix = false
  313. num  = 2
  314. if hw[num] ~= nil then
  315. reactor = peripheral.wrap(hw[num])
  316. reactor.setAllControlRodLevels(0)
  317. end
  318. draw_screen()
  319. end
  320. if y == 9 and x > 23 and x < 29 then
  321. ix = false
  322. num  = 2
  323. if hw[num] ~= nil then
  324. reactor = peripheral.wrap(hw[num])
  325. reactor.setAllControlRodLevels(50)
  326. end
  327. draw_screen()
  328. end
  329. if y == 9 and x > 28 and x < 33 then
  330. ix = false
  331. num  = 2
  332. if hw[num] ~= nil then
  333. reactor = peripheral.wrap(hw[num])
  334. reactor.setAllControlRodLevels(100)
  335. end
  336. draw_screen()
  337. end
  338. if y == 13 and x > 19 and x < 24 then
  339. ix = false
  340. num  = 3
  341. if hw[num] ~= nil then
  342. reactor = peripheral.wrap(hw[num])
  343. reactor.setAllControlRodLevels(0)
  344. end
  345. draw_screen()
  346. end
  347. if y == 13 and x > 23 and x < 29 then
  348. ix = false
  349. num  = 3
  350. if hw[num] ~= nil then
  351. reactor = peripheral.wrap(hw[num])
  352. reactor.setAllControlRodLevels(50)
  353. end
  354. draw_screen()
  355. end
  356. if y == 13 and x > 28 and x < 33 then
  357. ix = false
  358. num  = 3
  359. if hw[num] ~= nil then
  360. reactor = peripheral.wrap(hw[num])
  361. reactor.setAllControlRodLevels(100)
  362. end
  363. draw_screen()
  364. end
  365. if y == 17 and x > 19 and x < 24 then
  366. ix = false
  367. num  = 4
  368. if hw[num] ~= nil then
  369. reactor = peripheral.wrap(hw[num])
  370. reactor.setAllControlRodLevels(0)
  371. end
  372. draw_screen()
  373. end
  374. if y == 17 and x > 23 and x < 29 then
  375. ix = false
  376. num  = 4
  377. if hw[num] ~= nil then
  378. reactor = peripheral.wrap(hw[num])
  379. reactor.setAllControlRodLevels(50)
  380. end
  381. draw_screen()
  382. end
  383. if y == 17 and x > 28 and x < 33 then
  384. ix = false
  385. num  = 4
  386. if hw[num] ~= nil then
  387. reactor = peripheral.wrap(hw[num])
  388. reactor.setAllControlRodLevels(100)
  389. end
  390. draw_screen()
  391. end
  392. end
  393. end
  394. end
  395.  
  396. --prog start
  397. set_monitor()
  398. search()
  399. draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement