]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_ctfws/commitdiff
examples/ctfws: improve attention-getting behavior
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 18 Feb 2017 07:23:35 +0000 (02:23 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 18 Feb 2017 07:23:35 +0000 (02:23 -0500)
Add beeper!

ctfws-lcd.lua
init2.lua

index 19eca241289b7d5cf46c3c5e2d4776d74b179b22..b9c4f81b3627c17fe23ae4c136b22ddc2ebd6655 100644 (file)
@@ -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)
index 5c58372c79ec189715d56cd0db3e21356c3e8833..127a59fa0d8645c7d43fd01ba7b07fa510bc233d 100644 (file)
--- 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)