Skip to content
Draft
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
26 changes: 25 additions & 1 deletion build/devices/esp32/targets/m5atom_matrix/host/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Serial from "embedded:io/serial";
import SMBus from "embedded:io/smbus";
import SPI from "embedded:io/spi";
import PulseWidth from "embedded:io/pulsewidth";
import MPU6886 from "embedded:sensor/Accelerometer-Gyroscope/MPU6886";

const device = {
I2C: {
Expand Down Expand Up @@ -56,9 +57,32 @@ const device = {
pin: 33
}
},
io: {Analog, Digital, DigitalBank, I2C, PulseCount, PulseWidth, PWM, Serial, SMBus, SPI},
io: { Analog, Digital, DigitalBank, I2C, PulseCount, PulseWidth, PWM, Serial, SMBus, SPI },
pin: {
button: 39
},

sensor: {
IMU: class extends MPU6886 {
constructor(options) {
super({
...options,
sensor: {
...device.I2C.internal,
io: device.io.SMBus
}
});
}
sample() {
const sample = super.sample();
sample.accelerometer.y *= -1;
sample.accelerometer.z *= -1;
sample.gyroscope.x = sample.gyroscope.y * -1;
sample.gyroscope.y = sample.gyroscope.x;
sample.gyroscope.z *= -1;
return sample;
}
}
}
};

Expand Down
4 changes: 1 addition & 3 deletions build/devices/esp32/targets/m5atom_matrix/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"include": [
"$(MODDABLE)/modules/io/manifest.json",
"$(MODULES)/pins/digital/monitor/manifest.json",
"$(MODULES)/pins/smbus/manifest.json",
"$(MODULES)/drivers/sensors/mpu6886/manifest.json",
"$(MODULES)/drivers/neopixel/manifest.json"
],
Expand All @@ -11,14 +11,12 @@
},
"modules": {
"*": [
"$(MODULES)/drivers/mpu6886/*",
"../m5stack_fire/m5button"
],
"setup/target": "./setup-target"
},
"preload": [
"m5button",
"mpu6886",
"setup/target"
],
"creation": {
Expand Down
62 changes: 1 addition & 61 deletions build/devices/esp32/targets/m5atom_matrix/setup-target.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023 Moddable Tech, Inc.
* Copyright (c) 2020-2026 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Runtime.
*
Expand All @@ -18,64 +18,8 @@
*
*/

import Timer from "timer";

import M5Button from "m5button";

import NeoPixel from "neopixel";
import MPU6886 from "mpu6886";

class Accelerometer {
#sensor;
#timer;

constructor(sensor) {
this.#sensor = sensor;
}
start(frequency) {
this.stop();
this.#timer = Timer.repeat(id => {
if (!this.onreading)
return;

this.#sensor.configure({ operation: "accelerometer" });
const sample = this.#sensor.sample();
if (sample)
this.onreading(sample);
}, frequency);
}
stop() {
if (undefined !== this.#timer)
Timer.clear(this.#timer);
this.#timer = undefined;
}
}

class Gyro {
#sensor;
#timer;

constructor(sensor) {
this.#sensor = sensor;
}
start(frequency) {
this.stop();
this.#timer = Timer.repeat(id => {
if (!this.onreading)
return;

this.#sensor.configure({ operation: "gyroscope" });
const sample = this.#sensor.sample();
if (sample)
this.onreading({x: -sample.y, y: -sample.x, z: sample.z});
}, frequency);
}
stop() {
if (undefined !== this.#timer)
Timer.clear(this.#timer);
this.#timer = undefined;
}
}

export default function (done) {
globalThis.button = {
Expand All @@ -97,9 +41,5 @@ export default function (done) {
}
});

const sensor = new MPU6886;
globalThis.accelerometer = new Accelerometer(sensor);
globalThis.gyro = new Gyro(sensor);

done();
}
23 changes: 22 additions & 1 deletion build/devices/esp32/targets/m5atom_s3/host/provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Moddable Tech, Inc.
* Copyright (c) 2022-2026 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Runtime.
*
Expand Down Expand Up @@ -27,6 +27,7 @@ import PWM from "embedded:io/pwm";
import Serial from "embedded:io/serial";
import SMBus from "embedded:io/smbus";
import SPI from "embedded:io/spi";
import MPU6886 from "embedded:sensor/Accelerometer-Gyroscope/MPU6886";

