microsoft / jacdac

Device and service catalogs for Jacdac.
https://aka.ms/jacdac
Creative Commons Attribution 4.0 International
66 stars 26 forks source link

problem with MakeCode AccelerometerClient #958

Open tballmsft opened 2 years ago

tballmsft commented 2 years ago
  1. compile and flash microbit-machine (which now has following code):
machine.addClientFactory(jacdac.SRV_ACCELEROMETER, devid => {
    const client = new modules.AccelerometerClient(devid)
    client.onFaceDown(() => basic.showIcon(IconNames.Sad,0))
    client.onFaceUp(() => basic.showIcon(IconNames.Happy,0))
    client.onTiltLeft(() => basic.showArrow(ArrowNames.West))
    client.onTiltRight(() => basic.showArrow(ArrowNames.East))
    client.onTiltUp(() => basic.showArrow(ArrowNames.North))
    client.onTiltDown(() => basic.showArrow(ArrowNames.South))
})
  1. add physical accelerometer module,
  2. note that nothing happens (micro:bit screen doesn't change on accel events)
  3. connect to dashboard, now notice that micro:bit does respond
  4. disconnect from dashboard and see that micro:bit doesn't respond to accel events
tballmsft commented 2 years ago

@pelikhan - are you able to repro this?

pelikhan commented 2 years ago

Not investigated yet

tballmsft commented 2 years ago

starting into it... first question - why are we using control.onEvent in pxt-jacdac/routing.ts for dealing with Jacdac events?

        protected registerEvent(value: number, handler: () => void) {
            this.start()
            control.onEvent(this.eventId, value, handler)
        }
pelikhan commented 2 years ago

this predates adding event source support in jacdac base types. The trouble with dynamic clients is that we leak those handlers.

tballmsft commented 2 years ago

Works now: @pelikhan - did you do something to address this?

tballmsft commented 2 years ago

Now, doesn't work... race condition?