mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
merge examples
This commit is contained in:
@@ -45,7 +45,7 @@ eventLoop.subscribe(views.dialog.input, function (_sub, button, eventLoop, gui)
|
||||
|
||||
badusb.println("Flipper Model: " + flipper.getModel());
|
||||
badusb.println("Flipper Name: " + flipper.getName());
|
||||
badusb.println("Battery level: " + toString(flipper.getBatteryCharge()) + "%");
|
||||
badusb.println("Battery level: " + flipper.getBatteryCharge().toString() + "%");
|
||||
|
||||
// Alt+Numpad method works only on Windows!!!
|
||||
badusb.altPrintln("This was printed with Alt+Numpad method!");
|
||||
|
||||
@@ -45,7 +45,7 @@ function sendRandomModelAdvertisement() {
|
||||
|
||||
blebeacon.start();
|
||||
|
||||
print("Sent data for model ID " + toString(model));
|
||||
print("Sent data for model ID " + model.toString());
|
||||
|
||||
currentIndex = (currentIndex + 1) % watchValues.length;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ eventLoop.subscribe(views.bytekb.input, function (_sub, data, gui, views) {
|
||||
let data_view = Uint8Array(data);
|
||||
let text = "0x";
|
||||
for (let i = 0; i < data_view.length; i++) {
|
||||
text += toString(data_view[i], 16);
|
||||
text += data_view[i].toString(16);
|
||||
}
|
||||
views.helloDialog.set("text", "You typed:\n" + text);
|
||||
views.helloDialog.set("center", "Cool!");
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// Connect an 24C32N EEPROM to the I2C bus of the board. SDA=pin 15, SCL=pin 16, VCC=pin 9, GND=pin 8.
|
||||
let i2c = require("i2c");
|
||||
|
||||
function i2c_find_first_device() {
|
||||
let addr = -1;
|
||||
for (let try_addr = 0; try_addr !== 0xff; try_addr++) {
|
||||
if (i2c.isDeviceReady(try_addr, 5)) {
|
||||
addr = try_addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
let addr = i2c_find_first_device();
|
||||
if (addr === -1) {
|
||||
print("I2C device not found");
|
||||
print("Please connect a 24C32N EEPROM I2C device to the Flipper Zero.");
|
||||
print("SDA=pin 15, SCL=pin 16, VCC=pin 9, GND=pin 8.");
|
||||
} else {
|
||||
print("I2C device found at address: " + addr.toString(16));
|
||||
delay(1000);
|
||||
|
||||
// first two bytes are the start address (0x0000)
|
||||
// the remaining bytes are the data to store.
|
||||
// can also use Uint8Array([0x00, 0x00, ...]) as write parameter
|
||||
i2c.write(addr, [0x00, 0x00, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47]);
|
||||
while (i2c.isDeviceReady(addr, 9) === false) {
|
||||
print("Waiting for device to be ready...");
|
||||
}
|
||||
|
||||
// write the address to read from (we start at address 0x0001)
|
||||
// read 3 bytes - 0x42, 0x43, 0x44
|
||||
let data_buf = i2c.writeRead(addr, [0x00, 0x01], 3, 100);
|
||||
let data = Uint8Array(data_buf);
|
||||
print("Read bytes: " + data.length.toString());
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
print("data[" + i.toString() + "] = " + data[i].toString(16));
|
||||
}
|
||||
|
||||
// read two more bytes (0x45, 0x46) from current address
|
||||
data_buf = i2c.read(addr, 2);
|
||||
data = Uint8Array(data_buf);
|
||||
print("Read bytes: " + data.length.toString());
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
print("data[" + i.toString() + "] = " + data[i].toString(16));
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ eventLoop.subscribe(views.dialog.input, function (_sub, button, gui, views) {
|
||||
eventLoop.subscribe(views.textInput.input, function (_sub, text, gui, views, ctx) {
|
||||
gui.viewDispatcher.switchTo(views.loading);
|
||||
|
||||
let path = ctx.tmpTemplate + toString(ctx.tmpNumber++);
|
||||
let path = ctx.tmpTemplate + (ctx.tmpNumber++).toString();
|
||||
let file = storage.openFile(path, "w", "create_always");
|
||||
file.write(text);
|
||||
file.close();
|
||||
@@ -58,7 +58,7 @@ eventLoop.subscribe(views.textInput.input, function (_sub, text, gui, views, ctx
|
||||
} else if (typeof result === "string") {
|
||||
result = "'" + result + "'";
|
||||
} else if (typeof result === "number") {
|
||||
result = toString(result);
|
||||
result = result.toString();
|
||||
} else if (typeof result === "bigint") { // mJS doesn't support BigInt() but might aswell check
|
||||
result = "bigint";
|
||||
} else if (typeof result === "boolean") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
let sampleText = "Hello, World!";
|
||||
|
||||
let lengthOfText = "Length of text: " + toString(sampleText.length);
|
||||
let lengthOfText = "Length of text: " + sampleText.length.toString();
|
||||
print(lengthOfText);
|
||||
|
||||
let start = 7;
|
||||
@@ -9,7 +9,7 @@ let substringResult = sampleText.slice(start, end);
|
||||
print(substringResult);
|
||||
|
||||
let searchStr = "World";
|
||||
let result2 = toString(sampleText.indexOf(searchStr));
|
||||
let result2 = sampleText.indexOf(searchStr).toString();
|
||||
print(result2);
|
||||
|
||||
let upperCaseText = "Text in upper case: " + sampleText.toUpperCase();
|
||||
|
||||
@@ -6,7 +6,7 @@ while (1) {
|
||||
if (rx_data !== undefined) {
|
||||
serial.write(rx_data);
|
||||
let data_view = Uint8Array(rx_data);
|
||||
print("0x" + toString(data_view[0], 16));
|
||||
print("0x" + data_view[0].toString(16));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user