Sensor disable only works once.

Author: TsteinroeslandCreated Dec 29, 2023Updated Jan 2, 2024

Original bug posted in 2019: https://github.com/rwaldron/johnny-five/issues/1520

I'm also seeing this issue with a very simple approach using setTimeouts.

Code to reproduce:

const

const board = new Board({
  port: 'COM3',
})

board.on('ready', () => {
  const moistureSensor = new Sensor({
    pin: 'A0',
    freq: 100,
  })

  moistureSensor.on('data', value => {
    console.log(value)
  })

  setTimeout(() => {
    console.log('Disable')
    moistureSensor.disable()
  }, 1000)

  setTimeout(() => {
    console.log('Enable')
    moistureSensor.enable()
  }, 2000)

  setTimeout(() => {
    console.log('Disable')
    moistureSensor.disable()
  }, 3000)
})

Console:

413 413 413 413 413 413 413 413 413 Disable Enable 413 413 413 413 413 413 413 413 413 Disable 413 414 [.... Keeps logging forever until program is exited]