Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9397641
add-subcategories
THEb0nny Jun 7, 2023
8596741
first-support-version
THEb0nny Jul 11, 2023
61cb6cc
update
THEb0nny Jul 13, 2023
5753d38
Update ns.ts
THEb0nny Sep 26, 2023
6414efe
sens-sim-support
THEb0nny Oct 17, 2023
5dacf1a
min-and-max-metod
THEb0nny Oct 19, 2023
5087eb8
sim-support-new-chenges
THEb0nny Oct 20, 2023
9ff419d
for-sim
THEb0nny Oct 23, 2023
1387d1a
Update input.ts
THEb0nny Oct 23, 2023
98dc3b4
add-test
THEb0nny Oct 23, 2023
2e32bb1
fix-convert-range-bug
THEb0nny Oct 23, 2023
44825ed
Update light.ts
THEb0nny Oct 23, 2023
a093f15
Update test.ts
THEb0nny Oct 23, 2023
a78beb8
Update test.ts
THEb0nny Oct 23, 2023
d475ec5
Update test.ts
THEb0nny Oct 23, 2023
e1ceb06
removing-function-doesnt-work
THEb0nny Oct 23, 2023
a387ff2
checking-input-values
THEb0nny Oct 23, 2023
68b036b
set-nxt-light-sensor-svg
THEb0nny Oct 23, 2023
c9bec99
Update light.ts
THEb0nny Oct 24, 2023
515cb30
update-for-sim
THEb0nny Oct 24, 2023
5306528
Update NXT Light Sensor.svg
THEb0nny Nov 3, 2023
4152887
resolving-conflict-with-master
THEb0nny Nov 3, 2023
59d9776
resolving-conflict-with-master-2
THEb0nny Nov 3, 2023
d3e36fd
Merge branch 'master' into nxt-light-sensor-support
THEb0nny Nov 3, 2023
2c72a0b
resolving-conflict-with-master-3
THEb0nny Nov 3, 2023
a5f30eb
Update nxtLightSensorView.ts
THEb0nny Nov 3, 2023
9ec2384
Update input.ts
THEb0nny Nov 6, 2023
cc28b07
value-range-update
THEb0nny Nov 6, 2023
7915158
Update light.ts
THEb0nny Nov 6, 2023
b255a91
some-changes-for-the-mode
THEb0nny Nov 6, 2023
aaa09d8
LightWheelControl-is-always-activated-except-in-none-mode
THEb0nny Nov 6, 2023
70503a1
4096-to-4095
THEb0nny Nov 6, 2023
2f7fac2
enum-NXTLightIntensityMode
THEb0nny Nov 6, 2023
161f44d
light-sensor-svg-updage
THEb0nny Nov 10, 2023
a688fea
update-light-sensor-ts
THEb0nny Nov 10, 2023
43d9e1f
ambient-modes-set-invisible
THEb0nny Nov 12, 2023
79b7d2a
range-from-lego-sources
THEb0nny Nov 12, 2023
42d8eb0
sim-fix-for-sensor
THEb0nny Nov 12, 2023
261fd04
query-update-and-add-treshold-blocks
THEb0nny Nov 12, 2023
d507dce
test-upd
THEb0nny Nov 23, 2023
368d3a3
Update lightWheel.ts
THEb0nny Nov 27, 2023
229af21
changes-light-sensor-for-sim
THEb0nny Dec 8, 2023
b24c6ba
deviceType-analog-sens-class
THEb0nny Dec 8, 2023
a2eb462
Update light.ts
THEb0nny Dec 8, 2023
08c6c86
fix-range-for-refLight-and-ambLight
THEb0nny Dec 11, 2023
8cbe429
export-enum-DevConOff
THEb0nny Dec 11, 2023
18b3f88
bug-fix-from-previous-version
THEb0nny Dec 13, 2023
e6e2e6a
sensor-activation
THEb0nny Dec 13, 2023
a5bd2c1
Update light.ts
THEb0nny Dec 13, 2023
085e511
Update light.ts
THEb0nny Dec 13, 2023
c615b73
lib-not-include-by-defl
THEb0nny Dec 13, 2023
a58f178
light-to-bright
THEb0nny Dec 14, 2023
0161690
add-docs
THEb0nny Dec 14, 2023
bc48fe0
Update nxt-light-sensor.md
THEb0nny Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/core/dal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ declare const enum DAL {
DEVICE_TYPE_NXT_LIGHT = 2,
DEVICE_TYPE_NXT_SOUND = 3,
DEVICE_TYPE_NXT_COLOR = 4,
DEVICE_TYPE_NXT_ULTRASONIC = 5,
DEVICE_TYPE_NXT_TEMPERATURE = 6,
DEVICE_TYPE_TACHO = 7,
DEVICE_TYPE_MINITACHO = 8,
DEVICE_TYPE_NEWTACHO = 9,
Expand Down
2 changes: 2 additions & 0 deletions libs/core/ev3const.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define DEVICE_TYPE_NXT_LIGHT 2
#define DEVICE_TYPE_NXT_SOUND 3
#define DEVICE_TYPE_NXT_COLOR 4
#define DEVICE_TYPE_NXT_ULTRASONIC 5
#define DEVICE_TYPE_NXT_TEMPERATURE 6
#define DEVICE_TYPE_TACHO 7
#define DEVICE_TYPE_MINITACHO 8
#define DEVICE_TYPE_NEWTACHO 9
Expand Down
95 changes: 71 additions & 24 deletions libs/core/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ namespace sensors.internal {

function detectDevices() {
control.dmesg(`DETECT DEVICES (hash ${hashDevices()})`);
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS);
const inDcm = analogMM.slice(AnalogOff.InDcm, DAL.NUM_INPUTS);
const inConn = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS);

for (const sensorInfo of sensorInfos) {
const newConn = conns[sensorInfo.port];
const newConn = inConn[sensorInfo.port];
if (newConn == sensorInfo.connType && sensorInfo.sensor && sensorInfo.sensor.isActive()) {
continue;
}
Expand All @@ -252,9 +253,13 @@ namespace sensors.internal {
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_NXT_DUMB) {
sensorInfo.devType = inDcm[sensorInfo.port];
control.dmesg(`new NXT DUMB connection at port ${sensorInfo.port} dev type ${sensorInfo.devType}`);
} else if (newConn == DAL.CONN_INPUT_DUMB) {
control.dmesg(`new DUMB connection at port ${sensorInfo.port}`);
sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH; // TODO? for now assume touch sensor
//sensorInfo.devType = inDcm[sensorInfo.port]; // We get the result DEVICE_TYPE_UNKNOWN
sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH; // TODO? for now assume touch
control.dmesg(`new DUMB connection at ${sensorInfo.port} dev type ${sensorInfo.devType}`);
} else if (newConn == DAL.CONN_NONE || newConn == 0) {
control.dmesg(`disconnect at port ${sensorInfo.port}`);
} else {
Expand Down Expand Up @@ -351,13 +356,44 @@ namespace sensors.internal {
}

export class AnalogSensor extends Sensor {

protected mode: number; // the mode user asked for
protected realmode: number;

constructor(port: number) {
super(port)
super(port);
this.mode = 0;
this.realmode = 0;
}

_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) {
control.dmesg(`_setMode p=${this._port} m: ${this.realmode} -> ${v}`);
this.realmode = v;
setAnalogMode(this._port, this._deviceType(), this.mode);
}
}

_readPin1() {
if (!this.isActive()) return 0;
return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin1 + 2 * this._port);
}

_readPin6() {
if (!this.isActive()) return 0
return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin6 + 2 * this._port)
if (!this.isActive()) return 0;
return analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.InPin6 + 2 * this._port);
}

