diff --git a/applications/system/js_app/js_thread.c b/applications/system/js_app/js_thread.c index 95cad84f6..c448945de 100644 --- a/applications/system/js_app/js_thread.c +++ b/applications/system/js_app/js_thread.c @@ -337,9 +337,9 @@ static int32_t js_thread(void* arg) { mjs_set(mjs, global, "toString", ~0, MJS_MK_FN(js_global_to_string)); mjs_set(mjs, global, "ffi_address", ~0, MJS_MK_FN(js_ffi_address)); mjs_set(mjs, global, "require", ~0, MJS_MK_FN(js_require)); - mjs_set(mjs, global, "parse_int", ~0, MJS_MK_FN(js_parse_int)); - mjs_set(mjs, global, "to_upper_case", ~0, MJS_MK_FN(js_to_upper_case)); - mjs_set(mjs, global, "to_lower_case", ~0, MJS_MK_FN(js_to_lower_case)); + mjs_set(mjs, global, "parseInt", ~0, MJS_MK_FN(js_parse_int)); + mjs_set(mjs, global, "toUpperCase", ~0, MJS_MK_FN(js_to_upper_case)); + mjs_set(mjs, global, "toLowerCase", ~0, MJS_MK_FN(js_to_lower_case)); mjs_val_t console_obj = mjs_mk_object(mjs); mjs_set(mjs, console_obj, "log", ~0, MJS_MK_FN(js_console_log)); diff --git a/applications/system/js_app/modules/js_badusb.c b/applications/system/js_app/modules/js_badusb.c index 85a70b493..7a42d0a3a 100644 --- a/applications/system/js_app/modules/js_badusb.c +++ b/applications/system/js_app/modules/js_badusb.c @@ -104,7 +104,7 @@ static bool setup_parse_params( mjs_val_t pid_obj = mjs_get(mjs, arg, "pid", ~0); mjs_val_t mfr_obj = mjs_get(mjs, arg, "mfrName", ~0); mjs_val_t prod_obj = mjs_get(mjs, arg, "prodName", ~0); - mjs_val_t layout_obj = mjs_get(mjs, arg, "layout_path", ~0); + mjs_val_t layout_obj = mjs_get(mjs, arg, "layoutPath", ~0); if(mjs_is_number(vid_obj) && mjs_is_number(pid_obj)) { hid_cfg->vid = mjs_get_int32(mjs, vid_obj); diff --git a/applications/system/js_app/modules/js_subghz/js_subghz.c b/applications/system/js_app/modules/js_subghz/js_subghz.c index daa46e5e5..051566aec 100644 --- a/applications/system/js_app/modules/js_subghz/js_subghz.c +++ b/applications/system/js_app/modules/js_subghz/js_subghz.c @@ -282,6 +282,11 @@ static void js_subghz_transmit_file(struct mjs* mjs) { break; } + if(!subghz_devices_is_frequency_valid(js_subghz->radio_device, frequency)) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Unsupported frequency"); + break; + } + if(!flipper_format_read_string(fff_file, "Preset", temp_str)) { mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing Preset"); break; diff --git a/applications/system/js_app/modules/js_vgm/js_vgm.c b/applications/system/js_app/modules/js_vgm/js_vgm.c index 2d7a56b6e..8d48d843f 100644 --- a/applications/system/js_app/modules/js_vgm/js_vgm.c +++ b/applications/system/js_app/modules/js_vgm/js_vgm.c @@ -144,10 +144,10 @@ static void js_vgm_destroy(void* inst) { } static const JsModuleDescriptor js_vgm_desc = { - name: "vgm", - create: js_vgm_create, - destroy: js_vgm_destroy, - api_interface: NULL, + "vgm", + js_vgm_create, + js_vgm_destroy, + NULL, }; static const FlipperAppPluginDescriptor plugin_descriptor = { diff --git a/applications/system/js_app/modules/js_widget.c b/applications/system/js_app/modules/js_widget.c index 64390abe7..1c0e98b7c 100644 --- a/applications/system/js_app/modules/js_widget.c +++ b/applications/system/js_app/modules/js_widget.c @@ -866,7 +866,6 @@ static void* js_widget_create(struct mjs* mjs, mjs_val_t* object, JsModules* mod widget->view_holder = view_holder_alloc(); view_holder_attach_to_gui(widget->view_holder, gui); view_holder_set_back_callback(widget->view_holder, widget_exit, widget); - view_holder_set_view(widget->view_holder, widget->view); *object = widget_obj; return widget; diff --git a/applications/system/js_app/types/badusb/index.d.ts b/applications/system/js_app/types/badusb/index.d.ts index 4b49dc991..872b8fe04 100644 --- a/applications/system/js_app/types/badusb/index.d.ts +++ b/applications/system/js_app/types/badusb/index.d.ts @@ -32,9 +32,12 @@ export type KeyCode = MainKey | ModifierKey | number; /** * @brief Initializes the module + * + * Automatically unlocks USB profile, so qFlipper connection will be interrupted. + * * @param settings USB device settings. Omit to select default parameters */ -export declare function setup(settings?: { vid: number, pid: number, mfrName?: string, prodName?: string, layout_path: string }): void; +export declare function setup(settings?: { vid: number, pid: number, mfrName?: string, prodName?: string, layoutPath: string }): void; /** * @brief Tells whether the virtual USB HID device has successfully connected @@ -83,10 +86,19 @@ export declare function println(string: string, delay?: number): void; /** * @brief Prints a string by Alt+Numpad method - works only on Windows! * @param string The string to print + * @param delay How many milliseconds to wait between key presses */ -export declare function altPrintln(string: string): void; +export declare function altPrint(string: string, delay?: number): void; /** - * @brief Releases usb, Optional, but allows to interchange with usbdisk + * @brief Prints a string by Alt+Numpad method - works only on Windows! + * Presses "Enter" after printing the string + * @param string The string to print + * @param delay How many milliseconds to wait between key presses + */ +export declare function altPrintln(string: string, delay?: number): void; + +/** + * @brief Releases usb, optional, but allows to interchange with usbdisk */ export declare function quit(): void; diff --git a/applications/system/js_app/types/global.d.ts b/applications/system/js_app/types/global.d.ts index ab1660cf6..b3e4aac33 100644 --- a/applications/system/js_app/types/global.d.ts +++ b/applications/system/js_app/types/global.d.ts @@ -18,6 +18,34 @@ declare function print(...args: any[]): void; */ declare function toString(value: number, base?: number): string; +/** + * @brief Converts a string to a number + * @param text The string to convert to a number + */ +declare function parseInt(text: string): number; + +/** + * @brief Transforms a string to upper case + * @param text The string to transforms to upper case + */ +declare function toUpperCase(text: string): string; + +/** + * @brief Transforms a string to lower case + * @param text The string to transforms to lower case + */ +declare function toLowerCase(text: string): string; + +/** + * @brief Path to the directory containing the current script + */ +declare const __dirpath: string; + +/** + * @brief Path to the current script file + */ +declare const __filepath: string; + /** * @brief Reads a JS value from a file * diff --git a/applications/system/js_app/types/gui/byte_input.ts b/applications/system/js_app/types/gui/byte_input.ts new file mode 100644 index 000000000..92bd4c5a8 --- /dev/null +++ b/applications/system/js_app/types/gui/byte_input.ts @@ -0,0 +1,14 @@ +import type { View, ViewFactory } from "."; +import type { Contract } from "../event_loop"; + +type Props = { + header: string, + length: number, + defaultData: Uint8Array | ArrayBuffer, +} +declare class ByteInput extends View { + input: Contract; +} +declare class ByteInputFactory extends ViewFactory { } +declare const factory: ByteInputFactory; +export = factory; diff --git a/applications/system/js_app/types/gui/text_input.d.ts b/applications/system/js_app/types/gui/text_input.d.ts index 96652b1d4..bdb5b4d4c 100644 --- a/applications/system/js_app/types/gui/text_input.d.ts +++ b/applications/system/js_app/types/gui/text_input.d.ts @@ -5,6 +5,8 @@ type Props = { header: string, minLength: number, maxLength: number, + defaultText: string, + defaultTextClear: boolean, } declare class TextInput extends View { input: Contract; diff --git a/applications/system/js_app/types/serial/index.d.ts b/applications/system/js_app/types/serial/index.d.ts index 1a7ed6397..680f9bd6e 100644 --- a/applications/system/js_app/types/serial/index.d.ts +++ b/applications/system/js_app/types/serial/index.d.ts @@ -1,5 +1,8 @@ /** * @brief Initializes the serial port + * + * Automatically disables Expansion module service to prevent interference. + * * @param port The port to initialize (`"lpuart"` or `"start"`) * @param baudRate */ @@ -42,6 +45,19 @@ export declare function read(length: number, timeout?: number): string | undefin */ export declare function readln(timeout?: number): string; +/** + * @brief Read any available amount of data from the serial port + * + * Can be useful to avoid starving your loop with small reads. + * + * @param timeout The number of time, in milliseconds, after which this function + * will give up and return nothing. If unset, the function will + * wait forever. + * @returns The received data interpreted as ASCII, or `undefined` if 0 bytes + * were read. + */ +export declare function readAny(timeout?: number): string | undefined; + /** * @brief Reads data from the serial port * @param length The number of bytes to read @@ -75,3 +91,8 @@ export declare function readBytes(length: number, timeout?: number): ArrayBuffer * patterns matched. */ export declare function expect(patterns: string | number[] | string[] | number[][], timeout?: number): number | undefined; + +/** + * @brief Deinitializes the serial port, allowing multiple initializations per script run + */ +export declare function end(): void;