Created
January 26, 2015 06:02
-
-
Save ianjosephwilson/50ea091d1d42555d0cb6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//a data pin | |
//b clock pin | |
//r result | |
//w poll timeout | |
function sht.temp.report { | |
print "s.r.t"; | |
f = key(arg(1)); | |
hq.report("rawtemp", f); | |
free f; | |
} | |
function sht.temp.poll { | |
print "s.t.p"; | |
if (w > 200) { | |
w = 1; return; | |
} | |
if (dr(a) == 0) { | |
w = 0; | |
pinmode(a, 0); pinmode(b, 1); | |
m = custom.shiftin(a, b, 1); | |
pinmode(a, 1); | |
dw(a, 1); | |
dw(a, 0); | |
dw(b, 1); | |
dw(b, 0); | |
pinmode(a, 0); | |
l = custom.shiftin(a, b, 1); | |
r = ((m << 8) | l); | |
sht.clearcrc(); | |
sht.temp.report(r); | |
} else { | |
w = w + 1; | |
scout.delay(10, "sht.temp.poll"); | |
} | |
} | |
function sht.temp.execute { | |
print "s.t.e"; | |
a = 8; b = 4; w = 1; | |
pinmode(a, 1); pinmode(b, 1); | |
dw(a, 1); | |
dw(b, 1); | |
dw(a, 0); | |
dw(b, 0); | |
dw(b, 1); | |
dw(a, 1); | |
dw(b, 0); | |
custom.shiftout(a, b, 1, 0b00000011); | |
dw(b, 1); | |
pinmode(a, 0) | |
if (dr(a) == 1) { | |
print "ACK error 0"; | |
} | |
dw(b, 0); | |
if (dr(a) == 0) { | |
print "ACK error 1"; | |
} | |
scout.delay(10, "sht.temp.poll"); | |
} | |
function custom.shiftout { | |
x = arg(1); | |
y = arg(2); | |
z = arg(3); | |
v = arg(4); | |
if (z) { | |
i = 0b10000000; | |
while (i > 0) { | |
if (v & i) { | |
print "writing 1"; | |
dw(a, 1); | |
} else { | |
print "writing 0"; | |
dw(a, 0); | |
} | |
dw(b, 1); | |
dw(b, 0); | |
print i; | |
i = i >> 1; | |
} | |
} else { | |
i = 0b00000001; | |
while (i > 0) { | |
if (v & i) { | |
r = r | i; | |
} | |
dw(y, 1); | |
dw(y, 0); | |
print i; | |
i = i << 1; | |
} | |
} | |
} | |
function custom.shiftin { | |
x = arg(1); | |
y = arg(2); | |
z = arg(3); | |
r = 0; | |
if (z == 1) { | |
i = 0b10000000; | |
while (i > 0) { | |
if (dr(x) == 1) { | |
r = r | i; | |
} | |
dw(y, 1); | |
dw(y, 0); | |
i = i >> 1; | |
} | |
} else { | |
i = 0b00000001; | |
while (i > 0) { | |
if (dr(x) == 1) { | |
r = r | i; | |
} | |
dw(y, 1); | |
dw(y, 0); | |
i = i << 1; | |
} | |
} | |
return r; | |
} | |
function sht.clearcrc { | |
pinmode(a, 1); | |
pinmode(b, 1); | |
dw(a, 1); | |
dw(b, 1); | |
dw(b, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment