diff --git a/README.md b/README.md index 1000f30..0fe78f1 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ of Node.js and npm, the Node package manager. You can get those from You will also need the Node "serialport" package. Get that by typing: - npm install serialport + npm install serialport@8.0.5 + +> Note: This library uses calls from before the breaking changes introduced in the newer versions of serialport, and still needs to be updated. Now you can run the test suite by typing the following: diff --git a/client/MBFirmataClient.js b/client/MBFirmataClient.js index 238153c..fbad220 100644 --- a/client/MBFirmataClient.js +++ b/client/MBFirmataClient.js @@ -95,7 +95,10 @@ class MicrobitFirmataClient { this.MB_SCROLL_INTEGER = 0x05 this.MB_SET_TOUCH_MODE = 0x06 this.MB_DISPLAY_ENABLE = 0x07 + this.MB_COMPASS_CALIBRATE = 0x08 + // 0x08-0x0C reserved for additional micro:bit messages + this.MB_REPORT_EVENT = 0x0D this.MB_DEBUG_STRING = 0x0E this.MB_EXTENDED_SYSEX = 0x0F; // allow for 128 additional micro:bit messages @@ -515,6 +518,12 @@ class MicrobitFirmataClient { this.SYSEX_END]); } + compassCalibration() { + // Request that the micro:bit perform a compass calibration cycle + + this.myPort.write([this.SYSEX_START, this.MB_COMPASS_CALIBRATE, this.SYSEX_END]); + } + enableLightSensor() { // Enable the light sensor. // Note: When running, the light sensor monopolizes the A/D converter, preventing diff --git a/client/mbTests.js b/client/mbTests.js index abe6f94..fee8468 100644 --- a/client/mbTests.js +++ b/client/mbTests.js @@ -238,6 +238,8 @@ class Test5 { } mb.clearChannelData(); + mb.compassCalibration(); + clearScreen(); moveCursorTo(18, 0); console.log('Analog streaming test (light sensor enabled)'); diff --git a/client/package.json b/client/package.json new file mode 100644 index 0000000..b2f86c8 --- /dev/null +++ b/client/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "serialport": "^8.0.5" + } +} diff --git a/firmware/buildv2.py b/firmware/buildv2.py old mode 100644 new mode 100755 index cc6ee30..6c9b787 --- a/firmware/buildv2.py +++ b/firmware/buildv2.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # MIT License # @@ -81,7 +81,7 @@ def fileutils_copytree(src,dst): # change directory and run the build os.chdir(V2ROOT) -subprocess.call(["python", "build.py"]) +subprocess.call(["python3", "build.py"]) os.chdir(BACK) #restore original source folder diff --git a/firmware/source/mbFirmata.cpp b/firmware/source/mbFirmata.cpp index 00e1cca..8ed3f4d 100644 --- a/firmware/source/mbFirmata.cpp +++ b/firmware/source/mbFirmata.cpp @@ -337,6 +337,10 @@ static void systemReset() { samplingInterval = 100; } +static void calibrateCompass() { + compass.calibrate(); +} + // Pin Commands static void reportAnalogMapping() { @@ -663,6 +667,9 @@ static void dispatchSysexCommand(int sysexStart, int argBytes) { case SAMPLING_INTERVAL: setSamplingInterval((inbuf[sysexStart + 2] << 7) | inbuf[sysexStart + 1]); break; + case MB_COMPASS_CALIBRATE: + calibrateCompass(); + break; } } diff --git a/firmware/source/mbFirmata.h b/firmware/source/mbFirmata.h index 91b2af9..c3f3ee4 100644 --- a/firmware/source/mbFirmata.h +++ b/firmware/source/mbFirmata.h @@ -60,7 +60,10 @@ SOFTWARE. #define MB_SCROLL_INTEGER 0x05 #define MB_SET_TOUCH_MODE 0x06 #define MB_DISPLAY_ENABLE 0x07 +#define MB_COMPASS_CALIBRATE 0x08 + // 0x08-0x0C reserved for additional micro:bit commands + #define MB_REPORT_EVENT 0x0D #define MB_DEBUG_STRING 0x0E #define MB_EXTENDED_SYSEX 0x0F // can be used to add 128 additional micro:bit commands