arduino / arduino/ArduinoCore-API

Suggest adding I2C_writeAnything to Wire library

オープン
#62 コメント 7 件 リアクション 1 件 担当者 1 名 @cmaglie が担当を希望しています GitHub で見る
enhancement
主要言語
C++
スター
306
フォーク
150
PR マージ指標
30日以内にマージされた PR はありません

説明

I have the following small template library on my page about I2C ( http://www.gammon.com.au/i2c ):

``` C++
template unsigned int I2C_writeAnything (const T& value)
{
Wire.write((byte *) &value, sizeof (value));
return sizeof (value);
} // end of I2C_writeAnything

template unsigned int I2C_readAnything(T& value)
{
byte * p = (byte*) &value;
unsigned int i;
for (i = 0; i < sizeof value; i++)
*p++ = Wire.read();
return i;
} // end of I2C_readAnything
```

It has been suggested to me that I request that you include this in the standard Wire library (Wire.h). This lets you more easily send things like floats or structs via I2C. For example:

``` C++
float fnum = 42.666;
Wire.beginTransmission (SLAVE_ADDRESS);
I2C_writeAnything (fnum);
Wire.endTransmission ();
```

Being a template function it won't add any bloat unless you actually use it.

Related request: https://github.com/arduino/Arduino/issues/3692

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。