Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
75cf8da396 | |||
db9b6a995b | |||
fb255edafe | |||
f4c39f74e8 | |||
3e56e2c3e2 | |||
79b5f8cc88 | |||
312729142f | |||
5bd4aed0e1 | |||
cfaa4ae3ef | |||
faa839d59f | |||
630687bfce | |||
2b300a4094 | |||
5fb8c0de6e | |||
1f65cd59a8 |
9
.travis.yml
Normal file
9
.travis.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- "8.9.0"
|
||||||
|
script:
|
||||||
|
- "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
sudo: false
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
@ -190,12 +190,10 @@ if (true) {
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
forever(function () {
|
forever(function () {
|
||||||
while (true) {
|
while (sensors.color3.color() == ColorSensorColor.Black) {
|
||||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
|
||||||
motors.largeBC.steer(-30, 50)
|
motors.largeBC.steer(-30, 50)
|
||||||
}
|
}
|
||||||
while (true) {
|
while (sensors.color3.color() == ColorSensorColor.White) {
|
||||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
|
||||||
motors.largeBC.steer(30, 50)
|
motors.largeBC.steer(30, 50)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -209,11 +207,9 @@ Else the Color Sensor detects the color white, start motors ``B`` and ``C`` (dri
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
forever(function () {
|
forever(function () {
|
||||||
if (true) {
|
if (sensors.color3.color() == ColorSensorColor.Black) {
|
||||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
|
||||||
motors.largeBC.steer(-30, 50)
|
motors.largeBC.steer(-30, 50)
|
||||||
} else {
|
} else {
|
||||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
|
||||||
motors.largeBC.steer(30, 50)
|
motors.largeBC.steer(30, 50)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
import jobs.generation.Utilities;
|
|
||||||
import jobs.generation.InternalUtilities;
|
|
||||||
|
|
||||||
def project = GithubProject
|
|
||||||
def projectName = "pxt-ev3"
|
|
||||||
|
|
||||||
[true, false].each { isPR ->
|
|
||||||
def newJobName = projectName
|
|
||||||
|
|
||||||
if (isPR) {
|
|
||||||
newJobName += "_PR"
|
|
||||||
} else {
|
|
||||||
newJobName += "_Push"
|
|
||||||
}
|
|
||||||
|
|
||||||
def newJob = job(newJobName) {
|
|
||||||
steps {
|
|
||||||
shell("chmod +x ./jenkins.sh")
|
|
||||||
shell("./jenkins.sh ${isPR}")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPR) {
|
|
||||||
wrappers {
|
|
||||||
credentialsBinding {
|
|
||||||
string("PXT_ACCESS_TOKEN", "pxt_access_token")
|
|
||||||
string("PXT_RELEASE_REPO", "pxt_release_repo_ev3")
|
|
||||||
string("CROWDIN_KEY", "pxt_crowdin_key")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Utilities.setMachineAffinity(newJob, "Ubuntu", "20161020")
|
|
||||||
InternalUtilities.standardJobSetup(newJob, project, isPR, "*/*")
|
|
||||||
|
|
||||||
if (isPR) {
|
|
||||||
Utilities.addGithubPRTrigger(newJob, "Default Testing")
|
|
||||||
} else {
|
|
||||||
Utilities.addGithubPushTrigger(newJob)
|
|
||||||
}
|
|
||||||
}
|
|
56
jenkins.sh
56
jenkins.sh
@ -1,56 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Set up NVM
|
|
||||||
export NVM_DIR="/home/dotnet-bot/.nvm"
|
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
|
||||||
|
|
||||||
nvm install 8
|
|
||||||
|
|
||||||
# Set up build environment variables
|
|
||||||
echo ---------- Setting build environment variables
|
|
||||||
echo Git branch: $GIT_BRANCH
|
|
||||||
echo isPR: $1
|
|
||||||
|
|
||||||
originRegex="^origin/.*"
|
|
||||||
branchRegex="^origin/\K.*(?=$)"
|
|
||||||
releaseBranchRegex="^(master|v\d+)$"
|
|
||||||
|
|
||||||
if [[ "$GIT_BRANCH" =~ $originRegex ]]; then
|
|
||||||
branchName=$(echo ${GIT_BRANCH} | grep -oP $branchRegex)
|
|
||||||
echo Setting TRAVIS_BRANCH to ${branchName}
|
|
||||||
export TRAVIS_BRANCH=${branchName}
|
|
||||||
else
|
|
||||||
echo Setting TRAVIS_BRANCH to $GIT_BRANCH
|
|
||||||
export TRAVIS_BRANCH=$GIT_BRANCH
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$1" == "false" ]; then
|
|
||||||
echo Setting TRAVIS_PULL_REQUEST to false
|
|
||||||
export TRAVIS_PULL_REQUEST=false
|
|
||||||
|
|
||||||
if [[ "$TRAVIS_BRANCH" =~ $releaseBranchRegex ]]; then
|
|
||||||
if [[ -z $PXT_RELEASE_REPO ]]; then
|
|
||||||
echo Cannot find release repo\; skipping tag checks
|
|
||||||
else
|
|
||||||
gitTag=$(git describe --tags --exact-match 2> /dev/null)
|
|
||||||
builtTag=$(git ls-remote --tags $PXT_RELEASE_REPO | grep -o "refs/tags/$gitTag$")
|
|
||||||
|
|
||||||
echo Current tag: $gitTag
|
|
||||||
echo Built tag: $builtTag
|
|
||||||
|
|
||||||
if [[ ! -z $gitTag && -z $builtTag ]]; then
|
|
||||||
echo Built tag not found\; building tag
|
|
||||||
echo Setting TRAVIS_BRANCH to $gitTag
|
|
||||||
export TRAVIS_BRANCH=$gitTag
|
|
||||||
echo Setting TRAVIS_TAG to $gitTag
|
|
||||||
export TRAVIS_TAG=$gitTag
|
|
||||||
else
|
|
||||||
echo Not a tag build
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Perform build
|
|
||||||
npm install
|
|
||||||
npm test
|
|
@ -1,5 +1,5 @@
|
|||||||
const enum ColorSensorMode {
|
const enum ColorSensorMode {
|
||||||
None = -1,
|
None = 0,
|
||||||
//% block="reflected light intensity"
|
//% block="reflected light intensity"
|
||||||
ReflectedLightIntensity = 0,
|
ReflectedLightIntensity = 0,
|
||||||
//% block="ambient light intensity"
|
//% block="ambient light intensity"
|
||||||
@ -15,7 +15,9 @@ enum LightIntensityMode {
|
|||||||
//% block="reflected light"
|
//% block="reflected light"
|
||||||
Reflected = ColorSensorMode.ReflectedLightIntensity,
|
Reflected = ColorSensorMode.ReflectedLightIntensity,
|
||||||
//% block="ambient light"
|
//% block="ambient light"
|
||||||
Ambient = ColorSensorMode.AmbientLightIntensity
|
Ambient = ColorSensorMode.AmbientLightIntensity,
|
||||||
|
//% block="reflected light (raw)"
|
||||||
|
ReflectedRaw = ColorSensorMode.RefRaw
|
||||||
}
|
}
|
||||||
|
|
||||||
const enum ColorSensorColor {
|
const enum ColorSensorColor {
|
||||||
@ -93,6 +95,8 @@ namespace sensors {
|
|||||||
|| this.mode == ColorSensorMode.AmbientLightIntensity
|
|| this.mode == ColorSensorMode.AmbientLightIntensity
|
||||||
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
|
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
if (this.mode == ColorSensorMode.RefRaw || this.mode == ColorSensorMode.RgbRaw)
|
||||||
|
return this.getNumber(NumberFormat.UInt16LE, 0)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +118,7 @@ namespace sensors {
|
|||||||
|
|
||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
if (this.calibrating) return; // simply ignore data updates while calibrating
|
if (this.calibrating) return; // simply ignore data updates while calibrating
|
||||||
if (this.mode == ColorSensorMode.Color)
|
if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw)
|
||||||
control.raiseEvent(this._id, this._colorEventValue(curr));
|
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||||
else
|
else
|
||||||
this.thresholdDetector.setLevel(curr);
|
this.thresholdDetector.setLevel(curr);
|
||||||
@ -179,6 +183,22 @@ namespace sensors {
|
|||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current raw rgb values from the color sensor.
|
||||||
|
* @param sensor the color sensor to query the request
|
||||||
|
*/
|
||||||
|
//% help=sensors/color-sensor/rgbraw
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% this.fieldEditor="ports"
|
||||||
|
//% weight=98
|
||||||
|
//% group="Color Sensor"
|
||||||
|
//% blockGap=8
|
||||||
|
rgbRaw(): number[] {
|
||||||
|
this.setMode(ColorSensorMode.RgbRaw);
|
||||||
|
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the ambient light changes.
|
* Registers code to run when the ambient light changes.
|
||||||
* @param condition the light condition
|
* @param condition the light condition
|
||||||
@ -229,7 +249,12 @@ namespace sensors {
|
|||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
light(mode: LightIntensityMode) {
|
light(mode: LightIntensityMode) {
|
||||||
this.setMode(<ColorSensorMode><number>mode)
|
this.setMode(<ColorSensorMode><number>mode)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
switch(mode) {
|
||||||
|
case LightIntensityMode.ReflectedRaw:
|
||||||
|
return this.reflectedLightRaw();
|
||||||
|
default:
|
||||||
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,6 +273,15 @@ namespace sensors {
|
|||||||
return this.light(LightIntensityMode.Reflected);
|
return this.light(LightIntensityMode.Reflected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the raw reflection light value
|
||||||
|
*/
|
||||||
|
//%
|
||||||
|
reflectedLightRaw(): number {
|
||||||
|
this.setMode(ColorSensorMode.RefRaw);
|
||||||
|
return this.getNumber(NumberFormat.UInt16LE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a threshold value
|
* Set a threshold value
|
||||||
* @param condition the dark or bright light condition
|
* @param condition the dark or bright light condition
|
||||||
|
@ -25,8 +25,17 @@ namespace sensors.internal {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function bufferToString(buf: Buffer): string {
|
||||||
|
let s = ''
|
||||||
|
for (let i = 0; i < buf.length; i++)
|
||||||
|
s += String.fromCharCode(buf[i])
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
let analogMM: MMap
|
let analogMM: MMap
|
||||||
let uartMM: MMap
|
let uartMM: MMap
|
||||||
|
let IICMM: MMap
|
||||||
let devcon: Buffer
|
let devcon: Buffer
|
||||||
let sensorInfos: SensorInfo[]
|
let sensorInfos: SensorInfo[]
|
||||||
|
|
||||||
@ -36,11 +45,13 @@ namespace sensors.internal {
|
|||||||
sensors: Sensor[]
|
sensors: Sensor[]
|
||||||
connType: number
|
connType: number
|
||||||
devType: number
|
devType: number
|
||||||
|
iicid: string
|
||||||
|
|
||||||
constructor(p: number) {
|
constructor(p: number) {
|
||||||
this.port = p
|
this.port = p
|
||||||
this.connType = DAL.CONN_NONE
|
this.connType = DAL.CONN_NONE
|
||||||
this.devType = DAL.DEVICE_TYPE_NONE
|
this.devType = DAL.DEVICE_TYPE_NONE
|
||||||
|
this.iicid = ''
|
||||||
this.sensors = []
|
this.sensors = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,6 +68,9 @@ namespace sensors.internal {
|
|||||||
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
|
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
|
||||||
if (!uartMM) control.fail("no uart sensor")
|
if (!uartMM) control.fail("no uart sensor")
|
||||||
|
|
||||||
|
IICMM = control.mmap("/dev/lms_iic", IICOff.Size, 0)
|
||||||
|
if(!IICMM) control.fail("no iic sensor")
|
||||||
|
|
||||||
forever(() => {
|
forever(() => {
|
||||||
detectDevices()
|
detectDevices()
|
||||||
pause(500)
|
pause(500)
|
||||||
@ -89,6 +103,15 @@ namespace sensors.internal {
|
|||||||
//serial.writeLine("UART " + port + " / " + mode + " - " + info)
|
//serial.writeLine("UART " + port + " / " + mode + " - " + info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readIICID(port: number) {
|
||||||
|
let buf = output.createBuffer(IICStr.Size)
|
||||||
|
buf[IICStr.Port] = port
|
||||||
|
IICMM.ioctl(IO.IIC_READ_TYPE_INFO, buf)
|
||||||
|
let Manufacturer = bufferToString(buf.slice(IICStr.Manufacturer, 8))
|
||||||
|
let SensorType = bufferToString(buf.slice(IICStr.SensorType, 8))
|
||||||
|
return Manufacturer + SensorType ;
|
||||||
|
}
|
||||||
|
|
||||||
export function getBatteryInfo(): { temp: number; current: number } {
|
export function getBatteryInfo(): { temp: number; current: number } {
|
||||||
init();
|
init();
|
||||||
return {
|
return {
|
||||||
@ -97,6 +120,7 @@ namespace sensors.internal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let nonActivated = 0;
|
||||||
function detectDevices() {
|
function detectDevices() {
|
||||||
let conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
let conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||||
let numChanged = 0
|
let numChanged = 0
|
||||||
@ -114,6 +138,11 @@ namespace sensors.internal {
|
|||||||
let uinfo = readUartInfo(info.port, 0)
|
let uinfo = readUartInfo(info.port, 0)
|
||||||
info.devType = uinfo[TypesOff.Type]
|
info.devType = uinfo[TypesOff.Type]
|
||||||
control.dmesg(`UART type ${info.devType}`)
|
control.dmesg(`UART type ${info.devType}`)
|
||||||
|
} else if(newConn == DAL.CONN_NXT_IIC){
|
||||||
|
control.dmesg(`new IIC connection at ${info.port}`)
|
||||||
|
info.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN
|
||||||
|
info.iicid = readIICID(info.port)
|
||||||
|
control.dmesg(`IIC ID ${info.iicid.length}`)
|
||||||
} else if (newConn == DAL.CONN_INPUT_DUMB) {
|
} else if (newConn == DAL.CONN_INPUT_DUMB) {
|
||||||
control.dmesg(`new DUMB connection at ${info.port}`)
|
control.dmesg(`new DUMB connection at ${info.port}`)
|
||||||
// TODO? for now assume touch
|
// TODO? for now assume touch
|
||||||
@ -125,19 +154,26 @@ namespace sensors.internal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numChanged == 0)
|
if (numChanged == 0 && nonActivated == 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
nonActivated = 0;
|
||||||
for (let si of sensorInfos) {
|
for (let si of sensorInfos) {
|
||||||
if (si.sensor && si.sensor._deviceType() != si.devType) {
|
if(si.devType == DAL.DEVICE_TYPE_IIC_UNKNOWN){
|
||||||
si.sensor = null
|
si.sensor = si.sensors.filter(s => s._IICId() == si.iicid)[0]
|
||||||
}
|
if (!si.sensor) {
|
||||||
if (si.devType != DAL.DEVICE_TYPE_NONE) {
|
control.dmesg(`sensor not found for iicid=${si.iicid} at ${si.port}`)
|
||||||
// TODO figure out compiler problem when '|| null' is added here!
|
nonActivated++;
|
||||||
|
}else{
|
||||||
|
control.dmesg(`sensor connected iicid=${si.iicid} at ${si.port}`)
|
||||||
|
si.sensor._activated()
|
||||||
|
}
|
||||||
|
}else if (si.devType != DAL.DEVICE_TYPE_NONE) {
|
||||||
si.sensor = si.sensors.filter(s => s._deviceType() == si.devType)[0]
|
si.sensor = si.sensors.filter(s => s._deviceType() == si.devType)[0]
|
||||||
if (si.sensor == null) {
|
if (!si.sensor) {
|
||||||
control.dmesg(`sensor not found for type=${si.devType} at ${si.port}`)
|
control.dmesg(`sensor not found for type=${si.devType} at ${si.port}`)
|
||||||
} else {
|
nonActivated++;
|
||||||
|
}else{
|
||||||
control.dmesg(`sensor connected type=${si.devType} at ${si.port}`)
|
control.dmesg(`sensor connected type=${si.devType} at ${si.port}`)
|
||||||
si.sensor._activated()
|
si.sensor._activated()
|
||||||
}
|
}
|
||||||
@ -187,6 +223,10 @@ namespace sensors.internal {
|
|||||||
_deviceType() {
|
_deviceType() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_IICId() {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AnalogSensor extends Sensor {
|
export class AnalogSensor extends Sensor {
|
||||||
@ -212,7 +252,6 @@ namespace sensors.internal {
|
|||||||
|
|
||||||
_activated() {
|
_activated() {
|
||||||
this.realmode = 0
|
this.realmode = 0
|
||||||
// uartReset(this.port) // TODO is it ever needed?
|
|
||||||
this._setMode(this.mode)
|
this._setMode(this.mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,6 +282,55 @@ namespace sensors.internal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class IICSensor extends Sensor {
|
||||||
|
protected mode: number // the mode user asked for
|
||||||
|
protected realmode: number // the mode the hardware is in
|
||||||
|
private readLength: number
|
||||||
|
|
||||||
|
constructor(port: number) {
|
||||||
|
super(port)
|
||||||
|
this.mode = 0
|
||||||
|
this.realmode = 0
|
||||||
|
this.readLength = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_activated() {
|
||||||
|
this.realmode = 0
|
||||||
|
this._setMode(this.mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _setMode(m: number) {
|
||||||
|
let v = m | 0
|
||||||
|
this.mode = v
|
||||||
|
if (!this.isActive()) return
|
||||||
|
if (this.realmode != this.mode) {
|
||||||
|
this.realmode = v
|
||||||
|
setIICMode(this._port, this._deviceType() ,v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getBytes(): Buffer {
|
||||||
|
return getIICBytes(this.isActive() ? this._port : -1, this.readLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
getNumber(fmt: NumberFormat, off: number) {
|
||||||
|
if (!this.isActive())
|
||||||
|
return 0
|
||||||
|
return getIICNumber(this.readLength, fmt, off, this._port)
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction(deviceAddress: number, write: number[], read: number){
|
||||||
|
this.readLength = read;
|
||||||
|
transactionIIC(this._port, deviceAddress, write, read)
|
||||||
|
}
|
||||||
|
|
||||||
|
_deviceType (){
|
||||||
|
return DAL.DEVICE_TYPE_IIC_UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const iicsensor = new IICSensor(3)
|
||||||
|
|
||||||
function uartReset(port: number) {
|
function uartReset(port: number) {
|
||||||
if (port < 0) return
|
if (port < 0) return
|
||||||
control.dmesg(`UART reset at ${port}`)
|
control.dmesg(`UART reset at ${port}`)
|
||||||
@ -322,6 +410,48 @@ namespace sensors.internal {
|
|||||||
UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + off)
|
UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + off)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setIICMode(port: number, type: number, mode: number){
|
||||||
|
if(port < 0)return;
|
||||||
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_NXT_IIC)
|
||||||
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, type)
|
||||||
|
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||||
|
IICMM.ioctl(IO.IIC_SET_CONN, devcon)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transactionIIC(port: number, deviceAddress: number, writeBuf: number[], readLen: number){
|
||||||
|
if(port < 0)return;
|
||||||
|
let 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)
|
||||||
|
iicdata.setNumber(NumberFormat.Int8LE, IICDat.WrLng, writeBuf.length + 1)
|
||||||
|
for(let i = 0; i< writeBuf.length; i++)
|
||||||
|
iicdata.setNumber(NumberFormat.Int8LE, IICDat.WrData + i + 1, writeBuf[i])
|
||||||
|
iicdata.setNumber(NumberFormat.Int8LE, IICDat.WrData, deviceAddress)
|
||||||
|
iicdata.setNumber(NumberFormat.Int8LE, IICDat.RdLng, readLen)
|
||||||
|
IICMM.ioctl(IO.IIC_SETUP, iicdata)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIICBytes(port: number, length: number) {
|
||||||
|
if (port < 0) return output.createBuffer(length);
|
||||||
|
let index = IICMM.getNumber(NumberFormat.UInt16LE, IICOff.Actual + port * 2);
|
||||||
|
let buf = IICMM.slice(
|
||||||
|
IICOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index,
|
||||||
|
length
|
||||||
|
);
|
||||||
|
|
||||||
|
// Reverse
|
||||||
|
for (let i = 0; i < length / 2; i++) {
|
||||||
|
let c = buf[i]
|
||||||
|
buf[i] = buf[length - i - 1]
|
||||||
|
buf[length - i - 1] = c
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIICNumber(length: number, format: NumberFormat, off: number, port: number) {
|
||||||
|
return getIICBytes(port, length).getNumber(format, off)
|
||||||
|
}
|
||||||
|
|
||||||
const enum NxtColOff {
|
const enum NxtColOff {
|
||||||
Calibration = 0, // uint32[4][3]
|
Calibration = 0, // uint32[4][3]
|
||||||
@ -405,6 +535,52 @@ namespace sensors.internal {
|
|||||||
Size = 58
|
Size = 58
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const enum IICOff {
|
||||||
|
TypeData = 0, // Types[8][4]
|
||||||
|
Repeat = 1792, // uint16[300][4]
|
||||||
|
Raw = 4192, // int8[32][300][4]
|
||||||
|
Actual = 42592, // uint16[4]
|
||||||
|
LogIn = 42600, // uint16[4]
|
||||||
|
Status = 42608, // int8[4]
|
||||||
|
Output = 42612, // int8[32][4]
|
||||||
|
OutputLength = 42740, // int8[4]
|
||||||
|
Size = 42744
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum IICCtlOff {
|
||||||
|
TypeData = 0, // Types
|
||||||
|
Port = 56, // int8
|
||||||
|
Mode = 57, // int8
|
||||||
|
Size = 58
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum IICDat {
|
||||||
|
Result = 0, // result
|
||||||
|
Port = 4, // int8
|
||||||
|
Repeat = 5, // int8
|
||||||
|
Time = 6, // int16
|
||||||
|
WrLng = 8, // int8
|
||||||
|
WrData = 9, // int8[32]
|
||||||
|
RdLng = 41, // int8
|
||||||
|
RdData = 42, //int8[32]
|
||||||
|
Size = 74,
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum IICStr {
|
||||||
|
Port = 0, // int8
|
||||||
|
Time = 2, // int16
|
||||||
|
Type = 4, // int8
|
||||||
|
Mode = 5, // int8
|
||||||
|
Manufacturer = 6, // int8[9]
|
||||||
|
SensorType = 15, // int[9]
|
||||||
|
SetupLng = 24, // int8
|
||||||
|
SetupString = 28, // ulong
|
||||||
|
PollLng = 32, // int8
|
||||||
|
PollString = 36, // ulong
|
||||||
|
ReadLng = 40, // int8
|
||||||
|
Size = 44
|
||||||
|
}
|
||||||
|
|
||||||
const enum IO {
|
const enum IO {
|
||||||
UART_SET_CONN = 0xc00c7500,
|
UART_SET_CONN = 0xc00c7500,
|
||||||
UART_READ_MODE_INFO = 0xc03c7501,
|
UART_READ_MODE_INFO = 0xc03c7501,
|
||||||
|
@ -134,6 +134,7 @@ namespace motors {
|
|||||||
protected _brake: boolean;
|
protected _brake: boolean;
|
||||||
private _pauseOnRun: boolean;
|
private _pauseOnRun: boolean;
|
||||||
private _initialized: boolean;
|
private _initialized: boolean;
|
||||||
|
private _brakeSettleTime: number;
|
||||||
private _init: () => void;
|
private _init: () => void;
|
||||||
private _run: (speed: number) => void;
|
private _run: (speed: number) => void;
|
||||||
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
|
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
|
||||||
@ -147,6 +148,7 @@ namespace motors {
|
|||||||
this._brake = false;
|
this._brake = false;
|
||||||
this._pauseOnRun = true;
|
this._pauseOnRun = true;
|
||||||
this._initialized = false;
|
this._initialized = false;
|
||||||
|
this._brakeSettleTime = 10;
|
||||||
this._init = init;
|
this._init = init;
|
||||||
this._run = run;
|
this._run = run;
|
||||||
this._move = move;
|
this._move = move;
|
||||||
@ -204,6 +206,20 @@ namespace motors {
|
|||||||
writePWM(b)
|
writePWM(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the settle time after braking in milliseconds (default is 10ms).
|
||||||
|
*/
|
||||||
|
//% blockId=motorSetBrakeSettleTime block="set %motor|brake settle time %millis|ms"
|
||||||
|
//% motor.fieldEditor="motors"
|
||||||
|
//% weight=1 blockGap=8
|
||||||
|
//% group="Properties"
|
||||||
|
//% millis.defl=200 millis.min=0 millis.max=500
|
||||||
|
setBrakeSettleTime(millis: number) {
|
||||||
|
this.init();
|
||||||
|
// ensure in [0,500]
|
||||||
|
this._brakeSettleTime = Math.max(0, Math.min(500, millis | 0))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the motor(s).
|
* Stops the motor(s).
|
||||||
*/
|
*/
|
||||||
@ -221,8 +237,8 @@ namespace motors {
|
|||||||
protected settle() {
|
protected settle() {
|
||||||
// if we've recently completed a motor command with brake
|
// if we've recently completed a motor command with brake
|
||||||
// allow 500ms for robot to settle
|
// allow 500ms for robot to settle
|
||||||
if (this._brake)
|
if (this._brake && this._brakeSettleTime > 0)
|
||||||
pause(500);
|
pause(this._brakeSettleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected pauseOnRun(stepsOrTime: number) {
|
protected pauseOnRun(stepsOrTime: number) {
|
||||||
@ -396,7 +412,7 @@ namespace motors {
|
|||||||
*/
|
*/
|
||||||
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
||||||
//% motor.fieldEditor="motors"
|
//% motor.fieldEditor="motors"
|
||||||
//% weight=58
|
//% weight=58 blockGap=8
|
||||||
//% group="Properties"
|
//% group="Properties"
|
||||||
//% help=motors/motor/set-regulated
|
//% help=motors/motor/set-regulated
|
||||||
setRegulated(value: boolean) {
|
setRegulated(value: boolean) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const enum GyroSensorMode {
|
const enum GyroSensorMode {
|
||||||
None = -1,
|
None = 0,
|
||||||
Angle = 0,
|
Angle = 0,
|
||||||
Rate = 1,
|
Rate = 1,
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const enum InfraredSensorMode {
|
const enum InfraredSensorMode {
|
||||||
None = -1,
|
None = 0,
|
||||||
Proximity = 0,
|
Proximity = 0,
|
||||||
Seek = 1,
|
Seek = 1,
|
||||||
RemoteControl = 2,
|
RemoteControl = 2,
|
||||||
|
4670
package-lock.json
generated
4670
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "1.0.11",
|
"version": "1.1.5",
|
||||||
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
||||||
"private": true,
|
"private": false,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
"education",
|
"education",
|
||||||
|
@ -27,6 +27,7 @@ namespace pxsim.sensors {
|
|||||||
|
|
||||||
export function __sensorUsed(port: number, type: number) {
|
export function __sensorUsed(port: number, type: number) {
|
||||||
//console.log("SENSOR INIT " + port + ", type: " + type);
|
//console.log("SENSOR INIT " + port + ", type: " + type);
|
||||||
|
if (type == DAL.DEVICE_TYPE_IIC_UNKNOWN) return; // Ignore IIC
|
||||||
if (!ev3board().hasSensor(port)) {
|
if (!ev3board().hasSensor(port)) {
|
||||||
const sensor = ev3board().getSensor(port, type);
|
const sensor = ev3board().getSensor(port, type);
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
|
Reference in New Issue
Block a user