microsoft / pxt-ev3

Microsoft MakeCode editor for the LEGO MINDSTORMS EV3 Brick
https://makecode.mindstorms.com/
Other
54 stars 39 forks source link

Fixed set mode of raw reflection values (mode numbered zero) in simulator for nxt light sensor #1045

Open THEb0nny opened 9 months ago

THEb0nny commented 9 months ago

The _setMode() method was called, and just like at the beginning of this.mode = 0, this.realmode = 0, the algorithm in _setMode checks this.realmode != this.mode and only then calls setAnalogMode(), in which the mode is passed to the simulator.

When we find the DAL.CONN_NXT_DUMB sensor in detectDevices(), we additionally call setAnalogMode(). Perhaps the same thing needs to be done for DAL.CONN_INPUT_DUMB, but there is only one analog sensor ev3 (touch sensor), and it works without this change. This way you set the mode forcibly when the sensor is found, i.e. at the beginning.

I did the same thing as when finding DAL.CONN_INPUT_UART, in that case updateUartMode() is called.

THEb0nny commented 9 months ago

https://github.com/microsoft/pxt-ev3/assets/13646226/9442ec1e-cdbc-4e9e-9ef3-92e8eae652d9

THEb0nny commented 9 months ago

https://github.com/microsoft/pxt-ev3/assets/13646226/bd0bbb93-ee44-4182-829a-0d3dcb31ddb0

THEb0nny commented 9 months ago

@jwunderl you may want to consider this bugfix to the previous change. I initially forgot that there was such a problem, now I have fixed it.