I am in a process to write Espruino compatible module for Si114x Pulse sensor library which is basically a code conversion on Arduino library. The sensor uses I2C protocol for MCU comuniication.
I know that Espruino supports byte array in I2C.writeTo() method, and also stop:false/true option.
So if I would need to convert the below code what should be the best option for me?
void PulsePlug<T>::writeParam(uint8_t addr, uint8_t val)
{
// write to parameter ram
_i2c->beginTransmission(i2cAddr);
_i2c->write(Si114x::PARAM_WR);
_i2c->write(val);
// auto-increments into Si114x::COMMAND
_i2c->write(0xA0 | addr); // PARAM_SET
_i2c->endTransmission();
delay(10); // XXX Nothing in datasheet indicates this is required; was in
// original code.
}
uint8_t PulsePlug<T>::readParam(uint8_t addr)
{
// read from parameter ram
_i2c->beginTransmission(i2cAddr);
_i2c->write(Si114x::COMMAND);
_i2c->write(0x80 | addr); // PARAM_QUERY
_i2c->endTransmission();
delay(10); // NOTE: Nothing in datasheet indicates this is required - in original code.
return getReg(Si114x::PARAM_RD);
}
uint8_t PulsePlug<T>::getReg(uint8_t reg)
{
// get a register
_i2c->beginTransmission(i2cAddr);
_i2c->write(reg);
_i2c->endTransmission();
requestData(1);
uint8_t result = _i2c->read();
delay(10); // NOTE: Nothing in datasheet indicates this is required - in original code.
return result;
}
1- Combine all bytes to single byte array?
2- Individual writeTo() call having stop:false for the first call?
3- How should I care the delay, a setTimeout/ Promise?
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
Create headers by underlining text with ==== or ----
To *italicise* text put one asterisk each side of the word
To **bold** text put two asterisks each side of the word
Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png) That's the hard one: exclamation, square brackets and then the URL to the image in brackets.
* Create lists by starting lines with asterisks
1. Create numbered lists by starting lines with a number and a dot
> Quote text by starting lines with >
Mention another user by @username
For syntax highlighting, surround the code block with three backticks:
```
Your code goes here
```
Just like Github, a blank line must precede a code block.
If you upload more than 5 files we will display all attachments as thumbnails.
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.
Hi there,
I am in a process to write Espruino compatible module for Si114x Pulse sensor library which is basically a code conversion on Arduino library. The sensor uses I2C protocol for MCU comuniication.
I know that Espruino supports byte array in I2C.writeTo() method, and also stop:false/true option.
So if I would need to convert the below code what should be the best option for me?
1- Combine all bytes to single byte array?
2- Individual writeTo() call having stop:false for the first call?
3- How should I care the delay, a setTimeout/ Promise?
Reference:
Si114x datasheet
Arduino Library