surfacing missing repeat parameter (#380)

* surfacing missing repeat parameter

* updated docs
This commit is contained in:
Peli de Halleux 2017-04-03 10:30:25 -07:00 committed by GitHub
parent aac5bb8619
commit 37efefdcee
5 changed files with 19 additions and 11 deletions

View File

@ -4,7 +4,7 @@ Read one number from the specified 7-bit I2C address, in the specified
number format.
```sig
pins.i2cReadNumber(0, NumberFormat.Int8LE);
pins.i2cReadNumber(0, NumberFormat.Int8LE, false);
```
### Parameters
@ -17,6 +17,7 @@ pins.i2cReadNumber(0, NumberFormat.Int8LE);
* **Int** stands for "integer", and **UInt** stands for "unsigned integer".
* **LE** stands for "little-endian" and **BE** stands for "big-endian".
* The number in each format name stands for the number of bits in the format.
* ``repeated`` repeated start, true - don't send stop at end
### Example
@ -24,7 +25,7 @@ The following example reads a number in big-endian, 16-bit, unsigned integer
format from the 7-bit I2C address `32`.
```blocks
pins.i2cReadNumber(32, NumberFormat.UInt16BE);
pins.i2cReadNumber(32, NumberFormat.UInt16BE, false);
```
#### ~hint

View File

@ -4,7 +4,7 @@ Write the specified number to the specified 7-bit I2C address in the
specified number format.
```sig
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE, true);
```
### Parameters
@ -18,6 +18,7 @@ pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
* **Int** stands for "integer", and **UInt** stands for "unsigned integer".
* **LE** stands for "little-endian" and **BE** stands for "big-endian".
* The number in each format name stands for the number of bits in the format.
* ``repeated`` repeated start, true - don't send stop at end
### Example

View File

@ -250,8 +250,8 @@
"pins.analogWritePin|block": "analog write|pin %name|to %value",
"pins.digitalReadPin|block": "digital read|pin %name",
"pins.digitalWritePin|block": "digital write|pin %name|to %value",
"pins.i2cReadNumber|block": "i2c read number|at address %address|of format %format=i2c_sizeof",
"pins.i2cWriteNumber|block": "i2c write number|at address %address|with value %value|of format %format=i2c_sizeof",
"pins.i2cReadNumber|block": "i2c read number|at address %address|of format %format=i2c_sizeof|repeated %repeat",
"pins.i2cWriteNumber|block": "i2c write number|at address %address|with value %value|of format %format=i2c_sizeof|repeated %repeat",
"pins.map|block": "map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh",
"pins.onPulsed|block": "on|pin %pin|pulsed %pulse",
"pins.pulseDuration|block": "pulse duration (µs)",

View File

@ -22,9 +22,9 @@ namespace pins {
* Read one number from 7-bit I2C address.
*/
//% help=pins/i2c-read-number blockGap=8 advanced=true
//% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof" weight=7
export function i2cReadNumber(address: number, format: NumberFormat): number {
let buf = pins.i2cReadBuffer(address, pins.sizeOf(format))
//% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof|repeated %repeat" weight=7
export function i2cReadNumber(address: number, format: NumberFormat, repeated?: boolean): number {
let buf = pins.i2cReadBuffer(address, pins.sizeOf(format), repeated)
return buf.getNumber(format, 0)
}
@ -32,11 +32,11 @@ namespace pins {
* Write one number to a 7-bit I2C address.
*/
//% help=pins/i2c-write-number blockGap=8 advanced=true
//% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof" weight=6
export function i2cWriteNumber(address: number, value: number, format: NumberFormat): void {
//% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof|repeated %repeat" weight=6
export function i2cWriteNumber(address: number, value: number, format: NumberFormat, repeated?: boolean): void {
let buf = createBuffer(pins.sizeOf(format))
buf.setNumber(format, 0, value)
pins.i2cWriteBuffer(address, buf)
pins.i2cWriteBuffer(address, buf, repeated)
}
/**

6
tests/i2c.ts Normal file
View File

@ -0,0 +1,6 @@
let item = pins.i2cReadNumber(123, NumberFormat.Int8LE)
pins.i2cWriteNumber(123, 0, NumberFormat.Int8LE)
let item2 = pins.i2cReadNumber(123, NumberFormat.Int8LE, true)
pins.i2cWriteNumber(123, 0, NumberFormat.Int8LE, true)