瀏覽代碼

more stable button response, moved to pin D6

Abhinav Sinha 10 年之前
父節點
當前提交
fa673147a6
共有 7 個文件被更改,包括 48 次插入29 次删除
  1. 15 15
      configuration test scripts/index.html
  2. 二進制
      image.jpg
  3. 6 6
      init.lua
  4. 6 4
      interrupt.lua
  5. 7 2
      sendYo.lua
  6. 13 1
      wifiSetup.lua
  7. 1 1
      yorecipient.txt

+ 15 - 15
configuration test scripts/index.html

@@ -1,16 +1,16 @@
-<body>
-	<h1>YO Button setup</h1>
-	<form>
-		Current wifi SSID: <br>
-		<input type="text" value="1" readonly><br>
-		Current wifi password: <br>
-		<input type="text" value="2" readonly><br>
-		Yo Button's IP address: <br>
-		<input type="text" value="3" readonly><br>
-		New SSID: <br>
-		<input type="text" name="newssid"><br>
-		New password: <br>
-		<input type="text" name="newpass"><br>
-		<input type="submit" name="submit">
-	</form>
+<body>
+	<h1>YO Button setup</h1>
+	<form>
+		Current wifi SSID: <br>
+		<input type="text" value="1" readonly><br>
+		Current wifi password: <br>
+		<input type="text" value="2" readonly><br>
+		Yo Button's IP address: <br>
+		<input type="text" value="3" readonly><br>
+		New SSID: <br>
+		<input type="text" name="newssid"><br>
+		New password: <br>
+		<input type="text" name="newpass"><br>
+		<input type="submit" name="submit">
+	</form>
 </body>

二進制
image.jpg


+ 6 - 6
init.lua

@@ -1,7 +1,7 @@
-tmr.alarm(1, 3000, 0, 
-
-function ()
-	print("Starting delayedInit")
-	dofile("interrupt.lua")
-end
+tmr.alarm(1, 3000, 0, 
+
+function ()
+	print("Starting delayedInit")
+	dofile("interrupt.lua")
+end
 )

+ 6 - 4
interrupt.lua

@@ -1,13 +1,15 @@
-gpio.mode(4, gpio.INT, gpio.PULLUP)
+gpio.mode(6, gpio.INT, gpio.PULLUP)
 delay = 0
 setupStarted = 0
 function buttonHandler(level)
    x = tmr.now()
    if x > delay then
    	  --button has been debounced
-   	  print("handler called with level: "..level)
       delay = tmr.now()+50000
-      if level == 1 then
+      tmr.delay(2000)
+      level = gpio.read(6)
+      print("handler called with level: "..level)
+      if level == 0 then
       	--button pressed down initially
       	tmr.alarm(4, 2000, 0, function()
 			setupStarted = 1
@@ -24,4 +26,4 @@ function buttonHandler(level)
    end
 end
 
-gpio.trig(4, "both",buttonHandler)
+gpio.trig(6, "both",buttonHandler)

+ 7 - 2
sendYo.lua

@@ -2,16 +2,21 @@
 file.open("yorecipient.txt", "r")
 print("sending yo to "..file.readline())
 file.close()
+wifi.sleeptype(wifi.NONE_SLEEP)
 
 function generateContentString()
 	file.open("yorecipient.txt", "r")
 	return "api_token=99c680b7-5f9f-48fd-9459-46cda7e1c8fa&username="..string.upper(file.readline())
 end
 
-
+wifi.setmode(wifi.STATION)
 sk = nil
 sk = net.createConnection(net.TCP,0)
-sk:on("receive", function(sck, c) print(c) end )
+sk:on("receive", function(sck, c)
+    print(c)
+    wifi.sleeptype(wifi.MODEM_SLEEP)
+    end)
+    
 sk:on("connection", function(sk, payload)
 						contentString = generateContentString()
 						strlen = string.len(contentString)

+ 13 - 1
wifiSetup.lua

@@ -35,6 +35,11 @@ function updateWithNewValues(payload)
         file.write(newrecipient)
         file.close()
       end
+      setupStarted=0
+end
+
+function serveFile(c, f)
+  
 end
 
 function setupServerResponses()
@@ -50,7 +55,14 @@ function setupServerResponses()
       if(ind[1] ~= nil)then
         payload = string.sub(payload, 1, ind[1])
       end
+      --payload is reduced to the first line
       print(payload)
+      --[[requestedFile = string.match(payload, "/(.+) HTTP")
+      if file.open(requestedFile, "r") then
+        serveFile(conn, requestedFile)
+        return
+      end
+      --]]
       updateWithNewValues(payload)
 
       file.open("yorecipient.txt", "r")
@@ -84,4 +96,4 @@ function setupServerResponses()
   end)
 end
 
-startSetup()
+startSetup()

+ 1 - 1
yorecipient.txt

@@ -1 +1 @@
-epukaza
+epukaza