mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
JS: Docs and types for additions on top of OFW modules
This commit is contained in:
@@ -32,6 +32,9 @@ 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, layoutPath: string }): void;
|
||||
@@ -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;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
|
||||
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,
|
||||
minLength: number,
|
||||
maxLength: number,
|
||||
defaultText: string,
|
||||
defaultTextClear: boolean,
|
||||
}
|
||||
declare class TextInput extends View<Props> {
|
||||
input: Contract<string>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,12 +7,14 @@ let badusb = require("badusb");
|
||||
# Methods
|
||||
## setup
|
||||
Start USB HID with optional parameters. Should be called before all other methods.
|
||||
Automatically unlocks USB profile, so qFlipper connection will be interrupted.
|
||||
|
||||
### Parameters
|
||||
Configuration object (optional):
|
||||
- vid, pid (number): VID and PID values, both are mandatory
|
||||
- mfr_name (string): Manufacturer name (32 ASCII characters max), optional
|
||||
- prod_name (string): Product name (32 ASCII characters max), optional
|
||||
- mfrName (string): Manufacturer name (32 ASCII characters max), optional
|
||||
- prodName (string): Product name (32 ASCII characters max), optional
|
||||
- layoutPath (string): Path to keyboard layout file, optional
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
@@ -105,6 +107,40 @@ Same as `print` but ended with "ENTER" press.
|
||||
badusb.println("Hello, world!"); // print "Hello, world!" and press "ENTER"
|
||||
```
|
||||
|
||||
## altPrint
|
||||
Prints a string by Alt+Numpad method - works only on Windows!
|
||||
|
||||
### Parameters
|
||||
- A string to print
|
||||
- (optional) delay between key presses
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
badusb.altPrint("Hello, world!"); // print "Hello, world!"
|
||||
badusb.altPrint("Hello, world!", 100); // Add 100ms delay between key presses
|
||||
```
|
||||
|
||||
## altPrintln
|
||||
Same as `altPrint` but ended with "ENTER" press.
|
||||
|
||||
### Parameters
|
||||
- A string to print
|
||||
- (optional) delay between key presses
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
badusb.altPrintln("Hello, world!"); // print "Hello, world!" and press "ENTER"
|
||||
```
|
||||
|
||||
## quit
|
||||
Releases usb, optional, but allows to interchange with usbdisk.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
badusb.quit();
|
||||
usbdisk.start(...)
|
||||
```
|
||||
|
||||
# Key names list
|
||||
|
||||
## Modifier keys
|
||||
@@ -142,3 +178,4 @@ badusb.println("Hello, world!"); // print "Hello, world!" and press "ENTER"
|
||||
| TAB | |
|
||||
| MENU | Context menu key |
|
||||
| Fx | F1-F24 keys |
|
||||
| NUMx | NUM0-NUM9 keys |
|
||||
|
||||
@@ -48,3 +48,43 @@ Convert a number to string with an optional base.
|
||||
toString(123) // "123"
|
||||
toString(123, 16) // "0x7b"
|
||||
```
|
||||
|
||||
## parseInt
|
||||
Converts a string to a number.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
parseInt("123") // 123
|
||||
```
|
||||
|
||||
## toUpperCase
|
||||
Transforms a string to upper case.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
toUpperCase("Example") // "EXAMPLE"
|
||||
```
|
||||
|
||||
## toLowerCase
|
||||
Transforms a string to lower case.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
toLowerCase("Example") // "example"
|
||||
```
|
||||
|
||||
## __dirpath
|
||||
Path to the directory containing the current script.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
print(__dirpath); // /ext/apps/Scripts/Examples
|
||||
```
|
||||
|
||||
## __filepath
|
||||
Path to the current script file.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
print(__filepath); // /ext/apps/Scripts/Examples/path.js
|
||||
```
|
||||
|
||||
41
documentation/js/js_gui__byte_input.md
Normal file
41
documentation/js/js_gui__byte_input.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# js_gui__byte_input {#js_gui__byte_input}
|
||||
|
||||
# Byte input GUI view
|
||||
Displays a keyboard.
|
||||
|
||||
<img src="byte_input.png" width="200" alt="Sample screenshot of the view" />
|
||||
|
||||
```js
|
||||
let eventLoop = require("event_loop");
|
||||
let gui = require("gui");
|
||||
let byteInputView = require("gui/byte_input");
|
||||
```
|
||||
|
||||
This module depends on the `gui` module, which in turn depends on the
|
||||
`event_loop` module, so they _must_ be imported in this order. It is also
|
||||
recommended to conceptualize these modules first before using this one.
|
||||
|
||||
# Example
|
||||
For an example refer to the `gui.js` example script.
|
||||
|
||||
# View props
|
||||
## `length`
|
||||
Data buffer length
|
||||
|
||||
Type: `number`
|
||||
|
||||
## `header`
|
||||
Single line of text that appears above the keyboard
|
||||
|
||||
Type: `string`
|
||||
|
||||
## `defaultData`
|
||||
Data to show in byte input by default
|
||||
|
||||
Type: `Uint8Array | ArrayBuffer`
|
||||
|
||||
# View events
|
||||
## `input`
|
||||
Fires when the user selects the "save" button.
|
||||
|
||||
Item type: `ArrayBuffer`
|
||||
@@ -36,6 +36,16 @@ Single line of text that appears above the keyboard
|
||||
|
||||
Type: `string`
|
||||
|
||||
## `defaultText`
|
||||
Text to show in keyboard by default
|
||||
|
||||
Type: `string`
|
||||
|
||||
## `defaultTextClear`
|
||||
Whether to clear the default text when user inuts another key
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
# View events
|
||||
## `input`
|
||||
Fires when the user selects the "save" button and the text matches the length
|
||||
|
||||
@@ -8,6 +8,7 @@ let serial = require("serial");
|
||||
|
||||
## setup
|
||||
Configure serial port. Should be called before all other methods.
|
||||
Automatically disables Expansion module service to prevent interference.
|
||||
|
||||
### Parameters
|
||||
- Serial port name (usart, lpuart)
|
||||
@@ -67,6 +68,21 @@ serial.readln(); // Read without timeout
|
||||
serial.readln(5000); // Read with 5s timeout
|
||||
```
|
||||
|
||||
## readAny
|
||||
Read any available amount of data from serial port, can help avoid starving your loop with small reads
|
||||
|
||||
### Parameters
|
||||
(optional) Timeout value in ms
|
||||
|
||||
### Returns
|
||||
A sting of received characters or undefined if nothing was received before timeout.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
serial.readAny(); // Read without timeout
|
||||
serial.readAny(5000); // Read with 5s timeout
|
||||
```
|
||||
|
||||
## readBytes
|
||||
Read from serial port until line break character
|
||||
|
||||
@@ -104,4 +120,14 @@ serial.expect("# ", 1000);
|
||||
|
||||
// Infinitely wait for one of two strings, should return 0 if the first string got matched, 1 if the second one
|
||||
serial.expect([": not found", "Usage: "]);
|
||||
```
|
||||
|
||||
## end
|
||||
Deinitializes serial port, allowing multiple initializations per script run.
|
||||
|
||||
### Examples:
|
||||
```js
|
||||
serial.end();
|
||||
// Configure LPUART port with baudrate = 115200
|
||||
serial.setup("lpuart", 115200);
|
||||
```
|
||||
Reference in New Issue
Block a user