-
Notifications
You must be signed in to change notification settings - Fork 647
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
Comments
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 |
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());
}
);
}
} |
one time of raiseEvent trigger two time of pushMarkSpace |
This could be related to #1334 |
@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: |
This defect still exists on the latest MakeCode 2.0.6/5.15.12 A single event is received twice. @riknoll The MakerBit IR receiver extension is broken by this regression. Please let me know if you need more information. |
I checked this example on V1. It seems OK, so this seems to be a regression since V1 |
Old issue if this still repros let us know. Closing. |
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
The text was updated successfully, but these errors were encountered: