Skip to content

Commit 462ab25

Browse files
committed
upd examples
1 parent 79caf7b commit 462ab25

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

applications/system/js_app/examples/apps/Scripts/js_examples/blebeacon.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Script cannot work without blebeacon module so check before
2+
checkSdkFeatures(["blebeacon"]);
3+
14
let blebeacon = require("blebeacon");
25

36
// Stop if previous background beacon is active

applications/system/js_app/examples/apps/Scripts/js_examples/i2c.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Script cannot work without i2c module so check before
2+
checkSdkFeatures(["i2c"]);
3+
14
// Connect an 24C32N EEPROM to the I2C bus of the board. SDA=pin 15, SCL=pin 16, VCC=pin 9, GND=pin 8.
25
let i2c = require("i2c");
36

applications/system/js_app/examples/apps/Scripts/js_examples/spi.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
// Script cannot work without spi module so check before
2+
checkSdkFeatures(["spi"]);
3+
14
// Connect a w25q32 SPI device to the Flipper Zero.
25
// D1=pin 2 (MOSI), SLK=pin 5 (SCK), GND=pin 8 (GND), D0=pin 3 (MISO), CS=pin 4 (CS), VCC=pin 9 (3V3)
36
let spi = require("spi");
47

58
// Display textbox so user can scroll to see all output.
69
let eventLoop = require("event_loop");
710
let gui = require("gui");
11+
let textBoxView = require("gui/text_box");
812
let text = "SPI demo\n";
9-
let textBox = require("gui/text_box").makeWith({
13+
let textBox = textBoxView.makeWith({
1014
focus: "end",
1115
font: "text",
1216
text: text,

applications/system/js_app/examples/apps/Scripts/js_examples/subghz.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Script cannot work without subghz module so check before
2+
checkSdkFeatures(["subghz"]);
3+
14
let subghz = require("subghz");
25
subghz.setup();
36

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1+
// Script cannot work without usbdisk module so check before
2+
checkSdkFeatures(["usbdisk"]);
3+
14
let usbdisk = require("usbdisk");
5+
let storage = require("storage");
6+
7+
let imagePath = "/ext/apps_data/mass_storage/128MB.img";
8+
let imageSize = 128 * 1024 * 1024;
9+
10+
let imageExisted = storage.fileExists(imagePath);
11+
if (imageExisted) {
12+
print("Disk image '128MB' already exists");
13+
} else {
14+
// CreateImage isn't necessary to overall function, check when its used not at script start
15+
if (doesSdkSupport(["usbdisk-createimage"])) {
16+
print("Creating disk image '128MB'...");
17+
usbdisk.createImage(imagePath, imageSize);
18+
} else {
19+
die("Disk image '128MB' not present, can't auto-create");
20+
}
21+
}
22+
223
print("Starting UsbDisk...");
324
usbdisk.start("/ext/apps_data/mass_storage/128MB.img");
25+
426
print("Started, waiting until ejected...");
527
while (!usbdisk.wasEjected()) {
628
delay(1000);
729
}
30+
831
print("Ejected, stopping UsbDisk...");
932
usbdisk.stop();
33+
34+
if (!imageExisted) {
35+
print("Removing disk image...");
36+
storage.remove(imagePath);
37+
}
38+
1039
print("Done");

applications/system/js_app/examples/apps/Scripts/js_examples/widget.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
// Script cannot work without widget module so check before
2+
checkSdkFeatures(["widget"]);
3+
14
let widget = require("widget");
25

36
let demo_seconds = 30;
47

5-
print("Loading file", __filepath);
6-
print("From directory", __dirpath);
8+
print("Loading file", __filename);
9+
print("From directory", __dirname);
710

811
// addText supports "Primary" and "Secondary" font sizes.
912
widget.addText(10, 10, "Primary", "Example JS widget");
1013
widget.addText(10, 20, "Secondary", "Example widget from JS!");
1114

1215
// load a Xbm file from the same directory as this script.
13-
widget.addText(0, 30, "Secondary", __filepath);
14-
let logo = widget.loadImageXbm(__dirpath + "/widget-js.fxbm");
16+
widget.addText(0, 30, "Secondary", __filename);
17+
let logo = widget.loadImageXbm(__dirname + "/widget-js.fxbm");
1518

1619
// add a line (x1, y1, x2, y2)
1720
widget.addLine(10, 35, 120, 35);

0 commit comments

Comments
 (0)