_deviceType() {
return DAL.DEVICE_TYPE_UNKNOWN;
}
}

Expand All @@ -366,28 +402,29 @@ namespace sensors.internal {
protected realmode: number // the mode the hardware is in

constructor(port: number) {
super(port)
this.mode = 0
this.realmode = 0
super(port);
this.mode = 0;
this.realmode = 0;
}

_activated() {
this.realmode = 0
this._setMode(this.mode)
this.realmode = 0;
this._setMode(this.mode);
}

getStatus() {
return getUartStatus(this._port);
}

protected _setMode(m: number) {
//control.dmesg(`_setMode p=${this.port} m: ${this.realmode} -> ${m}`)
let v = m | 0
this.mode = v
if (!this.isActive()) return
//control.dmesg(`_setMode p=${this.port} m: ${this.realmode} -> ${m}`);
let v = m | 0;
this.mode = v;
if (!this.isActive()) return;
if (this.realmode != this.mode) {
this.realmode = v
setUartMode(this._port, v)
control.dmesg(`_setMode p=${this._port} m: ${this.realmode} -> ${v}`);
this.realmode = v;
setUartMode(this._port, v);
}
}

Expand Down Expand Up @@ -575,19 +612,29 @@ namespace sensors.internal {
DAL.MAX_DEVICE_DATALENGTH)
}

function getUartNumber(fmt: NumberFormat, off: number, port: number) {
function getUartNumber(fmt: NumberFormat, off: number, port: number): number {
if (port < 0) return 0
let index = uartMM.getNumber(NumberFormat.UInt16LE, UartOff.Actual + port * 2)
const index = uartMM.getNumber(NumberFormat.UInt16LE, UartOff.Actual + port * 2)
return uartMM.getNumber(fmt,
UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + off)
}

function setAnalogMode(port: number, type: number, mode: number) {
if (port < 0) return;
control.dmesg(`analog set type ${type} mode ${mode} at port ${port}`);
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_NXT_DUMB);
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, type);
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode);
analogMM.ioctl(0, devcon);
}

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)
control.dmesg(`iic set type ${type} mode ${mode} at port ${port}`);
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) {
Expand Down
4 changes: 2 additions & 2 deletions libs/ev3/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace console._screen {
if (!lines) {
lines = [];
console.addListener(log);
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => scroll(-3))
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => scroll(3))
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => scroll(-3));
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => scroll(3));
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/ev3/ns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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"]'
//% groups='["Touch Sensor", "Color Sensor", "Ultrasonic Sensor", "Gyro Sensor", "Infrared Sensor", "Remote Infrared Beacon", "Calibration", "Light Sensor"]'
//% subcategories='["NXT", "HiTechnic"]'
namespace sensors {
}
Expand Down
3 changes: 3 additions & 0 deletions libs/nxt-light-sensor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NXT Light sensor

The library to interact with the NXT Light Sensor.
10 changes: 10 additions & 0 deletions libs/nxt-light-sensor/docs/reference/sensors/nxt-light-sensor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# NXT light sensor

```cards
sensors.nxtLight1.light(NXTLightIntensityMode.Reflected)
sensors.nxtLight1.light(NXTLightIntensityMode.ReflectedRaw)
```

## See slso

[light](/reference/sensors/nxt-light-sensor/light)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# light

Get the amount of ambient or reflected light measured by the sensor.

```sig
sensors.nxtLight1.light(NXTLightIntensityMode.Reflected)
```

The light sensor adjusts itself to more accurately measure light depending on the source of the light. You decide if you want to measure _ambient_ light (light all around or direct light) or if you want to know how much light is reflected from a surface. The amount of light measured is in the range of `0` (darkest) to `100` (brightest).

## Parameters

* **mode**: the type of measurement for light. This is either ``ambient`` or ``reflected`` light.

## Returns

* a number that is the amount of light measured. No light (darkness) is `0` and the brightest light is `100`.

## Example

Make the status light show ``green`` if the ambient light is greater than `20`.

```blocks
forever(function () {
if (sensors.nxtLight1.light(NXTLightIntensityMode.Reflected) > 20) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
Loading