mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-26 22:40:25 +00:00
merge missing js backports of backports by Willy-JL
p1
This commit is contained in:
parent
2aff3bca73
commit
63d1890156
10 changed files with 93 additions and 12 deletions
|
@ -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, "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, "ffi_address", ~0, MJS_MK_FN(js_ffi_address));
|
||||||
mjs_set(mjs, global, "require", ~0, MJS_MK_FN(js_require));
|
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, "parseInt", ~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, "toUpperCase", ~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, "toLowerCase", ~0, MJS_MK_FN(js_to_lower_case));
|
||||||
|
|
||||||
mjs_val_t console_obj = mjs_mk_object(mjs);
|
mjs_val_t console_obj = mjs_mk_object(mjs);
|
||||||
mjs_set(mjs, console_obj, "log", ~0, MJS_MK_FN(js_console_log));
|
mjs_set(mjs, console_obj, "log", ~0, MJS_MK_FN(js_console_log));
|
||||||
|
|
|
@ -104,7 +104,7 @@ static bool setup_parse_params(
|
||||||
mjs_val_t pid_obj = mjs_get(mjs, arg, "pid", ~0);
|
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 mfr_obj = mjs_get(mjs, arg, "mfrName", ~0);
|
||||||
mjs_val_t prod_obj = mjs_get(mjs, arg, "prodName", ~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)) {
|
if(mjs_is_number(vid_obj) && mjs_is_number(pid_obj)) {
|
||||||
hid_cfg->vid = mjs_get_int32(mjs, vid_obj);
|
hid_cfg->vid = mjs_get_int32(mjs, vid_obj);
|
||||||
|
|
|
@ -282,6 +282,11 @@ static void js_subghz_transmit_file(struct mjs* mjs) {
|
||||||
break;
|
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)) {
|
if(!flipper_format_read_string(fff_file, "Preset", temp_str)) {
|
||||||
mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing Preset");
|
mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing Preset");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -144,10 +144,10 @@ static void js_vgm_destroy(void* inst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JsModuleDescriptor js_vgm_desc = {
|
static const JsModuleDescriptor js_vgm_desc = {
|
||||||
name: "vgm",
|
"vgm",
|
||||||
create: js_vgm_create,
|
js_vgm_create,
|
||||||
destroy: js_vgm_destroy,
|
js_vgm_destroy,
|
||||||
api_interface: NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||||
|
|
|
@ -866,7 +866,6 @@ static void* js_widget_create(struct mjs* mjs, mjs_val_t* object, JsModules* mod
|
||||||
widget->view_holder = view_holder_alloc();
|
widget->view_holder = view_holder_alloc();
|
||||||
view_holder_attach_to_gui(widget->view_holder, gui);
|
view_holder_attach_to_gui(widget->view_holder, gui);
|
||||||
view_holder_set_back_callback(widget->view_holder, widget_exit, widget);
|
view_holder_set_back_callback(widget->view_holder, widget_exit, widget);
|
||||||
view_holder_set_view(widget->view_holder, widget->view);
|
|
||||||
|
|
||||||
*object = widget_obj;
|
*object = widget_obj;
|
||||||
return widget;
|
return widget;
|
||||||
|
|
|
@ -32,9 +32,12 @@ export type KeyCode = MainKey | ModifierKey | number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the module
|
* @brief Initializes the module
|
||||||
|
*
|
||||||
|
* Automatically unlocks USB profile, so qFlipper connection will be interrupted.
|
||||||
|
*
|
||||||
* @param settings USB device settings. Omit to select default parameters
|
* @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
|
* @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!
|
* @brief Prints a string by Alt+Numpad method - works only on Windows!
|
||||||
* @param string The string to print
|
* @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;
|
export declare function quit(): void;
|
||||||
|
|
28
applications/system/js_app/types/global.d.ts
vendored
28
applications/system/js_app/types/global.d.ts
vendored
|
@ -18,6 +18,34 @@ declare function print(...args: any[]): void;
|
||||||
*/
|
*/
|
||||||
declare function toString(value: number, base?: number): string;
|
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
|
* @brief Reads a JS value from a file
|
||||||
*
|
*
|
||||||
|
|
14
applications/system/js_app/types/gui/byte_input.ts
Normal file
14
applications/system/js_app/types/gui/byte_input.ts
Normal file
|
@ -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<Props> {
|
||||||
|
input: Contract<string>;
|
||||||
|
}
|
||||||
|
declare class ByteInputFactory extends ViewFactory<Props, ByteInput> { }
|
||||||
|
declare const factory: ByteInputFactory;
|
||||||
|
export = factory;
|
|
@ -5,6 +5,8 @@ type Props = {
|
||||||
header: string,
|
header: string,
|
||||||
minLength: number,
|
minLength: number,
|
||||||
maxLength: number,
|
maxLength: number,
|
||||||
|
defaultText: string,
|
||||||
|
defaultTextClear: boolean,
|
||||||
}
|
}
|
||||||
declare class TextInput extends View<Props> {
|
declare class TextInput extends View<Props> {
|
||||||
input: Contract<string>;
|
input: Contract<string>;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the serial port
|
* @brief Initializes the serial port
|
||||||
|
*
|
||||||
|
* Automatically disables Expansion module service to prevent interference.
|
||||||
|
*
|
||||||
* @param port The port to initialize (`"lpuart"` or `"start"`)
|
* @param port The port to initialize (`"lpuart"` or `"start"`)
|
||||||
* @param baudRate
|
* @param baudRate
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +45,19 @@ export declare function read(length: number, timeout?: number): string | undefin
|
||||||
*/
|
*/
|
||||||
export declare function readln(timeout?: number): string;
|
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
|
* @brief Reads data from the serial port
|
||||||
* @param length The number of bytes to read
|
* @param length The number of bytes to read
|
||||||
|
@ -75,3 +91,8 @@ export declare function readBytes(length: number, timeout?: number): ArrayBuffer
|
||||||
* patterns matched.
|
* patterns matched.
|
||||||
*/
|
*/
|
||||||
export declare function expect(patterns: string | number[] | string[] | number[][], timeout?: number): number | undefined;
|
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;
|
||||||
|
|
Loading…
Reference in a new issue