Explorar o código

interrupt checks whether state is SETUP mode

etisab %!s(int64=10) %!d(string=hai) anos
pai
achega
db975c6778
Modificáronse 1 ficheiros con 14 adicións e 9 borrados
  1. 14 9
      BUILD/interrupt.lua

+ 14 - 9
BUILD/interrupt.lua

@@ -1,7 +1,8 @@
 -- using timer 5 for short/long press detection
 -- using timer 5 for short/long press detection
 longPress = 3000 -- 3 seconds
 longPress = 3000 -- 3 seconds
 buttonPin = 6 -- GPIO6
 buttonPin = 6 -- GPIO6
-DEBUG = false
+DEBUG = true
+SETUP = false
 
 
 function debugMsg(msg)
 function debugMsg(msg)
   if DEBUG then
   if DEBUG then
@@ -10,22 +11,24 @@ function debugMsg(msg)
 end
 end
 
 
 function shortOrLongPress()
 function shortOrLongPress()
+  level = gpio.read(buttonPin)
+
   debugMsg('The pin value has changed to '..gpio.read(buttonPin))
   debugMsg('The pin value has changed to '..gpio.read(buttonPin))
   debugMsg("detected level " .. level)
   debugMsg("detected level " .. level)
 
 
-  level = gpio.read(buttonPin)
   if level == 0 then -- button depressed
   if level == 0 then -- button depressed
     debugMsg("LONG PRESS TIMER START")
     debugMsg("LONG PRESS TIMER START")
     tmr.alarm(5, longPress, 0, function()
     tmr.alarm(5, longPress, 0, function()
-                                 if DEBUG then
-                                  print("LONG PRESS")
-                                 end 
+                                 debugMsg("LONG PRESS")
                                  dofile('wifiSetup.lua')
                                  dofile('wifiSetup.lua')
                                end)
                                end)
   else -- button released
   else -- button released
+    debugMsg("SETUP STATUS " .. tostring(SETUP))
     tmr.stop(5)
     tmr.stop(5)
-    debugMsg("SHORT PRESS")
-    dofile('sendYo.lua')
+    if not SETUP then
+      debugMsg("SHORT PRESS")
+      dofile('sendYo.lua')
+    end
   end
   end
 end
 end
 
 
@@ -38,8 +41,10 @@ function debounce (func)
     if now - last < delay then
     if now - last < delay then
       tmr.stop(5)
       tmr.stop(5)
       debugMsg("DEBOUNCE PREVENTED EXTRA PRESS")
       debugMsg("DEBOUNCE PREVENTED EXTRA PRESS")
-      debugMsg("DEBOUNCE INTERPRETED AS SHORT PRESS")
-      dofile('sendYo.lua')
+      if not SETUP then
+        debugMsg("DEBOUNCE INTERPRETED AS SHORT PRESS")
+        dofile('sendYo.lua')
+      end
       return
       return
     end
     end