Skip to content

Commit 79caf7b

Browse files
committed
Add js sdk changes
With type declarations and various missing parts added by Willy-JL
1 parent 8a2cf4d commit 79caf7b

File tree

19 files changed

+378
-26
lines changed

19 files changed

+378
-26
lines changed

applications/system/js_app/js_modules.c

+9
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ void js_check_sdk_compatibility(struct mjs* mjs) {
267267

268268
static const char* extra_features[] = {
269269
"baseline", // dummy "feature"
270+
271+
// extra modules
272+
"blebeacon",
273+
"i2c",
274+
"spi",
275+
"subghz",
276+
"usbdisk",
277+
"vgm",
278+
"widget",
270279
};
271280

272281
/**

applications/system/js_app/modules/js_subghz/js_subghz.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void js_subghz_transmit_file(struct mjs* mjs) {
223223
// - "repeat" as variable and loop in this code applies to RAW files only
224224
// parsed files handle repeat in protocol layer instead
225225
// We keep 0 as default, or literal value if specified by user
226-
// If user did not specify, -1 is detected below, and we use:
226+
// If user did not specify, 0 is detected below, and we use:
227227
// - 1 repeat for RAW
228228
// - 10 repeats for parsed, which is passed to protocol, and we loop once here
229229
uint32_t repeat = 0;

applications/system/js_app/packages/create-fz-app/README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# Flipper Zero JavaScript SDK Wizard
1+
# Flipper Unleashed Firmware JavaScript SDK Wizard
22
This package contains an interactive wizard that lets you scaffold a JavaScript
3-
application for Flipper Zero.
3+
application for Flipper Zero using the Custom Unleashed Firmware JS SDK.
4+
5+
This is a fork of the [Official Flipper Zero JS SDK Wizard](https://www.npmjs.com/package/@flipperdevices/create-fz-app),
6+
configured to use the [Unleashed FW JavaScript SDK]((https://www.npmjs.com/package/@darkflippers/fz-sdk-ul)) instead.
7+
No other changes are included.
48

59
## Getting started
610
Create your application using the interactive wizard:
711
```shell
8-
npx @flipperdevices/create-fz-app@latest
12+
npx @darkflippers/create-fz-app-ul@latest
913
```
1014

1115
Then, enter the directory with your application and launch it:

applications/system/js_app/packages/create-fz-app/package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
{
2-
"name": "@flipperdevices/create-fz-app",
3-
"version": "0.1.0",
4-
"description": "Template package for JS apps Flipper Zero",
2+
"name": "@darkflippers/create-fz-app-ul",
3+
"version": "0.1.1",
4+
"description": "Template package for JS apps for Flipper Zero using Unleashed Firmware JS SDK",
55
"bin": "index.js",
66
"type": "module",
77
"keywords": [
8+
"unleashed",
9+
"unleashed firmware",
10+
"ul",
11+
"darkflippers",
12+
"flipper cfw js",
813
"flipper",
914
"flipper zero"
1015
],
1116
"author": "Flipper Devices",
1217
"license": "GPL-3.0-only",
1318
"repository": {
1419
"type": "git",
15-
"url": "git+https://github.com/flipperdevices/flipperzero-firmware.git",
20+
"url": "git+https://github.com/DarkFlippers/unleashed-firmware.git",
1621
"directory": "applications/system/js_app/packages/create-fz-app"
1722
},
1823
"dependencies": {

applications/system/js_app/packages/create-fz-app/template/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// import modules
22
// caution: `eventLoop` HAS to be imported before `gui`, and `gui` HAS to be
33
// imported before any `gui` submodules.
4-
import * as eventLoop from "@flipperdevices/fz-sdk/event_loop";
5-
import * as gui from "@flipperdevices/fz-sdk/gui";
6-
import * as dialog from "@flipperdevices/fz-sdk/gui/dialog";
4+
import * as eventLoop from "@darkflippers/fz-sdk-ul/event_loop";
5+
import * as gui from "@darkflippers/fz-sdk-ul/gui";
6+
import * as dialog from "@darkflippers/fz-sdk-ul/gui/dialog";
77

88
// a common pattern is to declare all the views that your app uses on one object
99
const views = {

applications/system/js_app/packages/create-fz-app/template/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"name": "<app_name>",
33
"version": "1.0.0",
44
"scripts": {
5-
"build": "tsc && node node_modules/@flipperdevices/fz-sdk/sdk.js build",
6-
"start": "npm run build && node node_modules/@flipperdevices/fz-sdk/sdk.js upload"
5+
"build": "tsc && node node_modules/@darkflippers/fz-sdk-ul/sdk.js build",
6+
"start": "npm run build && node node_modules/@darkflippers/fz-sdk-ul/sdk.js upload"
77
},
88
"devDependencies": {
9-
"@flipperdevices/fz-sdk": "^0.1",
9+
"@darkflippers/fz-sdk-ul": "^0.1",
1010
"typescript": "^5.6.3"
1111
}
1212
}

applications/system/js_app/packages/create-fz-app/template/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"module": "CommonJS",
66
"noLib": true,
77
"target": "ES2015",
8+
"types": [],
89
},
910
"files": [
10-
"./node_modules/@flipperdevices/fz-sdk/global.d.ts",
11+
"./node_modules/@darkflippers/fz-sdk-ul/global.d.ts",
1112
],
1213
"include": [
1314
"./**/*.ts",
14-
"./**/*.js"
15+
"./**/*.js",
1516
],
1617
"exclude": [
1718
"./node_modules/**/*",

applications/system/js_app/packages/fz-sdk/README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
# Flipper Zero JavaScript SDK
2-
This package contains official tooling and typings for developing Flipper Zero
3-
applications in JavaScript.
1+
# Flipper Unleashed FW JavaScript SDK
2+
This package contains tooling and typings for developing Flipper Zero
3+
applications in JavaScript for Unleashed Custom Firmware (based on official SDK).
4+
5+
This is a fork of the [Official Flipper Zero JS SDK](https://www.npmjs.com/package/@flipperdevices/fz-sdk),
6+
with added types for the extra features provided by the Unleashed firmware JavaScript API.
7+
8+
Scripts made for Official Flipper Zero JS SDK will work on Unleashed Firmware too.
9+
If you use extra features provided by Unleashed FW JS SDK, you are encouraged to use syntax like
10+
`if (doesSdkSupport(["feature-name"])) { ... }` so that your JS app can work on Official
11+
Firmware too, aswell as all other compliant Custom Firmwares. If some of those extra
12+
features are essential to the functionality of your app, you can use `checkSdkFeatures(["feature1", "feature2"])`
13+
near the beginning of your script, which will show a warning to the user that these features
14+
are not available in their firmware distribution.
415

516
## Getting started
617
Create your application using the interactive wizard:
718
```shell
8-
npx @flipperdevices/create-fz-app@latest
19+
npx @darkflippers/create-fz-app-ul@latest
920
```
1021

1122
Then, enter the directory with your application and launch it:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Module for using the BLE extra beacon
3+
* @version Available with JS feature `blebeacon`
4+
* @module
5+
*/
6+
7+
/**
8+
* @brief Check if the BLE beacon is active
9+
*/
10+
export declare function isActive(): boolean;
11+
12+
/**
13+
* @brief Set BLE beacon configuration
14+
* @param mac The MAC address to use
15+
* @param power The power level to use, in GapAdvPowerLevel scale: 0x00 (-40dBm) to 0x1F (+6dBm)
16+
* @param minInterval Minimum advertisement interval
17+
* @param maxInterval Maximum advertisement interval
18+
*/
19+
export declare function setConfig(mac: Uint8Array, power?: number, minInterval?: number, maxInterval?: number): void;
20+
21+
/**
22+
* @brief Set BLE beacon advertisement data
23+
* @param data The advertisement data to use
24+
*/
25+
export declare function setData(data: Uint8Array): void;
26+
27+
/**
28+
* @brief Start BLE beacon
29+
*/
30+
export declare function start(): void;
31+
32+
/**
33+
* @brief Stop BLE beacon
34+
*/
35+
export declare function stop(): void;
36+
37+
/**
38+
* @brief Set whether the BLE beacon will remain active after the script exits
39+
* @param keep True if BLE beacon should remain active after script exit
40+
*/
41+
export declare function keepAlive(keep: boolean): void;

applications/system/js_app/packages/fz-sdk/flipper/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export declare function getBatteryCharge(): number;
2626
* @warning Do **NOT** use this to check the presence or absence of features. If
2727
* you do, I'm gonna be sad :( Instead, refer to `checkSdkFeatures` and
2828
* other similar mechanisms.
29-
* @note Original firmware reports `"flipperdevices"`.
29+
* @note Unleashed firmware reports `"unleashed"`. / Official firmware reports `"flipperdevices"`.
3030
* @version Added in JS SDK 0.1
3131
*/
3232
export declare const firmwareVendor: string;

applications/system/js_app/packages/fz-sdk/global.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ declare function chr(n: number): string | null;
202202
*/
203203
declare function require(module: string): any;
204204

205+
/**
206+
* @brief Exit JavaScript with given message
207+
* @param message The error message to show to user
208+
* @version Added in JS SDK 0.1
209+
*/
210+
declare function die(message: string): never;
211+
205212
/**
206213
* @brief mJS Foreign Pointer type
207214
*

applications/system/js_app/packages/fz-sdk/i2c/index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* I2C bus communication
3+
* @version Available with JS feature `i2c`
4+
* @module
5+
*/
6+
17
/**
28
* @brief Check if there is an I2C device ready on the bus
39
* @param address The device address to check

applications/system/js_app/packages/fz-sdk/package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
2-
"name": "@flipperdevices/fz-sdk",
3-
"version": "0.1.1",
4-
"description": "Type declarations and documentation for native JS modules available on Flipper Zero",
2+
"name": "@darkflippers/fz-sdk-ul",
3+
"version": "0.1.2",
4+
"description": "Type declarations and documentation for native JS modules available on Unleashed Custom Firmware for Flipper Zero",
55
"keywords": [
6+
"unleashed",
7+
"unleashed firmware",
8+
"ul",
9+
"darkflippers",
10+
"flipper unleashed fw sdk",
611
"flipper",
712
"flipper zero",
813
"framework"
@@ -11,7 +16,7 @@
1116
"license": "GPL-3.0-only",
1217
"repository": {
1318
"type": "git",
14-
"url": "git+https://github.com/flipperdevices/flipperzero-firmware.git",
19+
"url": "git+https://github.com/DarkFlippers/unleashed-firmware.git",
1520
"directory": "applications/system/js_app/packages/fz-sdk"
1621
},
1722
"type": "module",

applications/system/js_app/packages/fz-sdk/sdk.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import json5 from "json5";
1010
const __filename = fileURLToPath(import.meta.url);
1111
const __dirname = path.dirname(__filename);
1212

13+
const cfwSdkName = "@darkflippers/fz-sdk-ul/";
14+
const ofwSdkName = "@flipperdevices/fz-sdk/";
15+
1316
async function build(config) {
1417
await esbuild.build({
1518
entryPoints: ["./dist/index.js"],
@@ -19,7 +22,7 @@ async function build(config) {
1922
bundle: true,
2023
minify: config.minify,
2124
external: [
22-
"@flipperdevices/fz-sdk/*"
25+
"@darkflippers/fz-sdk-ul/*"
2326
],
2427
supported: {
2528
"array-spread": false,
@@ -74,6 +77,9 @@ async function build(config) {
7477
let outContents = fs.readFileSync(config.output, "utf8");
7578
outContents = "let exports = {};\n" + outContents;
7679

80+
// Transform CFW SDK name to OFW SDK name so all firmwares understand it
81+
outContents = outContents.replaceAll(`require("${cfwSdkName}`, `require("${ofwSdkName}`);
82+
7783
if (config.enforceSdkVersion) {
7884
const version = json5.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version;
7985
let [major, minor, _] = version.split(".");

applications/system/js_app/packages/fz-sdk/spi/index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* SPI bus communication
3+
* @version Available with JS feature `spi`
4+
* @module
5+
*/
6+
17
/**
28
* @brief Acquire SPI bus
39
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Module for using Sub-GHz transciever
3+
* @version Available with JS feature `subghz`
4+
* @module
5+
*/
6+
7+
/**
8+
* @brief Initialize Sub-GHz module
9+
*/
10+
export declare function setup(): void;
11+
12+
/**
13+
* @brief Deinitialize Sub-GHz module
14+
*/
15+
export declare function end(): void;
16+
17+
/**
18+
* @brief Set radio to receive mode
19+
*/
20+
export declare function setRx(): void;
21+
22+
/**
23+
* @brief Set radio to idle mode
24+
*/
25+
export declare function setIdle(): void;
26+
27+
/**
28+
* @brief Return current RSSI on current frequency, or undefined if radio is not in receive mode
29+
*/
30+
export declare function getRssi(): number | undefined;
31+
32+
type RadioState = "RX" | "TX" | "IDLE" | "";
33+
34+
/**
35+
* @brief Get current radio mode/state
36+
*/
37+
export declare function getState(): RadioState;
38+
39+
/**
40+
* @brief Get currently selected frequency
41+
*/
42+
export declare function getFrequency(): number;
43+
44+
/**
45+
* @brief Change current frequency, radio must be in idle mode
46+
*
47+
* Returns the effective frequency, since radio module cant use all precise
48+
* values and instead chooses closest one available
49+
*
50+
* @param frequency What frequency to use
51+
*/
52+
export declare function setFrequency(frequency: number): number;
53+
54+
/**
55+
* @brief Check whether the radio module in use is internal or external
56+
*/
57+
export declare function isExternal(): boolean;
58+
59+
/**
60+
* @brief Transmit a .sub file, return true on success or error on failure
61+
* @param path What .sub file to transmit
62+
* @param repeat How many times to repeat the signal
63+
*/
64+
export declare function transmitFile(path: string, repeat?: number): true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Module for USB mass storage emulation
3+
* @version Available with JS feature `usbdisk`
4+
* @module
5+
*/
6+
7+
/**
8+
* @brief Start emulating mass storage device
9+
* @param path The disk image to emulate
10+
*/
11+
export declare function start(path: string): void;
12+
13+
/**
14+
* @brief Stop emulating mass storage device
15+
*/
16+
export declare function stop(): void;
17+
18+
/**
19+
* @brief Check if the mass storage device was exected
20+
*
21+
* Useful as a loop condition with a delay, so UsbDisk keeps running until ejected
22+
*
23+
*/
24+
export declare function wasEjected(): boolean;

0 commit comments

Comments
 (0)