From 1fb87ecdc3eb4a09210c23dc1e9db3a2045c59cc Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 18 Feb 2017 02:23:35 -0500 Subject: [PATCH] examples/ctfws: improve attention-getting behavior Add beeper! --- ctfws-lcd.lua | 22 +++++++++++++++++----- init2.lua | 6 ++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ctfws-lcd.lua b/ctfws-lcd.lua index 19eca24..b9c4f81 100644 --- a/ctfws-lcd.lua +++ b/ctfws-lcd.lua @@ -68,17 +68,25 @@ local function drawSteadyBotLine(self,rix,maxt,rem) drawDS(lcd,3,13,maxt,self.dl_remain ,rem); self.dl_remain = rem end -local function attention(self) +local function attention(self,long) if self.attnState then return end local tq = self.tq local lcd = self.lcd local function doBlink() - if self.attnState <= 0 then self.attnState = nil ; return end + if self.attnState <= 0 then + self.attnState = nil + gpio.write(5,gpio.HIGH) -- silence beeper always + return + end self.attnState = self.attnState - 1 + -- blink lcd:light(false) tq:queue(250, function() lcd:light(true); tq:queue(500, doBlink) end) + -- chirp or scream + gpio.write(5,gpio.LOW) + if not long then tq:queue(100, function() gpio.write(5,gpio.HIGH) end) end end self.attnState = 2 @@ -92,10 +100,14 @@ local function drawTimes(self) local rix, maxt, ela = ctfws:times(rtctime.get) if rix == nil then drawNoGame(self.lcd, maxt) + if rix ~= self.dl_round then + self.dl_round = rix + attention(self,true) + end return false end if rix ~= self.dl_round then - if self.dl_round ~= nil then attention(self) end -- XXX beep when not forcibly reset + if self.dl_round ~= nil then attention(self,true) end self.dl_round = rix self.dl_elapsed = nil -- force redraws of times on round boundaries self.dl_remain = nil @@ -116,7 +128,7 @@ local function drawFlags(self) ctfws.flagsN, tostring(ctfws.flagsR), tostring(ctfws.flagsY)) :sub(1,20) lcd:put(lcd:locate(1,(20-#str)/2), str) - attention(self) + attention(self,false) end end @@ -147,7 +159,7 @@ local function drawMessage(self, msg) end self.mtmr:alarm(300, tmr.ALARM_AUTO, scroller) end - attention(self) + attention(self,false) end local function reset(self) diff --git a/init2.lua b/init2.lua index 5c58372..127a59f 100644 --- a/init2.lua +++ b/init2.lua @@ -11,7 +11,7 @@ end -- Grab some configuration parameters we might need, -- notably, the LCD address -ctfwshw = {} +local ctfwshw = {} if file.open("ctfws-misc.conf","r") then local conf = cjson.decode(file.read() or "") if type(conf) == "table" @@ -21,10 +21,12 @@ if file.open("ctfws-misc.conf","r") then end -- Hardware initialization +print("init2 hw") +gpio.mode(5,gpio.OUTPUT) -- beeper on GPIO14 i2c.setup(0,2,1,i2c.SLOW) -- init i2c on GPIO4 and GPIO5 lcd = dofile("lcd1602.lc")(ctfwshw.lcd or 0x27) tq = (dofile "tq.lc")(tmr.create()) -- give the LCD time to initialize properly -tq:queue(125, function() dofile("init3.lc") end) +tq:queue(125, function() print("init2 go3") dofile("init3.lc") end) -- 2.50.1