exposing i2c blocks in pins

This commit is contained in:
Peli de Halleux 2016-05-13 03:38:52 -07:00
parent 7a9c2e0fe4
commit 879a85bdbb

View File

@ -11,7 +11,7 @@ namespace pins {
* @param toLow the lower bound of the value's target range * @param toLow the lower bound of the value's target range
* @param toHigh the upper bound of the value's target range, eg: 4 * @param toHigh the upper bound of the value's target range, eg: 4
*/ */
//% help=pins/map weight=15 //% help=pins/map weight=3
//% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh" //% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh"
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number { export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow; return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;
@ -20,6 +20,8 @@ namespace pins {
/** /**
* Read one number from 7-bit I2C address. * Read one number from 7-bit I2C address.
*/ */
//% help=pins/i2c-read-number
//% 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 { export function i2cReadNumber(address: number, format: NumberFormat): number {
let buf = pins.i2cReadBuffer(address, pins.sizeOf(format)) let buf = pins.i2cReadBuffer(address, pins.sizeOf(format))
return buf.getNumber(format, 0) return buf.getNumber(format, 0)
@ -28,6 +30,8 @@ namespace pins {
/** /**
* Write one number to a 7-bit I2C address. * Write one number to a 7-bit I2C address.
*/ */
//% help=pins/i2c-write-number
//% 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 { export function i2cWriteNumber(address: number, value: number, format: NumberFormat): void {
let buf = createBuffer(pins.sizeOf(format)) let buf = createBuffer(pins.sizeOf(format))
buf.setNumber(format, 0, value) buf.setNumber(format, 0, value)
@ -37,6 +41,7 @@ namespace pins {
/** /**
* Get the size in bytes of specified number format. * Get the size in bytes of specified number format.
*/ */
//%
export function sizeOf(format: NumberFormat) { export function sizeOf(format: NumberFormat) {
switch (format) { switch (format) {
case NumberFormat.Int8LE: case NumberFormat.Int8LE: