diff --git a/libs/calliope-i2c/i2c.ts b/libs/calliope-i2c/i2c.ts index d1d0d7b4..0aa06b0e 100644 --- a/libs/calliope-i2c/i2c.ts +++ b/libs/calliope-i2c/i2c.ts @@ -1,3 +1,4 @@ +import rgbw = basic.rgbw; serial.writeLine("I2C"); // send to 0x44, register 0x00, value 0x46 (RESET ISL29125) pins.i2cWriteNumber(0x44, 0x0046, NumberFormat.UInt16BE); @@ -6,13 +7,17 @@ pins.i2cWriteNumber(0x44, 0x0105, NumberFormat.UInt16BE); basic.forever(() => { serial.writeString("["); pins.i2cWriteNumber(0x44, 0x0A, NumberFormat.Int8BE); - serial.writeNumber(pins.i2cReadNumber(0x44, NumberFormat.UInt8BE)); + let g = pins.i2cReadNumber(0x44, NumberFormat.UInt8BE); + serial.writeNumber(r); serial.writeString(","); pins.i2cWriteNumber(0x44, 0x0C, NumberFormat.UInt8BE); - serial.writeNumber(pins.i2cReadNumber(0x44, NumberFormat.UInt8BE)); + let r = pins.i2cReadNumber(0x44, NumberFormat.UInt8BE); + serial.writeNumber(g); serial.writeString(","); pins.i2cWriteNumber(0x44, 0x0E, NumberFormat.UInt8BE); - serial.writeNumber(pins.i2cReadNumber(0x44, NumberFormat.UInt8LE)); + let b = pins.i2cReadNumber(0x44, NumberFormat.UInt8LE); + serial.writeNumber(b); serial.writeLine("]"); + basic.setLedColor(basic.rgbw(r,g,b, 0)); basic.pause(1000); }); \ No newline at end of file diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 4947c44d..87793130 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -215,8 +215,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|repeat %repeat", + "pins.i2cWriteNumber|block": "i2c write number|at address %address|with value %value|of format %format=i2c_sizeof|repeat %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)", diff --git a/libs/core/pins.ts b/libs/core/pins.ts index 5f70b304..aec32295 100644 --- a/libs/core/pins.ts +++ b/libs/core/pins.ts @@ -22,9 +22,9 @@ namespace pins { * Read one number from 7-bit I2C address. */ //% help=pins/i2c-read-number blockGap=8 - //% 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|repeat %repeat" weight=7 + export function i2cReadNumber(address: number, format: NumberFormat, repeat?: boolean): number { + let buf = pins.i2cReadBuffer(address, pins.sizeOf(format), repeat) 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 - //% 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|repeat %repeat" weight=6 + export function i2cWriteNumber(address: number, value: number, format: NumberFormat, repeat?: boolean): void { let buf = createBuffer(pins.sizeOf(format)) buf.setNumber(format, 0, value) - pins.i2cWriteBuffer(address, buf) + pins.i2cWriteBuffer(address, buf, repeat) } /** diff --git a/tests/i2c.ts b/tests/i2c.ts new file mode 100644 index 00000000..d56d2d6b --- /dev/null +++ b/tests/i2c.ts @@ -0,0 +1,4 @@ +let item = pins.i2cReadNumber(123, NumberFormat.Int8LE) +pins.i2cWriteNumber(123, 0, NumberFormat.Int8LE) +let item = pins.i2cReadNumber(123, NumberFormat.Int8LE, true) +pins.i2cWriteNumber(123, 0, NumberFormat.Int8LE, true) \ No newline at end of file