Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
gpio.mode(5, gpio.OUTPUT) | ||
gpio.write(5, gpio.HIGH) | ||
|
||
gpio.mode(6, gpio.OUTPUT) | ||
gpio.write(6, gpio.LOW) | ||
tmr.delay(100000) | ||
gpio.write(5, gpio.LOW) | ||
gpio.mode(6, gpio.INPUT) | ||
local cnt = 0 | ||
while (gpio.read(6) == 0) do | ||
cnt = cnt + 1 | ||
if cnt > 4000 then | ||
break | ||
end | ||
tmr.delay(1000) | ||
end | ||
return cnt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
local pin = 7 | ||
|
||
local function read() | ||
local count = 0 | ||
local addr | ||
|
||
ow.setup(pin) | ||
|
||
ow.reset_search(pin) | ||
repeat | ||
count = count + 1 | ||
addr = ow.search(pin) | ||
tmr.wdclr() | ||
until((addr ~= nil) or (count > 100)) | ||
ow.reset_search(pin) | ||
|
||
if(addr == nil) then | ||
return result | ||
end | ||
local crc = ow.crc8(string.sub(addr,1,7)) | ||
if (crc == addr:byte(8)) then | ||
if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then | ||
ow.reset(pin) | ||
ow.select(pin, addr) | ||
ow.write(pin, 0x44, 1) | ||
tmr.delay(10000) | ||
present = ow.reset(pin) | ||
ow.select(pin, addr) | ||
ow.write(pin,0xBE,1) | ||
local data = string.char(ow.read(pin)) | ||
for i = 1, 8 do | ||
data = data .. string.char(ow.read(pin)) | ||
end | ||
crc = ow.crc8(string.sub(data,1,8)) | ||
if (crc == data:byte(9)) then | ||
local t = (data:byte(1) + data:byte(2) * 256) * 625 | ||
local t1 = t / 10000 | ||
local t2 = t % 10000 | ||
if t1 < -50 or t1 > 50 then return nil end | ||
return t1.."."..string.format("%04u", t2) | ||
end | ||
tmr.wdclr() | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
|
||
local res | ||
local i | ||
for i = 1,20 do | ||
res = read() | ||
if res ~= nil then return res end | ||
end | ||
return "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters