Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local state = false
- local modemSide = "back"
- local modem = peripheral.wrap(modemSide)
- local width, height = term.getSize()
- local data = {"info","off","Temp",0,"Coolant",0,"Damage",0,"Waste",0)
- local yh,yb = math.floor(height/2+3),height-1
- local xg,xd = 2,width-1
- local buttonY = math.floor(3 * height / 4)
- remoteID = 14
- rednet.open(modemSide)
- local function sendData(Data)
- rednet.send(remoteID,Data)
- end
- -- Fonction pour dessiner le bouton switch ON/OFF au centre
- local function drawButton(state, text)
- --term.clear()
- term.setCursorPos(xg,yh)
- local bgColor = colors.red
- local fgColor = colors.white
- if state then
- bgColor = colors.green
- fgColor = colors.black
- end
- -- Dessine le fond ecran tout en couleur du switch
- for y = yh, yb do
- term.setCursorPos(xg,y)
- term.setBackgroundColor(bgColor)
- term.write(string.rep(" ",xd-xg+1))
- --term.clear()
- end
- -- Calcule la position du texte pour le centrer
- local textLen = #text
- local x = math.floor((width - textLen) / 2) + 1
- local y = math.floor((yh+yb)/2)
- term.setCursorPos(x, y)
- term.setTextColor(fgColor)
- term.write(text)
- end
- -- Fonction d attente d un clic tactile, retourne true si sur le bouton
- local function waitTouch()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- if event == "mouse_click" then
- if y == buttonY then
- return true
- end
- end
- end
- end
- local function chState()
- while true do
- if state then
- drawButton(true, "ON")
- else
- drawButton(false, "OFF")
- end
- -- Attend un clic (toucher) clavier de l utilisateur
- local event, button, x, y = os.pullEvent("mouse_click")
- if y >= yh and y <= yb and x>=xg and x<=xd then
- state = not state -- Change l etat
- sendData(state)
- end
- end
- end
- local function dataDisplay()
- --TODO : display
- end
- local function dataUpdate()
- data = rednet.receive()
- end
- local function main()
- --TODO : multithread incluant le multithread de dataUpdate et chState
- end
Advertisement
Add Comment
Please, Sign In to add comment