Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURAZIONE
- -- Lato stampante
- LPT = "right"
- -- Lato floppy
- fd = "left"
- -- DICHIARAZIONE VARIABILI
- -- contatori totali
- consumoTotale = 0
- immissioneTotale = 0
- cliente = nil
- -- spese fisse totali
- speseFisseConsTotali = 0
- speseFisseImmTotali = 0
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
- "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then term.setBackgroundColor(nColour) end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
- end
- -- Icone
- function disegnaAvviso()
- drawFilledBox(5, 6, 13, 13, colours.yellow)
- for i = 7, 12, 1 do
- paintutils.drawPixel(9, i, colours.black)
- paintutils.drawPixel(9, 11, colours.yellow)
- end
- end
- function disegnaFloppy()
- drawFilledBox(4, 5, 18, 15, colours.lime)
- drawFilledBox(7, 5, 15, 8, colours.lightGrey)
- drawFilledBox(13, 6, 14, 7, colours.lime)
- drawFilledBox(5, 10, 17, 15, colours.white)
- paintutils.drawPixel(18, 5, colours.black)
- end
- function disegnaFoglio()
- drawFilledBox(4, 5, 18, 15, colours.white)
- paintutils.drawPixel(6, 12, colours.lime)
- paintutils.drawPixel(7, 13, colours.lime)
- paintutils.drawPixel(8, 14, colours.lime)
- px = 9
- py = 13
- for i = 1, 8, 1 do
- paintutils.drawPixel(px, py, colours.lime)
- px = px + 1
- py = py - 1
- end
- end
- function disegnaStampante()
- drawFilledBox(4, 10, 18, 15, colours.lightGrey)
- drawFilledBox(6, 6, 16, 10, colours.white)
- drawFilledBox(6, 14, 16, 14, colours.grey)
- end
- -- Funzione pulisci
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Funzioni colori
- function colore(sfumatura) term.setTextColour(sfumatura) end
- function fineColore() term.setTextColour(colours.white) end
- function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
- function fineSfondo() term.setBackgroundColour(colours.black) end
- -- Disegna il Titolo
- function disegnaTitolo()
- local tx, ty = term.getCursorPos()
- term.setCursorPos(1, 1)
- colore(colours.black)
- sfondo(colours.yellow)
- print(" Creazione Guidata Bolletta ")
- fineColore()
- fineSfondo()
- term.setCursorPos(tx, ty)
- end
- -- Schermata Consumo
- function finestraConsumo()
- -- Schermata iniziale
- clear()
- sfondo(colours.black)
- term.clear()
- disegnaTitolo()
- term.setCursorPos(1, 3)
- print(
- "Inserire i dati richiesti. Se il campo åA8 corretto, diventeråA0 verde. In caso contrario il computer chiederåA0 di reinserire il dato. Per annullare premere CTRL+T.")
- -- Intestatario del contratto
- term.setCursorPos(1, 9)
- term.write("Intestatario:")
- term.setCursorPos(15, 9)
- fineColore()
- if cliente == nil or cliente == "" then cliente = read() end
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(cliente)
- fineColore()
- -- Lettura contatore consumo
- colore(colours.white)
- term.setCursorPos(1, 11)
- term.write("Consumo (Wh):")
- term.setCursorPos(15, 11)
- fineColore()
- consumoAccettato = false
- conteggioErrori = 0
- while consumoAccettato == false do
- consumo = read()
- colore(colours.white)
- term.setCursorPos(14, 11)
- fineColore()
- if tonumber(consumo) == "" or tonumber(consumo) == nil or
- tonumber(consumo) < 0 then
- term.setCursorPos(15, 11)
- colore(colours.red)
- term.write("Il dato immesso non corrisponde ")
- fineColore()
- sleep(2)
- term.setCursorPos(15, 11)
- term.write(" ")
- term.setCursorPos(15, 11)
- else
- term.setCursorPos(15, 11)
- colore(colours.lime)
- term.write(consumo .. " Wh")
- consumoAccettato = true
- end
- end
- -- Lettura spese fisse
- colore(colours.white)
- term.setCursorPos(1, 13)
- term.write("Spese fisse:")
- term.setCursorPos(15, 13)
- fineColore()
- local sfAccettate = false
- conteggioErrori = 0
- while sfAccettate == false do
- speseFisseCons = read()
- colore(colours.white)
- term.setCursorPos(14, 13)
- fineColore()
- if tonumber(speseFisseCons) == "" or tonumber(speseFisseCons) == nil or
- tonumber(speseFisseCons) < 0 then
- term.setCursorPos(15, 13)
- colore(colours.red)
- term.write("Il dato immesso non corrisponde ")
- fineColore()
- sleep(2)
- term.setCursorPos(15, 13)
- term.write(" ")
- term.setCursorPos(15, 13)
- else
- term.setCursorPos(15, 13)
- colore(colours.lime)
- term.write(speseFisseCons .. " IC")
- sfAccettate = true
- end
- end
- -- Calcolo totale contatore consumo
- consumoTotale = consumoTotale + math.floor(consumo / 1000000)
- speseFisseConsTotali = speseFisseConsTotali + speseFisseCons
- end
- -- Schermata immissione
- function finestraImmissione()
- -- Schermata iniziale
- clear()
- sfondo(colours.black)
- term.clear()
- disegnaTitolo()
- term.setCursorPos(1, 3)
- print(
- "Inserire i dati richiesti. Se il campo åA8 corretto, diventeråA0 verde. In caso contrario il computer chiederåA0 di reinserire il dato. Per annullare premere CTRL+T.")
- -- Intestatario del contratto
- term.setCursorPos(1, 9)
- term.write("Intestatario:")
- fineColore()
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(cliente)
- fineColore()
- -- Lettura contatore immissione
- colore(colours.white)
- term.setCursorPos(1, 11)
- term.write("Immiss. (Wh):")
- term.setCursorPos(15, 11)
- fineColore()
- immissioneAccettata = false
- conteggioErrori = 0
- while immissioneAccettata == false do
- immissione = read()
- colore(colours.white)
- term.setCursorPos(14, 11)
- fineColore()
- if tonumber(immissione) == "" or tonumber(immissione) == nil or
- tonumber(immissione) < 0 then
- term.setCursorPos(15, 11)
- colore(colours.red)
- term.write("Il dato immesso non corrisponde ")
- fineColore()
- sleep(2)
- term.setCursorPos(15, 11)
- term.write(" ")
- term.setCursorPos(15, 11)
- else
- term.setCursorPos(15, 11)
- colore(colours.lime)
- term.write(immissione .. " Wh")
- immissioneAccettata = true
- end
- end
- -- Lettura spese fisse
- colore(colours.white)
- term.setCursorPos(1, 13)
- term.write("Spese fisse:")
- term.setCursorPos(15, 13)
- fineColore()
- local sfImmAccettate = false
- conteggioErrori = 0
- while sfImmAccettate == false do
- speseFisseImm = read()
- colore(colours.white)
- term.setCursorPos(14, 13)
- fineColore()
- if tonumber(speseFisseImm) == "" or tonumber(speseFisseImm) == nil or
- tonumber(speseFisseImm) < 0 then
- term.setCursorPos(15, 13)
- colore(colours.red)
- term.write("Il dato immesso non corrisponde ")
- fineColore()
- sleep(2)
- term.setCursorPos(15, 13)
- term.write(" ")
- term.setCursorPos(15, 13)
- else
- term.setCursorPos(15, 13)
- colore(colours.lime)
- term.write(speseFisseImm .. " IC")
- sfImmAccettate = true
- end
- end
- -- Calcolo totale contatore immissione
- immissioneTotale = immissioneTotale + math.floor(immissione / 1000000)
- speseFisseImmTotali = speseFisseImmTotali + speseFisseImm
- end
- -- MAIN LOOP
- -- DEL PROGRAMMA
- -- Stampante
- lpt = peripheral.wrap(LPT)
- sfondo(colors.black)
- clear()
- -- Disegna la finestra per i dati del consumo
- local dialogoAltroCont = false
- while dialogoAltroCont == false do
- finestraConsumo()
- -- Question box per un altro contatore
- clear()
- disegnaTitolo()
- colore(colors.black)
- sfondo(colors.yellow)
- term.setCursorPos(14, 7)
- term.write(" Consumo ")
- drawFilledBox(14, 8, 37, 14, colors.lightBlue)
- term.setCursorPos(15, 9)
- term.write("Inserire un altro")
- term.setCursorPos(15, 10)
- term.write("contatore consumo?")
- colore(colors.black)
- sfondo(colors.red)
- term.setCursorPos(16, 13)
- term.write(" No ")
- colore(colors.black)
- sfondo(colors.lime)
- term.setCursorPos(28, 13)
- term.write(" Si ")
- fineSfondo()
- fineColore()
- local scelta = false
- while scelta == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 16 and x < 24 and y == 13 then
- scelta = true
- dialogoAltroCont = true
- elseif event == "mouse_click" and x > 28 and x < 36 and y == 13 then
- scelta = true
- dialogoAltroCont = false
- end
- end
- end
- clear()
- disegnaTitolo()
- sleep(0.5)
- -- Question box per il Doppio Contatore
- colore(colors.black)
- sfondo(colors.yellow)
- term.setCursorPos(14, 7)
- term.write(" Immissione ")
- drawFilledBox(14, 8, 37, 14, colors.lightBlue)
- term.setCursorPos(15, 9)
- term.write("Il cliente possiede")
- term.setCursorPos(15, 10)
- term.write("il Doppio Contatore?")
- colore(colors.black)
- sfondo(colors.red)
- term.setCursorPos(16, 13)
- term.write(" No ")
- colore(colors.black)
- sfondo(colors.lime)
- term.setCursorPos(28, 13)
- term.write(" Si ")
- fineColore()
- fineSfondo()
- local dialogoDC = false
- while dialogoDC == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 16 and x < 24 and y == 13 then
- utenteConDC = false
- dialogoDC = true
- elseif event == "mouse_click" and x > 28 and x < 36 and y == 13 then
- utenteConDC = true
- dialogoDC = true
- end
- end
- -- debug only
- if utenteConDC == true then
- print("ACC-M")
- finDC = false
- while finDC == false do
- finestraImmissione()
- clear()
- disegnaTitolo()
- sleep(0.5)
- -- Question box per il Doppio Contatore
- colore(colors.black)
- sfondo(colors.yellow)
- term.setCursorPos(14, 7)
- term.write(" Immissione ")
- drawFilledBox(14, 8, 37, 14, colors.lightBlue)
- term.setCursorPos(15, 9)
- term.write("Inserire un altro")
- term.setCursorPos(15, 10)
- term.write("contatore immissione?")
- colore(colors.black)
- sfondo(colors.red)
- term.setCursorPos(16, 13)
- term.write(" No ")
- colore(colors.black)
- sfondo(colors.lime)
- term.setCursorPos(28, 13)
- term.write(" Si ")
- local dialogoAltroDC = false
- while dialogoAltroDC == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 16 and x < 24 and y == 13 then
- dialogoAltroDC = true
- finDC = true
- elseif event == "mouse_click" and x > 28 and x < 36 and y == 13 then
- finDC = false
- dialogoAltroDC = true
- end
- end
- end
- end
- fineSfondo()
- fineColore()
- clear()
- disegnaTitolo()
- term.setCursorPos(1, 3)
- print("Riepilogo:\n")
- -- Controllo variabili
- if consumoTotale == nil or consumoTotale == "" then consumoTotale = 0 end
- if immissioneTotale == nil or immissioneTotale == "" then immissioneTotale = 0 end
- if speseFisseConsTotali == nil or speseFisseConsTotali == "" then
- speseFisseConsTotali = 0
- end
- if speseFisseImmTotali == nil or speseFisseImmTotali == "" then
- speseFisseImmTotali = 0
- end
- colore(colors.lightGray)
- print("Energia")
- fineColore()
- print(" Consumo : " .. consumoTotale .. " IC")
- print(" Immissione : " .. immissioneTotale .. " IC\n")
- colore(colors.lightGray)
- term.setCursorPos(26, 5)
- print("Spese Fisse")
- fineColore()
- term.setCursorPos(27, 6)
- print(" S.F. consumo : " .. speseFisseConsTotali .. " IC")
- term.setCursorPos(27, 7)
- print(" S.F. immi : " .. speseFisseImmTotali .. " IC\n")
- -- Calcoli
- subtEnergia = consumoTotale - immissioneTotale
- subtSF = speseFisseConsTotali + speseFisseImmTotali
- granTotale = subtEnergia + subtSF
- colore(colors.lightGray)
- print("Subtotali")
- fineColore()
- print(" Subt. energia : " .. subtEnergia .. " IC")
- print(" Subt. S.F. : " .. subtSF .. " IC\n")
- colore(colors.yellow)
- print("Gran Totale : " .. granTotale .. " IC")
- term.setCursorPos(9, 17)
- sfondo(colors.red)
- colore(colors.black)
- term.write(" Annulla ")
- term.setCursorPos(28, 17)
- sfondo(colors.lime)
- colore(colors.black)
- term.write(" Conferma ")
- fineColore()
- fineSfondo()
- local scelta = false
- while scelta == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 9 and x < 23 and y == 17 then
- scelta = true
- continua = false
- elseif event == "mouse_click" and x > 28 and x < 42 and y == 17 then
- scelta = true
- continua = true
- end
- end
- clear()
- if continua == true then
- -- Recupera data
- local phpdate = http.get("http://172.16.20.220/data.php?q=ergb")
- local date = phpdate.readAll()
- phpdate.close()
- -- Stampa
- stampantePronta = false
- while stampantePronta == false do
- if lpt.getPaperLevel() == 0 then
- clear()
- disegnaTitolo()
- disegnaAvviso()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Inserire")
- term.setCursorPos(22, 10)
- term.write("carta")
- term.setCursorPos(22, 11)
- term.write("nella stampante")
- term.setCursorPos(22, 13)
- sfondo(colors.lime)
- term.write(" OK ")
- fineSfondo()
- attesa = false
- while attesa == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 22 and x < 31 and y == 13 then
- attesa = true
- end
- end
- elseif lpt.getInkLevel() == 0 then
- clear()
- disegnaTitolo()
- disegnaAvviso()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Inserire")
- term.setCursorPos(22, 10)
- term.write("inchiostro")
- term.setCursorPos(22, 11)
- term.write("nella stampante")
- term.setCursorPos(22, 13)
- sfondo(colors.lime)
- term.write(" OK ")
- fineSfondo()
- attesa = false
- while attesa == false do
- event, key, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x > 22 and x < 31 and y == 13 then
- attesa = true
- end
- end
- else
- stampantePronta = true
- end
- end
- clear()
- disegnaTitolo()
- disegnaStampante()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Stampa")
- term.setCursorPos(22, 10)
- term.write("bolletta")
- term.setCursorPos(22, 11)
- term.write("in corso")
- term.setCursorPos(22, 13)
- lpt.newPage()
- lpt.setPageTitle("Bolletta eRGB - "..cliente)
- lpt.write("¥BB Bolletta eRGB")
- lpt.setCursorPos(1,3)
- lpt.write("Cliente:")
- lpt.setCursorPos(10,3)
- lpt.write(cliente)
- lpt.setCursorPos(1,4)
- lpt.write("Data:")
- lpt.setCursorPos(10,4)
- lpt.write(date)
- lpt.setCursorPos(1,6)
- lpt.write("¥BB Letture")
- lpt.setCursorPos(1,8)
- lpt.write("Consumo:")
- lpt.setCursorPos(10,8)
- lpt.write(consumoTotale.." IC")
- lpt.setCursorPos(1,9)
- lpt.write("Immiss.:")
- lpt.setCursorPos(10,9)
- lpt.write(immissioneTotale.." IC")
- lpt.setCursorPos(1,11)
- lpt.write("¥BB Spese fisse")
- lpt.setCursorPos(1,13)
- lpt.write("Consumo:")
- lpt.setCursorPos(10,13)
- lpt.write(speseFisseConsTotali.." IC")
- lpt.setCursorPos(1,14)
- lpt.write("Immiss.:")
- lpt.setCursorPos(10,14)
- lpt.write(speseFisseConsTotali.." IC")
- lpt.setCursorPos(1,16)
- lpt.write("¥BB Totale")
- lpt.setCursorPos(1,18)
- lpt.write(granTotale.." IC")
- lpt.setCursorPos(1,20)
- lpt.write("Grazie per aver scelto")
- lpt.setCursorPos(1,21)
- lpt.write("eRGB")
- lpt.endPage()
- sleep(2)
- -- tabella disco
- be = {}
- be.UICnumber = cliente
- be.date = date
- be.totale = granTotale
- bedisco = textutils.serialize(be)
- -- Messaggio inserire il disco
- clear()
- if disk.isPresent(fd) == false then
- disegnaTitolo()
- disegnaFloppy()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Inserire il")
- term.setCursorPos(22, 10)
- term.write("Disco Bolletta Elettronica")
- term.setCursorPos(22, 11)
- term.write("nel lettore floppy")
- event, latoFloppy = os.pullEvent("disk")
- end
- disk.setLabel(fd, "DBE - "..cliente)
- local handle = assert(fs.open("disk/be", "w"), "TOC ERROR")
- handle.write(bedisco)
- handle.close()
- clear()
- disk.eject(fd)
- disegnaFoglio()
- fineColore()
- fineSfondo()
- term.setCursorPos(22, 9)
- term.write("Completato!")
- term.setCursorPos(22, 10)
- term.write("Ritirare la bolletta")
- term.setCursorPos(22, 11)
- term.write("e il disco floppy.")
- sleep(2)
- clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement