mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Fix micro:bit compass problems (fix #864)
This commit is contained in:
parent
a6bce4e14a
commit
3f733c67a4
@ -34,6 +34,7 @@
|
||||
Fix '.on' with long event names
|
||||
Enable F4Discovery button pull-down. Newer boards don't seem to have one fitted
|
||||
Add 'force' to 'Serial.setConsole' - you can force the console to stay in one place
|
||||
Fix micro:bit compass problems (fix #864)
|
||||
|
||||
1v85 : Ensure HttpServerResponse.writeHead actually sends the header right away
|
||||
- enables WebSocket Server support from JS
|
||||
|
||||
@ -183,7 +183,7 @@ void jswrap_microbit_show(JsVar *image) {
|
||||
while (jsvIteratorHasElement(&it)) {
|
||||
int ch = jsvIteratorGetIntegerValue(&it);
|
||||
if (str) {
|
||||
if (ch!="\n" && ch!="\r") {
|
||||
if (ch!='\n' && ch!='\r') {
|
||||
if (ch!=' ' && ch!='0')
|
||||
newState |= 1<<n;
|
||||
n++;
|
||||
@ -238,6 +238,7 @@ Get the current acceleration of the micro:bit from the on-board accelerometer
|
||||
JsVar *jswrap_microbit_acceleration() {
|
||||
unsigned char d[6];
|
||||
d[0] = 1;
|
||||
jshI2CWrite(EV_I2C1, MMA8652_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, MMA8652_ADDR, 7, d, true);
|
||||
JsVar *xyz = jsvNewObject();
|
||||
if (xyz) {
|
||||
@ -266,16 +267,17 @@ JsVar *jswrap_microbit_acceleration() {
|
||||
Get the current compass position for the micro:bit from the on-board magnetometer
|
||||
*/
|
||||
JsVar *jswrap_microbit_compass() {
|
||||
unsigned char d[7];
|
||||
unsigned char d[6];
|
||||
d[0] = 1;
|
||||
jshI2CWrite(EV_I2C1, MAG3110_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, MAG3110_ADDR, 6, d, true);
|
||||
JsVar *xyz = jsvNewObject();
|
||||
if (xyz) {
|
||||
int x = (d[1]<<8) | d[2];
|
||||
int x = (d[0]<<8) | d[1];
|
||||
if (x>>15) x-=65536;
|
||||
int y = (d[3]<<8) | d[4];
|
||||
int y = (d[2]<<8) | d[3];
|
||||
if (y>>15) y-=65536;
|
||||
int z = (d[5]<<8) | d[6];
|
||||
int z = (d[4]<<8) | d[5];
|
||||
if (z>>15) z-=65536;
|
||||
jsvObjectSetChildAndUnLock(xyz, "x", jsvNewFromInteger(x));
|
||||
jsvObjectSetChildAndUnLock(xyz, "y", jsvNewFromInteger(y));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user