Prebuilt files for momentum and official.

This commit is contained in:
Derek Jamison 2024-04-13 12:33:58 -05:00
parent c70c4fb65e
commit 6b9195fb42
6 changed files with 43 additions and 0 deletions

View File

@ -8,6 +8,9 @@ The [tone_rotate.js](./tone_rotate.js) script will play a tone using the speaker
Copy the [a_demo.js](./a_demo.js) and [tone_rotate.js](./tone_rotate.js) files to your `SD Card/apps/Scripts` directory. You can then run the scripts from the Flipper Zero (`Apps`, `Scripts`, `a_demo.js`). Copy the [a_demo.js](./a_demo.js) and [tone_rotate.js](./tone_rotate.js) files to your `SD Card/apps/Scripts` directory. You can then run the scripts from the Flipper Zero (`Apps`, `Scripts`, `a_demo.js`).
## Prebuilt apps
You can copy one of the FAL files from [prebuilt](./prebuilt/) onto `SD Card/apps_data/js_app/plugins/js_vgm.fal` and then you will be able to do `let vgm = require("vgm");`. The prebuilt files exposes the 4 APIs (getPitch, getRoll, getYaw, deltaYaw) from the video and they also expose a (`play(440,1.0,250);`) command -- since I wanted to see what would happen if I used furi_hal_speaker APIs in my module code. If you use the wrong one for your firmware, you will get `"vgm" module load fail`. You can also copy [tone_rotate_native.js](./prebuilt/tone_rotate_native.js) to the `SD Card/apps/Scripts/tone_rotate_native.js`. Running the script (`Apps`, `Scripts`, `tone_rotate_native`) should play tones as you rotate your Flipper with the VGM attached.
## Installing the JS speaker_api module ## Installing the JS speaker_api module
We wrote the speaker_api module in JavaScript (using furi_hal_xxx APIs to expose a new speaker module). This file [speaker_api.js](./speaker_api.js) should be copied to your `SD Card/apps/Scripts` directory. Once copied, your scripts can do a `let speaker = load(__dirpath + "/speaker_api.js");` and then `speaker.playTone(440, 1.0, 500);` to play a 440Hz tone, at full volume for 500ms. This file is a good example of how to use FFI to extend the Flipper Zero. If your APIs are part of the firmware, and don't use enumeration values, this is a good technqiue to use. (If they use enumeration values, it's possible that the values will change in the future, and your script will reference the improper id values.) We wrote the speaker_api module in JavaScript (using furi_hal_xxx APIs to expose a new speaker module). This file [speaker_api.js](./speaker_api.js) should be copied to your `SD Card/apps/Scripts` directory. Once copied, your scripts can do a `let speaker = load(__dirpath + "/speaker_api.js");` and then `speaker.playTone(440, 1.0, 500);` to play a 440Hz tone, at full volume for 500ms. This file is a good example of how to use FFI to extend the Flipper Zero. If your APIs are part of the firmware, and don't use enumeration values, this is a good technqiue to use. (If they use enumeration values, it's possible that the values will change in the future, and your script will reference the improper id values.)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,40 @@
let vgm = require("vgm");
//The pre-built vgm exposes a .play function, so we don't need the speaker_api.js file.
//let __dirpath = "/ext/apps/Scripts";
//let speaker = load(__dirpath + "/speaker_api.js");
let min_delta_angle = 29.98;
let max_wait_ms = 10000;
let freq_hz = 440;
//Uncomment below to test for various test cases...
//print(vgm.deltaYaw("30.312", 1000)); // Invalid arg (angle).
//print(vgm.deltaYaw()); // Invalid args. Pass (angle, [timeout]). Got 0 args.
//print(vgm.deltaYaw(1,2,3)); // Invalid args. Pass (angle, [timeout]). Got 3 args.
//print(vgm.deltaYaw(29.98, 1000)); // This should work fine.
// Show the pitch, roll, and yaw values for 5 seconds
for (let i = 0; i < 3; i++) {
print("P", vgm.getPitch(), "R", vgm.getRoll(), "Y", vgm.getYaw());
delay(1000);
}
// Play a sound that changes pitch based on yaw
for (let i = 0; i < 500; i++) {
print("Freq", freq_hz, "Hz");
// speaker.play(freq_hz, 1.0, 250);
vgm.play(freq_hz, 1.0, 250);
let delta = vgm.deltaYaw(min_delta_angle, max_wait_ms);
if (delta === undefined) {
print("No VGM detected. Exiting...");
break;
}
delta /= (min_delta_angle / 1.02);
if (delta > 0) {
freq_hz *= delta;
} else if (delta < 0) {
freq_hz /= -delta;
}
}