Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

one of time control.raiseEvent have two fo time control.onEvent! #2255

Closed
helloworld8686 opened this issue Jul 9, 2019 · 8 comments
Closed
Assignees

Comments

@helloworld8686
Copy link

control.raiseEvent and control.onEvent error
exmaple:
https://github.com/helloworld8686/stem6.git

in
https://makecode.microbit.org/v1#editor
run correct!

but
in
https://makecode.microbit.org/#editor
run error

@riknoll
Copy link
Member

riknoll commented Jul 10, 2019

Could you please provide a more compact code sample that shows the issue? Looks like there is a lot of code in that repo and I'm not sure where to start

@helloworld8686
Copy link
Author

helloworld8686 commented Jul 11, 2019

main.ts:

makerbit.connectInfrared(DigitalPin.P2)
basic.showIcon(IconNames.Heart)
serial.redirect(
SerialPin.P8,
SerialPin.P12,
BaudRate.BaudRate115200
)
serial.writeLine("1")

test.ts:

// MakerBit blocks supporting a Keyestudio Infrared Wireless Module Kit
// (receiver module+remote controller)
namespace makerbit {
 
  const MICROBIT_MAKERBIT_IR_MARK_SPACE = 777;

  function pushMarkSpace(markAndSpace: number): number {
    serial.writeNumber(markAndSpace);
    serial.writeLine("\n");
    return 0;    
  }
  

  /**
   * IO口检测到电压变化时,记录下脉宽周期,当完成一次高低变化时,触发一次 MICROBIT_MAKERBIT_IR_MARK_SPACE 事件,并且把高低变化的时间推送给事件
   * @param 
   */
  function enableIrMarkSpaceDetection(pin: DigitalPin) {
    let mark = 0;
    let space = 0;
    pins.setPull(pin, PinPullMode.PullNone)
    pins.onPulsed(pin, PulseValue.Low, () => {
      // HIGH
      mark = pins.pulseDuration();
      control.raiseEvent(MICROBIT_MAKERBIT_IR_MARK_SPACE, mark);
    });
/*
    pins.onPulsed(pin, PulseValue.High, () => {
      // LOW     
      space = pins.pulseDuration();
      control.raiseEvent(MICROBIT_MAKERBIT_IR_MARK_SPACE, space);
    });*/
  }

  /**
   * Connects to the IR receiver module at the specified pin.
   * @param pin IR receiver pin, eg: DigitalPin.P0
   */
  //% subcategory="遥控器"
  //% blockId="makerbit_infrared_connect"
  //% block="设置遥控器引脚 %pin"
  //% pin.fieldEditor="gridpicker"
  //% pin.fieldOptions.columns=4
  //% pin.fieldOptions.tooltips="false"
  //% weight=90
  export function connectInfrared(pin: DigitalPin): void {
      enableIrMarkSpaceDetection(pin);
      control.onEvent(
        MICROBIT_MAKERBIT_IR_MARK_SPACE,
        EventBusValue.MICROBIT_EVT_ANY,
        () => {
          pushMarkSpace(control.eventValue());
        }
      );
  }
}

@helloworld8686
Copy link
Author

one time of raiseEvent trigger two time of pushMarkSpace

@philipphenkel
Copy link
Contributor

This could be related to #1334

@philipphenkel
Copy link
Contributor

philipphenkel commented Jul 11, 2019

@riknoll Sorry, I have to correct myself: This is a regression and not related to the long-standing issue #1334.

Defect: For each control.raiseEvent two events are received when listening for ANY.

For reference:
It renders our infrared extension useless.
https://github.com/1010Technologies/pxt-makerbit-ir-receiver/blob/master/infrared.ts

@philipphenkel
Copy link
Contributor

This defect still exists on the latest MakeCode 2.0.6/5.15.12 A single event is received twice.
Here's the minimal code to reproduce it:
Bildschirmfoto 2019-09-07 um 12 49 48
https://makecode.microbit.org/_RWW5MrWE2UfX

@riknoll The MakerBit IR receiver extension is broken by this regression. Please let me know if you need more information.

@martinwork
Copy link
Contributor

I checked this example on V1. It seems OK, so this seems to be a regression since V1

@abchatra
Copy link
Collaborator

Old issue if this still repros let us know. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants