DEPSTRCZ

uni.lua

Sep 30th, 2022 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.92 KB | None | 0 0
  1. local term = require("term")
  2. local component = require("component")
  3. local computer = require("computer")
  4. local math = require("math")
  5. local event = require("event")
  6. local string = require("string")
  7. local unicode = require("unicode")
  8. local os = require("os")
  9. local fs = require('filesystem')
  10. local gpu = component.gpu
  11. gpu.setResolution(100,50)
  12. br = component.getPrimary("br_turbine")
  13. tur = component.br_turbine
  14. local speed =0
  15. local block = 1
  16. local block2 = 1
  17. local eng23 =0
  18. local kp=10
  19. local ki=0.1
  20. local pid=0
  21. local pid_p=0
  22. local pid_i=0
  23. local pidint = 0
  24. local del = 0
  25. local timer1=0
  26.  
  27.  
  28. local function claim(x,a,b)
  29. if x<a then
  30. return a
  31. end
  32. if x>b then
  33. return b
  34. end
  35. return x
  36. end
  37.  
  38. local function sig(a)
  39. return math.floor(a)
  40. end
  41.  
  42. local function englimit()
  43. if br.getEnergyStored() >= eng23 then
  44. br.setInductorEngaged(false)
  45. elseif br.getEnergyStored() < eng23 then
  46. br.setInductorEngaged(true)
  47. end
  48. end
  49.  
  50. local function speedlimit()
  51. if timer1>5 then
  52. timer1=0
  53. del = speed- tur.getRotorSpeed()
  54. pid_p = kp*del
  55. pid_i = ki*pidint
  56. pid = claim(pid_p+pid_i,1,2000)
  57. pidint=claim((pidint+del),0,2000/ki)
  58. pid=math.floor(pid)
  59. tur.setFluidFlowRateMax(pid)
  60. end
  61. timer1=timer1+1
  62. end
  63.  
  64. local function loadbar(x,y,width,cur,text,bg,fg)
  65. local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
  66. local oldbg = gpu.setBackground(bg)
  67. local oldfg = gpu.setForeground(fg)
  68. gpu.set(x,y,unicode.sub(raw,1,cur))
  69. gpu.setBackground(oldbg)
  70. gpu.setForeground(oldfg)
  71. gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
  72. end
  73.  
  74. local function setColor(bg,fg)
  75. gpu.setBackground(bg)
  76. gpu.setForeground(fg)
  77. end
  78.  
  79. local function bargraph(x,y,length,am,cap,na,col,colpol)
  80. local amount = am
  81. local capacity = cap
  82. local pct = amount / capacity
  83. local cur = math.floor(pct * length)
  84. local color = col
  85. local color2 = colpol
  86. local name = na
  87. local textfrac = string.format("%s / %s", amount, capacity)
  88. local textpct = string.format("%.02f%%", pct*100)
  89. local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 6) .. " " .. textpct .. " "
  90. local text1 = " FILL LEVEL : ("..name..")"
  91. loadbar(x,y,length,cur,text1,color,color2)
  92. loadbar(x,y+1,length,cur,text,color,color2)
  93. end
  94. --747872
  95. local function drawbars()
  96. amFuel = br.getInputAmount()
  97. capFuel = 4000
  98. naFuel = "STEAM"
  99. colFuel = 0x747872
  100. colpolFuel = 0x0000FF
  101. bargraph(2,13,98,amFuel,capFuel,naFuel,colFuel,colpolFuel)
  102. amWaste = br.getOutputAmount()
  103. capWaste = 4000
  104. naWaste = "WATER"
  105. colWaste = 0x00FFFF
  106. colpolWaste = 0xFF00FF
  107. bargraph(2,16,98,amWaste,capWaste,naWaste,colWaste,colpolWaste)
  108. amSteam = br.getRotorSpeed()
  109. capSteam = 3000
  110. naSteam = "ROTOR SPEED"
  111. colSteam = 0x8F8F8F
  112. colpolSteam = 0xFFFF00
  113. bargraph(2,19,98,amSteam,capSteam,naSteam,colSteam,colpolSteam)
  114. amWater = br.getEnergyStored()
  115. capWater = 1000000
  116. naWater = "STORED ENERGY"
  117. colWater = 0x68FF33
  118. colpolWater = 0x0000FF
  119. bargraph(2,22,98,amWater,capWater,naWater,colWater,colpolWater)
  120. en = tur.getEnergyProducedLastTick()
  121. en2 = en * 20
  122. en3 = en2 * 60
  123. en4 = en3 * 60
  124. gpu.set(3,43,string.format("%10f",sig(en)))
  125. gpu.set(25,43,string.format("%10f",sig(en2)))
  126. gpu.set(49,43,string.format("%10f",sig(en3)))
  127. gpu.set(74,43,string.format("%10f",sig(en4)))
  128. amstel = tur.getFluidFlowRate()
  129. gpu.set(19,33, string.format("%10d", speed))
  130. gpu.set(64,32, string.format("%10d", eng23))
  131. if block == 2 then
  132. speedlimit()
  133. end
  134. if block2 == 2 then
  135. englimit()
  136. end
  137. end
  138.  
  139. local function work(h,m)
  140. gpu.set(h,m," ")
  141. gpu.set(h,m+1," PWOER ON ")
  142. gpu.set(h,m+2," ")
  143. end
  144.  
  145. local function nwork(h,m)
  146. gpu.set(h,m," ")
  147. gpu.set(h,m+1," POWER OFF ")
  148. gpu.set(h,m+2," ")
  149. end
  150.  
  151. local function POWER()
  152. local ON = br.getActive()
  153. if ON == true then
  154. setColor(0x00FF00,0x000000)
  155. work(87,2)
  156. setColor(0x000000,0xFF0000)
  157. nwork(87,6)
  158. setColor(0x000000,0xFFFFFF)
  159. elseif ON == false then
  160. setColor(0x000000,0x00FF00)
  161. work(87,2)
  162. setColor(0xFF0000,0xFFFFFF)
  163. nwork(87,6)
  164. setColor(0x000000,0xFFFFFF)
  165. end
  166.  
  167. end
  168.  
  169. local function INGUCKTOR()
  170. local ONLINE = tur.getInductorEngaged()
  171. if ONLINE == true then
  172. setColor(0x00FF00,0x000000)
  173. work(55,2)
  174. setColor(0x000000,0xFF0000)
  175. nwork(55,6)
  176. setColor(0x000000,0xFFFFFF)
  177. elseif ONLINE == false then
  178. setColor(0x000000,0x00FF00)
  179. work(55,2)
  180. setColor(0xFF0000,0xFFFFFF)
  181. nwork(55,6)
  182. setColor(0x000000,0xFFFFFF)
  183. end
  184.  
  185. end
  186.  
  187. local function SPEEDINDICATOR()
  188. if block == 2 then
  189. setColor(0x00FF00,0x000000)
  190. work(33,28)
  191. setColor(0x000000,0xFF0000)
  192. nwork(3,28)
  193. setColor(0x000000,0xFFFFFF)
  194. elseif block == 1 then
  195. setColor(0x000000,0x00FF00)
  196. work(33,28)
  197. setColor(0xFF0000,0xFFFFFF)
  198. nwork(3,28)
  199. setColor(0x000000,0xFFFFFF)
  200. end
  201. end
  202.  
  203. local function ENGINDICATOR()
  204. if block2 == 2 then
  205. setColor(0x00FF00,0x000000)
  206. work(78,28)
  207. setColor(0x000000,0xFF0000)
  208. nwork(48,28)
  209. setColor(0x000000,0xFFFFFF)
  210. elseif block2 == 1 then
  211. setColor(0x000000,0x00FF00)
  212. work(78,28)
  213. setColor(0xFF0000,0xFFFFFF)
  214. nwork(48,28)
  215. setColor(0x000000,0xFFFFFF)
  216. end
  217. end
  218.  
  219. term.clear()
  220. gpu.set(1,1,"╔══════════════════════════════════╦════════════════╦══════════════╦════════════════╦══════════════╗")
  221. gpu.set(1,2,"║ ║ ║ ████████████ ║ ║ ████████████ ║")
  222. gpu.set(1,3,"║ ║ ║ █POWER ON █ ║ ║ █POWER ON █ ║")
  223. gpu.set(1,4,"║ ║ COIL ║ ████████████ ║ MAIN ║ ████████████ ║")
  224. gpu.set(1,5,"║ ║ -->╠══════════════╣ -->╠══════════════╣")
  225. gpu.set(1,6,"║ ║ CONTROL ║ ████████████ ║ SWITCH ║ ████████████ ║")
  226. gpu.set(1,7,"║ ║ ║ █POWER OFF █ ║ ║ █POWER OFF █ ║")
  227. gpu.set(1,8,"║ ║ ║ ████████████ ║ ║ ████████████ ║")
  228. gpu.set(1,9,"╠══════════════════════════════════╩════════════════╩══════════════╩════════════════╩══════════════╣")
  229. gpu.set(1,10,"║ ║")
  230. gpu.set(1,11,"║ ║")
  231. gpu.set(1,12,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  232. gpu.set(1,13,"║ ║")
  233. gpu.set(1,14,"║ ║")
  234. gpu.set(1,15,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  235. gpu.set(1,16,"║ ║")
  236. gpu.set(1,17,"║ ║")
  237. gpu.set(1,18,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  238. gpu.set(1,19,"║ ║")
  239. gpu.set(1,20,"║ ║")
  240. gpu.set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  241. gpu.set(1,22,"║ ║")
  242. gpu.set(1,23,"║ ║")
  243. gpu.set(1,24,"╠════════════════════════════════════════════╦════════════════════════════════════════════╦════════╣")
  244. gpu.set(1,25,"║ SPEED CONTROL ║ ENERGY BUFFER MANAGMENT ║ ║")
  245. gpu.set(1,26,"║ ║ ║ ║")
  246. gpu.set(1,27,"╠══════════════╦══════════════╦══════════════╣══════════════╦══════════════╦══════════════╣ ║")
  247. gpu.set(1,28,"║ ████████████ ║ ║ ████████████ ║ ████████████ ║ ║ ████████████ ║ ║")
  248. gpu.set(1,29,"║ █POWER ON █ ║ ║ █POWER OFF █ ║ █POWER ON █ ║ ║ █POWER OFF █ ║ ║")
  249. gpu.set(1,30,"║ ████████████ ║ ║ ████████████ ║ ████████████ ║ ║ ████████████ ║ ║")
  250. gpu.set(1,31,"╠══════════════╝ ╚══════════════╠══════════════╝ ╚══════════════╣ ║")
  251. gpu.set(1,32,"║ ► +1000 ◄ | | ► -1000 ◄ ║ ► +100000 ◄ | | ► -100000 ◄ ║ ║")
  252. gpu.set(1,33,"║ ► +100 ◄ | | ► -100 ◄ ║ ► +10000 ◄ | | ► -10000 ◄ ║ ║")
  253. gpu.set(1,34,"║ ► +10 ◄ | | ► -10 ◄ ║ ► +1000 ◄ | | ► -1000 ◄ ║ ║")
  254. gpu.set(1,35,"║ ► +1 ◄ | | ► -1 ◄ ║ ► +100 ◄ | | ► -100 ◄ ║ ║")
  255. gpu.set(1,36,"╠════════════════════════════════════════════╩════════════════════════════════════════════╩════════╣")
  256. gpu.set(1,37,"║ GENERATED ENERGY ║")
  257. gpu.set(1,38,"╠═════════════════════╦═══════════════════════╦════════════════════════╦═══════════════════════════╣")
  258. gpu.set(1,39,"║ REDSTONEFLUX/TICK ║ REDSTONEFLUX/SECOND ║ REDSTONEFLUX/MINUTS ║ REDSTONEFLUX/HOURSE ║")
  259. gpu.set(1,40,"║ ║ ║ ║ ║")
  260. gpu.set(1,41,"║ RF/T ║ RF/SEC ║ RF/M ║ RF/H ║")
  261. gpu.set(1,42,"║ ║ ║ ║ ║")
  262. gpu.set(1,43,"║ ║ ║ ║ ║")
  263. gpu.set(1,44,"╠═════════════════════╩═══════════════════════╩════════════════════════╩═══════════════════════════╣")
  264. gpu.set(1,45,"║ ║")
  265. gpu.set(1,46,"║ ║")
  266. gpu.set(1,47,"║ ║")
  267. gpu.set(1,48,"║ ║")
  268. gpu.set(1,49,"║ ║")
  269. gpu.set(1,50,"╚══════════════════════════════════════════════════════════════════════════════════════════════════╝")
  270.  
  271. POWER()
  272. INGUCKTOR()
  273. SPEEDINDICATOR()
  274. ENGINDICATOR()
  275.  
  276. local function onTouch(event,adress,x,y,clic,pseudo)
  277. if x==1 and y==1 then
  278. computer.pushSignal("quit")
  279. term.setCursor(1,1)
  280. return false
  281. elseif x > 85 and x < 100 and y > 1 and y < 5 then
  282. br.setActive(true)
  283. POWER()
  284. elseif x > 85 and x < 100 and y > 5 and y < 9 then
  285. br.setActive(false)
  286. POWER()
  287. elseif x > 54 and x < 67 and y > 1 and y < 5 then
  288. br.setInductorEngaged(true)
  289. INGUCKTOR()
  290. elseif x > 54 and x < 67 and y > 5 and y < 9 then
  291. br.setInductorEngaged(false)
  292. INGUCKTOR()
  293. elseif x > 2 and x < 15 and y > 28 and y < 30 then
  294. block = 1
  295. SPEEDINDICATOR()
  296. elseif x > 32 and x < 45 and y > 28 and y < 30 then
  297. block = 2
  298. SPEEDINDICATOR()
  299. elseif x > 47 and x < 60 and y > 28 and y < 30 then
  300. block2 = 1
  301. ENGINDICATOR()
  302. INGUCKTOR()
  303. elseif x > 77 and x < 90 and y > 28 and y < 30 then
  304. block2 = 2
  305. ENGINDICATOR()
  306. INGUCKTOR()
  307. elseif x > 50 and x < 57 and y == 32 then -- скорость +1000
  308. if eng23 >= 900000 then
  309. eng23 = 1000000
  310. else
  311. eng23 = eng23 + 100000
  312. end
  313. gpu.set(64,32, string.format("%10d", eng23))
  314. elseif x > 50 and x < 57 and y == 33 then -- скорость +100
  315. if eng23 >= 990000 then
  316. eng23 = 1000000
  317. else
  318. eng23 = eng + 10000
  319. end
  320. gpu.set(64,32, string.format("%10d", eng23))
  321. elseif x > 50 and x < 57 and y == 34 then -- скорость +10
  322. if eng23 >= 999000 then
  323. eng23 = 1000000
  324. else
  325. eng23 = eng23 + 1000
  326. end
  327. gpu.set(64,32, string.format("%10d", eng23))
  328. elseif x > 50 and x < 57 and y == 35 then -- скорость +1
  329. if eng23 >= 999900 then
  330. eng23 = 1000000
  331. else
  332. eng23 = eng23 + 100
  333. end
  334. gpu.set(64,32, string.format("%10d", eng23))
  335. elseif x > 80 and x < 87 and y == 32 then -- скорость -1000
  336. if eng23 <= 100000 then
  337. eng23 = 0
  338. else
  339. eng23 = eng23 - 100000
  340. end
  341. gpu.set(64,32, string.format("%10d", eng23))
  342. elseif x > 80 and x < 87 and y == 33 then -- скорость -100
  343. if eng23 <= 10000 then
  344. eng23 = 0
  345. else
  346. eng23 = eng23 - 10000
  347. end
  348. gpu.set(64,32, string.format("%10d", eng23))
  349. elseif x > 80 and x < 87 and y == 34 then -- скорость -10
  350. if eng23 <= 1000 then
  351. eng23 = 0
  352. else
  353. eng23 = eng23 - 1000
  354. end
  355. gpu.set(64,32, string.format("%10d", eng23))
  356. elseif x > 80 and x < 87 and y == 35 then -- скорость -1
  357. if eng23 <= 100 then
  358. eng23 = 0
  359. else
  360. eng23 = eng23 - 100
  361. end
  362. gpu.set(64,32, string.format("%10d", eng23))
  363. elseif x > 2 and x < 15 and y == 32 then -- скорость +1000
  364. if speed >= 2000 then
  365. speed = 3000
  366. else
  367. speed = speed + 1000
  368. end
  369. gpu.set(19,33, string.format("%10d", speed))
  370. elseif x > 2 and x < 15 and y == 33 then -- скорость +100
  371. if speed >= 2900 then
  372. speed = 3000
  373. else
  374. speed = speed + 100
  375. end
  376. gpu.set(19,33, string.format("%10d", speed))
  377. elseif x > 2 and x < 15 and y == 34 then -- скорость +10
  378. if speed >= 2990 then
  379. speed = 3000
  380. else
  381. speed = speed + 10
  382. end
  383. gpu.set(19,33, string.format("%10d", speed))
  384. elseif x > 2 and x < 15 and y == 35 then -- скорость +1
  385. if speed >= 2999 then
  386. speed = 3000
  387. else
  388. speed = speed + 1
  389. end
  390. gpu.set(19,33, string.format("%10d", speed))
  391. elseif x > 31 and x < 44 and y == 32 then -- скорость -1000
  392. if speed <= 1000 then
  393. speed = 0
  394. else
  395. speed = speed - 1000
  396. end
  397. gpu.set(19,33, string.format("%10d", speed))
  398. elseif x > 31 and x < 44 and y == 33 then -- скорость -100
  399. if speed <= 100 then
  400. speed = 0
  401. else
  402. speed = speed - 100
  403. end
  404. gpu.set(19,33, string.format("%10d", speed))
  405. elseif x > 31 and x < 44 and y == 34 then -- скорость -10
  406. if speed <= 10 then
  407. speed = 0
  408. else
  409. speed = speed - 10
  410. end
  411. gpu.set(19,33, string.format("%10d", speed))
  412. elseif x > 31 and x < 44 and y == 35 then -- скорость -1
  413. if speed <= 1 then
  414. speed = 0
  415. else
  416. speed = speed - 1
  417. end
  418. gpu.set(19,33, string.format("%10d", speed))
  419. end
  420. end
  421.  
  422. local function onTimer(_,timer)
  423. drawbars()
  424. return true
  425. end
  426.  
  427. event.listen("touch",onTouch)
  428. local timer = event.timer(0,onTimer,math.huge)
  429. event.pull("quit")
  430. event.cancel(timer)
  431. event.ignore("touch",onTouch)
  432. component.gpu.setResolution(100,50)
  433. term.clear()
Advertisement
Add Comment
Please, Sign In to add comment