This regards the new function that I added to the AT24 module (not available on the site yet), to read strings out of an eeprom without running out of memory.
Here's the code:
EEPROM.prototype.reads= function(add,bytes,i2ca) {
i2ca = (i2ca==undefined) ? this.i2ca : i2ca;
if (add+bytes>this.cap-1) {
return;
}
if (i2ca==this.i2ca) {
this.ca=add+bytes;
}
this.i2c.writeTo(0x50|i2ca,[add>>8&0xff,add&0xff]);
var outval="";
while (bytes > 0) {
var b=64;
if (bytes >= 64) {
bytes-=64;
} else {
b=bytes;
bytes=0;
}
outval=outval+this.arrayToString(this.i2c.readFrom(0x50|i2ca,b));
}
return outval;
};
It works fine with lengths up to around 3500 bytes - but after that, it crashes the espruino. I don't know what's going on internally that's killing it, and the exact limit seems to be effected by the other code around it (WTF?!), but this is a real issue for me.
When it hangs, the busyIndicator stays lit, and I need to hit the reset button to restore responsiveness.
That reads() function, of course, is to deal with the fact that there is no way to get a memory-efficient output from I2C.readFrom() (personally, I think I2C.readFrom should take an object as second argument, which could have property 'as', with options like "string" and "Uint8Array", ex: I2C.readFrom(100,{as:"string"}); )
I have no idea what could be causing this crash, and I don't really know how to proceed to debug it... I mean, it's my code that's causing the crash, but I have no idea why code that is sound at 3000 bytes is not sound at 4000 bytes.
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.
This regards the new function that I added to the AT24 module (not available on the site yet), to read strings out of an eeprom without running out of memory.
Here's the code:
It works fine with lengths up to around 3500 bytes - but after that, it crashes the espruino. I don't know what's going on internally that's killing it, and the exact limit seems to be effected by the other code around it (WTF?!), but this is a real issue for me.
When it hangs, the busyIndicator stays lit, and I need to hit the reset button to restore responsiveness.
That reads() function, of course, is to deal with the fact that there is no way to get a memory-efficient output from I2C.readFrom() (personally, I think I2C.readFrom should take an object as second argument, which could have property 'as', with options like "string" and "Uint8Array", ex: I2C.readFrom(100,{as:"string"}); )
I have no idea what could be causing this crash, and I don't really know how to proceed to debug it... I mean, it's my code that's causing the crash, but I have no idea why code that is sound at 3000 bytes is not sound at 4000 bytes.