From 87bff6f46f57e83fd6964547f0dc79f378756ba4 Mon Sep 17 00:00:00 2001 From: xiaolongx Date: Thu, 17 Nov 2016 13:11:52 +0800 Subject: [PATCH 1/2] [Samples] Update ButtonEnable.js and Blink-k64f.js on zjs-0.1 1. Fix onchange event in ButtonEnable.js 2. Use pins.LEDG instead of pins.D5 in samples/arduino/basics/Blink-k64f.js --- samples/arduino/basics/Blink-k64f.js | 2 +- samples/tests/ButtonEnable.js | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/samples/arduino/basics/Blink-k64f.js b/samples/arduino/basics/Blink-k64f.js index 1922a4daf..d520d0dde 100644 --- a/samples/arduino/basics/Blink-k64f.js +++ b/samples/arduino/basics/Blink-k64f.js @@ -16,7 +16,7 @@ var pins = require("k64f_pins"); // LEDG is the green LED within the RGB LED on the FRDM-K64F // 'out' direction is default, could be left out var pin = gpio.open({ - pin: pins.D5, + pin: pins.LEDG, direction: 'out' }); diff --git a/samples/tests/ButtonEnable.js b/samples/tests/ButtonEnable.js index 6ee49807a..a778685fc 100644 --- a/samples/tests/ButtonEnable.js +++ b/samples/tests/ButtonEnable.js @@ -6,7 +6,7 @@ // This version tests freeing a callback by changing the callback of btn2 // dynamically in response to btn1 state. Btn2 will only work to control its // LED while btn1 is down. -// +// // Note: If you use a Grove touch sensor as one of the buttons, wire it to IO4: // it doesn't work the other way and I haven't figured out why yet. It may // relate to IO5 being connected to both the X86 and ARC processors. @@ -25,19 +25,18 @@ var btn2 = gpio.open({ pin: pins.IO4, direction: 'in', edge: 'any' }); // turn off LED #2 initially led2.write(false); -btn1.on('change', function () { +btn1.onchange = function (event) { var value = btn1.read(); led1.write(value); if (value) { - // set up btn2 to toggle led2 while btn1 is down - btn2.on('change', function () { + // set up btn2 to toggle led2 while btn1 is down + btn2.onchange = function (event) { var value = btn2.read(); led2.write(value); - }); - } - else { + }; + } else { // disable btn2 again - btn2.on('change', null); + btn2.onchange = null; } -}); +}; From 9220270d1be6f8b9d9814201a9adb5de3d4e3e90 Mon Sep 17 00:00:00 2001 From: xiaolongx Date: Fri, 18 Nov 2016 10:00:26 +0800 Subject: [PATCH 2/2] Align comment in samples/tests/ButtonEnable.js --- samples/tests/ButtonEnable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/tests/ButtonEnable.js b/samples/tests/ButtonEnable.js index a778685fc..d864b5881 100644 --- a/samples/tests/ButtonEnable.js +++ b/samples/tests/ButtonEnable.js @@ -30,7 +30,7 @@ btn1.onchange = function (event) { led1.write(value); if (value) { - // set up btn2 to toggle led2 while btn1 is down + // set up btn2 to toggle led2 while btn1 is down btn2.onchange = function (event) { var value = btn2.read(); led2.write(value);