Created
January 25, 2015 23:32
-
-
Save ianjosephwilson/c9830d1bb212d35f1cf6 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 | |
//c control variable, temperature or humidity or nothing | |
//m most sig | |
//l least sig | |
//r result | |
//w waiting for d4 | |
function sht.report { | |
print "sht.report"; | |
hq.report("rawtemp", r); | |
} | |
function sht.wait { | |
print "sht.wait"; | |
w = 1; | |
} | |
function sht.temperature.execute { | |
print "sht.temperature.execute"; | |
// data pin | |
a = 4; | |
// clock pin; | |
b = 8; | |
c = 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); | |
shiftout(a, b, msbfirst, 0b00000011); | |
dw(b, 1); | |
pinmode(a, 0) | |
if (dr(a)) { | |
print "ACK error 0"; | |
} | |
dw(b, 0); | |
if (!dr(a)) { | |
print "ACK error 1"; | |
} | |
print "wait for sht.wait"; | |
power.sleep(4, "sht.wait"); | |
} | |
function sht.humidity.execute { | |
c = 2; | |
// TBD | |
} | |
function on.d4.low { | |
print "on.d4.low"; | |
if (w && c) { | |
if (c == 1) { | |
// do temperature | |
pinmode(a, 0); | |
pinmode(b, 1); | |
m = shiftin(a, b, msbfirst); | |
pinmode(a, 1); | |
dw(a, 1); | |
dw(a, 0); | |
dw(b, 1); | |
dw(b, 0); | |
pinmode(a, 0); | |
l = shiftin(a, b, msbfirst); | |
r = ((m << 8) | l); | |
sht.clearcrc(); | |
sht.report(); | |
} else if (c == 2) { | |
// do humidity | |
} else { | |
// do nothing | |
} | |
// Reset c. | |
c = 0; | |
// Reset w. | |
w = 0; | |
} | |
} | |
function sht.clearcrc { | |
print "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