added a player folder
This commit is contained in:
parent
b47db0f6d9
commit
7893fa2bd1
4 changed files with 0 additions and 0 deletions
1
player/autorun.lua
Normal file
1
player/autorun.lua
Normal file
|
@ -0,0 +1 @@
|
|||
dofile("main.lua")
|
48
player/letter_display.lua
Normal file
48
player/letter_display.lua
Normal file
|
@ -0,0 +1,48 @@
|
|||
client = mqtt.client("Player", "mqtt.leizour.fr", 8883, true)
|
||||
client:connect("student", "O99Rq8$F12NXzhL5caya")
|
||||
-- CLK (clock) : D15
|
||||
-- DT (data) : D2
|
||||
-- SW (Bouton): D4
|
||||
-- dir = direction de tournage de l'encodeur
|
||||
-- counter = nombre de crans tournés
|
||||
-- button = bouton poussoir
|
||||
|
||||
playing = false
|
||||
mot = ""
|
||||
last_clicked = 0
|
||||
function action(dir, counter, button)
|
||||
cls()
|
||||
lettre = string.char((counter % 26)+65)
|
||||
if button==1 then
|
||||
if playing then
|
||||
client:publish("pendu/lettre", lettre, mqtt.QOS0)
|
||||
else
|
||||
if os.time() - last_clicked > 1 then
|
||||
mot = mot..lettre
|
||||
last_clicked = os.time()
|
||||
else
|
||||
client:publish("pendu/mot", mot, mqtt.QOS0)
|
||||
mot = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
console("Choix lettre : "..lettre)
|
||||
if not playing then
|
||||
console("Mot : "..mot)
|
||||
end
|
||||
end
|
||||
|
||||
function handle_message(len, message, topic_len, topic_name)
|
||||
if topic_name == "pendu/gamestate" then
|
||||
if message == "PLAYING" then
|
||||
playing = true
|
||||
elseif message == "WAITING" then
|
||||
playing = false
|
||||
mot = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
client:subscribe("pendu/gamestate", mqtt.QOS0, handle_message)
|
||||
enc = encoder.attach(pio.GPIO15, pio.GPIO2, pio.GPIO4, action)
|
||||
|
6
player/main.lua
Normal file
6
player/main.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
dofile("screen.lua")
|
||||
|
||||
-- connecte l'écran sur les pins 18 et 19
|
||||
attachscreen(18, 19, 0x3C)
|
||||
|
||||
dofile("letter_display.lua")
|
73
player/screen.lua
Normal file
73
player/screen.lua
Normal file
|
@ -0,0 +1,73 @@
|
|||
function attachscreen(sda, scl, i2cadd)
|
||||
try (
|
||||
function ()
|
||||
i2c.setpins(0,sda,scl)
|
||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE, false, i2cadd)
|
||||
gdisplay.clear()
|
||||
gdisplay.setfont(gdisplay.FONT_LCD)
|
||||
gdisplay.setwrap(false)
|
||||
end,
|
||||
|
||||
function (where, line, error, message)
|
||||
print("Couldn't attach the screen.\nError in "..where.." at "..line.." "..error..": "..message)
|
||||
end,
|
||||
|
||||
function () end
|
||||
)
|
||||
end
|
||||
|
||||
local consolepos = 0
|
||||
local consoletab = {}
|
||||
local consolemax = 6
|
||||
local oledflip = 1
|
||||
|
||||
function flip()
|
||||
oledflip = oledflip+1; if oledflip > 3 then oledflip = 0 end
|
||||
if oledflip==0 then
|
||||
consolemax = 6
|
||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE_FLIP, false, i2cadd)
|
||||
elseif oledflip==1 then
|
||||
consolemax = 6
|
||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE, false, i2cadd)
|
||||
elseif oledflip==2 then
|
||||
consolemax = 13
|
||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.PORTRAIT, false, i2cadd)
|
||||
else
|
||||
consolemax = 13
|
||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.PORTRAIT_FLIP, false, i2cadd)
|
||||
end
|
||||
cls()
|
||||
end
|
||||
|
||||
function cls()
|
||||
if (consolemax==6) then gdisplay.clear()
|
||||
else
|
||||
gdisplay.rect( {0,0}, 128, 9*consolemax, {0,0,0}, {0,0,0} )
|
||||
end
|
||||
if oledflip ~= 1 then gdisplay.clear() end
|
||||
consolepos = 0
|
||||
consoletab={}
|
||||
for i=0, consolemax do
|
||||
consoletab[i] = ""
|
||||
end
|
||||
end
|
||||
|
||||
function console(msg)
|
||||
if (consolepos <= consolemax) then
|
||||
consoletab[consolepos] = msg
|
||||
gdisplay.write({0, consolepos*9},msg)
|
||||
consolepos = consolepos+1
|
||||
else
|
||||
for i = 1, consolemax do
|
||||
consoletab[i-1] = consoletab[i]
|
||||
end
|
||||
consoletab[consolemax] = msg
|
||||
if (consolemax==6) then gdisplay.clear()
|
||||
else
|
||||
gdisplay.rect( {0,0}, 128, 9*consolemax+9, {0,0,0}, {0,0,0} )
|
||||
end
|
||||
for i=0, consolemax do
|
||||
gdisplay.write({0, i*9},consoletab[i])
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue