Converting between strings and array of bytes? #231
Replies: 8 comments
-
Posted at 2014-03-17 by @gfwilliams That's cool - do you think you'll be able to contribute a module to interface to the EEPROM when you're done? Hopefully if you get a SOIC one you'll be able to solder it onto the proto area :) I'm afraid that at the moment I think the best way of doing it is to just loop over the array and append to the string:
In 'normal' JS you could do |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-17 by DrAzzy Yeah, will definitely contribute module for it. It'll be a pretty simple module, though. I like writing modules. I got a breakout board with the EEPROM in DIP-8 package (socketed), so no soldering onto the prototyping area for now. Will probably get some SOIC-8 ones if this works out well, and do just that. The I2C EEPROMs, in the largest sizes I see available, are limited to 4 per I2C bus (each one has 2 pins dedicated to setting address) - which means one could just fit the maximum loadout of I2C EEPROM's onto the prototyping area. One of the things that I'm imagining doing with this is having the Espruino check that the modules it needs are present on the SD card, in node_modules directory - and if they're not, extract them from the EEPROM and write them to the SD card (so when we pull the SD card to get the recorded data, we can just put in a blank micro SD card in it's place, hit reset, and have it sort itself out). You say things like "at the moment" - does that mean that you're planning to change something that would make this more graceful in the near future, or just that someone might at some point do so? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-18 by @gfwilliams Well, once the code is written to Espruino, you don't actually need the SD card for modules at all (they're all stored internally). Even if you want to load stuff from scratch, you can use Modules.addCached to directly load the module from EEPROM into memory :) For the built-in functions, there's a bug open about it, and I have a branch here that's working towards fixing it. It could be some time before it's done though as it's quite a big change :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-19 by DrAzzy Oh, well, that makes life easier! It also means I need to be somewhat more aware of what is and isn't loaded when I save(). For example my DISK_ERR generator, if you paste in the whole block of code, the module won't be loaded when it saves, because onInit() hasn't been called, and the require()'s are in the init functions, as I ran into when the SD card mysteriously failed (that's how I knew it happened - it started complaining that the modules were missing when I restarted it). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-19 by @gfwilliams Yes, that's tricky - but it only happens when you paste code into the left (rather than using the right). I guess this is something that the Web IDE could be aware of (and could warn you about)... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-19 by DrAzzy Wait, so if I do...
It will not have the modules loaded if I paste it into the left side, and after saving it, it will need them on the SD card. But if I do it on the right side, and send it like that, the modules will get loaded by the IDE and be save()ed, and I won't need to have them on the SD card? (I never use the right-hand side of the IDE because it's hard to read on on a retina class screen without a way to scale up the text - I just do everything in sublime text and copy/paste it into the left side). If there are two versions of a module with the same name, the one on the website, and the one on the SD card (say, because I'm updating it), which one will be used if I send it through the IDE? (for example, would this force it to load off the SD card, or does it do it at the end?):
I'm just trying to make sure I understand how this module loading system works. It's a little disconcerting how it isn't made clear when the IDE is summoning a module from the internet and adding it to the Espruino's module cache. For that matter, is there a location on the local filesystem that the IDE will check before it goes online? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-20 by @gfwilliams
Yes - well, they'll be loaded by the Web IDE and will be save()d when you type
The one on the website (if you use the right-hand side). You can force loading from SD by doing:
When you click
No, that would force a load off the SD card.
Well, it's meant to be virtually invisible. It might make more sense if it wrote some description onto the console I guess...
No, but you can change the URL used for modules in settings, and can set it to a local webserver. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-03-20 by DrAzzy Thanks, I think I have a much better idea of how the module system works now. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-03-17 by DrAzzy
Say I have an I2C EEPROM... Now, obviously I'm going to want to read and write strings, not just arrays of bytes.
I see that I2C.writeTo() is described as accepting a string - so that handles the writing part.
How do I go the other direction?
I2C.readFrom() returns an array of bytes - and you can't eval() an array of bytes - is there any way other than looping through each byte and looking up what character it should be?
(I know the whole I2C EEPROM bit is kinda silly, since we have the microSD card slot... but they're so dirt cheap, I couldn't resist ordering one)
Beta Was this translation helpful? Give feedback.
All reactions