Oh, I see. I was doing switch/case wrong, and left out the breaks. I always forget the syntax for switch/case.
exports.connect = function(spi,cs) {
return new MAX31855(spi,cs);
};
function MAX31855(spi,cs) {
this.spi=spi;
this.cs=cs;
}
MAX31855.prototype.getTemp = function () {
var d = SPI1.send("\0\0\0\0",C0);
var trtn={};
trtn.temp=(d.charCodeAt(0)<<6 | d.charCodeAt(1)>>2)*0.25;
trtn.fault=0;
if (d.charCodeAt(1) & 1) {
var fault = (d.charCodeAt(3) & 7);
trtn.fault=fault;
switch (fault) {
case 1:
trtn.faultstring="No probe detected";
break;
case 3:
trtn.faultstring="Probe shorted to Ground";
break;
case 4:
trtn.faultstring="Probe shorted to VCC";
break;
}
}
return trtn;
};
Should now return an object with properties temp (the temperature), fault (the fault code) and faultstring (with a description of the error condition, if available).
Version on my website updated, so this should work:
SPI1.setup({ miso:B4, sck:B3, baud:1000000 });
var max=require("http://drazzy.com/espruino/MAX31855.js").connect(SPI1,C0);
console.log(max.getTemp());
I'll be submitting this module if it works - want me to credit you as something more, ah, personal than "User7341"? :-P
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Oh, I see. I was doing switch/case wrong, and left out the breaks. I always forget the syntax for switch/case.
Should now return an object with properties temp (the temperature), fault (the fault code) and faultstring (with a description of the error condition, if available).
Version on my website updated, so this should work:
I'll be submitting this module if it works - want me to credit you as something more, ah, personal than "User7341"? :-P