summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2016-02-07 10:55:46 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2016-02-07 10:55:46 +0000
commit0adfbd60c76be188318429d51a21f6476981130f (patch)
treef3cb9bd58186685a1630b3896efb2f9e7ddf3802
parentfa01c0afa30b51175e773211f17c8cf6e0e0e8da (diff)
downloadbeerometer-0adfbd60c76be188318429d51a21f6476981130f.tar.bz2
Initial firmware bits and bobs
-rw-r--r--.gitignore1
-rw-r--r--firmware/counter.lua87
-rw-r--r--firmware/init.lua2
-rw-r--r--firmware/telnetd.lua41
4 files changed, 131 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index a3db457..ba0810a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.bak
*-bak
+*~
diff --git a/firmware/counter.lua b/firmware/counter.lua
new file mode 100644
index 0000000..7bc4798
--- /dev/null
+++ b/firmware/counter.lua
@@ -0,0 +1,87 @@
+-- These are based on rev.D layout
+local p1_g = 6 -- Marked #12
+local p2_g = 5 -- Marked #14
+local p3_g = 0 -- Marked #16
+local p4_g = 7 -- Marked #13
+local p5_g = 1 -- Marked #4 Note, these two may be swapped due to
+local p6_g = 2 -- Marked #5 module construction, needs verification.
+
+local p1_c, p2_c, p3_c, p4_c, p5_c, p6_c = 0, 0, 0, 0, 0, 0
+
+local function p1_cb()
+ p1_c = p1_c + 1
+end
+
+local function p2_cb()
+ p2_c = p2_c + 1
+end
+
+local function p3_cb()
+ p3_c = p3_c + 1
+end
+
+local function p4_cb()
+ p4_c = p4_c + 1
+end
+
+local function p5_cb()
+ p5_c = p5_c + 1
+end
+
+local function p6_cb()
+ p6_c = p6_c + 1
+end
+
+print("Setting up pump 1, on GPIO #" .. tostring(p1_g))
+gpio.mode(p1_g, gpio.INT, gpio.PULLUP)
+gpio.trig(p1_g, "down", p1_cb)
+
+print("Setting up pump 2, on GPIO #" .. tostring(p2_g))
+gpio.mode(p2_g, gpio.INT, gpio.PULLUP)
+gpio.trig(p2_g, "down", p2_cb)
+
+print("Setting up pump 3, on GPIO #" .. tostring(p3_g))
+gpio.mode(p3_g, gpio.INT, gpio.PULLUP)
+gpio.trig(p3_g, "down", p3_cb)
+
+print("Setting up pump 4, on GPIO #" .. tostring(p4_g))
+gpio.mode(p4_g, gpio.INT, gpio.PULLUP)
+gpio.trig(p4_g, "down", p4_cb)
+
+print("Setting up pump 5, on GPIO #" .. tostring(p5_g))
+gpio.mode(p5_g, gpio.INT, gpio.PULLUP)
+gpio.trig(p5_g, "down", p5_cb)
+
+print("Setting up pump 6, on GPIO #" .. tostring(p6_g))
+gpio.mode(p6_g, gpio.INT, gpio.PULLUP)
+gpio.trig(p6_g, "down", p6_cb)
+
+local function report()
+ local ret = {}
+ local p1_cc, p2_cc, p3_cc, p4_cc, p5_cc, p6_cc = p1_c, p2_c, p3_c, p4_c, p5_c, p6_c
+ p1_c, p2_c, p3_c, p4_c, p5_c, p6_c = 0, 0, 0, 0, 0, 0
+ if p1_cc > 0 then
+ ret[#ret+1] = "p1="..tostring(p1_cc)
+ end
+ if p2_cc > 0 then
+ ret[#ret+1] = "p2="..tostring(p2_cc)
+ end
+ if p3_cc > 0 then
+ ret[#ret+1] = "p3="..tostring(p3_cc)
+ end
+ if p4_cc > 0 then
+ ret[#ret+1] = "p4="..tostring(p4_cc)
+ end
+ if p5_cc > 0 then
+ ret[#ret+1] = "p5="..tostring(p5_cc)
+ end
+ if p6_cc > 0 then
+ ret[#ret+1] = "p6="..tostring(p6_cc)
+ end
+ return table.concat(ret, "&")
+end
+
+return {
+ report = report
+}
+
diff --git a/firmware/init.lua b/firmware/init.lua
new file mode 100644
index 0000000..7944c1a
--- /dev/null
+++ b/firmware/init.lua
@@ -0,0 +1,2 @@
+print("Beer'o'Meter v1.0, starting...")
+dofile "telnetd.lc"
diff --git a/firmware/telnetd.lua b/firmware/telnetd.lua
new file mode 100644
index 0000000..5aba784
--- /dev/null
+++ b/firmware/telnetd.lua
@@ -0,0 +1,41 @@
+print("====Wicon, a LUA console over wifi.==========")
+print("Author: openthings@163.com. copyright&GPL V2.")
+print("Last modified 2014-11-19. V0.2")
+print("Wicon Server starting ......")
+
+function startServer()
+ print("Wifi AP connected. Wicon IP:")
+ print(wifi.sta.getip())
+ sv=net.createServer(net.TCP, 180)
+ sv:listen(8080, function(conn)
+ print("Wifi console connected.")
+
+ function s_output(str)
+ if (conn~=nil) then
+ conn:send(str)
+ end
+ end
+ node.output(s_output,0)
+
+ conn:on("receive", function(conn, pl)
+ node.input(pl)
+ if (conn==nil) then
+ print("conn is nil.")
+ end
+ end)
+ conn:on("disconnection",function(conn)
+ node.output(nil)
+ end)
+ end)
+ print("Wicon Server running at :8080")
+ print("===Now,Using xcon_tcp logon and input LUA.====")
+end
+
+tmr.alarm(0, 1000, 1, function()
+ if wifi.sta.getip()==nil then
+ print("Connect AP, Waiting...")
+ else
+ startServer()
+ tmr.stop(0)
+ end
+end)