diff --git a/libs/color-sensor/color.ts b/libs/color-sensor/color.ts index 007c7064..34fd3f82 100644 --- a/libs/color-sensor/color.ts +++ b/libs/color-sensor/color.ts @@ -81,7 +81,7 @@ namespace sensors { else maxModeRange = 100; // ReflectedLightIntensity or AmbientLightIntensity this._setMode(m); // Change mode pause(MODE_SWITCH_DELAY); - pauseUntil(() => (this.getStatus() == 8 && (this.mode == ColorSensorMode.RgbRaw ? this._queryArr()[0] : this._query()) <= maxModeRange)); // Pause until mode change + pauseUntil(() => (this.getStatus() == 8 && this._query()[0] <= maxModeRange)); // Pause until mode change } else { this._setMode(m); } @@ -98,47 +98,33 @@ namespace sensors { if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.AmbientLightIntensity || this.mode == ColorSensorMode.ReflectedLightIntensity) - return this.getNumber(NumberFormat.UInt8LE, 0) + return [this.getNumber(NumberFormat.UInt8LE, 0)]; else if (this.mode == ColorSensorMode.RefRaw) - return this.getNumber(NumberFormat.UInt16LE, 0) - return 0 - } - - _queryArr(): number[] { - if (this.mode == ColorSensorMode.RgbRaw) { + return [this.getNumber(NumberFormat.UInt16LE, 0)]; + else if (this.mode == ColorSensorMode.RgbRaw) { return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)]; } - return [0, 0, 0]; + return [0]; } - _info(): string { + _info() { switch (this.mode) { case ColorSensorMode.Color: - return ["none", + return [["none", "black", "blue", "green", "yellow", "red", "white", - "brown"][this._query()]; + "brown"][this._query()[0]]]; case ColorSensorMode.AmbientLightIntensity: case ColorSensorMode.ReflectedLightIntensity: - return `${this._query()}%`; - case ColorSensorMode.RgbRaw: - return "array"; - default: - return this._query().toString(); - } - } - - _infoArr(): string[] { - switch (this.mode) { + return [`${this._query()}%`]; case ColorSensorMode.RgbRaw: - const queryArr = this._queryArr().map(number => number.toString()); - return queryArr; + return this._query().map(number => number.toString()); default: - return ["0", "0", "0"]; + return [this._query()[0].toString()]; } } diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 3033d3c0..34c6bca2 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -1,30 +1,3 @@ - -/** - * Patterns for lights under the buttons. - */ -const enum StatusLight { - //% block=off enumval=0 - Off = 0, - //% block=green enumval=1 - Green = 1, - //% block=red enumval=2 - Red = 2, - //% block=orange enumval=3 - Orange = 3, - //% block="green flash" enumval=4 - GreenFlash = 4, - //% block="red flash" enumval=5 - RedFlash = 5, - //% block="orange flash" enumval=6 - OrangeFlash = 6, - //% block="green pulse" enumval=7 - GreenPulse = 7, - //% block="red pulse" enumval=8 - RedPulse = 8, - //% block="orange pulse" enumval=9 - OrangePulse = 9, -} - /** * User interaction on buttons */ @@ -246,34 +219,4 @@ namespace control { } return r } -} - -namespace brick { - // the brick starts with the red color - let currPattern: StatusLight = StatusLight.Off; - - /** - * Gets the current light pattern. - */ - //% weight=99 group="Buttons" - //% help=brick/status-light - export function statusLight() { - return currPattern; - } - - /** - * Set lights. - * @param pattern the lights pattern to use. eg: StatusLight.Orange - */ - //% blockId=setLights block="set status light to %pattern" - //% weight=100 group="Buttons" - //% help=brick/set-status-light - export function setStatusLight(pattern: StatusLight): void { - if (currPattern === pattern) - return - currPattern = pattern; - const cmd = output.createBuffer(2) - cmd[0] = pattern + 48 - brick.internal.getBtnsMM().write(cmd) - } -} +} \ No newline at end of file diff --git a/libs/core/indicator.ts b/libs/core/indicator.ts new file mode 100644 index 00000000..c327a70b --- /dev/null +++ b/libs/core/indicator.ts @@ -0,0 +1,55 @@ +/** + * Patterns for lights under the buttons. + */ +const enum StatusLight { + //% block=off enumval=0 + Off = 0, + //% block=green enumval=1 + Green = 1, + //% block=red enumval=2 + Red = 2, + //% block=orange enumval=3 + Orange = 3, + //% block="green flash" enumval=4 + GreenFlash = 4, + //% block="red flash" enumval=5 + RedFlash = 5, + //% block="orange flash" enumval=6 + OrangeFlash = 6, + //% block="green pulse" enumval=7 + GreenPulse = 7, + //% block="red pulse" enumval=8 + RedPulse = 8, + //% block="orange pulse" enumval=9 + OrangePulse = 9, +} + +namespace brick { + // the brick starts with the red color + let currPattern: StatusLight = StatusLight.Off; + + /** + * Gets the current light pattern. + */ + //% weight=99 group="Indicator" + //% help=brick/status-light + export function statusLight() { + return currPattern; + } + + /** + * Set lights. + * @param pattern the lights pattern to use. eg: StatusLight.Orange + */ + //% blockId=setLights block="set status light to %pattern" + //% weight=100 group="Indicator" + //% help=brick/set-status-light + export function setStatusLight(pattern: StatusLight): void { + if (currPattern === pattern) + return + currPattern = pattern; + const cmd = output.createBuffer(2) + cmd[0] = pattern + 48 + brick.internal.getBtnsMM().write(cmd) + } +} diff --git a/libs/core/input.ts b/libs/core/input.ts index 9e1c5fff..a56cfde7 100644 --- a/libs/core/input.ts +++ b/libs/core/input.ts @@ -1,4 +1,8 @@ namespace sensors.internal { + + const UART_PORT_CHANGED = 1; + const UART_DATA_READY = 8; + export class Poller { private query: () => number; private update: (previous: number, current: number) => void; @@ -7,7 +11,7 @@ namespace sensors.internal { private previousValue: number; private currentValue: number; private lastQuery: number; // track down the last time we did a query/update cycle - private lastPause: number; // track down the last time we pause in the sensor polling loop + private lastPause: number; // track down the last time we pause in the sensor polling loop constructor(interval: number, query: () => number, update: (previous: number, current: number) => void) { this.interval = interval | 0; @@ -35,6 +39,7 @@ namespace sensors.internal { private poll() { control.runInBackground(() => { + pause(this.interval); this.lastQuery = this.lastPause = control.millis(); this.previousValue = this.currentValue = this.query(); this.update(this.previousValue, this.currentValue); @@ -55,12 +60,12 @@ namespace sensors.internal { return s } - let analogMM: MMap - let uartMM: MMap - let IICMM: MMap - let powerMM: MMap - let devcon: Buffer - let devPoller: Poller + let analogMM: MMap; + let uartMM: MMap; + let IICMM: MMap; + let powerMM: MMap; + let devcon: Buffer; + let devPoller: Poller; let sensorInfos: SensorInfo[]; let batteryInfo: { @@ -94,7 +99,7 @@ namespace sensors.internal { } private query() { - if (this.sensor) return this.sensor._query(); + if (this.sensor) return this.sensor._query()[0]; return 0; } @@ -120,10 +125,11 @@ namespace sensors.internal { powerMM = control.mmap("/dev/lms_power", 2, 0) - devPoller = new Poller(250, () => { return hashDevices(); }, + devPoller = new Poller(900, () => { return hashDevices(); }, (prev, curr) => { detectDevices(); - }); + } + ); } export function getActiveSensors(): Sensor[] { @@ -131,25 +137,6 @@ namespace sensors.internal { return sensorInfos.filter(si => si.sensor && si.sensor.isActive()).map(si => si.sensor); } - function readUartInfo(port: number, mode: number) { - let buf = output.createBuffer(UartCtlOff.Size) - buf[UartCtlOff.Port] = port - buf[UartCtlOff.Mode] = mode - uartMM.ioctl(IO.UART_READ_MODE_INFO, buf) - return buf - //let info = `t:${buf[TypesOff.Type]} c:${buf[TypesOff.Connection]} m:${buf[TypesOff.Mode]} n:${buf.slice(0, 12).toHex()}` - //serial.writeLine("UART " + port + " / " + mode + " - " + info) - } - - export function readIICID(port: number) { - const buf = output.createBuffer(IICStr.Size) - buf[IICStr.Port] = port - IICMM.ioctl(IO.IIC_READ_TYPE_INFO, buf) - const manufacturer = bufferToString(buf.slice(IICStr.Manufacturer, 8)) - const sensorType = bufferToString(buf.slice(IICStr.SensorType, 8)) - return manufacturer + sensorType; - } - const ADC_REF = 5000 //!< [mV] maximal value on ADC const ADC_RES = 4095 //!< [CNT] maximal count on ADC // see c_ui.c @@ -220,42 +207,7 @@ namespace sensors.internal { const CinCnt = batteryInfo.CinCnt; const CoutCnt = batteryInfo.CoutCnt; const VinCnt = batteryInfo.VinCnt; - /* -void cUiUpdatePower(void) -{ -#ifndef Linux_X86 - DATAF CinV; - DATAF CoutV; - - if ((UiInstance.Hw == FINAL) || (UiInstance.Hw == FINALB)) - { - CinV = CNT_V(UiInstance.CinCnt) / AMP_CIN; - UiInstance.Vbatt = (CNT_V(UiInstance.VinCnt) / AMP_VIN) + CinV + VCE; - - UiInstance.Ibatt = CinV / SHUNT_IN; - CoutV = CNT_V(UiInstance.CoutCnt) / AMP_COUT; - UiInstance.Imotor = CoutV / SHUNT_OUT; - - } - else - { - CinV = CNT_V(UiInstance.CinCnt) / EP2_AMP_CIN; - UiInstance.Vbatt = (CNT_V(UiInstance.VinCnt) / AMP_VIN) + CinV + VCE; - - UiInstance.Ibatt = CinV / EP2_SHUNT_IN; - UiInstance.Imotor = 0; - - } - -#endif -#ifdef DEBUG_TEMP_SHUTDOWN - - UiInstance.Vbatt = 7.0; - UiInstance.Ibatt = 5.0; - -#endif -} - */ + const CinV = CNT_V(CinCnt) / AMP_CIN; const Vbatt = CNT_V(VinCnt) / AMP_VIN + CinV + VCE; const Ibatt = CinV / SHUNT_IN; @@ -281,82 +233,68 @@ void cUiUpdatePower(void) return r; } - let nonActivated = 0; function detectDevices() { - control.dmesg(`detect devices (hash ${hashDevices()})`) - const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS) - let numChanged = 0; - const uartSensors: SensorInfo[] = []; + control.dmesg(`DETECT DEVICES (hash ${hashDevices()})`); + const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS); for (const sensorInfo of sensorInfos) { - const newConn = conns[sensorInfo.port] - if (newConn == sensorInfo.connType - && sensorInfo.sensor - && sensorInfo.sensor.isActive()) { - if (newConn == DAL.CONN_INPUT_UART) - uartSensors.push(sensorInfo); + const newConn = conns[sensorInfo.port]; + if (newConn == sensorInfo.connType && sensorInfo.sensor && sensorInfo.sensor.isActive()) { continue; } - numChanged++ - sensorInfo.connType = newConn - sensorInfo.devType = DAL.DEVICE_TYPE_NONE + sensorInfo.connType = newConn; + sensorInfo.devType = DAL.DEVICE_TYPE_NONE; if (newConn == DAL.CONN_INPUT_UART) { - control.dmesg(`new UART connection at ${sensorInfo.port}`) + const status = getUartStatus(sensorInfo.port); + control.dmesg(`new UART connection at port ${sensorInfo.port} with status ${status}`); updateUartMode(sensorInfo.port, 0); - uartSensors.push(sensorInfo); } else if (newConn == DAL.CONN_NXT_IIC) { - control.dmesg(`new IIC connection at ${sensorInfo.port}`) - sensorInfo.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN - sensorInfo.iicid = readIICID(sensorInfo.port) - control.dmesg(`IIC ID ${sensorInfo.iicid.length}`) + sensorInfo.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN; + sensorInfo.iicid = readIICID(sensorInfo.port); + control.dmesg(`new IIC connection at port ${sensorInfo.port} with ID ${sensorInfo.iicid.length}`); } else if (newConn == DAL.CONN_INPUT_DUMB) { - control.dmesg(`new DUMB connection at ${sensorInfo.port}`) - // TODO? for now assume touch - sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH + control.dmesg(`new DUMB connection at port ${sensorInfo.port}`); + sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH; // TODO? for now assume touch sensor } else if (newConn == DAL.CONN_NONE || newConn == 0) { - //control.dmesg(`disconnect at port ${sensorInfo.port}`) + control.dmesg(`disconnect at port ${sensorInfo.port}`); } else { - control.dmesg(`unknown connection type: ${newConn} at ${sensorInfo.port}`) + control.dmesg(`unknown connection type ${newConn} at port ${sensorInfo.port}`); } } - if (uartSensors.length > 0) { + const uartSens = sensorInfos.filter(si => si.connType == DAL.CONN_INPUT_UART).length; + if (uartSens > 0) { setUartModes(); - for (const sensorInfo of uartSensors) { - let uinfo = readUartInfo(sensorInfo.port, 0) - sensorInfo.devType = uinfo[TypesOff.Type] + for (const sensorInfo of sensorInfos.filter(si => si.connType == DAL.CONN_INPUT_UART && si.devType == DAL.CONN_NONE)) { + const uinfo = readUartInfo(sensorInfo.port, 0); + sensorInfo.devType = uinfo[TypesOff.Type]; const mode = uinfo[TypesOff.Mode]; - control.dmesg(`UART type ${sensorInfo.devType} mode ${mode}`) + control.dmesg(`UART type ${sensorInfo.devType} mode ${mode} at port ${sensorInfo.port}`); } } - if (numChanged == 0 && nonActivated == 0) - return - - //control.dmesg(`updating sensor status`) - nonActivated = 0; - for (const sensorInfo of sensorInfos) { + control.dmesg(`UPDATE SENSOR STATUS`); + for (const sensorInfo of sensorInfos.filter(si => !si.sensor)) { if (sensorInfo.devType == DAL.DEVICE_TYPE_IIC_UNKNOWN) { - sensorInfo.sensor = sensorInfo.sensors.filter(s => s._IICId() == sensorInfo.iicid)[0] + sensorInfo.sensor = sensorInfo.sensors.filter(s => s._IICId() == sensorInfo.iicid)[0]; if (!sensorInfo.sensor) { - control.dmesg(`sensor not found for iicid=${sensorInfo.iicid} at ${sensorInfo.port}`) - nonActivated++; + control.dmesg(`sensor not found for iicid=${sensorInfo.iicid} at port ${sensorInfo.port}`); } else { - control.dmesg(`sensor connected iicid=${sensorInfo.iicid} at ${sensorInfo.port}`) - sensorInfo.sensor._activated() + control.dmesg(`sensor connected iicid=${sensorInfo.iicid} at port ${sensorInfo.port}`); + sensorInfo.sensor._activated(); } } else if (sensorInfo.devType != DAL.DEVICE_TYPE_NONE) { - sensorInfo.sensor = sensorInfo.sensors.filter(s => s._deviceType() == sensorInfo.devType)[0] + sensorInfo.sensor = sensorInfo.sensors.filter(s => s._deviceType() == sensorInfo.devType)[0]; if (!sensorInfo.sensor) { - control.dmesg(`sensor not found for type=${sensorInfo.devType} at ${sensorInfo.port}`) - nonActivated++; + control.dmesg(`sensor not found for type=${sensorInfo.devType} at port ${sensorInfo.port}`); } else { - control.dmesg(`sensor connected type=${sensorInfo.devType} at ${sensorInfo.port}`) - sensorInfo.sensor._activated() + control.dmesg(`sensor connected type=${sensorInfo.devType} at port ${sensorInfo.port}`); + sensorInfo.sensor._activated(); } } } - //control.dmesg(`detect devices done`) + + control.dmesg(`DETECT DEVICES DONE`); } export class Sensor extends control.Component { @@ -392,16 +330,12 @@ void cUiUpdatePower(void) return sensorInfos[this._port].sensor == this } - _query() { - return 0 - } - - _info(): string { - return this._query().toString(); + _query(): number[] { + return [0]; } - _infoArr(): string[] { - return [this._query().toString()]; + _info(): string[] { + return [this._query()[0].toString()]; } _update(prev: number, curr: number) { @@ -520,7 +454,28 @@ void cUiUpdatePower(void) } } - export const iicsensor = new IICSensor(3) + export const i2csensor1 = new IICSensor(1); + export const i2csensor2 = new IICSensor(2); + export const i2csensor3 = new IICSensor(3); + export const i2csensor4 = new IICSensor(4); + + function readUartInfo(port: number, mode: number) { + let buf = output.createBuffer(UartCtlOff.Size); + buf[UartCtlOff.Port] = port; + buf[UartCtlOff.Mode] = mode; + uartMM.ioctl(IO.UART_READ_MODE_INFO, buf); + //control.dmesg(`UART_READ_MODE p:${port} t:${buf[TypesOff.Type]} c:${buf[TypesOff.Connection]} m:${buf[TypesOff.Mode]} n:${buf.slice(0, 12).toHex()}`); + return buf; + } + + export function readIICID(port: number) { + const buf = output.createBuffer(IICStr.Size); + buf[IICStr.Port] = port; + IICMM.ioctl(IO.IIC_READ_TYPE_INFO, buf); + const manufacturer = bufferToString(buf.slice(IICStr.Manufacturer, 8)); + const sensorType = bufferToString(buf.slice(IICStr.SensorType, 8)); + return manufacturer + sensorType; + } function uartReset(port: number) { if (port < 0) return @@ -537,16 +492,18 @@ void cUiUpdatePower(void) } function waitNonZeroUartStatus(port: number) { - while (true) { - if (port < 0) return 0 - let s = getUartStatus(port) - if (s) return s - pause(25) + let retry = 20; + while (retry-- > 0) { + const s = getUartStatus(port); + if (s) return s; + control.dmesg(`UART status 0 at port ${port}, waiting...`); + pause(25); } + return 0; } function uartClearChange(port: number) { - control.dmesg(`UART clear change`); + control.dmesg(`UART clear change at port ${port}`); while (true) { let status = getUartStatus(port) if (port < 0) break @@ -557,18 +514,17 @@ void cUiUpdatePower(void) devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART) devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 0) devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, 0) - + control.dmesg(`UART_CLEAR_CHANGED status ${status} ${devcon.toHex()}`) uartMM.ioctl(IO.UART_CLEAR_CHANGED, devcon) - uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port, - getUartStatus(port) & 0xfffe) + uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port, getUartStatus(port) & 0xfffe) pause(10) } } function setUartModes() { - control.dmesg(`UART set modes 0x${devcon.toHex()}`) - uartMM.ioctl(IO.UART_SET_CONN, devcon) + control.dmesg(`UART_SET_CONN ${devcon.toHex()}`); + uartMM.ioctl(IO.UART_SET_CONN, devcon); const ports: number[] = []; for (let port = 0; port < DAL.NUM_INPUTS; ++port) { if (devcon.getNumber(NumberFormat.Int8LE, DevConOff.Connection + port) == DAL.CONN_INPUT_UART) { @@ -578,38 +534,36 @@ void cUiUpdatePower(void) while (ports.length) { const port = ports.pop(); - const status = waitNonZeroUartStatus(port) - control.dmesg(`UART status ${status} at ${port}`); + const status = waitNonZeroUartStatus(port); + control.dmesg(`UART status ${status} at port ${port}`); if (!(status & UART_DATA_READY)) setUartMode(port, devcon[DevConOff.Mode + port]); } } function updateUartMode(port: number, mode: number) { - control.dmesg(`UART update mode to ${mode} at ${port}`) + control.dmesg(`UART update mode to ${mode} at port ${port}`); devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART) devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33) devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode) } - - const UART_PORT_CHANGED = 1 - const UART_DATA_READY = 8 + function setUartMode(port: number, mode: number) { while (true) { - if (port < 0) return + if (port < 0) return; updateUartMode(port, mode); - control.dmesg(`UART set mode 0x${devcon.toHex()}`) - uartMM.ioctl(IO.UART_SET_CONN, devcon) - let status = waitNonZeroUartStatus(port) + control.dmesg(`UART_SET_CONN ${devcon.toHex()}`); + uartMM.ioctl(IO.UART_SET_CONN, devcon); + let status = waitNonZeroUartStatus(port); if (status & UART_PORT_CHANGED) { - control.dmesg(`UART clear changed at ${port}`) - uartClearChange(port) + control.dmesg(`UART clear changed at port ${port}`); + uartClearChange(port); } else { - control.dmesg(`UART status ${status}`); + control.dmesg(`UART status ${status} at port ${port}`); if (status & UART_DATA_READY) break; } - pause(10) + pause(10); } } @@ -638,7 +592,7 @@ void cUiUpdatePower(void) export function transactionIIC(port: number, deviceAddress: number, writeBuf: number[], readLen: number) { if (port < 0) return; - let iicdata = output.createBuffer(IICDat.Size) + const iicdata = output.createBuffer(IICDat.Size) iicdata.setNumber(NumberFormat.Int8LE, IICDat.Port, port) iicdata.setNumber(NumberFormat.Int8LE, IICDat.Repeat, 0) iicdata.setNumber(NumberFormat.Int16LE, IICDat.Time, 0) diff --git a/libs/core/pxt.json b/libs/core/pxt.json index d2b1a923..b72d6d61 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -13,6 +13,7 @@ "timer.ts", "serialnumber.cpp", "buttons.ts", + "indicator.ts", "screen.cpp", "battery.ts", "output.cpp", diff --git a/libs/ev3/brick.ts b/libs/ev3/brick.ts index 16c073ef..d8c5f10c 100644 --- a/libs/ev3/brick.ts +++ b/libs/ev3/brick.ts @@ -6,7 +6,7 @@ namespace brick { //% help=reference/brick/exit-program //% weight=10 //% blockGap=8 - //% group="Buttons" + //% group="Program" export function exitProgram() { control.reset(); } diff --git a/libs/ev3/ns.ts b/libs/ev3/ns.ts index 6a0f436d..812781b8 100644 --- a/libs/ev3/ns.ts +++ b/libs/ev3/ns.ts @@ -1,5 +1,5 @@ //% color="#68C3E2" weight=100 icon="\uf106" -//% groups='["Buttons", "Screen", "Power"]' +//% groups='["Buttons", "Indicator", "Screen", "Power", "Program"]' //% labelLineWidth=60 namespace brick { } @@ -7,6 +7,7 @@ namespace brick { //% color="#C8509B" weight=95 icon="\uf10f" //% labelLineWidth=100 //% groups='["Touch Sensor", "Color Sensor", "Ultrasonic Sensor", "Gyro Sensor", "Infrared Sensor", "Remote Infrared Beacon", "Calibration"]' +//% subcategories='["NXT", "HiTechnic"]' namespace sensors { } diff --git a/libs/gyro-sensor/gyro.ts b/libs/gyro-sensor/gyro.ts index 208a748f..7e73153e 100644 --- a/libs/gyro-sensor/gyro.ts +++ b/libs/gyro-sensor/gyro.ts @@ -23,10 +23,10 @@ namespace sensors { return DAL.DEVICE_TYPE_GYRO } - _query(): number { + _query() { const v = this.getNumber(NumberFormat.Int16LE, 0); this._angle.integrate(v - this._drift); - return v; + return [v]; } setMode(m: GyroSensorMode) { @@ -73,7 +73,7 @@ namespace sensors { this.poke(); if (this._calibrating) pauseUntil(() => !this._calibrating, 2000); - return this._query() - this._drift; + return this._query()[0] - this._drift; } /** @@ -253,21 +253,21 @@ namespace sensors { const n = 10; let d = 0; for (let i = 0; i < n; ++i) { - d += this._query(); + d += this._query()[0]; pause(20); } this._drift = d / n; this._angle.reset(); } - _info(): string { + _info() { if (this._calibrating) - return "cal..."; + return ["cal..."]; - let r = `${this._query()}r`; + let r = `${this._query()[0]}r`; if (this._drift != 0) r += `-${this._drift | 0}`; - return r; + return [r]; } } diff --git a/libs/infrared-sensor/ir.ts b/libs/infrared-sensor/ir.ts index cadecac7..99763386 100644 --- a/libs/infrared-sensor/ir.ts +++ b/libs/infrared-sensor/ir.ts @@ -155,19 +155,19 @@ namespace sensors { _query() { if (this.mode == InfraredSensorMode.RemoteControl) - return mapButton(this.getNumber(NumberFormat.UInt8LE, this._channel)); + return [mapButton(this.getNumber(NumberFormat.UInt8LE, this._channel))]; else if (this.mode == InfraredSensorMode.Proximity) { - return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff; + return [this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff]; } - return 0 + return [0]; } - _info(): string { + _info() { if (this.mode == InfraredSensorMode.RemoteControl) - return "remote"; + return ["remote"]; else if (this.mode == InfraredSensorMode.Proximity) - return `${this._query()}%`; - return ""; + return [`${this._query()}%`]; + return [""]; } _update(prev: number, curr: number) { diff --git a/libs/screen/targetoverrides.ts b/libs/screen/targetoverrides.ts index 0d0005a9..d10b7ecf 100644 --- a/libs/screen/targetoverrides.ts +++ b/libs/screen/targetoverrides.ts @@ -272,13 +272,13 @@ namespace brick { const x = (si.port() - 1) * col + 2; const inf = si._info(); if (screenMode != ScreenMode.Ports) return; - if (inf == "array") { - let infArr = si._infoArr(); + if (inf.length > 1) { + let infArr = si._info(); for (let data = 0, str = Math.min(infArr.length + 1, 4); data < Math.min(infArr.length, 3); data++, str--) { screen.print(infArr[data], x, h - str * lineHeight8, 1, infArr[data].length > 4 ? image.font5 : image.font8); } - } else if (inf) { - screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8); + } else if (inf[0]) { + screen.print(inf[0], x, h - 2 * lineHeight8, 1, inf[0].length > 4 ? image.font5 : image.font8); } } } diff --git a/libs/touch-sensor/touch.ts b/libs/touch-sensor/touch.ts index 854220b4..8c3fb979 100644 --- a/libs/touch-sensor/touch.ts +++ b/libs/touch-sensor/touch.ts @@ -12,11 +12,11 @@ namespace sensors { } _query() { - return this._readPin6() > 2500 ? 1 : 0 + return this._readPin6() > 2500 ? [1] : [0]; } - _info(): string { - return this._query() ? "pres" : "rel"; + _info() { + return this._query() ? ["pres"] : ["rel"]; } _update(prev: number, curr: number) { diff --git a/libs/ultrasonic-sensor/ultrasonic.ts b/libs/ultrasonic-sensor/ultrasonic.ts index 8ed8bc22..a9fe0690 100644 --- a/libs/ultrasonic-sensor/ultrasonic.ts +++ b/libs/ultrasonic-sensor/ultrasonic.ts @@ -23,12 +23,12 @@ namespace sensors { return DAL.DEVICE_TYPE_ULTRASONIC } - _query(): number { - return ((this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff) / 10) >> 0; // range is 0..2550, in 0.1 cm increments. + _query() { + return [((this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff) / 10) >> 0]; // range is 0..2550, in 0.1 cm increments. } - _info(): string { - return `${this.distance()}cm` + _info() { + return [`${this.distance()}cm`]; } _update(prev: number, curr: number) { @@ -87,7 +87,7 @@ namespace sensors { this.poke(); // it supposedly also has an inch mode, but we stick to cm this._setMode(0) - return this._query(); + return this._query()[0]; } diff --git a/package.json b/package.json index b000b91e..8846277c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ }, "dependencies": { "pxt-common-packages": "11.1.2", - "pxt-core": "9.1.10" + "pxt-core": "9.1.23" }, "scripts": { "test": "node node_modules/pxt-core/built/pxt.js travis" diff --git a/theme/style.less b/theme/style.less index cd1bcf93..20931df9 100644 --- a/theme/style.less +++ b/theme/style.less @@ -76,6 +76,11 @@ min-width: 2.0rem; } +/* lego and microsoft logos separator */ +.menubar .ui.menu .brand:before { + border-left: 2px solid #888888; +} + /* Editor menu toggle */ #root:not(.hc) #editordropdown { padding: 0 1em; @@ -102,7 +107,7 @@ } .menubar .ui.item.editor-menuitem .item.toggle { - height: 45px; + height: 100%; } .sandboxfooter a:not(.thin) {