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

[Code.org Integration] Compass Calibration Placeholder #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]

> 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:

Expand Down
9 changes: 9 additions & 0 deletions client/MBFirmataClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions client/mbTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class Test5 {
}
mb.clearChannelData();

mb.compassCalibration();

clearScreen();
moveCursorTo(18, 0);
console.log('Analog streaming test (light sensor enabled)');
Expand Down
5 changes: 5 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"serialport": "^8.0.5"
}
}
4 changes: 2 additions & 2 deletions firmware/buildv2.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# MIT License
#
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions firmware/source/mbFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ static void systemReset() {
samplingInterval = 100;
}

static void calibrateCompass() {
compass.calibrate();
}

// Pin Commands

static void reportAnalogMapping() {
Expand Down Expand Up @@ -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;
}
}

Expand Down
3 changes: 3 additions & 0 deletions firmware/source/mbFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down