Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
devsaurus 2015-02-08 13:14:09 +01:00
commit 5a67fec4f3
7 changed files with 99 additions and 23 deletions

View File

@ -75,7 +75,7 @@ else
endif
endif
#############################################################
ESPTOOL = ../tools/esptool.py
ESPTOOL ?= ../tools/esptool.py
CSRCS ?= $(wildcard *.c)

View File

@ -5,7 +5,7 @@
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- require("irsend").nec(4, 0x00ff00ff)
-- dofile("irsend.lua").nec(4, 0x00ff00ff)
------------------------------------------------------------------------------
local M
do

View File

@ -6,7 +6,7 @@
-- Heavily based on work of Christee <Christee@nodemcu.com>
--
-- Example:
-- require("bmp085").read(sda, scl)
-- dofile("bmp085.lua").read(sda, scl)
------------------------------------------------------------------------------
local M
do
@ -59,20 +59,13 @@ do
MD = r16(0xBE)
end
-- get raw P
local p
-- NB: optimize for oss = 0
if not oss then oss = 0 end
if oss == 0 then
oss = 0
w8(0xF4, 0x34)
tmr.delay(5000)
p = r8(0xF6) * 256 + r8(0xF7)
else
if oss <= 0 then oss = 0 end
if oss > 3 then oss = 3 end
w8(0xF4, 0x34 + 64 * oss)
tmr.delay(30000)
p = r8(0xF6) * 65536 + r8(0xF7) * 256 + r8(0xF8)
p = p / 2^(8 - oss)
end
tmr.delay((4 + 3 ^ oss) * 1000)
local p = r8(0xF6) * 65536 + r8(0xF7) * 256 + r8(0xF8)
p = p / 2 ^ (8 - oss)
-- get T
w8(0xF4, 0x2E)
tmr.delay(5000)
@ -86,14 +79,14 @@ do
local X1 = B2 * (B6 * B6 / 4096) / 2048
local X2 = AC2 * B6 / 2048
local X3 = X1 + X2
local B3 = ((AC1 * 4 + X3) * 2^oss + 2) / 4
local B3 = ((AC1 * 4 + X3) * 2 ^ oss + 2) / 4
X1 = AC3 * B6 / 8192
X2 = (B1 * (B6 * B6 / 4096)) / 65536
X3 = (X1 + X2 + 2) / 4
local B4 = AC4 * (X3 + 32768) / 32768
local B7 = (p - B3) * (50000 / 2^oss)
local B7 = (p - B3) * (50000 / 2 ^ oss)
p = B7 / B4 * 2
X1 = (p / 256)^2
X1 = (p / 256) ^ 2
X1 = (X1 * 3038) / 65536
X2 = (-7357 * p) / 65536
p = p + (X1 + X2 + 3791) / 16

View File

@ -5,8 +5,8 @@
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- print("DHT11", require("dht22").read(4))
-- print("DHT22", require("dht22").read(4, true))
-- print("DHT11", dofile("dht22.lua").read(4))
-- print("DHT22", dofile("dht22.lua").read(4, true))
-- NB: the very first read sometimes fails
------------------------------------------------------------------------------
local M

View File

@ -5,7 +5,7 @@
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- require("ds18b20").read(4, function(r) for k, v in pairs(r) do print(k, v) end end)
-- dofile("ds18b20.lua").read(4, function(r) for k, v in pairs(r) do print(k, v) end end)
------------------------------------------------------------------------------
local M
do

View File

@ -0,0 +1,83 @@
------------------------------------------------------------------------------
-- Redis client module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- local redis = dofile("redis.lua").connect(host, port)
-- redis:publish("chan1", foo")
-- redis:subscribe("chan1", function(channel, msg) print(channel, msg) end)
------------------------------------------------------------------------------
local M
do
-- const
local REDIS_PORT = 6379
-- cache
local pairs, tonumber = pairs, tonumber
--
local publish = function(self, chn, s)
self._fd:send(("*3\r\n$7\r\npublish\r\n$%d\r\n%s\r\n$%d\r\n%s\r\n"):format(
#chn, chn, #s, s
))
-- TODO: confirmation? then queue of answers needed
end
local subscribe = function(self, chn, handler)
-- TODO: subscription to all channels, with single handler
self._fd:send(("*2\r\n$9\r\nsubscribe\r\n$%d\r\n%s\r\n"):format(
#chn, chn
))
self._handlers[chn] = handler
-- TODO: confirmation? then queue of answers needed
end
local unsubscribe = function(self, chn)
self._handlers[chn] = false
end
-- NB: pity we can not just augment what net.createConnection returns
local close = function(self)
self._fd:close()
end
local connect = function(host, port)
local _fd = net.createConnection(net.TCP, 0)
local self = {
_fd = _fd,
_handlers = { },
-- TODO: consider metatables?
close = close,
publish = publish,
subscribe = subscribe,
unsubscribe = unsubscribe,
}
_fd:on("connection", function()
--print("+FD")
end)
_fd:on("disconnection", function()
-- FIXME: this suddenly occurs. timeout?
--print("-FD")
end)
_fd:on("receive", function(fd, s)
--print("IN", s)
-- TODO: subscription to all channels
-- lookup message pattern to determine channel and payload
-- NB: pairs() iteration gives no fixed order!
for chn, handler in pairs(self._handlers) do
local p = ("*3\r\n$7\r\nmessage\r\n$%d\r\n%s\r\n$"):format(#chn, chn)
if s:find(p, 1, true) then
-- extract and check message length
-- NB: only the first TCP packet considered!
local _, start, len = s:find("(%d-)\r\n", #p)
if start and tonumber(len) == #s - start - 2 and handler then
handler(chn, s:sub(start + 1, -2)) -- ends with \r\n
end
end
end
end)
_fd:connect(port or REDIS_PORT, host)
return self
end
-- expose
M = {
connect = connect,
}
end
return M

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
#
# ESP8266 ROM Bootloader Utility
# https://github.com/themadinventor/esptool