const device = {
I2C: {
Expand Down Expand Up @@ -61,6 +62,26 @@ const device = {
backlight: 16,
displayDC: 33,
displaySelect: 15
},
sensor: {
IMU: class extends MPU6886 {
constructor(options) {
super({
...options,
sensor: {
...device.I2C.internal,
io: device.io.SMBus
}
});
}
sample() {
const sample = super.sample();
sample.accelerometer.x *= -1;
sample.accelerometer.y *= -1;
sample.gyroscope.x *= -1;
return sample;
}
}
}
};

Expand Down
4 changes: 1 addition & 3 deletions build/devices/esp32/targets/m5atom_s3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"BEFORE_DEBUGGING_MESSAGE": "Press and release the Reset button."
},
"include": [
"$(MODULES)/pins/smbus/manifest.json",
"$(MODDABLE)/modules/io/manifest.json",
"$(MODULES)/pins/digital/manifest.json",
"$(MODULES)/pins/digital/monitor/manifest.json",
"$(MODDABLE)/modules/drivers/ili9341/manifest.json",
Expand All @@ -17,14 +17,12 @@
],
"modules": {
"*": [
"$(MODULES)/drivers/mpu6886/*",
"../m5stack_fire/m5button"
],
"setup/target": "./setup-target"
},
"preload": [
"setup/target",
"mpu6886",
"m5button"
],
"config": {
Expand Down
62 changes: 0 additions & 62 deletions build/devices/esp32/targets/m5atom_s3/setup-target.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import Digital from "pins/digital";
//import Monitor from "monitor";
import M5Button from "m5button";
import config from "mc/config";
import Timer from "timer";
import Button from "button";
import I2C from "pins/i2c";
import MPU6886 from "mpu6886";

class Flash {
constructor(options) {
Expand All @@ -29,61 +23,5 @@ export default function (done) {
a: new M5Button(41)
};

const sensor = new MPU6886;
globalThis.accelerometer = new Accelerometer(sensor);
globalThis.gyro = new Gyro(sensor);

done();
}

class Accelerometer {
#sensor;
#timer;

constructor(sensor) {
this.#sensor = sensor;
}
start(frequency) {
this.stop();
this.#timer = Timer.repeat(id => {
if (!this.onreading)
return;

this.#sensor.configure({ operation: "accelerometer" });
const sample = this.#sensor.sample();
if (sample)
this.onreading({x: sample.x, y: -sample.y, z: -sample.z});
}, frequency);
}
stop() {
if (undefined !== this.#timer)
Timer.clear(this.#timer);
this.#timer = undefined;
}
}

class Gyro {
#sensor;
#timer;

constructor(sensor) {
this.#sensor = sensor;
}
start(frequency) {
this.stop();
this.#timer = Timer.repeat(id => {
if (!this.onreading)
return;

this.#sensor.configure({ operation: "gyroscope" });
const sample = this.#sensor.sample();
if (sample)
this.onreading({x: -sample.y, y: -sample.x, z: -sample.z});
}, frequency);
}
stop() {
if (undefined !== this.#timer)
Timer.clear(this.#timer);
this.#timer = undefined;
}
}
23 changes: 22 additions & 1 deletion build/devices/esp32/targets/m5atom_s3_echo_base/host/provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Moddable Tech, Inc.
* Copyright (c) 2022-2026 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Runtime.
*
Expand Down Expand Up @@ -27,6 +27,7 @@ import PWM from "embedded:io/pwm";
import Serial from "embedded:io/serial";
import SMBus from "embedded:io/smbus";
import SPI from "embedded:io/spi";
import MPU6886 from "embedded:sensor/Accelerometer-Gyroscope/MPU6886";

const device = {
I2C: {
Expand Down Expand Up @@ -61,6 +62,26 @@ const device = {
backlight: 16,
displayDC: 33,
displaySelect: 15
},
sensor: {
IMU: class extends MPU6886 {
constructor(options) {
super({
...options,
sensor: {
...device.I2C.internal,
io: device.io.SMBus
}
});
}
sample() {
const sample = super.sample();
sample.accelerometer.x *= -1;
sample.accelerometer.y *= -1;
sample.gyroscope.x *= -1;
return sample;
}
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"BEFORE_DEBUGGING_MESSAGE": "Press and release the Reset button."
},
"include": [
"$(MODDABLE)/modules/io/manifest.json",
"$(MODULES)/pins/smbus/manifest.json",
"$(MODULES)/pins/digital/manifest.json",
"$(MODULES)/pins/digital/monitor/manifest.json",
Expand All @@ -20,15 +21,13 @@
"pins/audioout": "$(MODULES)/pins/i2s/*",
"pins/smbus": "$(MODULES)/pins/smbus/smbus",
"*": [
"$(MODULES)/drivers/mpu6886/*",
"../m5stack_fire/m5button"
]
},
"preload": [
"pins/audioout",
"audioin",
"setup/target",
"mpu6886",
"m5button"
],
"config": {
Expand Down
Loading