BangleApps/typescript/types/main.d.ts

8375 lines
283 KiB
TypeScript
Raw Normal View History

2022-07-20 13:07:21 +00:00
/* Note: This file was automatically generated. */
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Class containing [micro:bit's](https://www.espruino.com/MicroBit) utility functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Microbit
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Microbit: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* The micro:bit's speaker pin
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_SPEAKER
*/
SPEAKER: Pin
/**
* The micro:bit's microphone pin
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* `MIC_ENABLE` should be set to 1 before using this
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_MIC
*/
MIC: Pin
/**
* The micro:bit's microphone enable pin
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_MIC_ENABLE
*/
MIC_ENABLE: Pin
/**
* @url http://www.espruino.com/Reference#l_Microbit_mag
*/
mag: () => any;
/**
* @url http://www.espruino.com/Reference#l_Microbit_accel
*/
accel: () => any;
/**
* **Note:** This function is only available on the [BBC micro:bit](https://espruino.com//MicroBit) board
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Write the given value to the accelerometer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_accelWr
*/
accelWr: (addr: number, data: number) => void;
/**
* Turn on the accelerometer, and create `Microbit.accel` and `Microbit.gesture` events.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** The accelerometer is currently always enabled - this code
* just responds to interrupts and reads
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_accelOn
*/
accelOn: () => void;
/**
* Turn off events from the accelerometer (started with `Microbit.accelOn`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_accelOff
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
accelOff: () => void;
/**
* Play a waveform on the Micro:bit's speaker
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_play
*/
play: (waveform: any, samplesPerSecond: any, callback: any) => void;
/**
* Records sound from the micro:bit's onboard microphone and returns the result
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Microbit_record
*/
record: (samplesPerSecond: any, callback: any, samples: any) => void;
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_tensorflow_undefined
*/
/**
* Class containing an instance of TFMicroInterpreter
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#TFMicroInterpreter
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function TFMicroInterpreter(): void;
type TFMicroInterpreter = {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_TFMicroInterpreter_getInput
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getInput: () => EspruinoArrayBufferView;
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l_TFMicroInterpreter_getOutput
*/
getOutput: () => EspruinoArrayBufferView;
/**
* @url http://www.espruino.com/Reference#l_TFMicroInterpreter_invoke
*/
invoke: () => void;
}
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Class containing utility functions for accessing IO on the hexagonal badge
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Badge
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Badge: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Capacitive sense - the higher the capacitance, the higher the number returned.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Supply a corner number between 1 and 6, and an integer value will be returned that is proportional to the capacitance
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Badge_capSense
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
capSense: (corner: number) => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return an approximate battery percentage remaining based on
* a normal CR2032 battery (2.8 - 2.2v)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Badge_getBatteryPercentage
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getBatteryPercentage: () => number;
/**
* Set the LCD's contrast
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Badge_setContrast
*/
setContrast: (c: number) => void;
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Class containing [Puck.js's](http://www.puck-js.com) utility functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Puck
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Puck: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn on the magnetometer, take a single reading, and then turn it off again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* An object of the form `{x,y,z}` is returned containing magnetometer readings.
* Due to residual magnetism in the Puck and magnetometer itself, with
* no magnetic field the Puck will not return `{x:0,y:0,z:0}`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Instead, it's up to you to figure out what the 'zero value' is for your
* Puck in your location and to then subtract that from the value returned. If
* you're not trying to measure the Earth's magnetic field then it's a good idea
* to just take a reading at startup and use that.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* With the aerial at the top of the board, the `y` reading is vertical, `x` is
* horizontal, and `z` is through the board.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Readings are in increments of 0.1 micro Tesla (uT). The Earth's magnetic field
* varies from around 25-60 uT, so the reading will vary by 250 to 600 depending
* on location.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_mag
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
mag: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn on the magnetometer, take a single temperature reading from the MAG3110 chip, and then turn it off again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* (If the magnetometer is already on, this just returns the last reading obtained)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* `E.getTemperature()` uses the microcontroller's temperature sensor, but this uses the magnetometer's.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The reading obtained is an integer (so no decimal places), but the sensitivity is factory trimmed. to 1°C, however the temperature
* offset isn't - so absolute readings may still need calibrating.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_magTemp
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
magTemp: () => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn the magnetometer on and start periodic sampling. Samples will then cause
* a 'mag' event on 'Puck':
2022-07-20 19:07:18 +00:00
*
* ```
* Puck.magOn();
* Puck.on('mag', function(xyz) {
* console.log(xyz);
* // {x:..., y:..., z:...}
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* // Turn events off with Puck.magOff();
* ```
*
2022-07-20 18:35:57 +00:00
* This call will be ignored if the sampling is already on.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If given an argument, the sample rate is set (if not, it's at 0.63 Hz).
* The sample rate must be one of the following (resulting in the given power consumption):
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* - 80 Hz - 900uA
* - 40 Hz - 550uA
* - 20 Hz - 275uA
* - 10 Hz - 137uA
* - 5 Hz - 69uA
* - 2.5 Hz - 34uA
* - 1.25 Hz - 17uA
* - 0.63 Hz - 8uA
* - 0.31 Hz - 8uA
* - 0.16 Hz - 8uA
* - 0.08 Hz - 8uA
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* When the battery level drops too low while sampling is turned on,
* the magnetometer may stop sampling without warning, even while other
* Puck functions continue uninterrupted.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_magOn
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
magOn: (samplerate: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn the magnetometer off
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_magOff
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
magOff: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a register on the LIS3MDL / MAX3110 Magnetometer. Can be used for configuring advanced functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information and links to modules that use this function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_magWr
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
magWr: (reg: number, data: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Reads a register from the LIS3MDL / MAX3110 Magnetometer. Can be used for configuring advanced functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information and links to modules that use this function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_magRd
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
magRd: (reg: number) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* On Puck.js v2.0 this will use the on-board PCT2075TP temperature sensor, but on Puck.js the less accurate on-chip Temperature sensor is used.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_getTemperature
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getTemperature: () => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Accepted values are:
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* - 1.6 Hz (no Gyro) - 40uA (2v05 and later firmware)
* - 12.5 Hz (with Gyro)- 350uA
* - 26 Hz (with Gyro) - 450 uA
* - 52 Hz (with Gyro) - 600 uA
* - 104 Hz (with Gyro) - 900 uA
* - 208 Hz (with Gyro) - 1500 uA
* - 416 Hz (with Gyro) (not recommended)
* - 833 Hz (with Gyro) (not recommended)
* - 1660 Hz (with Gyro) (not recommended)
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* Once `Puck.accelOn()` is called, the `Puck.accel` event will be called each time data is received. `Puck.accelOff()` can be called to turn the accelerometer off.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For instance to light the red LED whenever Puck.js is face up:
2022-07-20 19:07:18 +00:00
*
* ```
* Puck.on('accel', function(a) {
* digitalWrite(LED1, a.acc.z > 0);
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* Puck.accelOn();
* ```
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_accelOn
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
accelOn: (samplerate: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn the accelerometer off after it has been turned on by `Puck.accelOn()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_accelOff
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
accelOff: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn on the accelerometer, take a single reading, and then turn it off again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The values reported are the raw values from the chip. In normal configuration:
*
* - accelerometer: full-scale (32768) is 4g, so you need to divide by 8192 to get correctly scaled values
* - gyro: full-scale (32768) is 245 dps, so you need to divide by 134 to get correctly scaled values
*
* If taking more than one reading, we'd suggest you use `Puck.accelOn()` and the `Puck.accel` event.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_accel
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
accel: () => any;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a register on the LSM6DS3TR-C Accelerometer. Can be used for configuring advanced functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information and links to modules that use this function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_accelWr
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
accelWr: (reg: number, data: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Reads a register from the LSM6DS3TR-C Accelerometer. Can be used for configuring advanced functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Check out [the Puck.js page on the accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals)
* for more information and links to modules that use this function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_accelRd
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
accelRd: (reg: number) => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Transmit the given set of IR pulses - data should be an array of pulse times
* in milliseconds (as `[on, off, on, off, on, etc]`).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example `Puck.IR(pulseTimes)` - see [http://www.espruino.com/Puck.js+Infrared](http://www.espruino.com/Puck.js+Infrared)
* for a full example.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can also attach an external LED to Puck.js, in which case
* you can just execute `Puck.IR(pulseTimes, led_cathode, led_anode)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* It is also possible to just supply a single pin for IR transmission
* with `Puck.IR(pulseTimes, led_anode)` (on 2v05 and above).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_IR
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
IR: (data: any, cathode: Pin, anode: Pin) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Capacitive sense - the higher the capacitance, the higher the number returned.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If called without arguments, a value depending on the capacitance of what is
* attached to pin D11 will be returned. If you attach a length of wire to D11,
* you'll be able to see a higher value returned when your hand is near the wire
* than when it is away.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can also supply pins to use yourself, however if you do this then
* the TX pin must be connected to RX pin and sense plate via a roughly 1MOhm
* resistor.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When not supplying pins, Puck.js uses an internal resistor between D12(tx)
* and D11(rx).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_capSense
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
capSense: (tx: Pin, rx: Pin) => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return a light value based on the light the red LED is seeing.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** If called more than 5 times per second, the received light value
* may not be accurate.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_light
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
light: () => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* DEPRECATED - Please use `E.getBattery()` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Return an approximate battery percentage remaining based on
* a normal CR2032 battery (2.8 - 2.2v).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_getBatteryPercentage
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getBatteryPercentage: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Run a self-test, and return true for a pass. This checks for shorts
* between pins, so your Puck shouldn't have anything connected to it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This self-test auto starts if you hold the button on your Puck
* down while inserting the battery, leave it pressed for 3 seconds (while
* the green LED is lit) and release it soon after all LEDs turn on. 5
* red blinks is a fail, 5 green is a pass.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If the self test fails, it'll set the Puck.js Bluetooth advertising name
* to `Puck.js !ERR` where ERR is a 3 letter error code.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Puck_selfTest
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
selfTest: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
};
/**
* This library handles interfacing with a FAT32 filesystem on an SD card. The API is designed to be similar to node.js's - However Espruino does not currently support asynchronous file IO, so the functions behave like node.js's xxxxSync functions. Versions of the functions with 'Sync' after them are also provided for compatibility.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To use this, you must type `var fs = require('fs')` to get access to the library
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See [the page on File IO](http://www.espruino.com/File+IO) for more information, and for examples on wiring up an SD card if your device doesn't come with one.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** If you want to remove an SD card after you have started using it, you *must* call `E.unmountSD()` or you may cause damage to the card.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_undefined
*/
/**
* This is the File object - it allows you to stream data to and from files (As opposed to the `require('fs').readFile(..)` style functions that read an entire file).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To create a File object, you must type `var fd = E.openFile('filepath','mode')` - see [E.openFile](#l_E_openFile) for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** If you want to remove an SD card after you have started using it, you *must* call `E.unmountSD()` or you may cause damage to the card.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#File
*/
declare function EspruinoFile(): void;
type EspruinoFile = {
/**
* Close an open file.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_File_close
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
close: () => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Write data to a file.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** By default this function flushes all changes to the
* SD card, which makes it slow (but also safe!). You can use
* `E.setFlags({unsyncFiles:1})` to disable this behaviour and
* really speed up writes - but then you must be sure to close
* all files you are writing before power is lost or you will
* cause damage to your SD card's filesystem.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_File_write
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
write: (buffer: any) => number;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Read data in a file in byte size chunks
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_File_read
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
read: (length: number) => any;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Skip the specified number of bytes forward in the file
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_File_skip
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
skip: (nBytes: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Seek to a certain position in the file
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_File_seek
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
seek: (nBytes: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Pipe this file to a stream (an object with a 'write' method)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_File_pipe
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
pipe: (destination: any, options: any) => void;
}
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
/**
* Class containing utility functions for the Seeed WIO LTE board
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#WioLTE
*/
declare const WioLTE: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the WIO's LED
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_LED
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
LED: (red: number, green: number, blue: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the power of Grove connectors, except for `D38` and `D39` which are always on.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_setGrovePower
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setGrovePower: (onoff: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn power to the WIO's LED on or off.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Turning the LED on won't immediately display a color - that must be done with `WioLTE.LED(r,g,b)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_setLEDPower
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setLEDPower: (onoff: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_D38
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D38: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_D20
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D20: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_A6
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
A6: any
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_I2C
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
I2C: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_UART
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
UART: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WioLTE_A4
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
A4: any
};
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Class containing utility functions for [Pixl.js](http://www.espruino.com/Pixl.js)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Pixl
*/
declare const Pixl: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* DEPRECATED - Please use `E.getBattery()` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Return an approximate battery percentage remaining based on
* a normal CR2032 battery (2.8 - 2.2v)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pixl_getBatteryPercentage
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getBatteryPercentage: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the LCD's contrast
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pixl_setContrast
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setContrast: (c: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to turn Pixl.js's LCD off or on.
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* - With the LCD off, Pixl.js draws around 0.1mA
* - With the LCD on, Pixl.js draws around 0.25mA
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pixl_setLCDPower
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setLCDPower: (isOn: boolean) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a command directly to the ST7567 LCD controller
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pixl_lcdw
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
lcdw: (c: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Display a menu on Pixl.js's screen, and set up the buttons to navigate through it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* DEPRECATED: Use `E.showMenu`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pixl_menu
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
menu: (menu: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This class exists in order to interface Espruino with fast-moving trigger wheels. Trigger wheels are physical discs with evenly spaced teeth cut into them, and often with one or two teeth next to each other missing. A sensor sends a signal whenever a tooth passed by, and this allows a device to measure not only RPM, but absolute position.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This class is currently in testing - it is NOT AVAILABLE on normal boards.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Trig
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Trig: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the position of the trigger wheel at the given time (from getTime)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_getPosAtTime
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getPosAtTime: (time: number) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Initialise the trigger class
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_setup
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setup: (pin: Pin, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set a trigger for a certain point in the cycle
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_setTrigger
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setTrigger: (num: number, pos: number, pins: any, pulseLength: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Disable a trigger
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_killTrigger
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
killTrigger: (num: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the current state of a trigger
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_getTrigger
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getTrigger: (num: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the RPM of the trigger wheel
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_getRPM
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getRPM: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the current error flags from the trigger wheel - and zero them
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_getErrors
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getErrors: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the current error flags from the trigger wheel - and zero them
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Trig_getErrorArray
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getErrorArray: () => any;
};
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Cryptographic functions
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This library is currently only included in builds for boards where there is space. For other boards there is `crypto.js` which implements SHA1 in JS.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_undefined
*/
/**
* Class containing AES encryption/decryption
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This library is currently only included in builds for boards where there is space. For other boards there is `crypto.js` which implements SHA1 in JS.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#AES
*/
declare const AES: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_AES_encrypt
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
encrypt: (passphrase: any, key: any, options: any) => ArrayBuffer;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_AES_decrypt
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
decrypt: (passphrase: any, key: any, options: any) => ArrayBuffer;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* This class provides Graphics operations that can be applied to a surface.
2022-07-20 19:07:18 +00:00
*
* Use Graphics.createXXX to create a graphics object that renders in the way you want. See [the Graphics page](https://www.espruino.com/Graphics) for more information.
2022-07-20 19:07:18 +00:00
*
* **Note:** On boards that contain an LCD, there is a built-in 'LCD' object of type Graphics. For instance to draw a line you'd type: `LCD.drawLine(0,0,100,100)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#Graphics
*/
2022-07-20 15:57:03 +00:00
declare const Graphics: {
2022-07-20 13:35:57 +00:00
/**
* On devices like Pixl.js or HYSTM boards that contain a built-in display
2022-07-20 13:35:57 +00:00
* this will return an instance of the graphics class that can be used to
* access that display.
2022-07-20 19:07:18 +00:00
*
* Internally, this is stored as a member called `gfx` inside the 'hiddenRoot'.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getInstance
*/
2022-07-20 15:57:03 +00:00
getInstance: () => any;
2022-07-20 13:35:57 +00:00
/**
* Create a Graphics object that renders to an Array Buffer. This will have a field called 'buffer' that can get used to get at the buffer itself
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_createArrayBuffer
*/
2022-07-20 15:57:03 +00:00
createArrayBuffer: (width: number, height: number, bpp: number, options: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Create a Graphics object that renders by calling a JavaScript callback function to draw pixels
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_createCallback
*/
2022-07-20 15:57:03 +00:00
createCallback: (width: number, height: number, bpp: number, callback: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Create a Graphics object that renders to SDL window (Linux-based devices only)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_createSDL
*/
2022-07-20 15:57:03 +00:00
createSDL: (width: number, height: number, bpp: number) => Graphics;
2022-07-20 13:35:57 +00:00
2022-07-20 15:57:03 +00:00
/**
* Create a simple Black and White image for use with `Graphics.drawImage`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Use as follows:
2022-07-20 19:07:18 +00:00
*
* ```
* var img = Graphics.createImage(`
2022-07-20 15:57:03 +00:00
* XXXXXXXXX
2022-07-20 19:07:18 +00:00
* X X
* X X X
* X X X
* X X
2022-07-20 15:57:03 +00:00
* XXXXXXXXX
* `);
* g.drawImage(img, x,y);
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* If the characters at the beginning and end of the string are newlines, they
* will be ignored. Spaces are treated as `0`, and any other character is a `1`
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_createImage
*/
createImage: (str: any) => any;
};
2022-07-20 13:35:57 +00:00
2022-07-20 13:07:21 +00:00
type Graphics = {
2022-07-20 13:35:57 +00:00
/**
* Set the current font
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFont6x15
*/
setFont6x15: (scale: number) => Graphics;
2022-07-20 18:35:57 +00:00
/**
* Set the current font
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFont12x20
*/
setFont12x20: (scale: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* On instances of graphics that drive a display with
2022-07-20 13:07:21 +00:00
* an offscreen buffer, calling this function will
* copy the contents of the offscreen buffer to the
* screen.
2022-07-20 19:07:18 +00:00
*
* Call this when you have drawn something to Graphics
* and you want it shown on the screen.
2022-07-20 19:07:18 +00:00
*
* If a display does not have an offscreen buffer,
* it may not have a `g.flip()` method.
2022-07-20 19:07:18 +00:00
*
* On Bangle.js 1, there are different graphics modes
* chosen with `Bangle.setLCDMode()`. The default mode
* is unbuffered and in this mode `g.flip()` does not
* affect the screen contents.
2022-07-20 19:07:18 +00:00
*
* On some devices, this command will attempt to
2022-07-20 13:07:21 +00:00
* only update the areas of the screen that have
* changed in order to increase speed. If you have
* accessed the `Graphics.buffer` directly then you
* may need to use `Graphics.flip(true)` to force
* a full update of the screen.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_flip
*/
flip: (all: boolean) => void;
2022-07-20 15:57:03 +00:00
/**
* On Graphics instances with an offscreen buffer, this
* is an `ArrayBuffer` that provides access to the underlying
* pixel data.
2022-07-20 19:07:18 +00:00
*
* ```
* g=Graphics.createArrayBuffer(8,8,8)
* g.drawLine(0,0,7,7)
* print(new Uint8Array(g.buffer))
* new Uint8Array([
* 255, 0, 0, 0, 0, 0, 0, 0,
* 0, 255, 0, 0, 0, 0, 0, 0,
* 0, 0, 255, 0, 0, 0, 0, 0,
* 0, 0, 0, 255, 0, 0, 0, 0,
* 0, 0, 0, 0, 255, 0, 0, 0,
* 0, 0, 0, 0, 0, 255, 0, 0,
* 0, 0, 0, 0, 0, 0, 255, 0,
* 0, 0, 0, 0, 0, 0, 0, 255])
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_buffer
*/
buffer: any
2022-07-20 13:35:57 +00:00
/**
* The width of this Graphics instance
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getWidth
*/
getWidth: () => number;
2022-07-20 13:35:57 +00:00
/**
* The height of this Graphics instance
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getHeight
*/
getHeight: () => number;
2022-07-20 13:35:57 +00:00
/**
* The number of bits per pixel of this Graphics instance
2022-07-20 19:07:18 +00:00
*
* **Note:** Bangle.js 2 behaves a little differently here. The display
* is 3 bit, so `getBPP` returns 3 and `asBMP`/`asImage`/etc return 3 bit images.
* However in order to allow dithering, the colors returned by `Graphics.getColor` and `Graphics.theme`
* are actually 16 bits.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getBPP
*/
getBPP: () => number;
2022-07-20 13:35:57 +00:00
/**
* Reset the state of Graphics to the defaults (eg. Color, Font, etc)
* that would have been used when Graphics was initialised.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_reset
*/
reset: () => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Clear the LCD with the Background Color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_clear
*/
clear: (reset: boolean) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Fill a rectangular area in the Foreground Color
2022-07-20 19:07:18 +00:00
*
* On devices with enough memory, you can specify `{x,y,x2,y2,r}` as the first
* argument, which allows you to draw a rounded rectangle.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_fillRect
*/
fillRect: (x1: any, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Fill a rectangular area in the Background Color
2022-07-20 19:07:18 +00:00
*
* On devices with enough memory, you can specify `{x,y,x2,y2,r}` as the first
* argument, which allows you to draw a rounded rectangle.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_clearRect
*/
clearRect: (x1: any, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw an unfilled rectangle 1px wide in the Foreground Color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawRect
*/
drawRect: (x1: any, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a filled circle in the Foreground Color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_fillCircle
*/
fillCircle: (x: number, y: number, rad: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw an unfilled circle 1px wide in the Foreground Color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawCircle
*/
drawCircle: (x: number, y: number, rad: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a circle, centred at (x,y) with radius r in the current foreground color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawCircleAA
*/
drawCircleAA: (x: number, y: number, r: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a filled ellipse in the Foreground Color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_fillEllipse
*/
fillEllipse: (x1: number, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw an ellipse in the Foreground Color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawEllipse
*/
drawEllipse: (x1: number, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Get a pixel's color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getPixel
*/
getPixel: (x: number, y: number) => number;
2022-07-20 13:35:57 +00:00
/**
* Set a pixel's color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setPixel
*/
setPixel: (x: number, y: number, col: any) => Graphics;
2022-07-20 15:57:03 +00:00
/**
* Work out the color value to be used in the current bit depth based on the arguments.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* This is used internally by setColor and setBgColor
2022-07-20 19:07:18 +00:00
*
* ```
* // 1 bit
* g.toColor(1,1,1) => 1
* // 16 bit
* g.toColor(1,0,0) => 0xF800
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_toColor
*/
toColor: (r: any, g: any, b: any) => number;
/**
* Blend between two colors, and return the result.
2022-07-20 19:07:18 +00:00
*
* ```
* // dark yellow - halfway between red and green
* var col = g.blendColor("#f00","#0f0", 0.5);
* // Get a color 25% brighter than the theme's background colour
* var col = g.blendColor(g.theme.fg,g.theme.bg, 0.75);
* // then...
* g.setColor(col).fillRect(10,10,100,100);
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_blendColor
*/
blendColor: (col_a: any, col_b: any, amt: any) => number;
2022-07-20 13:35:57 +00:00
/**
* Set the color to use for subsequent drawing operations.
2022-07-20 19:07:18 +00:00
*
* If just `r` is specified as an integer, the numeric value will be written directly into a pixel. eg. On a 24 bit `Graphics` instance you set bright blue with either `g.setColor(0,0,1)` or `g.setColor(0x0000FF)`.
2022-07-20 19:07:18 +00:00
*
* A good shortcut to ensure you get white on all platforms is to use `g.setColor(-1)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* The mapping is as follows:
*
* - 32 bit: `r,g,b` => `0xFFrrggbb`
* - 24 bit: `r,g,b` => `0xrrggbb`
* - 16 bit: `r,g,b` => `0brrrrrggggggbbbbb` (RGB565)
* - Other bpp: `r,g,b` => white if `r+g+b > 50%`, otherwise black (use `r` on its own as an integer)
*
* If you specified `color_order` when creating the `Graphics` instance, `r`,`g` and `b` will be swapped as you specified.
2022-07-20 19:07:18 +00:00
*
* **Note:** On devices with low flash memory, `r` **must** be an integer representing the color in the current bit depth. It cannot
* be a floating point value, and `g` and `b` are ignored.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setColor
*/
setColor: (r: any, g: any, b: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Set the background color to use for subsequent drawing operations.
2022-07-20 19:07:18 +00:00
*
* See `Graphics.setColor` for more information on the mapping of `r`, `g`, and `b` to pixel values.
2022-07-20 19:07:18 +00:00
*
* **Note:** On devices with low flash memory, `r` **must** be an integer representing the color in the current bit depth. It cannot
* be a floating point value, and `g` and `b` are ignored.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setBgColor
*/
setBgColor: (r: any, g: any, b: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Get the color to use for subsequent drawing operations
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getColor
*/
getColor: () => number;
2022-07-20 13:35:57 +00:00
/**
* Get the background color to use for subsequent drawing operations
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getBgColor
*/
getBgColor: () => number;
2022-07-20 13:35:57 +00:00
/**
* This sets the 'clip rect' that subsequent drawing operations are clipped to
* sit between.
2022-07-20 19:07:18 +00:00
*
* These values are inclusive - eg `g.setClipRect(1,0,5,0)` will ensure that only
* pixel rows 1,2,3,4,5 are touched on column 0.
2022-07-20 19:07:18 +00:00
*
* **Note:** For maximum flexibility on Bangle.js 1, the values here are not range checked. For normal
* use, X and Y should be between 0 and `getWidth()-1`/`getHeight()-1`.
2022-07-20 19:07:18 +00:00
*
* **Note:** The x/y values here are rotated, so that if `Graphics.setRotation` is used
* they correspond to the coordinates given to the draw functions, *not to the
* physical device pixels*.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setClipRect
*/
setClipRect: (x1: number, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Make subsequent calls to `drawString` use the built-in 4x6 pixel bitmapped Font
2022-07-20 19:07:18 +00:00
*
* It is recommended that you use `Graphics.setFont("4x6")` for more flexibility.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFontBitmap
*/
setFontBitmap: () => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Make subsequent calls to `drawString` use a Vector Font of the given height.
2022-07-20 19:07:18 +00:00
*
* It is recommended that you use `Graphics.setFont("Vector", size)` for more flexibility.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFontVector
*/
setFontVector: (size: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Make subsequent calls to `drawString` use a Custom Font of the given height. See the [Fonts page](http://www.espruino.com/Fonts) for more
* information about custom fonts and how to create them.
2022-07-20 19:07:18 +00:00
*
* For examples of use, see the [font modules](https://www.espruino.com/Fonts#font-modules).
2022-07-20 19:07:18 +00:00
*
* **Note:** while you can specify the character code of the first character with `firstChar`,
* the newline character 13 will always be treated as a newline and not rendered.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFontCustom
*/
setFontCustom: (bitmap: any, firstChar: number, width: any, height: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Set the alignment for subsequent calls to `drawString`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFontAlign
*/
setFontAlign: (x: number, y: number, rotation: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Set the font by name. Various forms are available:
*
* - `g.setFont("4x6")` - standard 4x6 bitmap font
* - `g.setFont("Vector:12")` - vector font 12px high
* - `g.setFont("4x6:2")` - 4x6 bitmap font, doubled in size
* - `g.setFont("6x8:2x3")` - 6x8 bitmap font, doubled in width, tripled in height
*
2022-07-20 13:07:21 +00:00
* You can also use these forms, but they are not recommended:
*
* - `g.setFont("Vector12")` - vector font 12px high
* - `g.setFont("4x6",2)` - 4x6 bitmap font, doubled in size
*
* `g.getFont()` will return the current font as a String.
2022-07-20 19:07:18 +00:00
*
* For a list of available font names, you can use `g.getFonts()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setFont
*/
setFont: (name: any, size: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Get the font by name - can be saved and used with `Graphics.setFont`.
2022-07-20 19:07:18 +00:00
*
* Normally this might return something like `"4x6"`, but if a scale
* factor is specified, a colon and then the size is reported, like "4x6:2"
2022-07-20 19:07:18 +00:00
*
* **Note:** For custom fonts, `Custom` is currently
* reported instead of the font name.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getFont
*/
getFont: () => string;
2022-07-20 13:35:57 +00:00
/**
* Return an array of all fonts currently in the Graphics library.
2022-07-20 19:07:18 +00:00
*
* **Note:** Vector fonts are specified as `Vector#` where `#` is the font height. As there
* are effectively infinite fonts, just `Vector` is included in the list.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getFonts
*/
getFonts: () => any[];
2022-07-20 13:35:57 +00:00
/**
* Return the height in pixels of the current font
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getFontHeight
*/
getFontHeight: () => number;
2022-07-20 13:35:57 +00:00
/**
* Return the size in pixels of a string of text in the current font
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_stringWidth
*/
stringWidth: (str: any) => number;
2022-07-20 13:35:57 +00:00
/**
* Return the width and height in pixels of a string of text in the current font
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_stringMetrics
*/
stringMetrics: (str: any) => any;
2022-07-20 15:57:03 +00:00
/**
* Wrap a string to the given pixel width using the current font, and return the
* lines as an array.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* To render within the screen's width you can do:
2022-07-20 19:07:18 +00:00
*
* ```
* g.drawString(g.wrapString(text, g.getWidth()).join("\n")),
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_wrapString
*/
wrapString: (str: any, maxWidth: number) => any;
/**
* Draw a string of text in the current font.
2022-07-20 19:07:18 +00:00
*
* ```
* g.drawString("Hello World", 10, 10);
* ```
*
2022-07-20 15:57:03 +00:00
* Images may also be embedded inside strings (eg to render Emoji or characters not in the current font).
* To do this, just add `0` then the image string ([about Images](http://www.espruino.com/Graphics#images-bitmaps))
* For example:
2022-07-20 19:07:18 +00:00
*
* ```
* g.drawString("Hi \0\7\5\1\x82 D\x17\xC0");
* // draws:
* // # # # # #
* // # # #
* // ### ## #
* // # # # # #
* // # # ### #####
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawString
*/
drawString: (str: any, x: number, y: number, solid: boolean) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a line between x1,y1 and x2,y2 in the current foreground color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawLine
*/
drawLine: (x1: number, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a line between x1,y1 and x2,y2 in the current foreground color
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawLineAA
*/
drawLineAA: (x1: number, y1: number, x2: number, y2: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a line from the last position of lineTo or moveTo to this position
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_lineTo
*/
lineTo: (x: number, y: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Move the cursor to a position - see lineTo
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_moveTo
*/
moveTo: (x: number, y: number) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw a polyline (lines between each of the points in `poly`) in the current foreground color
2022-07-20 19:07:18 +00:00
*
* **Note:** there is a limit of 64 points (128 XY elements) for polygons
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawPoly
*/
drawPoly: (poly: any, closed: boolean) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Draw an **antialiased** polyline (lines between each of the points in `poly`) in the current foreground color
2022-07-20 19:07:18 +00:00
*
* **Note:** there is a limit of 64 points (128 XY elements) for polygons
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawPolyAA
*/
drawPolyAA: (poly: any, closed: boolean) => Graphics;
2022-07-20 15:57:03 +00:00
/**
* Draw a filled polygon in the current foreground color.
2022-07-20 19:07:18 +00:00
*
* ```
* g.fillPoly([
* 16, 0,
* 31, 31,
* 26, 31,
* 16, 12,
* 6, 28,
* 0, 27 ]);
* ```
*
2022-07-20 15:57:03 +00:00
* This fills from the top left hand side of the polygon (low X, low Y)
* *down to but not including* the bottom right. When placed together polygons
* will align perfectly without overdraw - but this will not fill the
* same pixels as `drawPoly` (drawing a line around the edge of the polygon).
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** there is a limit of 64 points (128 XY elements) for polygons
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_fillPoly
*/
fillPoly: (poly: any) => Graphics;
/**
* Draw a filled polygon in the current foreground color.
2022-07-20 19:07:18 +00:00
*
* ```
* g.fillPolyAA([
* 16, 0,
* 31, 31,
* 26, 31,
* 16, 12,
* 6, 28,
* 0, 27 ]);
* ```
*
2022-07-20 15:57:03 +00:00
* This fills from the top left hand side of the polygon (low X, low Y)
* *down to but not including* the bottom right. When placed together polygons
* will align perfectly without overdraw - but this will not fill the
* same pixels as `drawPoly` (drawing a line around the edge of the polygon).
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** there is a limit of 64 points (128 XY elements) for polygons
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_fillPolyAA
*/
fillPolyAA: (poly: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Set the current rotation of the graphics device.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setRotation
*/
setRotation: (rotation: number, reflect: boolean) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Return the width and height in pixels of an image (either Graphics, Image Object, Image String or ArrayBuffer). Returns
* `undefined` if image couldn't be decoded.
2022-07-20 19:07:18 +00:00
*
* `frames` is also included is the image contains more information than you'd expect for a single bitmap. In
* this case the bitmap might be an animation with multiple frames
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_imageMetrics
*/
imageMetrics: (str: any) => any;
2022-07-20 15:57:03 +00:00
/**
* Image can be:
*
* - An object with the following fields `{ width : int, height : int, bpp : optional int, buffer : ArrayBuffer/String, transparent: optional int, palette : optional Uint16Array(2/4/16) }`. bpp = bits per pixel (default is 1), transparent (if defined) is the colour that will be treated as transparent, and palette is a color palette that each pixel will be looked up in first
* - A String where the the first few bytes are: `width,height,bpp,[transparent,]image_bytes...`. If a transparent colour is specified the top bit of `bpp` should be set.
* - An ArrayBuffer Graphics object (if `bpp<8`, `msb:true` must be set) - this is disabled on devices without much flash memory available
*
* Draw an image at the specified position.
*
* - If the image is 1 bit, the graphics foreground/background colours will be used.
* - If `img.palette` is a Uint16Array or 2/4/16 elements, color data will be looked from the supplied palette
* - On Bangle.js, 2 bit images blend from background(0) to foreground(1) colours
* - On Bangle.js, 4 bit images use the Apple Mac 16 color palette
* - On Bangle.js, 8 bit images use the Web Safe 216 color palette
* - Otherwise color data will be copied as-is. Bitmaps are rendered MSB-first
*
* If `options` is supplied, `drawImage` will allow images to be rendered at any scale or angle. If `options.rotate` is set it will
* center images at `x,y`. `options` must be an object of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* rotate : float, // the amount to rotate the image in radians (default 0)
* scale : float, // the amount to scale the image up (default 1)
* frame : int // if specified and the image has frames of data
* // after the initial frame, draw one of those frames from the image
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* For example:
2022-07-20 19:07:18 +00:00
*
* ```
* // In the top left of the screen
* g.drawImage(img,0,0);
* // In the top left of the screen, twice as big
* g.drawImage(img,0,0,{scale:2});
* // In the center of the screen, twice as big, 45 degrees
* g.drawImage(img, g.getWidth()/2, g.getHeight()/2,
* {scale:2, rotate:Math.PI/4});
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawImage
*/
drawImage: (image: any, x: number, y: number, options: any) => Graphics;
/**
* Draws multiple images *at once* - which avoids flicker on unbuffered systems
* like Bangle.js. Maximum layer count right now is 4.
2022-07-20 19:07:18 +00:00
*
* ```
* layers = [ {
* {x : int, // x start position
* y : int, // y start position
2022-07-20 15:57:03 +00:00
* image : string/object,
2022-07-20 19:07:18 +00:00
* scale : float, // scale factor, default 1
* rotate : float, // angle in radians
* center : bool // center on x,y? default is top left
* repeat : should this image be repeated (tiled?)
* nobounds : bool // if true, the bounds of the image are not used to work out the default area to draw
2022-07-20 15:57:03 +00:00
* }
* ]
2022-07-20 19:07:18 +00:00
* options = { // the area to render. Defaults to rendering just enough to cover what&#x27;s requested
2022-07-20 15:57:03 +00:00
* x,y,
* width,height
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_drawImages
*/
drawImages: (layers: any, options: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Return this Graphics object as an Image that can be used with `Graphics.drawImage`.
* Check out [the Graphics reference page](http://www.espruino.com/Graphics#images-bitmaps)
* for more information on images.
2022-07-20 19:07:18 +00:00
*
* Will return undefined if data can't be allocated for the image.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* The image data itself will be referenced rather than copied if:
*
* - An image `object` was requested (not `string`)
* - The Graphics instance was created with `Graphics.createArrayBuffer`
* - Is 8 bpp *OR* the `{msb:true}` option was given
* - No other format options (zigzag/etc) were given
*
* Otherwise data will be copied, which takes up more space and
* may be quite slow.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_asImage
*/
asImage: (type: any) => any;
2022-07-20 13:35:57 +00:00
/**
* Return the area of the Graphics canvas that has been modified, and optionally clear
* the modified area to 0.
2022-07-20 19:07:18 +00:00
*
* For instance if `g.setPixel(10,20)` was called, this would return `{x1:10, y1:20, x2:10, y2:20}`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_getModified
*/
getModified: (reset: boolean) => any;
2022-07-20 13:35:57 +00:00
/**
* Scroll the contents of this graphics in a certain direction. The remaining area
* is filled with the background color.
2022-07-20 19:07:18 +00:00
*
* Note: This uses repeated pixel reads and writes, so will not work on platforms that
* don't support pixel reads.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_scroll
*/
scroll: (x: number, y: number) => Graphics;
2022-07-20 15:57:03 +00:00
/**
* Blit one area of the screen (x1,y1 w,h) to another (x2,y2 w,h)
2022-07-20 19:07:18 +00:00
*
* ```
* g.blit({
* x1:0, y1:0,
* w:32, h:32,
* x2:100, y2:100,
* setModified : true // should we set the modified area?
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* Note: This uses repeated pixel reads and writes, so will not work on platforms that
* don't support pixel reads.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_blit
*/
blit: (options: any) => Graphics;
2022-07-20 13:35:57 +00:00
/**
* Create a Windows BMP file from this Graphics instance, and return it as a String.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_asBMP
*/
asBMP: () => any;
2022-07-20 13:35:57 +00:00
/**
* Create a URL of the form `data:image/bmp;base64,...` that can be pasted into the browser.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* The Espruino Web IDE can detect this data on the console and render the image inline automatically.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_asURL
*/
asURL: () => any;
2022-07-20 13:35:57 +00:00
/**
* Output this image as a bitmap URL of the form `data:image/bmp;base64,...`. The Espruino Web IDE will detect this on the console and will render the image inline automatically.
2022-07-20 19:07:18 +00:00
*
* This is identical to `console.log(g.asURL())` - it is just a convenient function for easy debugging and producing screenshots of what is currently in the Graphics instance.
2022-07-20 19:07:18 +00:00
*
* **Note:** This may not work on some bit depths of Graphics instances. It will also not work for the main Graphics instance
* of Bangle.js 1 as the graphics on Bangle.js 1 are stored in write-only memory.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_dump
*/
dump: () => void;
2022-07-20 13:35:57 +00:00
/**
* Calculate the square area under a Bezier curve.
2022-07-20 19:07:18 +00:00
*
* x0,y0: start point
2022-07-20 13:07:21 +00:00
* x1,y1: control point
* y2,y2: end point
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* Max 10 points without start point.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_quadraticBezier
*/
quadraticBezier: (arr: any, options: any) => any;
2022-07-20 15:57:03 +00:00
/**
* Transformation can be:
*
* - An object of the form
*
2022-07-20 19:07:18 +00:00
* ```
* {
* x: float, // x offset (default 0)
* y: float, // y offset (default 0)
* scale: float, // scale factor (default 1)
* rotate: float, // angle in radians (default 0)
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
2022-07-20 15:57:03 +00:00
*
* - A six-element array of the form `[a,b,c,d,e,f]`, which represents the 2D transformation matrix
*
2022-07-20 19:07:18 +00:00
* ```
* a c e
* b d f
* 0 0 1
* ```
*
2022-07-20 15:57:03 +00:00
* Apply a transformation to an array of vertices.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_transformVertices
*/
transformVertices: (verts: any, transformation: any) => any;
/**
* Returns an object of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* fg : 0xFFFF, // foreground colour
* bg : 0, // background colour
* fg2 : 0xFFFF, // accented foreground colour
* bg2 : 0x0007, // accented background colour
* fgH : 0xFFFF, // highlighted foreground colour
* bgH : 0x02F7, // highlighted background colour
* dark : true, // Is background dark (eg. foreground should be a light colour)
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* These values can then be passed to `g.setColor`/`g.setBgColor` for example `g.setColor(g.theme.fg2)`. When the Graphics
* instance is reset, the background color is automatically set to `g.theme.bg` and foreground is set to `g.theme.fg`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* On Bangle.js these values can be changed by writing updated values to `theme` in `settings.js` and reloading the app - or they can
* be changed temporarily by calling `Graphics.setTheme`
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_theme
*/
theme: any
/**
* Set the global colour scheme. On Bangle.js, this is reloaded from `settings.json` for each new app loaded.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* See `Graphics.theme` for the fields that can be provided. For instance you can change
* the background to red using:
2022-07-20 19:07:18 +00:00
*
* ```
* g.setTheme({bg:"#f00"});
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Graphics_setTheme
*/
setTheme: (theme: any) => Graphics;
2022-07-20 13:07:21 +00:00
}
2022-07-20 13:35:57 +00:00
/**
* A simple VT100 terminal emulator.
2022-07-20 19:07:18 +00:00
*
* When data is sent to the `Terminal` object, `Graphics.getInstance()`
* is called and if an instance of `Graphics` is found then characters
* are written to it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Terminal
*/
declare const Terminal: Serial;
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Library that initialises a network device that calls into JavaScript
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NetworkJS_undefined
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
/**
* This library implements a telnet console for the Espruino interpreter. It requires a network
* connection, e.g. Wifi, and **currently only functions on the ESP8266 and on Linux **. It uses
* port 23 on the ESP8266 and port 2323 on Linux.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** To enable on Linux, run `./espruino --telnet`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_TelnetServer_undefined
*/
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* This class helps to convert URLs into Objects of information ready for http.request/get
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#url
*/
declare const url: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* A utility function to split a URL into parts
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This is useful in web servers for instance when handling a request.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For instance `url.parse("/a?b=c&d=e",true)` returns `{"method":"GET","host":"","path":"/a?b=c&d=e","pathname":"/a","search":"?b=c&d=e","port":80,"query":{"b":"c","d":"e"}}`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_url_parse
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
parse: (urlStr: any, parseQuery: boolean) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This library allows you to create TCPIP servers and clients
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* In order to use this, you will need an extra module to get network connectivity.
2022-07-20 19:07:18 +00:00
*
* This is designed to be a cut-down version of the [node.js library](http://nodejs.org/api/net.html). Please see the [Internet](https://espruino.com//Internet) page for more information on how to use it.
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_net_undefined
*/
/**
* The socket server created by `require('net').createServer`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Server
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function Server(): void;
type Server = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Start listening for new connections on the given port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Server_listen
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
listen: (port: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Stop listening for new connections
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Server_close
*/
close: () => void;
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* An actual socket connection - allowing transmit/receive of TCP data
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Socket
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function Socket(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type Socket = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return how many bytes are available to read. If there is already a listener for data, this will always return 0.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Socket_available
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
available: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return a string containing characters that have been received
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Socket_read
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
read: (chars: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Pipe this to a stream (an object with a 'write' method)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Socket_pipe
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
pipe: (destination: any, options: any) => void;
/**
* This function writes the `data` argument as a string. Data that is passed in
* (including arrays) will be converted to a string with the normal JavaScript
* `toString` method.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you wish to send binary data then you need to convert that data directly to a
* String. This can be done with `String.fromCharCode`, however it's often easier
* and faster to use the Espruino-specific `E.toString`, which will read its arguments
* as an array of bytes and convert that to a String:
2022-07-20 19:07:18 +00:00
*
* ```
* socket.write(E.toString([0,1,2,3,4,5]));
* ```
*
2022-07-20 18:35:57 +00:00
* If you need to send something other than bytes, you can use 'Typed Arrays', or
* even `DataView`:
2022-07-20 19:07:18 +00:00
*
* ```
* var d = new DataView(new ArrayBuffer(8)); // 8 byte array buffer
* d.setFloat32(0, 765.3532564); // write float at bytes 0-3
* d.setInt8(4, 42); // write int8 at byte 4
* socket.write(E.toString(d.buffer))
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Socket_write
*/
write: (data: any) => boolean;
/**
* Close this socket - optional data to append as an argument.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See `Socket.write` for more information about the data argument
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Socket_end
*/
end: (data: any) => void;
2022-07-20 13:07:21 +00:00
}
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This library allows you to create UDP/DATAGRAM servers and clients
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* In order to use this, you will need an extra module to get network connectivity.
2022-07-20 19:07:18 +00:00
*
* This is designed to be a cut-down version of the [node.js library](http://nodejs.org/api/dgram.html). Please see the [Internet](https://espruino.com//Internet) page for more information on how to use it.
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_dgram_undefined
*/
/**
* An actual socket connection - allowing transmit/receive of TCP data
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#dgramSocket
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function dgramSocket(): void;
type dgramSocket = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_dgramSocket_send
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
send: (buffer: any, offset: any, length: any, args: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_dgramSocket_bind
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
bind: (port: number, callback: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Close the socket
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_dgramSocket_close
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
close: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_dgramSocket_addMembership
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
addMembership: (group: any, ip: any) => void;
}
/**
* This library allows you to create TCPIP servers and clients using TLS encryption
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* In order to use this, you will need an extra module to get network connectivity.
2022-07-20 19:07:18 +00:00
*
* This is designed to be a cut-down version of the [node.js library](http://nodejs.org/api/tls.html). Please see the [Internet](https://espruino.com//Internet) page for more information on how to use it.
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_tls_undefined
*/
/**
* @url http://www.espruino.com/Reference#l_CC3000_undefined
*/
/**
* An instantiation of a WiFi network adaptor
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#WLAN
*/
declare function WLAN(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type WLAN = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Connect to a wireless network
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WLAN_connect
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
connect: (ap: any, key: any, callback: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Completely uninitialise and power down the CC3000. After this you'll have to use `require("CC3000").connect()` again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WLAN_disconnect
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
disconnect: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Completely uninitialise and power down the CC3000, then reconnect to the old access point.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WLAN_reconnect
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reconnect: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the current IP address
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WLAN_getIP
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getIP: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the current IP address for get an IP from DHCP (if no options object is specified).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Changes are written to non-volatile memory, but will only take effect after calling `wlan.reconnect()`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WLAN_setIP
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setIP: (options: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Class containing utility functions for the [ESP8266](http://www.espruino.com/EspruinoESP8266)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#ESP8266
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const ESP8266: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* **DEPRECATED** - please use `Wifi.ping` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Perform a network ping request. The parameter can be either a String or a numeric IP address.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_ping
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
ping: (ipAddr: any, pingCallback: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Perform a hardware reset/reboot of the esp8266.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_reboot
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reboot: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* At boot time the esp8266's firmware captures the cause of the reset/reboot. This function returns this information in an object with the following fields:
*
2022-07-20 18:35:57 +00:00
* - `reason`: "power on", "wdt reset", "exception", "soft wdt", "restart", "deep sleep", or "reset pin"
* - `exccause`: exception cause
* - `epc1`, `epc2`, `epc3`: instruction pointers
* - `excvaddr`: address being accessed
* - `depc`: (?)
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_getResetInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getResetInfo: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Enable or disable the logging of debug information. A value of `true` enables debug logging while a value of `false` disables debug logging. Debug output is sent to UART1 (gpio2).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_logDebug
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
logDebug: (enable: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the debug logging mode. It can be disabled (which frees ~1.2KB of heap), enabled in-memory only, or in-memory and output to a UART.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_setLog
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setLog: (mode: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Prints the contents of the debug log to the console.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_printLog
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
printLog: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns one line from the log or up to 128 characters.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_readLog
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
readLog: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Dumps info about all sockets to the log. This is for troubleshooting the socket implementation.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_dumpSocketInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
dumpSocketInfo: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Note:** This is deprecated. Use `E.setClock(80/160)`
* **Note:**
* Set the operating frequency of the ESP8266 processor. The default is 160Mhz.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Warning**: changing the cpu frequency affects the timing of some I/O operations, notably of software SPI and I2C, so things may be a bit slower at 80Mhz.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_setCPUFreq
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setCPUFreq: (freq: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns an object that contains details about the state of the ESP8266 with the following fields:
*
* - `sdkVersion` - Version of the SDK.
* - `cpuFrequency` - CPU operating frequency in Mhz.
* - `freeHeap` - Amount of free heap in bytes.
* - `maxCon` - Maximum number of concurrent connections.
* - `flashMap` - Configured flash size&map: '512KB:256/256' .. '4MB:512/512'
* - `flashKB` - Configured flash size in KB as integer
* - `flashChip` - Type of flash chip as string with manufacturer & chip, ex: '0xEF 0x4016`
*
* @url http://www.espruino.com/Reference#l_ESP8266_getState
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getState: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Note:** This is deprecated. Use `require("Flash").getFree()`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_getFreeFlash
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getFreeFlash: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_crc32
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
crc32: (arrayOfData: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **This function is deprecated.** Please use `require("neopixel").write(pin, data)` instead
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_neopixelWrite
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
neopixelWrite: (pin: Pin, arrayOfData: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Put the ESP8266 into 'deep sleep' for the given number of microseconds,
* reducing power consumption drastically.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* meaning of option values:
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* 0 - the 108th Byte of init parameter decides whether RF calibration will be performed or not.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* 1 - run RF calibration after waking up. Power consumption is high.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* 2 - no RF calibration after waking up. Power consumption is low.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* 4 - no RF after waking up. Power consumption is the lowest.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** unlike normal Espruino boards' 'deep sleep' mode, ESP8266 deep sleep actually turns off the processor. After the given number of microseconds have elapsed, the ESP8266 will restart as if power had been turned off and then back on. *All contents of RAM will be lost*.
* Connect GPIO 16 to RST to enable wakeup.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Special:** 0 microseconds cause sleep forever until external wakeup RST pull down occurs.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP8266_deepSleep
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
deepSleep: (micros: any, option: any) => void;
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Library for communication with the WIZnet Ethernet module
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WIZnet_undefined
*/
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
/**
* An instantiation of an Ethernet network adaptor
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Ethernet
*/
declare function Ethernet(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type Ethernet = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the current IP address, subnet, gateway and mac address.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Ethernet_getIP
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getIP: (options: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the current IP address or get an IP from DHCP (if no options object is specified)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If 'mac' is specified as an option, it must be a string of the form `"00:01:02:03:04:05"`
* The default mac is 00:08:DC:01:02:03.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Ethernet_setIP
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setIP: (options: any, callback: any) => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set hostname allow to set the hosname used during the dhcp request.
* min 8 and max 12 char, best set before calling `eth.setIP()`
* Default is WIZnet010203, 010203 is the default nic as part of the mac.
* Best to set the hosname before calling setIP().
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Ethernet_setHostname
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setHostname: (hostname: any, callback: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns the hostname
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Ethernet_getHostname
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getHostname: (callback: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the current status of the ethernet device
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Ethernet_getStatus
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getStatus: (options: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
/**
* The Wifi library is designed to control the Wifi interface. It supports functionality
* such as connecting to wifi networks, getting network information, starting an access
* point, etc.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* It is available on these devices:
*
* - [Espruino WiFi](http://www.espruino.com/WiFi#using-wifi)
* - [ESP8266](http://www.espruino.com/EspruinoESP8266)
* - [ESP32](http://www.espruino.com/ESP32)
*
* **Certain features may or may not be implemented on your device** however
* we have documented what is available and what isn't.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you're not using one of the devices above, a separate WiFi library is
* provided. For instance:
*
* - An [ESP8266 connected to an Espruino board](http://www.espruino.com/ESP8266#software)
* - An [CC3000 WiFi Module](http://www.espruino.com/CC3000)
*
* [Other ways of connecting to the net](http://www.espruino.com/Internet#related-pages) such
* as GSM, Ethernet and LTE have their own libraries.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can use the WiFi library as follows:
2022-07-20 19:07:18 +00:00
*
* ```
* var wifi = require("Wifi");
* wifi.connect("my-ssid", {password:"my-pwd"}, function(ap){ console.log("connected:", ap); });
* ```
*
2022-07-20 18:35:57 +00:00
* On ESP32/ESP8266 if you want the connection to happen automatically at boot, add `wifi.save();`.
* On other platforms, place `wifi.connect` in a function called `onInit`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_undefined
*/
/**
* This library allows you to create http servers and make http requests
2022-07-20 19:07:18 +00:00
*
* In order to use this, you will need an extra module to get network connectivity such as the [TI CC3000](https://espruino.com//CC3000) or [WIZnet W5500](https://espruino.com//WIZnet).
*
* This is designed to be a cut-down version of the [node.js library](http://nodejs.org/api/http.html). Please see the [Internet](https://espruino.com//Internet) page for more information on how to use it.
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_http_undefined
*/
/**
* The HTTP server created by `require('http').createServer`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#httpSrv
*/
declare function httpSrv(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type httpSrv = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Start listening for new HTTP connections on the given port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSrv_listen
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
listen: (port: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Stop listening for new HTTP connections
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSrv_close
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
close: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
/**
* The HTTP server request
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#httpSRq
*/
declare function httpSRq(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type httpSRq = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The headers to sent to the server with this HTTP request.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRq_headers
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
headers: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The HTTP method used with this request. Often `"GET"`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRq_method
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
method: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The URL requested in this HTTP request, for instance:
*
2022-07-20 18:35:57 +00:00
* - `"/"` - the main page
* - `"/favicon.ico"` - the web page's icon
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRq_url
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
url: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return how many bytes are available to read. If there is already a listener for data, this will always return 0.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRq_available
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
available: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return a string containing characters that have been received
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRq_read
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
read: (chars: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Pipe this to a stream (an object with a 'write' method)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRq_pipe
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
pipe: (destination: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* The HTTP server response
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#httpSRs
*/
declare function httpSRs(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type httpSRs = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The headers to send back along with the HTTP response.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The default contents are:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* "Connection": "close"
* }
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRs_headers
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
headers: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function writes the `data` argument as a string. Data that is passed in
* (including arrays) will be converted to a string with the normal JavaScript
* `toString` method. For more information about sending binary data see `Socket.write`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRs_write
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
write: (data: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* See `Socket.write` for more information about the data argument
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRs_end
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
end: (data: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send the given status code and headers. If not explicitly called
* this will be done automatically the first time data is written
* to the response.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This cannot be called twice, or after data has already been sent
* in the response.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRs_writeHead
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
writeHead: (statusCode: number, headers: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set a value to send in the header of this HTTP response. This updates the `httpSRs.headers` property.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Any headers supplied to `writeHead` will overwrite any headers with the same name.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpSRs_setHeader
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setHeader: (name: any, value: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
/**
* The HTTP client request, returned by `http.request()` and `http.get()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#httpCRq
*/
declare function httpCRq(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type httpCRq = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function writes the `data` argument as a string. Data that is passed in
* (including arrays) will be converted to a string with the normal JavaScript
* `toString` method. For more information about sending binary data see `Socket.write`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRq_write
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
write: (data: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Finish this HTTP request - optional data to append as an argument
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See `Socket.write` for more information about the data argument
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRq_end
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
end: (data: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* The HTTP client response, passed to the callback of `http.request()` an `http.get()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#httpCRs
*/
declare function httpCRs(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type httpCRs = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The headers received along with the HTTP response
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_headers
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
headers: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The HTTP response's status code - usually `"200"` if all went well
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_statusCode
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
statusCode: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The HTTP response's status message - Usually `"OK"` if all went well
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_statusMessage
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
statusMessage: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The HTTP version reported back by the server - usually `"1.1"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_httpVersion
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
httpVersion: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return how many bytes are available to read. If there is a 'data' event handler, this will always return 0.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_available
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
available: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return a string containing characters that have been received
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_read
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
read: (chars: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Pipe this to a stream (an object with a 'write' method)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_httpCRs_pipe
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
pipe: (destination: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This library provides TV out capability on the Espruino and Espruino Pico.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See the [Television](https://espruino.com//Television) page for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_tv_undefined
2022-07-20 13:07:21 +00:00
*/
2022-07-20 13:35:57 +00:00
/**
2022-07-20 19:07:18 +00:00
* Simple library for compression/decompression using [heatshrink](https://github.com/atomicobject/heatshrink), an [LZSS](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Storer%E2%80%93Szymanski) compression tool.
*
2022-07-20 18:35:57 +00:00
* Espruino uses heatshrink internally to compress RAM down to fit in Flash memory when `save()` is used. This just exposes that functionality.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Functions here take and return buffers of data. There is no support for streaming, so both the compressed and decompressed data must be able to fit in memory at the same time.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_heatshrink_undefined
2022-07-20 13:07:21 +00:00
*/
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This class provides functionality to recognise gestures drawn
* on a touchscreen. It is only built into Bangle.js 2.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Usage:
2022-07-20 19:07:18 +00:00
*
* ```
* var strokes = {
* stroke1 : Unistroke.new(new Uint8Array([x1, y1, x2, y2, x3, y3, ...])),
* stroke2 : Unistroke.new(new Uint8Array([x1, y1, x2, y2, x3, y3, ...])),
* stroke3 : Unistroke.new(new Uint8Array([x1, y1, x2, y2, x3, y3, ...]))
2022-07-20 18:35:57 +00:00
* };
2022-07-20 19:07:18 +00:00
* var r = Unistroke.recognise(strokes,new Uint8Array([x1, y1, x2, y2, x3, y3, ...]))
* print(r); // stroke1/stroke2/stroke3
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Unistroke
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Unistroke: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Create a new Unistroke based on XY coordinates
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Unistroke_new
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
new: (xy: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Recognise based on an object of named strokes, and a list of XY coordinates
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Unistroke_recognise
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
recognise: (strokes: any, xy: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The NRF class is for controlling functionality of the Nordic nRF51/nRF52 chips.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Most functionality is related to Bluetooth Low Energy, however there are also some functions related to NFC that apply to NRF52-based devices.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#NRF
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const NRF: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return an object with information about the security
* state of the current peripheral connection:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* connected // The connection is active (not disconnected).
* encrypted // Communication on this link is encrypted.
* mitm_protected // The encrypted communication is also protected against man-in-the-middle attacks.
* bonded // The peer is bonded with us
* connected_addr // If connected=true, the MAC address of the currently connected device
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* If there is no active connection, `{connected:false}` will be returned.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See `NRF.setSecurity` for information about negotiating a secure connection.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getSecurityStatus: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get this device's default Bluetooth MAC address.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For Puck.js, the last 5 characters of this (eg. `ee:ff`)
* are used in the device's advertised Bluetooth name.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_getAddress
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getAddress: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Change the services and characteristics Espruino advertises.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you want to **change** the value of a characteristic, you need
* to use `NRF.updateServices()` instead
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To expose some information on Characteristic `ABCD` on service `BCDE` you could do:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setServices({
* 0xBCDE : {
* 0xABCD : {
* value : "Hello",
* readable : true
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* });
* ```
*
2022-07-20 18:35:57 +00:00
* Or to allow the 3 LEDs to be controlled by writing numbers 0 to 7 to a
* characteristic, you can do the following. `evt.data` is an ArrayBuffer.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setServices({
* 0xBCDE : {
* 0xABCD : {
2022-07-20 18:35:57 +00:00
* writable : true,
2022-07-20 19:07:18 +00:00
* onWrite : function(evt) {
* digitalWrite([LED3,LED2,LED1], evt.data[0]);
2022-07-20 18:35:57 +00:00
* }
* }
* }
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* You can supply many different options:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setServices({
* 0xBCDE : {
* 0xABCD : {
* value : "Hello", // optional
* maxLen : 5, // optional (otherwise is length of initial value)
* broadcast : false, // optional, default is false
* readable : true, // optional, default is false
* writable : true, // optional, default is false
* notify : true, // optional, default is false
* indicate : true, // optional, default is false
* description: "My Characteristic", // optional, default is null,
* security: { // optional - see NRF.setSecurity
* read: { // optional
* encrypted: false, // optional, default is false
* mitm: false, // optional, default is false
* lesc: false, // optional, default is false
* signed: false // optional, default is false
2022-07-20 18:35:57 +00:00
* },
2022-07-20 19:07:18 +00:00
* write: { // optional
* encrypted: true, // optional, default is false
* mitm: false, // optional, default is false
* lesc: false, // optional, default is false
* signed: false // optional, default is false
2022-07-20 18:35:57 +00:00
* }
* },
2022-07-20 19:07:18 +00:00
* onWrite : function(evt) { // optional
* console.log("Got ", evt.data); // an ArrayBuffer
2022-07-20 18:35:57 +00:00
* },
2022-07-20 19:07:18 +00:00
* onWriteDesc : function(evt) { // optional - called when the &#x27;cccd&#x27; descriptor is written
* // for example this is called when notifications are requested by the client:
* console.log("Notifications enabled = ", evt.data[0]&1);
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* // more characteristics allowed
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* // more services allowed
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** UUIDs can be integers between `0` and `0xFFFF`, strings of
* the form `"ABCD"`, or strings of the form `"ABCDABCD-ABCD-ABCD-ABCD-ABCDABCDABCD"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* `options` can be of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setServices(undefined, {
* hid : new Uint8Array(...), // optional, default is undefined. Enable BLE HID support
* uart : true, // optional, default is true. Enable BLE UART support
* advertise: [ &#x27;180D&#x27; ] // optional, list of service UUIDs to advertise
* ancs : true, // optional, Bangle.js-only, enable Apple ANCS support for notifications
* ams : true // optional, Bangle.js-only, enable Apple AMS support for media control
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* To enable BLE HID, you must set `hid` to an array which is the BLE report
* descriptor. The easiest way to do this is to use the `ble_hid_controls`
* or `ble_hid_keyboard` modules.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Just creating a service doesn't mean that the service will
* be advertised. It will only be available after a device connects. To
* advertise, specify the UUIDs you wish to advertise in the `advertise`
* field of the second `options` argument. For example this will create
* and advertise a heart rate service:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setServices({
* 0x180D: { // heart_rate
* 0x2A37: { // heart_rate_measurement
* notify: true,
* value : [0x06, heartrate],
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* }, { advertise: [ &#x27;180D&#x27; ] });
* ```
*
2022-07-20 18:35:57 +00:00
* You may specify 128 bit UUIDs to advertise, however you may get a `DATA_SIZE`
* exception because there is insufficient space in the Bluetooth LE advertising
* packet for the 128 bit UART UUID as well as the UUID you specified. In this
* case you can add `uart:false` after the `advertise` element to disable the
* UART, however you then be unable to connect to Puck.js's console via Bluetooth.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you absolutely require two or more 128 bit UUIDs then you will have to
* specify your own raw advertising data packets with `NRF.setAdvertising`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** The services on Espruino can only be modified when there is
* no device connected to it as it requires a restart of the Bluetooth stack.
* **iOS devices will 'cache' the list of services** so apps like
* NRF Connect may incorrectly display the old services even after you
* have modified them. To fix this, disable and re-enable Bluetooth on your
* iOS device, or use an Android device to run NRF Connect.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Not all combinations of security configuration values are valid, the valid combinations are: encrypted,
* encrypted + mitm, lesc, signed, signed + mitm. See `NRF.setSecurity` for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setServices
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setServices: (data: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Change the data that Espruino advertises.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Data can be of the form `{ UUID : data_as_byte_array }`. The UUID should be
* a [Bluetooth Service ID](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example to return battery level at 95%, do:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setAdvertising({
* 0x180F : [95] // Service data 0x180F = 95
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* Or you could report the current temperature:
2022-07-20 19:07:18 +00:00
*
* ```
* setInterval(function() {
2022-07-20 18:35:57 +00:00
* NRF.setAdvertising({
2022-07-20 19:07:18 +00:00
* 0x1809 : [Math.round(E.getTemperature())]
* });
* }, 30000);
* ```
*
2022-07-20 18:35:57 +00:00
* If you specify a value for the object key, Service Data is advertised. However
* if you specify `undefined`, the Service UUID is advertised:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setAdvertising({
* 0x180D : undefined // Advertise service UUID 0x180D (HRM)
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* Service UUIDs can also be supplied in the second argument of
* `NRF.setServices`, but those go in the scan response packet.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can also supply the raw advertising data in an array. For example
* to advertise as an Eddystone beacon:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setAdvertising([0x03, // Length of Service List
* 0x03, // Param: Service List
* 0xAA, 0xFE, // Eddystone ID
* 0x13, // Length of Service Data
* 0x16, // Service Data
* 0xAA, 0xFE, // Eddystone ID
* 0x10, // Frame type: URL
* 0xF8, // Power
* 0x03, // https://
* &#x27;g&#x27;,&#x27;o&#x27;,&#x27;o&#x27;,&#x27;.&#x27;,&#x27;g&#x27;,&#x27;l&#x27;,&#x27;/&#x27;,&#x27;B&#x27;,&#x27;3&#x27;,&#x27;J&#x27;,&#x27;0&#x27;,&#x27;O&#x27;,&#x27;c&#x27;],
* {interval:100});
* ```
*
2022-07-20 18:35:57 +00:00
* (However for Eddystone we'd advise that you use the [Espruino Eddystone library](https://espruino.com//Puck.js+Eddystone))
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** When specifying data as an array, certain advertising options such as
* `discoverable` and `showName` won't have any effect.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** The size of Bluetooth LE advertising packets is limited to 31 bytes. If
* you want to advertise more data, consider using an array for `data` (See below), or
* `NRF.setScanResponse`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can even specify an array of arrays or objects, in which case each advertising packet
* will be used in turn - for instance to make your device advertise battery level and its name
* as well as both Eddystone and iBeacon :
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setAdvertising([
* {0x180F : [Puck.getBatteryPercentage()]}, // normal advertising, with battery %
* require("ble_ibeacon").get(...), // iBeacon
* require("ble_eddystone").get(...), // eddystone
* ], {interval:300});
* ```
*
2022-07-20 18:35:57 +00:00
* `options` is an object, which can contain:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* name: "Hello" // The name of the device
* showName: true/false // include full name, or nothing
* discoverable: true/false // general discoverable, or limited - default is limited
* connectable: true/false // whether device is connectable - default is true
* scannable : true/false // whether device can be scanned for scan response packets - default is true
* interval: 600 // Advertising interval in msec, between 20 and 10000 (default is 375ms)
* manufacturer: 0x0590 // IF sending manufacturer data, this is the manufacturer ID
* manufacturerData: [...] // IF sending manufacturer data, this is an array of data
* phy: "1mbps/2mbps/coded" // (NRF52840 only) use the long-range coded phy for transmission (1mbps default)
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* Setting `connectable` and `scannable` to false gives the lowest power consumption
* as the BLE radio doesn't have to listen after sending advertising.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **NOTE:** Non-`connectable` advertising can't have an advertising interval less than 100ms
* according to the BLE spec.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* So for instance to set the name of Puck.js without advertising any
* other data you can just use the command:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setAdvertising({},{name:"Hello"});
* ```
*
2022-07-20 18:35:57 +00:00
* You can also specify 'manufacturer data', which is another form of advertising data.
* We've registered the Manufacturer ID 0x0590 (as Pur3 Ltd) for use with *Official
* Espruino devices* - use it to advertise whatever data you'd like, but we'd recommend
* using JSON.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example by not advertising a device name you can send up to 24 bytes of JSON on
* Espruino's manufacturer ID:
2022-07-20 19:07:18 +00:00
*
* ```
* var data = {a:1,b:2};
* NRF.setAdvertising({},{
2022-07-20 18:35:57 +00:00
* showName:false,
2022-07-20 19:07:18 +00:00
* manufacturer:0x0590,
* manufacturerData:JSON.stringify(data)
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* If you're using [EspruinoHub](https://github.com/espruino/EspruinoHub) then it will
* automatically decode this into the folling MQTT topics:
*
2022-07-20 18:35:57 +00:00
* - `/ble/advertise/ma:c_:_a:dd:re:ss/espruino` -> `{"a":10,"b":15}`
* - `/ble/advertise/ma:c_:_a:dd:re:ss/a` -> `1`
* - `/ble/advertise/ma:c_:_a:dd:re:ss/b` -> `2`
*
2022-07-20 18:35:57 +00:00
* Note that **you only have 24 characters available for JSON**, so try to use
* the shortest field names possible and avoid floating point values that can
* be very long when converted to a String.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setAdvertising
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setAdvertising: (data: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* If a device is connected to Espruino, disconnect from it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_disconnect
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
disconnect: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Disable Bluetooth advertising and disconnect from any device that
* connected to Puck.js as a peripheral (this won't affect any devices
* that Puck.js initiated connections to).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This makes Puck.js undiscoverable, so it can't be connected to.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Use `NRF.wake()` to wake up and make Puck.js connectable again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_sleep
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
sleep: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Enable Bluetooth advertising (this is enabled by default), which
* allows other devices to discover and connect to Puck.js.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Use `NRF.sleep()` to disable advertising.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_wake
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
wake: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Restart the Bluetooth softdevice (if there is currently a BLE connection,
* it will queue a restart to be done when the connection closes).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You shouldn't need to call this function in normal usage. However, Nordic's
* BLE softdevice has some settings that cannot be reset. For example there
* are only a certain number of unique UUIDs. Once these are all used the
* only option is to restart the softdevice to clear them all out.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_restart
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
restart: (callback: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set this device's default Bluetooth MAC address:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setAddress("ff:ee:dd:cc:bb:aa random");
* ```
*
2022-07-20 18:35:57 +00:00
* Addresses take the form:
*
* - `"ff:ee:dd:cc:bb:aa"` or `"ff:ee:dd:cc:bb:aa public"` for a public address
* - `"ff:ee:dd:cc:bb:aa random"` for a random static address (the default for Espruino)
*
* This may throw a `INVALID_BLE_ADDR` error if the upper two bits
* of the address don't match the address type.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To change the address, Espruino must restart the softdevice. It will only do
* so when it is disconnected from other devices.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setAddress
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setAddress: (addr: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the battery level in volts (the voltage that the NRF chip is running off of).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This is the battery level of the device itself - it has nothing to with any
* device that might be connected.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_getBattery
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getBattery: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This is just like `NRF.setAdvertising`, except instead of advertising
* the data, it returns the packet that would be advertised as an array.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_getAdvertisingData
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getAdvertisingData: (data: any, options: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The raw scan response data should be supplied as an array. For example to return "Sample" for the device name:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setScanResponse([0x07, // Length of Data
* 0x09, // Param: Complete Local Name
* &#x27;S&#x27;, &#x27;a&#x27;, &#x27;m&#x27;, &#x27;p&#x27;, &#x27;l&#x27;, &#x27;e&#x27;]);
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** `NRF.setServices(..., {advertise:[ ... ]})` writes advertised
* services into the scan response - so you can't use both `advertise`
* and `NRF.setServices` or one will overwrite the other.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setScanResponse
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setScanResponse: (data: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Update values for the services and characteristics Espruino advertises.
* Only services and characteristics previously declared using `NRF.setServices` are affected.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To update the '0xABCD' characteristic in the '0xBCDE' service:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.updateServices({
* 0xBCDE : {
* 0xABCD : {
* value : "World"
2022-07-20 18:35:57 +00:00
* }
* }
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* You can also use 128 bit UUIDs, for example `"b7920001-3c1b-4b40-869f-3c0db9be80c6"`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To define a service and characteristic and then notify connected clients of a
* change to it when a button is pressed:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setServices({
* 0xBCDE : {
* 0xABCD : {
* value : "Hello",
* maxLen : 20,
* notify: true
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* });
* setWatch(function() {
* NRF.updateServices({
* 0xBCDE : {
* 0xABCD : {
* value : "World!",
* notify: true
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* });
* }, BTN, { repeat:true, edge:"rising", debounce: 50 });
* ```
*
2022-07-20 18:35:57 +00:00
* This only works if the characteristic was created with `notify: true` using `NRF.setServices`,
* otherwise the characteristic will be updated but no notification will be sent.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Also note that `maxLen` was specified. If it wasn't then the maximum length of
* the characteristic would have been 5 - the length of `"Hello"`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To indicate (i.e. notify with ACK) connected clients of a change to the '0xABCD' characteristic in the '0xBCDE' service:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.updateServices({
* 0xBCDE : {
* 0xABCD : {
* value : "World",
* indicate: true
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* });
* ```
*
2022-07-20 18:35:57 +00:00
* This only works if the characteristic was created with `indicate: true` using `NRF.setServices`,
* otherwise the characteristic will be updated but no notification will be sent.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** See `NRF.setServices` for more information
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_updateServices
*/
updateServices: (data: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Start/stop listening for BLE advertising packets within range. Returns a
* `BluetoothDevice` for each advertsing packet. **By default this is not an active scan, so
* Scan Response advertising data is not included (see below)**
2022-07-20 19:07:18 +00:00
*
* ```
* // Start scanning
* packets=10;
* NRF.setScan(function(d) {
2022-07-20 18:35:57 +00:00
* packets--;
2022-07-20 19:07:18 +00:00
* if (packets<=0)
* NRF.setScan(); // stop scanning
* else
* console.log(d); // print packet info
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* Each `BluetoothDevice` will look a bit like:
2022-07-20 19:07:18 +00:00
*
* ```
* BluetoothDevice {
* "id": "aa:bb:cc:dd:ee:ff", // address
* "rssi": -89, // signal strength
* "services": [ "128bit-uuid", ... ], // zero or more service UUIDs
* "data": new Uint8Array([ ... ]).buffer, // ArrayBuffer of returned data
* "serviceData" : { "0123" : [ 1 ] }, // if service data is in &#x27;data&#x27;, it&#x27;s extracted here
* "manufacturer" : 0x1234, // if manufacturer data is in &#x27;data&#x27;, the 16 bit manufacturer ID is extracted here
* "manufacturerData" : [...], // if manufacturer data is in &#x27;data&#x27;, the data is extracted here
* "name": "DeviceName" // the advertised device name
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* You can also supply a set of filters (as described in `NRF.requestDevice`) as a second argument, which will
* allow you to filter the devices you get a callback for. This helps
* to cut down on the time spent processing JavaScript code in areas with
* a lot of Bluetooth advertisements. For example to find only devices
* with the manufacturer data `0x0590` (Espruino's ID) you could do:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setScan(function(d) {
* console.log(d.manufacturerData);
* }, { filters: [{ manufacturerData:{0x0590:{}} }] });
* ```
*
2022-07-20 18:35:57 +00:00
* You can also specify `active:true` in the second argument to perform
* active scanning (this requests scan response packets) from any
* devices it finds.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Using a filter in `setScan` filters each advertising packet individually. As
* a result, if you filter based on a service UUID and a device advertises with multiple packets
* (or a scan response when `active:true`) only the packets matching the filter are returned. To
* aggregate multiple packets you can use `NRF.findDevices`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** BLE advertising packets can arrive quickly - faster than you'll
* be able to print them to the console. It's best only to print a few, or
* to use a function like `NRF.findDevices(..)` which will collate a list
* of available devices.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Using setScan turns the radio's receive mode on constantly. This
* can draw a *lot* of power (12mA or so), so you should use it sparingly or
* you can run your battery down quickly.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setScan
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setScan: (callback: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to quickly filter through Bluetooth devices.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For instance if you wish to scan for multiple different types of device at the same time
* then you could use `NRF.findDevices` with all the filters you're interested in. When scanning
* is finished you can then use `NRF.filterDevices` to pick out just the devices of interest.
2022-07-20 19:07:18 +00:00
*
* ```
* // the two types of device we&#x27;re interested in
* var filter1 = [{serviceData:{"fe95":{}}}];
* var filter2 = [{namePrefix:"Pixl.js"}];
* // the following filter will return both types of device
2022-07-20 18:35:57 +00:00
* var allFilters = filter1.concat(filter2);
2022-07-20 19:07:18 +00:00
* // now scan for both types of device, and filter them out afterwards
* NRF.findDevices(function(devices) {
* var devices1 = NRF.filterDevices(devices, filter1);
* var devices2 = NRF.filterDevices(devices, filter2);
* // ...
2022-07-20 18:35:57 +00:00
* }, {filters : allFilters});
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_filterDevices
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
filterDevices: (devices: any, filters: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Utility function to return a list of BLE devices detected in range. Behind the scenes,
* this uses `NRF.setScan(...)` and collates the results.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.findDevices(function(devices) {
* console.log(devices);
* }, 1000);
* ```
*
2022-07-20 18:35:57 +00:00
* prints something like:
2022-07-20 19:07:18 +00:00
*
* ```
* [
2022-07-20 18:35:57 +00:00
* BluetoothDevice {
2022-07-20 19:07:18 +00:00
* "id": "e7:e0:57:ad:36:a2 random",
* "rssi": -45,
* "services": [ "4567" ],
* "serviceData" : { "0123" : [ 1 ] },
* "manufacturerData" : [...],
* "data": new ArrayBuffer([ ... ]),
* "name": "Puck.js 36a2"
2022-07-20 18:35:57 +00:00
* },
* BluetoothDevice {
2022-07-20 19:07:18 +00:00
* "id": "c0:52:3f:50:42:c9 random",
* "rssi": -65,
* "data": new ArrayBuffer([ ... ]),
* "name": "Puck.js 8f57"
2022-07-20 18:35:57 +00:00
* }
* ]
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* For more information on the structure returned, see `NRF.setScan`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you want to scan only for specific devices you can replace the timeout with an object
* of the form `{filters: ..., timeout : ..., active: bool}` using the filters
* described in `NRF.requestDevice`. For example to search for devices with Espruino's `manufacturerData`:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.findDevices(function(devices) {
2022-07-20 18:35:57 +00:00
* ...
2022-07-20 19:07:18 +00:00
* }, {timeout : 2000, filters : [{ manufacturerData:{0x0590:{}} }] });
* ```
*
2022-07-20 18:35:57 +00:00
* You could then use [`BluetoothDevice.gatt.connect(...)`](https://espruino.com//Reference#l_BluetoothRemoteGATTServer_connect) on
* the device returned to make a connection.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can also use [`NRF.connect(...)`](https://espruino.com//Reference#l_NRF_connect) on just the `id` string returned, which
* may be useful if you always want to connect to a specific device.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Using findDevices turns the radio's receive mode on for 2000ms (or however long you specify). This
* can draw a *lot* of power (12mA or so), so you should use it sparingly or you can run your battery down quickly.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** The 'data' field contains the data of *the last packet received*. There may have been more
* packets. To get data for each packet individually use `NRF.setScan` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_findDevices
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
findDevices: (callback: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Start/stop listening for RSSI values on the currently active connection
* (where This device is a peripheral and is being connected to by a 'central' device)
2022-07-20 19:07:18 +00:00
*
* ```
* // Start scanning
* NRF.setRSSIHandler(function(rssi) {
* console.log(rssi); // prints -85 (or similar)
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* // Stop Scanning
* NRF.setRSSIHandler();
* ```
*
2022-07-20 18:35:57 +00:00
* RSSI is the 'Received Signal Strength Indication' in dBm
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setRSSIHandler
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setRSSIHandler: (callback: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the BLE radio transmit power. The default TX power is 0 dBm, and
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setTxPower
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setTxPower: (power: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **THIS IS DEPRECATED** - please use `NRF.setConnectionInterval` for
* peripheral and `NRF.connect(addr, options)`/`BluetoothRemoteGATTServer.connect(options)`
* for central connections.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This sets the connection parameters - these affect the transfer speed and
* power usage when the device is connected.
*
* - When not low power, the connection interval is between 7.5 and 20ms
* - When low power, the connection interval is between 500 and 1000ms
*
* When low power connection is enabled, transfers of data over Bluetooth
* will be very slow, however power usage while connected will be drastically
* decreased.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This will only take effect after the connection is disconnected and
* re-established.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setLowPowerConnection
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setLowPowerConnection: (lowPower: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Enables NFC and starts advertising the given URL. For example:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.nfcURL("http://espruino.com");
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcURL
*/
nfcURL: (url: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Enables NFC and with an out of band 16 byte pairing key.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example the following will enable out of band pairing on BLE
* such that the device will pair when you tap the phone against it:
2022-07-20 19:07:18 +00:00
*
* ```
* var bleKey = [0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00];
* NRF.on(&#x27;security&#x27;,s=>print("security",JSON.stringify(s)));
* NRF.nfcPair(bleKey);
* NRF.setSecurity({oob:bleKey, mitm:true});
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcPair
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
nfcPair: (key: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Enables NFC with a record that will launch the given android app.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.nfcAndroidApp("no.nordicsemi.android.nrftoolbox")
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcAndroidApp
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
nfcAndroidApp: (app: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Enables NFC and starts advertising with Raw data. For example:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.nfcRaw(new Uint8Array([193, 1, 0, 0, 0, 13, 85, 3, 101, 115, 112, 114, 117, 105, 110, 111, 46, 99, 111, 109]));
* // same as NRF.nfcURL("http://espruino.com");
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcRaw
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
nfcRaw: (payload: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Advanced NFC Functionality.** If you just want to advertise a URL, use `NRF.nfcURL` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Enables NFC and starts advertising. `NFCrx` events will be
* fired when data is received.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.nfcStart();
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcStart
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
nfcStart: (payload: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Advanced NFC Functionality.** If you just want to advertise a URL, use `NRF.nfcURL` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Disables NFC.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.nfcStop();
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcStop
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
nfcStop: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Advanced NFC Functionality.** If you just want to advertise a URL, use `NRF.nfcURL` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Acknowledges the last frame and optionally transmits a response.
* If payload is an array, then a array.length byte nfc frame is sent.
* If payload is a int, then a 4bit ACK/NACK is sent.
* **Note:** `nfcSend` should always be called after an `NFCrx` event.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.nfcSend(new Uint8Array([0x01, 0x02, ...]));
* // or
* NRF.nfcSend(0x0A);
* // or
* NRF.nfcSend();
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_nfcSend
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
nfcSend: (payload: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send a USB HID report. HID must first be enabled with `NRF.setServices({}, {hid: hid_report})`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_sendHIDReport
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
sendHIDReport: (data: any, callback: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Check if Apple Notification Center Service (ANCS) is currently active on the BLE connection
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_ancsIsActive
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
ancsIsActive: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send an ANCS action for a specific Notification UID. Corresponds to posaction/negaction in the 'ANCS' event that was received
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_ancsAction
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
ancsAction: (uid: number, positive: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get ANCS info for a notification, eg:
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_ancsGetNotificationInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
ancsGetNotificationInfo: (uid: number) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get ANCS info for an app (add id is available via `ancsGetNotificationInfo`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Promise returns:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* "uid" : int,
* "appId" : string,
* "title" : string,
* "subtitle" : string,
* "message" : string,
* "messageSize" : string,
* "date" : string,
* "posAction" : string,
* "negAction" : string,
* "name" : string,
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_ancsGetAppInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
ancsGetAppInfo: (id: any) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Check if Apple Media Service (AMS) is currently active on the BLE connection
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_amsIsActive
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
amsIsActive: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get Apple Media Service (AMS) info for the current media player.
* "playbackinfo" returns a concatenation of three comma-separated values:
*
* - PlaybackState: a string that represents the integer value of the playback state:
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* - PlaybackStatePaused = 0
* - PlaybackStatePlaying = 1
* - PlaybackStateRewinding = 2
* - PlaybackStateFastForwarding = 3
*
* - PlaybackRate: a string that represents the floating point value of the playback rate.
* - ElapsedTime: a string that represents the floating point value of the elapsed time of the current track, in seconds
*
* @url http://www.espruino.com/Reference#l_NRF_amsGetPlayerInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
amsGetPlayerInfo: (id: any) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get Apple Media Service (AMS) info for the currently-playing track
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_amsGetTrackInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
amsGetTrackInfo: (id: any) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send an AMS command to an Apple Media Service device to control music playback
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Command is one of play, pause, playpause, next, prev, volup, voldown, repeat, shuffle, skipforward, skipback, like, dislike, bookmark
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_amsCommand
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
amsCommand: (id: any) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Search for available devices matching the given filters. Since we have no UI here,
* Espruino will pick the FIRST device it finds, or it'll call `catch`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* `options` can have the following fields:
*
* - `filters` - a list of filters that a device must match before it is returned (see below)
* - `timeout` - the maximum time to scan for in milliseconds (scanning stops when a match
* is found. eg. `NRF.requestDevice({ timeout:2000, filters: [ ... ] })`
* - `active` - whether to perform active scanning (requesting 'scan response' packets from any
* devices that are found). eg. `NRF.requestDevice({ active:true, filters: [ ... ] })`
* - `phy` - (NRF52840 only) use the long-range coded phy (`"1mbps"` default, can be `"1mbps/2mbps/both/coded"`)
* - `extended` - (NRF52840 only) support receiving extended-length advertising packets (default=true if phy isn't `"1mbps"`)
*
* **NOTE:** `timeout` and `active` are not part of the Web Bluetooth standard.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The following filter types are implemented:
*
* - `services` - list of services as strings (all of which must match). 128 bit services must be in the form '01230123-0123-0123-0123-012301230123'
* - `name` - exact device name
* - `namePrefix` - starting characters of device name
* - `id` - exact device address (`id:"e9:53:86:09:89:99 random"`) (this is Espruino-specific, and is not part of the Web Bluetooth spec)
* - `serviceData` - an object containing service characteristics which must all match (`serviceData:{"1809":{}}`). Matching of actual service data is not supported yet.
* - `manufacturerData` - an object containing manufacturer UUIDs which must all match (`manufacturerData:{0x0590:{}}`). Matching of actual manufacturer data is not supported yet.
*
2022-07-20 19:07:18 +00:00
* ```
* NRF.requestDevice({ filters: [{ namePrefix: &#x27;Puck.js&#x27; }] }).then(function(device) { ... });
* // or
* NRF.requestDevice({ filters: [{ services: [&#x27;1823&#x27;] }] }).then(function(device) { ... });
* // or
* NRF.requestDevice({ filters: [{ manufacturerData:{0x0590:{}} }] }).then(function(device) { ... });
* ```
*
2022-07-20 18:35:57 +00:00
* As a full example, to send data to another Puck.js to turn an LED on:
2022-07-20 19:07:18 +00:00
*
* ```
* var gatt;
* NRF.requestDevice({ filters: [{ namePrefix: &#x27;Puck.js&#x27; }] }).then(function(device) {
* return device.gatt.connect();
* }).then(function(g) {
2022-07-20 18:35:57 +00:00
* gatt = g;
2022-07-20 19:07:18 +00:00
* return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
* }).then(function(service) {
* return service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
* }).then(function(characteristic) {
* return characteristic.writeValue("LED1.set()\n");
* }).then(function() {
2022-07-20 18:35:57 +00:00
* gatt.disconnect();
2022-07-20 19:07:18 +00:00
* console.log("Done!");
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* Or slightly more concisely, using ES6 arrow functions:
2022-07-20 19:07:18 +00:00
*
* ```
* var gatt;
* NRF.requestDevice({ filters: [{ namePrefix: &#x27;Puck.js&#x27; }]}).then(
* device => device.gatt.connect()).then(
* g => (gatt=g).getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e")).then(
* service => service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e")).then(
* characteristic => characteristic.writeValue("LED1.reset()\n")).then(
* () => { gatt.disconnect(); console.log("Done!"); } );
* ```
*
2022-07-20 18:35:57 +00:00
* Note that you have to keep track of the `gatt` variable so that you can
* disconnect the Bluetooth connection when you're done.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** Using a filter in `NRF.requestDevice` filters each advertising packet individually. As
* soon as a matching advertisement is received, `NRF.requestDevice` resolves the promise and stops
* scanning. This means that if you filter based on a service UUID and a device advertises with multiple packets
* (or a scan response when `active:true`) only the packet matching the filter is returned - you may not
* get the device's name is that was in a separate packet. To aggregate multiple packets you can use `NRF.findDevices`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_requestDevice
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
requestDevice: (options: any) => Promise<any>;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Connect to a BLE device by MAC address. Returns a promise,
* the argument of which is the `BluetoothRemoteGATTServer` connection.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.connect("aa:bb:cc:dd:ee").then(function(server) {
* // ...
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* This has the same effect as calling `BluetoothDevice.gatt.connect` on a `BluetoothDevice` requested
* using `NRF.requestDevice`. It just allows you to specify the address directly (without having to scan).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can use it as follows - this would connect to another Puck device and turn its LED on:
2022-07-20 19:07:18 +00:00
*
* ```
* var gatt;
* NRF.connect("aa:bb:cc:dd:ee random").then(function(g) {
2022-07-20 18:35:57 +00:00
* gatt = g;
2022-07-20 19:07:18 +00:00
* return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
* }).then(function(service) {
* return service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
* }).then(function(characteristic) {
* return characteristic.writeValue("LED1.set()\n");
* }).then(function() {
2022-07-20 18:35:57 +00:00
* gatt.disconnect();
2022-07-20 19:07:18 +00:00
* console.log("Done!");
2022-07-20 15:57:03 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** Espruino Bluetooth devices use a type of BLE address known as 'random static',
* which is different to a 'public' address. To connect to an Espruino device you'll need
* to use an address string of the form `"aa:bb:cc:dd:ee random"` rather than just
* `"aa:bb:cc:dd:ee"`. If you scan for devices with `NRF.findDevices`/`NRF.setScan` then
* addresses are already reported in the correct format.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_connect
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
connect: (mac: any, options: any) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* If set to true, whenever a device bonds it will be added to the
* whitelist.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When set to false, the whitelist is cleared and newly bonded
* devices will not be added to the whitelist.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This is remembered between `reset()`s but isn't
* remembered after power-on (you'll have to add it to `onInit()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setWhitelist
*/
setWhitelist: (whitelisting: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* When connected, Bluetooth LE devices communicate at a set interval.
* Lowering the interval (eg. more packets/second) means a lower delay when
* sending data, higher bandwidth, but also more power consumption.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* By default, when connected as a peripheral Espruino automatically adjusts the
* connection interval. When connected it's as fast as possible (7.5ms) but when idle
* for over a minute it drops to 200ms. On continued activity (>1 BLE operation) the
* interval is raised to 7.5ms again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The options for `interval` are:
*
* - `undefined` / `"auto"` : (default) automatically adjust connection interval
* - `100` : set min and max connection interval to the same number (between 7.5ms and 4000ms)
* - `{minInterval:20, maxInterval:100}` : set min and max connection interval as a range
*
* This configuration is not remembered during a `save()` - you will have to
* re-set it via `onInit`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** If connecting to another device (as Central), you can use
* an extra argument to `NRF.connect` or `BluetoothRemoteGATTServer.connect`
* to specify a connection interval.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This overwrites any changes imposed by the deprecated `NRF.setLowPowerConnection`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setConnectionInterval
*/
setConnectionInterval: (interval: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sets the security options used when connecting/pairing. This applies to both central
* *and* peripheral mode.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setSecurity({
* display : bool // default false, can this device display a passkey
2022-07-20 18:35:57 +00:00
* // - sent via the `BluetoothDevice.passkey` event
2022-07-20 19:07:18 +00:00
* keyboard : bool // default false, can this device enter a passkey
2022-07-20 18:35:57 +00:00
* // - request sent via the `BluetoothDevice.passkeyRequest` event
2022-07-20 19:07:18 +00:00
* bond : bool // default true, Perform bonding
* mitm : bool // default false, Man In The Middle protection
* lesc : bool // default false, LE Secure Connections
* passkey : // default "", or a 6 digit passkey to use
* oob : [0..15] // if specified, Out Of Band pairing is enabled and
* // the 16 byte pairing code supplied here is used
* encryptUart : bool // default false (unless oob or passkey specified)
2022-07-20 18:35:57 +00:00
* // This sets the BLE UART service such that it
2022-07-20 19:07:18 +00:00
* // is encrypted and can only be used from a bonded connection
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* **NOTE:** Some combinations of arguments will cause an error. For example
* supplying a passkey without `display:1` is not allowed. If `display:1` is set
* you do not require a physical display, the user just needs to know
* the passkey you supplied.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For instance, to require pairing and to specify a passkey, use:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setSecurity({passkey:"123456", mitm:1, display:1});
* ```
*
2022-07-20 18:35:57 +00:00
* However, while most devices will request a passkey for pairing at
* this point it is still possible for a device to connect without
* requiring one (eg. using the 'NRF Connect' app).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To force a passkey you need to protect each characteristic
* you define with `NRF.setSecurity`. For instance the following
* code will *require* that the passkey `123456` is entered
* before the characteristic `9d020002-bf5f-1d1a-b52a-fe52091d5b12`
* can be read.
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.setSecurity({passkey:"123456", mitm:1, display:1});
2022-07-20 18:35:57 +00:00
* NRF.setServices({
* "9d020001-bf5f-1d1a-b52a-fe52091d5b12" : {
* "9d020002-bf5f-1d1a-b52a-fe52091d5b12" : {
2022-07-20 19:07:18 +00:00
* // readable always
* value : "Not Secret"
2022-07-20 18:35:57 +00:00
* },
* "9d020003-bf5f-1d1a-b52a-fe52091d5b12" : {
2022-07-20 19:07:18 +00:00
* // readable only once bonded
* value : "Secret",
* readable : true,
* security: {
* read: {
* mitm: true,
* encrypted: true
2022-07-20 18:35:57 +00:00
* }
* }
* },
* "9d020004-bf5f-1d1a-b52a-fe52091d5b12" : {
2022-07-20 19:07:18 +00:00
* // readable always
* // writable only once bonded
* value : "Readable",
* readable : true,
* writable : true,
* onWrite : function(evt) {
2022-07-20 18:35:57 +00:00
* console.log("Wrote ", evt.data);
* },
2022-07-20 19:07:18 +00:00
* security: {
* write: {
* mitm: true,
* encrypted: true
2022-07-20 18:35:57 +00:00
* }
* }
* }
* }
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** If `passkey` or `oob` is specified, the Nordic UART service (if enabled)
* will automatically be set to require encryption, but otherwise it is open.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_setSecurity
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setSecurity: (options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NRF_startBonding
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
startBonding: (forceRepair: boolean) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The Bluetooth Serial port - used when data is sent or received over Bluetooth Smart on nRF51/nRF52 chips.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_Bluetooth
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Bluetooth: Serial & {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bluetooth_setConsole
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setConsole: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* A Web Bluetooth-style device - you can request one using `NRF.requestDevice(address)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example:
2022-07-20 19:07:18 +00:00
*
* ```
* var gatt;
* NRF.requestDevice({ filters: [{ name: &#x27;Puck.js abcd&#x27; }] }).then(function(device) {
* console.log("found device");
* return device.gatt.connect();
* }).then(function(g) {
2022-07-20 18:35:57 +00:00
* gatt = g;
2022-07-20 19:07:18 +00:00
* console.log("connected");
* return gatt.startBonding();
* }).then(function() {
* console.log("bonded", gatt.getSecurityStatus());
2022-07-20 18:35:57 +00:00
* gatt.disconnect();
2022-07-20 19:07:18 +00:00
* }).catch(function(e) {
* console.log("ERROR",e);
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#BluetoothDevice
*/
declare function BluetoothDevice(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type BluetoothDevice = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothDevice_gatt
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
gatt: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothDevice_rssi
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
rssi: boolean
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* To be used as a response when the event `BluetoothDevice.sendPasskey` has been received.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **This is not part of the Web Bluetooth Specification.** It has been added
* specifically for Espruino.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothDevice_sendPasskey
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
sendPasskey: (passkey: any) => void;
2022-07-20 13:07:21 +00:00
}
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Web Bluetooth-style GATT server - get this using `NRF.connect(address)`
* or `NRF.requestDevice(options)` and `response.gatt.connect`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* [https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver](https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#BluetoothRemoteGATTServer
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function BluetoothRemoteGATTServer(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type BluetoothRemoteGATTServer = {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Connect to a BLE device - returns a promise,
* the argument of which is the `BluetoothRemoteGATTServer` connection.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See [`NRF.requestDevice`](https://espruino.com//Reference#l_NRF_requestDevice) for usage examples.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* `options` is an optional object containing:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* minInterval // min connection interval in milliseconds, 7.5 ms to 4 s
* maxInterval // max connection interval in milliseconds, 7.5 ms to 4 s
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* By default the interval is 20-200ms (or 500-1000ms if `NRF.setLowPowerConnection(true)` was called.
* During connection Espruino negotiates with the other device to find a common interval that can be
* used.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For instance calling:
2022-07-20 19:07:18 +00:00
*
* ```
* NRF.requestDevice({ filters: [{ namePrefix: &#x27;Pixl.js&#x27; }] }).then(function(device) {
* return device.gatt.connect({minInterval:7.5, maxInterval:7.5});
* }).then(function(g) {
* ```
*
2022-07-20 18:35:57 +00:00
* will force the connection to use the fastest connection interval possible (as long as the device
* at the other end supports it).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** The Web Bluetooth spec states that if a device hasn't advertised its name, when connected
* to a device the central (in this case Espruino) should automatically retrieve the name from the
* corresponding characteristic (`0x2a00` on service `0x1800`). Espruino does not automatically do this.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_connect
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
connect: (options: any) => Promise<any>;
2022-07-20 15:57:03 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_connected
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
connected: boolean
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_handle
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
handle: number
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Disconnect from a previously connected BLE device connected with
* `BluetoothRemoteGATTServer.connect` - this does not disconnect from something that has
* connected to the Espruino.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** While `.disconnect` is standard Web Bluetooth, in the spec it
* returns undefined not a `Promise` for implementation reasons. In Espruino
* we return a `Promise` to make it easier to detect when Espruino is free
* to connect to something else.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_disconnect
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
disconnect: () => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Start negotiating bonding (secure communications) with the connected device,
* and return a Promise that is completed on success or failure.
2022-07-20 19:07:18 +00:00
*
* ```
* var gatt;
* NRF.requestDevice({ filters: [{ name: &#x27;Puck.js abcd&#x27; }] }).then(function(device) {
* console.log("found device");
* return device.gatt.connect();
* }).then(function(g) {
2022-07-20 18:35:57 +00:00
* gatt = g;
2022-07-20 19:07:18 +00:00
* console.log("connected");
* return gatt.startBonding();
* }).then(function() {
* console.log("bonded", gatt.getSecurityStatus());
2022-07-20 18:35:57 +00:00
* gatt.disconnect();
2022-07-20 19:07:18 +00:00
* }).catch(function(e) {
* console.log("ERROR",e);
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* **This is not part of the Web Bluetooth Specification.** It has been added
* specifically for Espruino.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_startBonding
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
startBonding: (forceRePair: boolean) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Return an object with information about the security
* state of the current connection:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* connected // The connection is active (not disconnected).
* encrypted // Communication on this link is encrypted.
* mitm_protected // The encrypted communication is also protected against man-in-the-middle attacks.
* bonded // The peer is bonded with us
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* See `BluetoothRemoteGATTServer.startBonding` for information about
* negotiating a secure connection.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **This is not part of the Web Bluetooth Specification.** It has been added
* specifically for Puck.js.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getSecurityStatus
*/
getSecurityStatus: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* See `NRF.connect` for usage examples.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getPrimaryService
*/
getPrimaryService: (service: any) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getPrimaryServices
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getPrimaryServices: () => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Start/stop listening for RSSI values on the active GATT connection
2022-07-20 19:07:18 +00:00
*
* ```
* // Start listening for RSSI value updates
* gattServer.setRSSIHandler(function(rssi) {
* console.log(rssi); // prints -85 (or similar)
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* // Stop listening
2022-07-20 18:35:57 +00:00
* gattServer.setRSSIHandler();
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* RSSI is the 'Received Signal Strength Indication' in dBm
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_setRSSIHandler
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setRSSIHandler: (callback: any) => void;
2022-07-20 13:07:21 +00:00
}
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Web Bluetooth-style GATT service - get this using `BluetoothRemoteGATTServer.getPrimaryService(s)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* [https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice](https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#BluetoothRemoteGATTService
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function BluetoothRemoteGATTService(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type BluetoothRemoteGATTService = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTService_device
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
device: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* See `NRF.connect` for usage examples.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTService_getCharacteristic
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getCharacteristic: (characteristic: any) => Promise<any>;
/**
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTService_getCharacteristics
*/
getCharacteristics: () => Promise<any>;
}
/**
* Web Bluetooth-style GATT characteristic - get this using `BluetoothRemoteGATTService.getCharacteristic(s)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* [https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic](https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#BluetoothRemoteGATTCharacteristic
*/
declare function BluetoothRemoteGATTCharacteristic(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type BluetoothRemoteGATTCharacteristic = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_service
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
service: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Write a characteristic's value
2022-07-20 19:07:18 +00:00
*
* ```
* var device;
* NRF.connect(device_address).then(function(d) {
2022-07-20 18:35:57 +00:00
* device = d;
2022-07-20 19:07:18 +00:00
* return d.getPrimaryService("service_uuid");
* }).then(function(s) {
* console.log("Service ",s);
* return s.getCharacteristic("characteristic_uuid");
* }).then(function(c) {
* return c.writeValue("Hello");
* }).then(function(d) {
2022-07-20 18:35:57 +00:00
* device.disconnect();
2022-07-20 19:07:18 +00:00
* }).catch(function() {
* console.log("Something&#x27;s broken.");
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_writeValue
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
writeValue: (data: any) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Read a characteristic's value, return a promise containing a `DataView`
2022-07-20 19:07:18 +00:00
*
* ```
* var device;
* NRF.connect(device_address).then(function(d) {
2022-07-20 18:35:57 +00:00
* device = d;
2022-07-20 19:07:18 +00:00
* return d.getPrimaryService("service_uuid");
* }).then(function(s) {
* console.log("Service ",s);
* return s.getCharacteristic("characteristic_uuid");
* }).then(function(c) {
* return c.readValue();
* }).then(function(d) {
* console.log("Got:", JSON.stringify(d.buffer));
2022-07-20 18:35:57 +00:00
* device.disconnect();
2022-07-20 19:07:18 +00:00
* }).catch(function() {
* console.log("Something&#x27;s broken.");
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_readValue
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
readValue: () => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Starts notifications - whenever this characteristic's value changes, a `characteristicvaluechanged` event is fired
* and `characteristic.value` will then contain the new value as a `DataView`.
2022-07-20 19:07:18 +00:00
*
* ```
* var device;
* NRF.connect(device_address).then(function(d) {
2022-07-20 18:35:57 +00:00
* device = d;
2022-07-20 19:07:18 +00:00
* return d.getPrimaryService("service_uuid");
* }).then(function(s) {
* console.log("Service ",s);
* return s.getCharacteristic("characteristic_uuid");
* }).then(function(c) {
* c.on(&#x27;characteristicvaluechanged&#x27;, function(event) {
* console.log("-> ",event.target.value); // this is a DataView
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* return c.startNotifications();
* }).then(function(d) {
* console.log("Waiting for notifications");
* }).catch(function() {
* console.log("Something&#x27;s broken.");
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* For example, to listen to the output of another Puck.js's Nordic
* Serial port service, you can use:
2022-07-20 19:07:18 +00:00
*
* ```
* var gatt;
* NRF.connect("pu:ck:js:ad:dr:es random").then(function(g) {
2022-07-20 18:35:57 +00:00
* gatt = g;
2022-07-20 19:07:18 +00:00
* return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
* }).then(function(service) {
* return service.getCharacteristic("6e400003-b5a3-f393-e0a9-e50e24dcca9e");
* }).then(function(characteristic) {
* characteristic.on(&#x27;characteristicvaluechanged&#x27;, function(event) {
* console.log("RX: "+JSON.stringify(event.target.value.buffer));
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* return characteristic.startNotifications();
* }).then(function() {
* console.log("Done!");
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_startNotifications
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
startNotifications: () => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Stop notifications (that were requested with `BluetoothRemoteGATTCharacteristic.startNotifications`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_stopNotifications
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
stopNotifications: () => Promise<any>;
2022-07-20 13:07:21 +00:00
}
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Class containing utility functions for the [Bangle.js Smart Watch](http://www.espruino.com/Bangle.js)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Bangle
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Bangle: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to turn Bangle.js's LCD off or on.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This function resets the Bangle's 'activity timer' (like
* pressing a button or the screen would) so after a time period
* of inactivity set by `Bangle.setLCDTimeout` the screen will
* turn off.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you want to keep the screen on permanently (until apps
* are changed) you can do:
2022-07-20 19:07:18 +00:00
*
* ```
* Bangle.setLCDTimeout(0); // turn off the timeout
* Bangle.setLCDPower(1); // keep screen on
* ```
*
2022-07-20 18:35:57 +00:00
* **When on full, the LCD draws roughly 40mA.** You can adjust
* When brightness using `Bange.setLCDBrightness`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setLCDPower
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setLCDPower: (isOn: boolean) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to adjust the brightness of Bangle.js's display, and
* hence prolong its battery life.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Due to hardware design constraints, software PWM has to be used which
* means that the display may flicker slightly when Bluetooth is active
* and the display is not at full power.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Power consumption**
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* - 0 = 7mA
* - 0.1 = 12mA
* - 0.2 = 18mA
* - 0.5 = 28mA
* - 0.9 = 40mA (switching overhead)
* - 1 = 40mA
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setLCDBrightness
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setLCDBrightness: (brightness: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to change the way graphics is handled on Bangle.js.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Available options for `Bangle.setLCDMode` are:
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* - `Bangle.setLCDMode()` or `Bangle.setLCDMode("direct")` (the default) - The drawable area is 240x240 16 bit. Unbuffered, so draw calls take effect immediately. Terminal and vertical scrolling work (horizontal scrolling doesn't).
* - `Bangle.setLCDMode("doublebuffered")` - The drawable area is 240x160 16 bit, terminal and scrolling will not work. `g.flip()` must be called for draw operations to take effect.
* - `Bangle.setLCDMode("120x120")` - The drawable area is 120x120 8 bit, `g.getPixel`, terminal, and full scrolling work. Uses an offscreen buffer stored on Bangle.js, `g.flip()` must be called for draw operations to take effect.
* - `Bangle.setLCDMode("80x80")` - The drawable area is 80x80 8 bit, `g.getPixel`, terminal, and full scrolling work. Uses an offscreen buffer stored on Bangle.js, `g.flip()` must be called for draw operations to take effect.
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* You can also call `Bangle.setLCDMode()` to return to normal, unbuffered `"direct"` mode.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setLCDMode
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setLCDMode: (mode: any) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* The current LCD mode.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* See `Bangle.setLCDMode` for examples.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_getLCDMode
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getLCDMode: () => any;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This can be used to move the displayed memory area up or down temporarily. It's
* used for displaying notifications while keeping the main display contents
* intact.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setLCDOffset
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setLCDOffset: (y: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to turn Bangle.js's LCD power saving on or off.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* With power saving off, the display will remain in the state you set it with `Bangle.setLCDPower`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* With power saving on, the display will turn on if a button is pressed, the watch is turned face up, or the screen is updated (see `Bangle.setOptions` for configuration). It'll turn off automatically after the given timeout.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This function also sets the Backlight and Lock timeout (the time at which the touchscreen/buttons start being ignored). To set both separately, use `Bangle.setOptions`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setLCDTimeout
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setLCDTimeout: (isOn: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set how often the watch should poll for new acceleration/gyro data and kick the Watchdog timer. It isn't
* recommended that you make this interval much larger than 1000ms, but values up to 4000ms are allowed.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Calling this will set `Bangle.setOptions({powerSave: false})` - disabling the dynamic adjustment of
* poll interval to save battery power when Bangle.js is stationary.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setPollInterval
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setPollInterval: (interval: number) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set internal options used for gestures, etc...
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* - `wakeOnBTN1` should the LCD turn on when BTN1 is pressed? default = `true`
* - `wakeOnBTN2` (Bangle.js 1) should the LCD turn on when BTN2 is pressed? default = `true`
* - `wakeOnBTN3` (Bangle.js 1) should the LCD turn on when BTN3 is pressed? default = `true`
* - `wakeOnFaceUp` should the LCD turn on when the watch is turned face up? default = `false`
* - `wakeOnTouch` should the LCD turn on when the touchscreen is pressed? default = `false`
* - `wakeOnTwist` should the LCD turn on when the watch is twisted? default = `true`
* - `twistThreshold` How much acceleration to register a twist of the watch strap? Can be negative for oppsite direction. default = `800`
* - `twistMaxY` Maximum acceleration in Y to trigger a twist (low Y means watch is facing the right way up). default = `-800`
* - `twistTimeout` How little time (in ms) must a twist take from low->high acceleration? default = `1000`
* - `gestureStartThresh` how big a difference before we consider a gesture started? default = `sqr(800)`
* - `gestureEndThresh` how small a difference before we consider a gesture ended? default = `sqr(2000)`
* - `gestureInactiveCount` how many samples do we keep after a gesture has ended? default = `4`
* - `gestureMinLength` how many samples must a gesture have before we notify about it? default = `10`
* - `powerSave` after a minute of not being moved, Bangle.js will change the accelerometer poll interval down to 800ms (10x accelerometer samples).
* On movement it'll be raised to the default 80ms. If `Bangle.setPollInterval` is used this is disabled, and for it to work the poll interval
* must be either 80ms or 800ms. default = `true`. Setting `powerSave:false` will disable this automatic power saving, but will **not** change
* the poll interval from its current value. If you desire a specific interval (eg the default 80ms) you must set it manually with `Bangle.setPollInterval(80)`
* after setting `powerSave:false`.
* - `lockTimeout` how many milliseconds before the screen locks
* - `lcdPowerTimeout` how many milliseconds before the screen turns off
* - `backlightTimeout` how many milliseconds before the screen's backlight turns off
* - `hrmPollInterval` set the requested poll interval (in milliseconds) for the heart rate monitor. On Bangle.js 2 only 10,20,40,80,160,200 ms are supported, and polling rate may not be exact. The algorithm's filtering is tuned for 20-40ms poll intervals, so higher/lower intervals may effect the reliability of the BPM reading.
* - `seaLevelPressure` (Bangle.js 2) Normally 1013.25 millibars - this is used for calculating altitude with the pressure sensor
2022-07-20 15:57:03 +00:00
*
2022-07-20 18:35:57 +00:00
* Where accelerations are used they are in internal units, where `8192 = 1g`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setOptions
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setOptions: (options: any) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return the current state of options as set by `Bangle.setOptions`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_getOptions
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getOptions: () => any;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Also see the `Bangle.lcdPower` event
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isLCDOn
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
isLCDOn: () => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* This function can be used to lock or unlock Bangle.js
* (eg whether buttons and touchscreen work or not)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setLocked
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setLocked: (isLocked: boolean) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Also see the `Bangle.lock` event
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isLocked
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
isLocked: () => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isCharging
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
isCharging: () => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a command directly to the ST7735 LCD controller
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_lcdWr
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
lcdWr: (cmd: number, data: any) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the power to the Heart rate monitor
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When on, data is output via the `HRM` event on `Bangle`:
2022-07-20 19:07:18 +00:00
*
* ```
* Bangle.setHRMPower(true, "myapp");
* Bangle.on(&#x27;HRM&#x27;,print);
* ```
*
2022-07-20 18:35:57 +00:00
* *When on, the Heart rate monitor draws roughly 5mA*
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setHRMPower
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setHRMPower: (isOn: boolean, appID: any) => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Is the Heart rate monitor powered?
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Set power with `Bangle.setHRMPower(...);`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isHRMOn
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
isHRMOn: () => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the power to the GPS.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When on, data is output via the `GPS` event on `Bangle`:
2022-07-20 19:07:18 +00:00
*
* ```
* Bangle.setGPSPower(true, "myapp");
* Bangle.on(&#x27;GPS&#x27;,print);
* ```
*
2022-07-20 18:35:57 +00:00
* *When on, the GPS draws roughly 20mA*
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setGPSPower
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
setGPSPower: (isOn: boolean, appID: any) => boolean;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Is the GPS powered?
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Set power with `Bangle.setGPSPower(...);`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isGPSOn
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
isGPSOn: () => boolean;
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
/**
* Get the last available GPS fix info (or `undefined` if GPS is off).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The fix info received is the same as you'd get from the `Bangle.GPS` event.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_getGPSFix
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getGPSFix: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the power to the Compass
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When on, data is output via the `mag` event on `Bangle`:
2022-07-20 19:07:18 +00:00
*
* ```
* Bangle.setCompassPower(true, "myapp");
* Bangle.on(&#x27;mag&#x27;,print);
* ```
*
2022-07-20 18:35:57 +00:00
* *When on, the compass draws roughly 2mA*
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setCompassPower
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setCompassPower: (isOn: boolean, appID: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Is the compass powered?
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Set power with `Bangle.setCompassPower(...);`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isCompassOn
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
isCompassOn: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Resets the compass minimum/maximum values. Can be used if the compass isn't
* providing a reliable heading any more.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_resetCompass
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
resetCompass: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the power to the barometer IC. Once enbled, `Bangle.pressure` events
* are fired each time a new barometer reading is available.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When on, the barometer draws roughly 50uA
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setBarometerPower
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setBarometerPower: (isOn: boolean, appID: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Is the Barometer powered?
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Set power with `Bangle.setBarometerPower(...);`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_isBarometerOn
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
isBarometerOn: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns the current amount of steps recorded by the step counter
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_getStepCount
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getStepCount: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sets the current value of the step counter
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setStepCount
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setStepCount: (count: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the most recent Magnetometer/Compass reading. Data is in the same format as the `Bangle.on('mag',` event.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Returns an `{x,y,z,dx,dy,dz,heading}` object
*
* - `x/y/z` raw x,y,z magnetometer readings
* - `dx/dy/dz` readings based on calibration since magnetometer turned on
* - `heading` in degrees based on calibrated readings (will be NaN if magnetometer hasn't been rotated around 360 degrees)
*
* To get this event you must turn the compass on
* with `Bangle.setCompassPower(1)`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_getCompass
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getCompass: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get the most recent accelerometer reading. Data is in the same format as the `Bangle.on('accel',` event.
*
* - `x` is X axis (left-right) in `g`
* - `y` is Y axis (up-down) in `g`
* - `z` is Z axis (in-out) in `g`
* - `diff` is difference between this and the last reading in `g` (calculated by comparing vectors, not magnitudes)
* - `td` is the elapsed
* - `mag` is the magnitude of the acceleration in `g`
*
* @url http://www.espruino.com/Reference#l_Bangle_getAccel
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getAccel: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* `range` is one of:
*
* - `undefined` or `'current'` - health data so far in the last 10 minutes is returned,
* - `'last'` - health data during the last 10 minutes
* - `'day'` - the health data so far for the day
*
* `getHealthStatus` returns an object containing:
*
* - `movement` is the 32 bit sum of all `acc.diff` readings since power on (and rolls over). It is the difference in accelerometer values as `g*8192`
* - `steps` is the number of steps during this period
* - `bpm` the best BPM reading from HRM sensor during this period
* - `bpmConfidence` best BPM confidence (0-100%) during this period
*
* @url http://www.espruino.com/Reference#l_Bangle_getHealthStatus
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getHealthStatus: (range: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Feature flag - If true, this Bangle.js firmware reads `setting.json` and
* modifies beep & buzz behaviour accordingly (the bootloader
* doesn't need to do it).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_F_BEEPSET
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
F_BEEPSET: boolean
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Reads debug info
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_dbg
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
dbg: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a register on the accelerometer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_accelWr
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
accelWr: (reg: number, data: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Reads a register from the accelerometer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** On Espruino 2v06 and before this function only returns a number (`cnt` is ignored).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_accelRd
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
accelRd: (reg: number, cnt: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a register on the barometer IC
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_barometerWr
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
barometerWr: (reg: number, data: number) => void;
2022-07-20 15:57:03 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Reads a register from the barometer IC
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_barometerRd
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
barometerRd: (reg: number, cnt: number) => any;
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a register on the Magnetometer/Compass
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_compassWr
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
compassWr: (reg: number, data: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Read a register on the Magnetometer/Compass
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_compassRd
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
compassRd: (reg: number, cnt: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes a register on the Heart rate monitor
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_hrmWr
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
hrmWr: (reg: number, data: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Read a register on the Heart rate monitor
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_hrmRd
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
hrmRd: (reg: number, cnt: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Changes a pin state on the IO expander
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_ioWr
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
ioWr: (mask: number, isOn: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Read temperature, pressure and altitude data. A promise is returned
* which will be resolved with `{temperature, pressure, altitude}`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If the Barometer has been turned on with `Bangle.setBarometerPower` then this will
* return almost immediately with the reading. If the Barometer is off, conversions take
* between 500-750ms.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Altitude assumes a sea-level pressure of 1013.25 hPa
2022-07-20 19:07:18 +00:00
*
* ```
* Bangle.getPressure().then(d=>{
* console.log(d);
* // {temperature, pressure, altitude}
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_getPressure
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
getPressure: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Perform a Spherical [Web Mercator projection](https://en.wikipedia.org/wiki/Web_Mercator_projection)
* of latitude and longitude into `x` and `y` coordinates, which are roughly
* equivalent to meters from `{lat:0,lon:0}`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This is the formula used for most online mapping and is a good way
* to compare GPS coordinates to work out the distance between them.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_project
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
project: (latlong: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Use the piezo speaker to Beep for a certain time period and frequency
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_beep
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
beep: (time: number, freq: number) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Use the vibration motor to buzz for a certain time period
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_buzz
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
buzz: (time: number, strength: number) => Promise<any>;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn Bangle.js off. It can only be woken by pressing BTN1.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_off
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
off: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Turn Bangle.js (mostly) off, but keep the CPU in sleep
* mode until BTN1 is pressed to preserve the RTC (current time).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_softOff
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
softOff: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
*
* - On platforms with an LCD of >=8bpp this is 222 x 104 x 2 bits
* - Otherwise it's 119 x 56 x 1 bits
*
* @url http://www.espruino.com/Reference#l_Bangle_getLogo
*/
getLogo: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Load all widgets from flash Storage. Call this once at the beginning
* of your application if you want any on-screen widgets to be loaded.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* They will be loaded into a global `WIDGETS` array, and
* can be rendered with `Bangle.drawWidgets`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_loadWidgets
*/
loadWidgets: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_drawWidgets
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
drawWidgets: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Load the Bangle.js app launcher, which will allow the user
* to select an application to launch.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_showLauncher
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
showLauncher: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_setUI
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setUI: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Erase all storage and reload it with the default
* contents.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This is only available on Bangle.js 2.0. On Bangle.js 1.0
* you need to use `Install Default Apps` under the `More...` tab
* of [http://banglejs.com/apps](http://banglejs.com/apps)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_factoryReset
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
factoryReset: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns the rectangle on the screen that is currently
* reserved for the app.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Bangle_appRect
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
appRect: any
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This library allows you to write to Neopixel/WS281x/APA10x/SK6812 LED strips
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* These use a high speed single-wire protocol which needs platform-specific
* implementation on some devices - hence this library to simplify things.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_neopixel_undefined
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
/**
* Create a software OneWire implementation on the given pin
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_OneWire
*/
declare function OneWire(pin: Pin): any;
type OneWire = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Perform a reset cycle
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_reset
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reset: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Select a ROM - always performs a reset first
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_select
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
select: (rom: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Skip a ROM
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_skip
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
skip: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Write one or more bytes
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_write
*/
write: (data: any, power: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Read a byte
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_read
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
read: (count: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Search for devices
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_OneWire_search
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
search: (command: number) => any;
}
/**
* This is the built-in JavaScript class that is the prototype for:
*
* - [Uint8Array](https://espruino.com//Reference#Uint8Array)
* - [UintClamped8Array](https://espruino.com//Reference#UintClamped8Array)
* - [Int8Array](https://espruino.com//Reference#Int8Array)
* - [Uint16Array](https://espruino.com//Reference#Uint16Array)
* - [Int16Array](https://espruino.com//Reference#Int16Array)
* - [Uint24Array](https://espruino.com//Reference#Uint24Array) (Espruino-specific - not standard JS)
* - [Uint32Array](https://espruino.com//Reference#Uint32Array)
* - [Int32Array](https://espruino.com//Reference#Int32Array)
* - [Float32Array](https://espruino.com//Reference#Float32Array)
* - [Float64Array](https://espruino.com//Reference#Float64Array)
*
* If you want to access arrays of differing types of data
* you may also find `DataView` useful.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#ArrayBufferView
*/
declare function EspruinoArrayBufferView(): void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type EspruinoArrayBufferView = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The buffer this view references
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_buffer
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
buffer: any
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The length, in bytes, of the `ArrayBufferView`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_byteLength
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
byteLength: number
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The offset, in bytes, to the first byte of the view within the backing `ArrayBuffer`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_byteOffset
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
byteOffset: number
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Copy the contents of `array` into this one, mapping `this[x+offset]=array[x];`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_set
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
set: (arr: any, offset: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return an array which is made from the following: `A.map(function) = [function(A[0]), function(A[1]), ...]`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This returns an `ArrayBuffer` of the same type it was called on. To get an `Array`, use `Array.map`, eg. `[].map.call(myArray, x=>x+1)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_map
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
map: (fn: any, thisArg: any) => EspruinoArrayBufferView;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Returns a smaller part of this array which references the same data (it doesn't copy it).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_subarray
*/
subarray: (begin: number, end: any) => EspruinoArrayBufferView;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return the index of the value in the array, or `-1`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_indexOf
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
indexOf: (value: any, startIndex: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return `true` if the array includes the value, `false` otherwise
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_includes
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
includes: (value: any, startIndex: number) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Join all elements of this array together into one string, using 'separator' between them. eg. `[1,2,3].join(' ')=='1 2 3'`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_join
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
join: (separator: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Do an in-place quicksort of the array
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_sort
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
sort: (variable: any) => EspruinoArrayBufferView;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Executes a provided function once per array element.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_forEach
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
forEach: (fn: any, thisArg: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Execute `previousValue=initialValue` and then `previousValue = callback(previousValue, currentValue, index, array)` for each element in the array, and finally return previousValue.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_reduce
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reduce: (callback: any, initialValue: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Fill this array with the given value, for every index `>= start` and `< end`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_fill
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
fill: (value: any, start: number, end: any) => EspruinoArrayBufferView;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return an array which contains only those elements for which the callback function returns 'true'
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_filter
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
filter: (fn: any, thisArg: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return the array element where `function` returns `true`, or `undefined` if it doesn't returns `true` for any element.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_find
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
find: (fn: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return the array element's index where `function` returns `true`, or `-1` if it doesn't returns `true` for any element.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_findIndex
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
findIndex: (fn: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Reverse the contents of this `ArrayBufferView` in-place
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_reverse
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reverse: () => EspruinoArrayBufferView;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return a copy of a portion of this array (in a new array).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This currently returns a normal `Array`, not an `ArrayBuffer`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ArrayBufferView_slice
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
slice: (start: number, end: any) => any[];
}
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Create a typed array based on the given input. Either an existing Array Buffer, an Integer as a Length, or a simple array. If an `ArrayBufferView` (eg. `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied rather than referenced.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Uint24Array_Uint24Array
*/
declare function Uint24Array(arr: any, byteOffset: number, length: number): EspruinoArrayBufferView;
type Uint24Array = {
}
/**
* Create a software SPI port. This has limited functionality (no baud rate), but it can work on any pins.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Use `SPI.setup` to configure this port.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_SPI
*/
declare const SPI: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Try and find an SPI hardware device that will work on this pin (eg. `SPI1`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* May return undefined if no device can be found.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_find
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
find: (pin: Pin) => any;
};
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type SPI = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set up this SPI port as an SPI Master.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Options can contain the following (defaults are shown where relevant):
2022-07-20 19:07:18 +00:00
*
* ```
* {
2022-07-20 18:35:57 +00:00
* sck:pin,
* miso:pin,
* mosi:pin,
2022-07-20 19:07:18 +00:00
* baud:integer=100000, // ignored on software SPI
* mode:integer=0, // between 0 and 3
* order:string=&#x27;msb&#x27; // can be &#x27;msb&#x27; or &#x27;lsb&#x27;
* bits:8 // only available for software SPI
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* If `sck`,`miso` and `mosi` are left out, they will automatically be chosen. However if one or more is specified then the unspecified pins will not be set up.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can find out which pins to use by looking at [your board's reference page](#boards) and searching for pins with the `SPI` marker. Some boards such as those based on `nRF52` chips can have SPI on any pins, so don't have specific markings.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The SPI `mode` is between 0 and 3 - see [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase](http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* On STM32F1-based parts, you cannot mix AF and non-AF pins (SPI pins are usually grouped on the chip - and you can't mix pins from two groups). Espruino will not warn you about this.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_setup
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setup: (options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send data down SPI, and return the result. Sending an integer will return an integer, a String will return a String, and anything else will return a Uint8Array.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For maximum speeds, please pass either Strings or Typed Arrays as arguments. Note that you can even pass arrays of arrays, like `[1,[2,3,4],5]`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_send
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
send: (data: any, nss_pin: Pin) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Write a character or array of characters to SPI - without reading the result back.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For maximum speeds, please pass either Strings or Typed Arrays as arguments.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_write
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
write: (data: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send data down SPI, using 4 bits for each 'real' bit (MSB first). This can be useful for faking one-wire style protocols
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_send4bit
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
send4bit: (data: any, bit0: number, bit1: number, nss_pin: Pin) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Send data down SPI, using 8 bits for each 'real' bit (MSB first). This can be useful for faking one-wire style protocols
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_SPI_send8bit
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
send8bit: (data: any, bit0: number, bit1: number, nss_pin: Pin) => void;
}
/**
* The first SPI port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_SPI1
*/
declare const SPI1: SPI;
/**
* The second SPI port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_SPI2
*/
declare const SPI2: SPI;
/**
* The third SPI port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_SPI3
*/
declare const SPI3: SPI;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Create a software I2C port. This has limited functionality (no baud rate), but it can work on any pins.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Use `I2C.setup` to configure this port.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_I2C_I2C
*/
declare const I2C: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Try and find an I2C hardware device that will work on this pin (eg. `I2C1`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* May return undefined if no device can be found.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_I2C_find
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
find: (pin: Pin) => any;
};
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type I2C = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set up this I2C port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If not specified in options, the default pins are used (usually the lowest numbered pins on the lowest port that supports this peripheral)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_I2C_setup
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setup: (options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Transmit to the slave device with the given address. This is like Arduino's beginTransmission, write, and endTransmission rolled up into one.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_I2C_writeTo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
writeTo: (address: any, data: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Request bytes from the given slave device, and return them as a Uint8Array (packed array of bytes). This is like using Arduino Wire's requestFrom, available and read functions. Sends a STOP
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_I2C_readFrom
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
readFrom: (address: any, quantity: number) => Uint8Array;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* The first I2C port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_I2C1
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const I2C1: I2C;
/**
* The second I2C port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_I2C2
*/
declare const I2C2: I2C;
/**
* The third I2C port
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_I2C3
*/
declare const I2C3: I2C;
/**
* Create a waveform class. This allows high speed input and output of waveforms. It has an internal variable called `buffer` (as well as `buffer2` when double-buffered - see `options` below) which contains the data to input/output.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When double-buffered, a 'buffer' event will be emitted each time a buffer is finished with (the argument is that buffer). When the recording stops, a 'finish' event will be emitted (with the first argument as the buffer).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Waveform_Waveform
*/
declare function Waveform(samples: number, options: any): any;
type Waveform = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Will start outputting the waveform on the given pin - the pin must have previously been initialised with analogWrite. If not repeating, it'll emit a `finish` event when it is done.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Waveform_startOutput
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
startOutput: (output: Pin, freq: number, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Will start inputting the waveform on the given pin that supports analog. If not repeating, it'll emit a `finish` event when it is done.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Waveform_startInput
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
startInput: (output: Pin, freq: number, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Stop a waveform that is currently outputting
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Waveform_stop
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
stop: () => void;
}
/**
* Creates a pin from the given argument (or returns undefined if no argument)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_Pin
*/
declare function Pin(value: any): any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type Pin = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns the input state of the pin as a boolean.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset the pin's state to `"input"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_read
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
read: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sets the output state of the pin to a 1
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset the pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_set
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
set: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sets the output state of the pin to a 0
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset the pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_reset
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reset: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sets the output state of the pin to the parameter given
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset the pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_write
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
write: (value: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sets the output state of the pin to the parameter given at the specified time.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** this **doesn't** change the mode of the pin to an output. To do that, you need to use `pin.write(0)` or `pinMode(pin, 'output')` first.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_writeAtTime
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
writeAtTime: (value: boolean, time: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return the current mode of the given pin. See `pinMode` for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_getMode
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getMode: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Set the mode of the given pin. See [`pinMode`](#l__global_pinMode) for more information on pin modes.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_mode
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
mode: (mode: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Toggles the state of the pin from off to on, or from on to off.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This method doesn't currently work on the ESP8266 port of Espruino.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset the pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_toggle
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
toggle: () => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Get information about this pin and its capabilities. Of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* "port" : "A", // the Pin&#x27;s port on the chip
* "num" : 12, // the Pin&#x27;s number
* "in_addr" : 0x..., // (if available) the address of the pin&#x27;s input address in bit-banded memory (can be used with peek)
* "out_addr" : 0x..., // (if available) the address of the pin&#x27;s output address in bit-banded memory (can be used with poke)
* "analog" : { ADCs : [1], channel : 12 }, // If analog input is available
* "functions" : {
* "TIM1":{type:"CH1, af:0},
* "I2C3":{type:"SCL", af:1}
2022-07-20 18:35:57 +00:00
* }
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* Will return undefined if pin is not valid.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Pin_getInfo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getInfo: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Create a software Serial port. This has limited functionality (only low baud rates), but it can work on any pins.
2022-07-20 19:07:18 +00:00
*
* Use `Serial.setup` to configure this port.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_Serial
*/
2022-07-20 15:57:03 +00:00
declare const Serial: {
2022-07-20 13:35:57 +00:00
/**
* Try and find a USART (Serial) hardware device that will work on this pin (eg. `Serial1`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:35:57 +00:00
* May return undefined if no device can be found.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Serial_find
*/
2022-07-20 15:57:03 +00:00
find: (pin: Pin) => any;
2022-07-20 13:35:57 +00:00
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:35:57 +00:00
2022-07-20 13:07:21 +00:00
type Serial = {
2022-07-20 13:35:57 +00:00
/**
* Set this Serial port as the port for the JavaScript console (REPL).
2022-07-20 19:07:18 +00:00
*
* Unless `force` is set to true, changes in the connection state of the board
* (for instance plugging in USB) will cause the console to change.
2022-07-20 19:07:18 +00:00
*
* See `E.setConsole` for a more flexible version of this function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_setConsole
*/
setConsole: (force: boolean) => void;
2022-07-20 15:57:03 +00:00
/**
* Setup this Serial port with the given baud rate and options.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* eg.
2022-07-20 19:07:18 +00:00
*
* ```
* Serial1.setup(9600,{rx:a_pin, tx:a_pin});
* ```
*
2022-07-20 15:57:03 +00:00
* The second argument can contain:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* rx:pin, // Receive pin (data in to Espruino)
* tx:pin, // Transmit pin (data out of Espruino)
* ck:pin, // (default none) Clock Pin
* cts:pin, // (default none) Clear to Send Pin
* bytesize:8, // (default 8)How many data bits - 7 or 8
* parity:null/&#x27;none&#x27;/&#x27;o&#x27;/&#x27;odd&#x27;/&#x27;e&#x27;/&#x27;even&#x27;,
* // (default none) Parity bit
* stopbits:1, // (default 1) Number of stop bits to use
* flow:null/undefined/&#x27;none&#x27;/&#x27;xon&#x27;, // (default none) software flow control
* path:null/undefined/string // Linux Only - the path to the Serial device to use
* errors:false // (default false) whether to forward framing/parity errors
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* You can find out which pins to use by looking at [your board's reference page](#boards)
* and searching for pins with the `UART`/`USART` markers.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* If not specified in options, the default pins are used for rx and tx
* (usually the lowest numbered pins on the lowest port that supports
* this peripheral). `ck` and `cts` are not used unless specified.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Note that even after changing the RX and TX pins, if you have called setup
* before then the previous RX and TX pins will still be connected to the Serial
* port as well - until you set them to something else using `digitalWrite` or
* `pinMode`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Flow control can be xOn/xOff (`flow:'xon'`) or hardware flow control
* (receive only) if `cts` is specified. If `cts` is set to a pin, the
* pin's value will be 0 when Espruino is ready for data and 1 when it isn't.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* By default, framing or parity errors don't create `framing` or `parity` events
* on the `Serial` object because storing these errors uses up additional
* storage in the queue. If you're intending to receive a lot of malformed
* data then the queue might overflow `E.getErrorFlags()` would return `FIFO_FULL`.
* However if you need to respond to `framing` or `parity` errors then
* you'll need to use `errors:true` when initialising serial.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* On Linux builds there is no default Serial device, so you must specify
* a path to a device - for instance: `Serial1.setup(9600,{path:"/dev/ttyACM0"})`
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* You can also set up 'software serial' using code like:
2022-07-20 19:07:18 +00:00
*
* ```
* var s = new Serial();
* s.setup(9600,{rx:a_pin, tx:a_pin});
* ```
*
2022-07-20 15:57:03 +00:00
* However software serial doesn't use `ck`, `cts`, `parity`, `flow` or `errors` parts of the initialisation object.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Serial_setup
*/
setup: (baudrate: any, options: any) => void;
2022-07-20 13:35:57 +00:00
/**
* If the serial (or software serial) device was set up,
* uninitialise it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_unsetup
*/
unsetup: () => void;
2022-07-20 13:35:57 +00:00
/**
* Print a string to the serial port - without a line feed
2022-07-20 19:07:18 +00:00
*
* **Note:** This function replaces any occurances of `\n` in the string with `\r\n`. To avoid this, use `Serial.write`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_print
*/
print: (string: any) => void;
2022-07-20 13:35:57 +00:00
/**
* Print a line to the serial port with a newline (`\r\n`) at the end of it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** This function converts data to a string first, eg `Serial.print([1,2,3])` is equivalent to `Serial.print("1,2,3"). If you'd like to write raw bytes, use `Serial.write`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_println
*/
println: (string: any) => void;
2022-07-20 13:35:57 +00:00
/**
* Write a character or array of data to the serial port
2022-07-20 19:07:18 +00:00
*
* This method writes unmodified data, eg `Serial.write([1,2,3])` is equivalent to `Serial.write("\1\2\3")`. If you'd like data converted to a string first, use `Serial.print`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_write
*/
write: (data: any) => void;
2022-07-20 15:57:03 +00:00
/**
* Add data to this device as if it came directly from the input - it will be
* returned via `serial.on('data', ...)`;
2022-07-20 19:07:18 +00:00
*
* ```
* Serial1.on(&#x27;data&#x27;, function(d) { print("Got",d); });
* Serial1.inject(&#x27;Hello World&#x27;);
* // prints "Got Hel","Got lo World" (characters can be split over multiple callbacks)
* ```
*
2022-07-20 15:57:03 +00:00
* This is most useful if you wish to send characters to Espruino's
* REPL (console) while it is on another device.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_Serial_inject
*/
inject: (data: any) => void;
2022-07-20 13:35:57 +00:00
/**
* Return how many bytes are available to read. If there is already a listener for data, this will always return 0.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_available
*/
available: () => number;
2022-07-20 13:35:57 +00:00
/**
* Return a string containing characters that have been received
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_read
*/
read: (chars: number) => any;
2022-07-20 13:35:57 +00:00
/**
* Pipe this USART to a stream (an object with a 'write' method)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Serial_pipe
*/
pipe: (destination: any, options: any) => void;
}
2022-07-20 13:35:57 +00:00
/**
* The USB Serial port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_USB
*/
declare const USB: Serial;
2022-07-20 13:35:57 +00:00
/**
* The first Serial (USART) port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Serial1
*/
declare const Serial1: Serial;
2022-07-20 13:35:57 +00:00
/**
* The second Serial (USART) port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Serial2
*/
declare const Serial2: Serial;
2022-07-20 13:35:57 +00:00
/**
* The third Serial (USART) port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Serial3
*/
declare const Serial3: Serial;
2022-07-20 13:35:57 +00:00
/**
* The fourth Serial (USART) port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Serial4
*/
declare const Serial4: Serial;
2022-07-20 13:35:57 +00:00
/**
* The fifth Serial (USART) port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Serial5
*/
declare const Serial5: Serial;
2022-07-20 13:35:57 +00:00
/**
* The sixth Serial (USART) port
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_Serial6
*/
declare const Serial6: Serial;
2022-07-20 13:35:57 +00:00
/**
* A loopback serial device. Data sent to `LoopbackA` comes out of `LoopbackB` and vice versa
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_LoopbackA
2022-07-20 18:35:57 +00:00
*/
declare const LoopbackA: Serial;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* A loopback serial device. Data sent to `LoopbackA` comes out of `LoopbackB` and vice versa
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_LoopbackB
*/
declare const LoopbackB: Serial;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* A telnet serial device that maps to the built-in telnet console server (devices that have built-in wifi only).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_Telnet
*/
declare const Telnet: any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* This module allows you to read and write part of the nonvolatile flash
* memory of your device using a filesystem-like API.
2022-07-20 19:07:18 +00:00
*
* Also see the `Flash` library, which provides a low level, more dangerous way
* to access all parts of your flash memory.
2022-07-20 19:07:18 +00:00
*
* The `Storage` library provides two distinct types of file:
*
* - `require("Storage").write(...)`/`require("Storage").read(...)`/etc create simple
* contiguous files of fixed length. This is the recommended file type.
* - `require("Storage").open(...)` creates a `StorageFile`, which stores the file in
* numbered chunks (`"filename\1"`/`"filename\2"`/etc). It allows data to be appended
* and for the file to be read line by line.
*
* You must read a file using the same method you used to write it - eg. you can't create a
* file with `require("Storage").open(...)` and then read it with `require("Storage").read(...)`.
2022-07-20 19:07:18 +00:00
*
* **Note:** In firmware 2v05 and later, the maximum length for filenames
* is 28 characters. However in 2v04 and earlier the max length is 8.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_Storage_undefined
*/
2022-07-20 15:57:03 +00:00
/**
* These objects are created from `require("Storage").open`
* and allow Storage items to be read/written.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* The `Storage` library writes into Flash memory (which
* can only be erased in chunks), and unlike a normal filesystem
* it allocates files in one long contiguous area to allow them
* to be accessed easily from Espruino.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* This presents a challenge for `StorageFile` which allows you
* to append to a file, so instead `StorageFile` stores files
* in chunks. It uses the last character of the filename
* to denote the chunk number (eg `"foobar\1"`, `"foobar\2"`, etc).
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* This means that while `StorageFile` files exist in the same
* area as those from `Storage`, they should be
* read using `Storage.open` (and not `Storage.read`).
2022-07-20 19:07:18 +00:00
*
* ```
* f = s.open("foobar","w");
* f.write("Hell");
* f.write("o World\n");
* f.write("Hello\n");
* f.write("World 2\n");
* // there&#x27;s no need to call &#x27;close&#x27;
* // then
* f = s.open("foobar","r");
* f.read(13) // "Hello World\nH"
* f.read(13) // "ello\nWorld 2\n"
* f.read(13) // "Hello World 3"
* f.read(13) // "\n"
* f.read(13) // undefined
* // or
* f = s.open("foobar","r");
* f.readLine() // "Hello World\n"
* f.readLine() // "Hello\n"
* f.readLine() // "World 2\n"
* f.readLine() // "Hello World 3\n"
* f.readLine() // undefined
* // now get rid of file
* f.erase();
* ```
*
2022-07-20 15:57:03 +00:00
* **Note:** `StorageFile` uses the fact that all bits of erased flash memory
* are 1 to detect the end of a file. As such you should not write character
* code 255 (`"\xFF"`) to these files.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#StorageFile
*/
declare function StorageFile(): void;
type StorageFile = {
/**
* Read 'len' bytes of data from the file, and return a String containing those bytes.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* If the end of the file is reached, the String may be smaller than the amount of bytes
* requested, or if the file is already at the end, `undefined` is returned.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_StorageFile_read
*/
read: (len: number) => string;
/**
* Read a line of data from the file (up to and including `"\n"`)
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_StorageFile_readLine
*/
readLine: () => string;
/**
* Return the length of the current file.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* This requires Espruino to read the file from scratch,
* which is not a fast operation.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_StorageFile_getLength
*/
getLength: () => number;
/**
* Append the given data to a file. You should not attempt to append `"\xFF"` (character code 255).
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_StorageFile_write
*/
write: (data: any) => void;
/**
* Erase this file
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_StorageFile_erase
*/
erase: () => void;
2022-07-20 13:07:21 +00:00
}
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Built-in class that caches the modules used by the `require` command
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Modules
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Modules: {
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Return an array of module names that have been cached
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Modules_getCached
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getCached: () => any;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Remove the given module from the list of cached modules
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Modules_removeCached
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
removeCached: (id: any) => void;
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Remove all cached modules
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Modules_removeAllCached
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
removeAllCached: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Add the given module to the cache
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Modules_addCached
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
addCached: (id: any, sourcecode: any) => void;
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
};
/**
* This module allows you to read and write the nonvolatile flash memory of your device.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Also see the `Storage` library, which provides a safer file-like
* interface to nonvolatile storage.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* It should be used with extreme caution, as it is easy to overwrite parts of Flash
* memory belonging to Espruino or even its bootloader. If you damage the bootloader
* then you may need external hardware such as a USB-TTL converter to restore it. For
* more information on restoring the bootloader see `Advanced Reflashing` in your
* board's reference pages.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* To see which areas of memory you can and can't overwrite, look at the values
* reported by `process.memory()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** On Nordic platforms there are checks in place to help you avoid
* 'bricking' your device be damaging the bootloader. You can disable these with `E.setFlags({unsafeFlash:1})`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Flash_undefined
*/
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
/**
* This is the built-in JavaScript class for Espruino utility functions.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#E
*/
declare const E: {
2022-07-20 15:57:03 +00:00
/**
* Setup the filesystem so that subsequent calls to `E.openFile` and `require('fs').*` will use an SD card on the supplied SPI device and pin.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* It can even work using software SPI - for instance:
2022-07-20 19:07:18 +00:00
*
* ```
* // DI/CMD = C7
* // DO/DAT0 = C8
* // CK/CLK = C9
* // CD/CS/DAT3 = C6
2022-07-20 15:57:03 +00:00
* var spi = new SPI();
* spi.setup({mosi:C7, miso:C8, sck:C9});
* E.connectSDCard(spi, C6);
2022-07-20 19:07:18 +00:00
* console.log(require("fs").readdirSync());
* ```
*
2022-07-20 15:57:03 +00:00
* See [the page on File IO](http://www.espruino.com/File+IO) for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** We'd strongly suggest you add a pullup resistor from CD/CS pin to 3.3v. It is
* good practise to avoid accidental writes before Espruino is initialised, and some cards
* will not work reliably without one.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** If you want to remove an SD card after you have started using it, you *must* call `E.unmountSD()` or you may cause damage to the card.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_connectSDCard
*/
connectSDCard: (spi: any, csPin: Pin) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Unmount the SD card, so it can be removed. If you remove the SD card without calling this you may cause corruption, and you will be unable to access another SD card until you reset Espruino or call `E.unmountSD()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_unmountSD
*/
2022-07-20 15:57:03 +00:00
unmountSD: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Open a file
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_openFile
*/
2022-07-20 15:57:03 +00:00
openFile: (path: any, mode: any) => EspruinoFile;
/**
* Change the paramters used for the flash filesystem.
* The default address is the last 1Mb of 4Mb Flash, 0x300000, with total size of 1Mb.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Before first use the media needs to be formatted.
2022-07-20 19:07:18 +00:00
*
* ```
* fs=require("fs");
* try {
* fs.readdirSync();
* } catch (e) { //&#x27;Uncaught Error: Unable to mount media : NO_FILESYSTEM&#x27;
* console.log(&#x27;Formatting FS - only need to do once&#x27;);
* E.flashFatFS({ format: true });
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* fs.writeFileSync("bang.txt", "This is the way the world ends\nnot with a bang but a whimper.\n");
* fs.readdirSync();
* ```
*
2022-07-20 15:57:03 +00:00
* This will create a drive of 100 * 4096 bytes at 0x300000. Be careful with the selection of flash addresses as you can overwrite firmware!
* You only need to format once, as each will erase the content.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* `E.flashFatFS({ addr:0x300000,sectors:100,format:true });`
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_flashFatFS
*/
flashFatFS: (options: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l_E_showMenu
*/
showMenu: () => void;
/**
* A utility function for displaying a full screen message on the screen.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Draws to the screen and returns immediately.
2022-07-20 19:07:18 +00:00
*
* ```
* E.showMessage("These are\nLots of\nLines","My Title")
* ```
*
2022-07-20 18:35:57 +00:00
* or to display an image as well as text:
2022-07-20 19:07:18 +00:00
*
* ```
* E.showMessage("Lots of text will wrap automatically",{
* title:"Warning",
* img:atob("FBQBAfgAf+Af/4P//D+fx/n+f5/v+f//n//5//+f//n////3//5/n+P//D//wf/4B/4AH4A=")
2022-07-20 18:35:57 +00:00
* })
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_E_showMessage
*/
showMessage: (message: any, options: any) => void;
/**
* @url http://www.espruino.com/Reference#l_E_showPrompt
*/
showPrompt: () => void;
/**
* Displays a full screen prompt on the screen, with a single 'Ok' button.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When the button is pressed the promise is resolved.
2022-07-20 19:07:18 +00:00
*
* ```
* E.showAlert("Hello").then(function() {
* print("Ok pressed");
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* // or
* E.showAlert("These are\nLots of\nLines","My Title").then(function() {
* print("Ok pressed");
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* To remove the window, call `E.showAlert()` with no arguments.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_E_showAlert
*/
showAlert: (message: any, options: any) => any;
/**
* @url http://www.espruino.com/Reference#l_E_showScroller
*/
showScroller: () => void;
2022-07-20 13:35:57 +00:00
/**
* Use the microcontroller's internal thermistor to work out the temperature.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* On Puck.js v2.0 this will use the on-board PCT2075TP temperature sensor, but on other devices it may not be desperately well calibrated.
2022-07-20 19:07:18 +00:00
*
* While this is implemented on Espruino boards, it may not be implemented on other devices. If so it'll return NaN.
2022-07-20 19:07:18 +00:00
*
* **Note:** This is not entirely accurate and varies by a few degrees from chip to chip. It measures the **die temperature**, so when connected to USB it could be reading 10 over degrees C above ambient temperature. When running from battery with `setDeepSleep(true)` it is much more accurate though.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getTemperature
*/
2022-07-20 15:57:03 +00:00
getTemperature: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Check the internal voltage reference. To work out an actual voltage of an input pin, you can use `analogRead(pin)*E.getAnalogVRef()`
2022-07-20 19:07:18 +00:00
*
* **Note:** This value is calculated by reading the voltage on an internal voltage reference with the ADC.
* It will be slightly noisy, so if you need this for accurate measurements we'd recommend that you call
* this function several times and average the results.
2022-07-20 19:07:18 +00:00
*
* While this is implemented on Espruino boards, it may not be implemented on other devices. If so it'll return NaN.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getAnalogVRef
*/
2022-07-20 15:57:03 +00:00
getAnalogVRef: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* ADVANCED: This is a great way to crash Espruino if you're not sure what you are doing
2022-07-20 19:07:18 +00:00
*
* Create a native function that executes the code at the given address. Eg. `E.nativeCall(0x08012345,'double (double,double)')(1.1, 2.2)`
2022-07-20 19:07:18 +00:00
*
* If you're executing a thumb function, you'll almost certainly need to set the bottom bit of the address to 1.
2022-07-20 19:07:18 +00:00
*
* Note it's not guaranteed that the call signature you provide can be used - there are limits on the number of arguments allowed.
2022-07-20 19:07:18 +00:00
*
* When supplying `data`, if it is a 'flat string' then it will be used directly, otherwise it'll be converted to a flat string and used.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_nativeCall
*/
2022-07-20 15:57:03 +00:00
nativeCall: (addr: number, sig: any, data: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Clip a number to be between min and max (inclusive)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_clip
*/
2022-07-20 15:57:03 +00:00
clip: (x: number, min: number, max: number) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Sum the contents of the given Array, String or ArrayBuffer and return the result
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_sum
*/
2022-07-20 15:57:03 +00:00
sum: (arr: any) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Work out the variance of the contents of the given Array, String or ArrayBuffer and return the result. This is equivalent to `v=0;for (i in arr) v+=Math.pow(mean-arr[i],2)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_variance
*/
2022-07-20 15:57:03 +00:00
variance: (arr: any, mean: number) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Convolve arr1 with arr2. This is equivalent to `v=0;for (i in arr1) v+=arr1[i] * arr2[(i+offset) % arr2.length]`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_convolve
*/
2022-07-20 15:57:03 +00:00
convolve: (arr1: any, arr2: any, offset: number) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Performs a Fast Fourier Transform (FFT) in 32 bit floats on the supplied data and writes it back into the
2022-07-20 13:07:21 +00:00
* original arrays. Note that if only one array is supplied, the data written back is the modulus of the complex
* result `sqrt(r*r+i*i)`.
2022-07-20 19:07:18 +00:00
*
* In order to perform the FFT, there has to be enough room on the stack to allocate two arrays of 32 bit
2022-07-20 13:07:21 +00:00
* floating point numbers - this will limit the maximum size of FFT possible to around 1024 items on
* most platforms.
2022-07-20 19:07:18 +00:00
*
* **Note:** on the Original Espruino board, FFTs are performed in 64bit arithmetic as there isn't
* space to include the 32 bit maths routines (2x more RAM is required).
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_FFT
*/
2022-07-20 15:57:03 +00:00
FFT: (arrReal: any, arrImage: any, inverse: boolean) => void;
/**
* Enable the watchdog timer. This will reset Espruino if it isn't able to return to the idle loop within the timeout.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* If `isAuto` is false, you must call `E.kickWatchdog()` yourself every so often or the chip will reset.
2022-07-20 19:07:18 +00:00
*
* ```
* E.enableWatchdog(0.5); // automatic mode
* while(1); // Espruino will reboot because it has not been idle for 0.5 sec
* ```
*
* ```
* E.enableWatchdog(1, false);
* setInterval(function() {
* if (everything_ok)
* E.kickWatchdog();
* }, 500);
* // Espruino will now reset if everything_ok is false,
* // or if the interval fails to be called
* ```
*
2022-07-20 15:57:03 +00:00
* **NOTE:** This is only implemented on STM32 and nRF5x devices (all official Espruino boards).
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **NOTE:** On STM32 (Pico, WiFi, Original) with `setDeepSleep(1)` you need to
* explicitly wake Espruino up with an interval of less than the watchdog timeout or the watchdog will fire and
* the board will reboot. You can do this with `setInterval("", time_in_milliseconds)`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_enableWatchdog
*/
enableWatchdog: (timeout: number, isAuto: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Kicks a Watchdog timer set up with `E.enableWatchdog(..., false)`. See
* `E.enableWatchdog` for more information.
2022-07-20 19:07:18 +00:00
*
* **NOTE:** This is only implemented on STM32 and nRF5x devices (all official Espruino boards).
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_kickWatchdog
*/
2022-07-20 15:57:03 +00:00
kickWatchdog: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Get and reset the error flags. Returns an array that can contain:
2022-07-20 19:07:18 +00:00
*
* `'FIFO_FULL'`: The receive FIFO filled up and data was lost. This could be state transitions for setWatch, or received characters.
2022-07-20 19:07:18 +00:00
*
* `'BUFFER_FULL'`: A buffer for a stream filled up and characters were lost. This can happen to any stream - Serial,HTTP,etc.
2022-07-20 19:07:18 +00:00
*
* `'CALLBACK'`: A callback (`setWatch`, `setInterval`, `on('data',...)`) caused an error and so was removed.
2022-07-20 19:07:18 +00:00
*
* `'LOW_MEMORY'`: Memory is running low - Espruino had to run a garbage collection pass or remove some of the command history
2022-07-20 19:07:18 +00:00
*
* `'MEMORY'`: Espruino ran out of memory and was unable to allocate some data that it needed.
2022-07-20 19:07:18 +00:00
*
* `'UART_OVERFLOW'` : A UART received data but it was not read in time and was lost
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getErrorFlags
*/
2022-07-20 15:57:03 +00:00
getErrorFlags: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Get Espruino's interpreter flags that control the way it handles your JavaScript code.
*
* - `deepSleep` - Allow deep sleep modes (also set by setDeepSleep)
* - `pretokenise` - When adding functions, pre-minify them and tokenise reserved words
* - `unsafeFlash` - Some platforms stop writes/erases to interpreter memory to stop you bricking the device accidentally - this removes that protection
* - `unsyncFiles` - When writing files, *don't* flush all data to the SD card after each command (the default is *to* flush). This is much faster, but can cause filesystem damage if power is lost without the filesystem unmounted.
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getFlags
*/
2022-07-20 15:57:03 +00:00
getFlags: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Set the Espruino interpreter flags that control the way it handles your JavaScript code.
2022-07-20 19:07:18 +00:00
*
* Run `E.getFlags()` and check its description for a list of available flags and their values.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_setFlags
*/
2022-07-20 15:57:03 +00:00
setFlags: (flags: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l_E_pipe
2022-07-20 13:07:21 +00:00
*/
2022-07-20 15:57:03 +00:00
pipe: (source: any, destination: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Create an ArrayBuffer from the given string. This is done via a reference, not a copy - so it is very fast and memory efficient.
2022-07-20 19:07:18 +00:00
*
* Note that this is an ArrayBuffer, not a Uint8Array. To get one of those, do: `new Uint8Array(E.toArrayBuffer('....'))`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_toArrayBuffer
*/
2022-07-20 15:57:03 +00:00
toArrayBuffer: (str: any) => EspruinoArrayBufferView;
/**
* This creates a Uint8Array from the given arguments. These are handled as follows:
*
* - `Number` -> read as an integer, using the lowest 8 bits
* - `String` -> use each character's numeric value (eg. `String.charCodeAt(...)`)
* - `Array` -> Call itself on each element
* - `ArrayBuffer` or Typed Array -> use the lowest 8 bits of each element
* - `Object`:
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* - `{data:..., count: int}` -> call itself `object.count` times, on `object.data`
* - `{callback : function}` -> call the given function, call itself on return value
*
2022-07-20 19:07:18 +00:00
* For example:
2022-07-20 15:57:03 +00:00
*
2022-07-20 19:07:18 +00:00
* ```
* E.toUint8Array([1,2,3])
* =new Uint8Array([1, 2, 3])
* E.toUint8Array([1,{data:2,count:3},3])
* =new Uint8Array([1, 2, 2, 2, 3])
* E.toUint8Array("Hello")
* =new Uint8Array([72, 101, 108, 108, 111])
* E.toUint8Array(["hi",{callback:function() { return [1,2,3] }}])
* =new Uint8Array([104, 105, 1, 2, 3])
* ```
2022-07-20 15:57:03 +00:00
*
* @url http://www.espruino.com/Reference#l_E_toUint8Array
*/
toUint8Array: (args: any) => Uint8Array;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* This performs the same basic function as `JSON.stringify`,
* however `JSON.stringify` adds extra characters to conform
* to the JSON spec which aren't required if outputting JS.
2022-07-20 19:07:18 +00:00
*
* `E.toJS` will also stringify JS functions, whereas
* `JSON.stringify` ignores them.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* For example:
*
* - `JSON.stringify({a:1,b:2}) == '{"a":1,"b":2}'`
* - `E.toJS({a:1,b:2}) == '{a:1,b:2}'`
*
* **Note:** Strings generated with `E.toJS` can't be
* reliably parsed by `JSON.parse` - however they are
* valid JS so will work with `eval` (but this has security
* implications if you don't trust the source of the string).
2022-07-20 19:07:18 +00:00
*
* On the desktop [JSON5 parsers](https://github.com/json5/json5)
* will parse the strings produced by `E.toJS` without trouble.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_toJS
*/
2022-07-20 15:57:03 +00:00
toJS: (arg: any) => string;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* This creates and returns a special type of string, which actually references
2022-07-20 13:07:21 +00:00
* a specific memory address. It can be used in order to use sections of
* Flash memory directly in Espruino (for example to execute code straight
* from flash memory with `eval(E.memoryArea( ... ))`)
2022-07-20 19:07:18 +00:00
*
* **Note:** This is only tested on STM32-based platforms (Espruino Original
* and Espruino Pico) at the moment.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_memoryArea
*/
2022-07-20 15:57:03 +00:00
memoryArea: (addr: number, len: number) => string;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* This writes JavaScript code into Espruino's flash memory, to be executed on
* startup. It differs from `save()` in that `save()` saves the whole state of
* the interpreter, whereas this just saves JS code that is executed at boot.
2022-07-20 19:07:18 +00:00
*
* Code will be executed before `onInit()` and `E.on('init', ...)`.
2022-07-20 19:07:18 +00:00
*
* If `alwaysExec` is `true`, the code will be executed even after a call to
* `reset()`. This is useful if you're making something that you want to
2022-07-20 13:07:21 +00:00
* program, but you want some code that is always built in (for instance
* setting up a display or keyboard).
2022-07-20 19:07:18 +00:00
*
* To remove boot code that has been saved previously, use `E.setBootCode("")`
2022-07-20 19:07:18 +00:00
*
* **Note:** this removes any code that was previously saved with `save()`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_setBootCode
*/
2022-07-20 15:57:03 +00:00
setBootCode: (code: any, alwaysExec: boolean) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* This sets the clock frequency of Espruino's processor. It will return `0` if
* it is unimplemented or the clock speed cannot be changed.
2022-07-20 19:07:18 +00:00
*
* **Note:** On pretty much all boards, UART, SPI, I2C, PWM, etc will change
* frequency and will need setting up again in order to work.
2022-07-20 19:07:18 +00:00
*
* # STM32F4
*
* Options is of the form `{ M: int, N: int, P: int, Q: int }` - see the 'Clocks'
* section of the microcontroller's reference manual for what these mean.
*
* - System clock = 8Mhz * N / ( M * P )
* - USB clock (should be 48Mhz) = 8Mhz * N / ( M * Q )
*
2022-07-20 13:07:21 +00:00
* Optional arguments are:
*
* - `latency` - flash latency from 0..15
* - `PCLK1` - Peripheral clock 1 divisor (default: 2)
* - `PCLK2` - Peripheral clock 2 divisor (default: 4)
*
* The Pico's default is `{M:8, N:336, P:4, Q:7, PCLK1:2, PCLK2:4}`, use
* `{M:8, N:336, P:8, Q:7, PCLK:1, PCLK2:2}` to halve the system clock speed
2022-07-20 13:07:21 +00:00
* while keeping the peripherals running at the same speed (omitting PCLK1/2
* will lead to the peripherals changing speed too).
2022-07-20 19:07:18 +00:00
*
* On STM32F4 boards (eg. Espruino Pico), the USB clock needs to be kept at 48Mhz
* or USB will fail to work. You'll also experience USB instability if the processor
* clock falls much below 48Mhz.
2022-07-20 19:07:18 +00:00
*
* # ESP8266
*
2022-07-20 13:07:21 +00:00
* Just specify an integer value, either 80 or 160 (for 80 or 160Mhz)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_setClock
*/
2022-07-20 15:57:03 +00:00
setClock: (options: any) => number;
/**
* Changes the device that the JS console (otherwise known as the REPL)
* is attached to. If the console is on a device, that
* device can be used for programming Espruino.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Rather than calling `Serial.setConsole` you can call
* `E.setConsole("DeviceName")`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* This is particularly useful if you just want to
* remove the console. `E.setConsole(null)` will
* make the console completely inaccessible.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* `device` may be `"Serial1"`,`"USB"`,`"Bluetooth"`,`"Telnet"`,`"Terminal"`,
* any other *hardware* `Serial` device, or `null` to disable the console completely.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* `options` is of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* force : bool // default false, force the console onto this device so it does not move
* // if false, changes in connection state (eg USB/Bluetooth) can move
* // the console automatically.
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_setConsole
*/
setConsole: (device: any, options: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Returns the current console device - see `E.setConsole` for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getConsole
*/
2022-07-20 15:57:03 +00:00
getConsole: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Reverse the 8 bits in a byte, swapping MSB and LSB.
2022-07-20 19:07:18 +00:00
*
* For example, `E.reverseByte(0b10010000) == 0b00001001`.
2022-07-20 19:07:18 +00:00
*
* Note that you can reverse all the bytes in an array with: `arr = arr.map(E.reverseByte)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_reverseByte
*/
2022-07-20 15:57:03 +00:00
reverseByte: (x: number) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Output the current list of Utility Timer Tasks - for debugging only
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_dumpTimers
*/
2022-07-20 15:57:03 +00:00
dumpTimers: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Dump any locked variables that aren't referenced from `global` - for debugging memory leaks only.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_dumpLockedVars
*/
2022-07-20 15:57:03 +00:00
dumpLockedVars: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Dump any locked variables that aren't referenced from `global` - for debugging memory leaks only.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_dumpFreeList
*/
2022-07-20 15:57:03 +00:00
dumpFreeList: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Show fragmentation.
*
2022-07-20 15:57:03 +00:00
* - ` ` is free space
* - `#` is a normal variable
* - `L` is a locked variable (address used, cannopt be moved)
* - `=` represents data in a Flat String (must be contiguous)
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_dumpFragmentation
*/
2022-07-20 15:57:03 +00:00
dumpFragmentation: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Dumps a comma-separated list of all allocated variables
2022-07-20 13:07:21 +00:00
* along with the variables they link to. Can be used
* to visualise where memory is used.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_dumpVariables
*/
2022-07-20 15:57:03 +00:00
dumpVariables: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* BETA: defragment memory!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_defrag
*/
2022-07-20 15:57:03 +00:00
defrag: () => void;
/**
* Return the number of variable blocks used by the supplied variable. This is
* useful if you're running out of memory and you want to be able to see what
* is taking up most of the available space.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* If `depth>0` and the variable can be recursed into, an array listing all property
* names (including internal Espruino names) and their sizes is returned. If
* `depth>1` there is also a `more` field that inspects the objects's children's
* children.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* For instance `E.getSizeOf(function(a,b) { })` returns `5`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* But `E.getSizeOf(function(a,b) { }, 1)` returns:
2022-07-20 19:07:18 +00:00
*
* ```
* [
2022-07-20 15:57:03 +00:00
* {
2022-07-20 19:07:18 +00:00
* "name": "a",
* "size": 1 },
2022-07-20 15:57:03 +00:00
* {
2022-07-20 19:07:18 +00:00
* "name": "b",
* "size": 1 },
2022-07-20 15:57:03 +00:00
* {
2022-07-20 19:07:18 +00:00
* "name": "\xFFcod",
* "size": 2 }
2022-07-20 15:57:03 +00:00
* ]
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* In this case setting depth to `2` will make no difference as there are
* no more children to traverse.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* See [http://www.espruino.com/Internals](http://www.espruino.com/Internals) for more information
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_getSizeOf
*/
getSizeOf: (v: any, depth: number) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Return the address in memory of the given variable. This can then
* be used with `peek` and `poke` functions. However, changing data in
* JS variables directly (flatAddress=false) will most likely result in a crash.
2022-07-20 19:07:18 +00:00
*
* This functions exists to allow embedded targets to set up
2022-07-20 13:07:21 +00:00
* peripherals such as DMA so that they write directly to
* JS variables.
2022-07-20 19:07:18 +00:00
*
* See [http://www.espruino.com/Internals](http://www.espruino.com/Internals) for more information
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getAddressOf
*/
2022-07-20 15:57:03 +00:00
getAddressOf: (v: any, flatAddress: boolean) => number;
/**
* Take each element of the `from` array, look it up in `map` (or call `map(value,index)`
* if it is a function), and write it into the corresponding
* element in the `to` array.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* You can use an array to map:
2022-07-20 19:07:18 +00:00
*
* ```
* var a = new Uint8Array([1,2,3,1,2,3]);
* var lut = new Uint8Array([128,129,130,131]);
* E.mapInPlace(a, a, lut);
* // a = [129, 130, 131, 129, 130, 131]
* ```
*
2022-07-20 15:57:03 +00:00
* Or `undefined` to pass straight through, or a function to do a normal 'mapping':
2022-07-20 19:07:18 +00:00
*
* ```
* var a = new Uint8Array([0x12,0x34,0x56,0x78]);
* var b = new Uint8Array(8);
* E.mapInPlace(a, b, undefined); // straight through
* // b = [0x12,0x34,0x56,0x78,0,0,0,0]
* E.mapInPlace(a, b, (value,index)=>index); // write the index in the first 4 (because a.length==4)
* // b = [0,1,2,3,4,0,0,0]
* E.mapInPlace(a, b, undefined, 4); // 4 bits from 8 bit input -> 2x as many outputs, msb-first
* // b = [1, 2, 3, 4, 5, 6, 7, 8]
* E.mapInPlace(a, b, undefined, -4); // 4 bits from 8 bit input -> 2x as many outputs, lsb-first
* // b = [2, 1, 4, 3, 6, 5, 8, 7]
* E.mapInPlace(a, b, a=>a+2, 4);
* // b = [3, 4, 5, 6, 7, 8, 9, 10]
* var b = new Uint16Array(4);
* E.mapInPlace(a, b, undefined, 12); // 12 bits from 8 bit input, msb-first
* // b = [0x123, 0x456, 0x780, 0]
* E.mapInPlace(a, b, undefined, -12); // 12 bits from 8 bit input, lsb-first
* // b = [0x412, 0x563, 0x078, 0]
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_mapInPlace
*/
mapInPlace: (from: any, to: any, map: any, bits: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Search in an Object, Array, or Function
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_lookupNoCase
*/
2022-07-20 15:57:03 +00:00
lookupNoCase: (haystack: any, needle: any, returnKey: boolean) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Get the current interpreter state in a text form such that it can be copied to a new device
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_dumpStr
*/
2022-07-20 15:57:03 +00:00
dumpStr: () => string;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Set the seed for the random number generator used by `Math.random()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_srand
*/
2022-07-20 15:57:03 +00:00
srand: (v: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Unlike 'Math.random()' which uses a pseudo-random number generator, this
2022-07-20 13:07:21 +00:00
* method reads from the internal voltage reference several times, xoring and
* rotating to try and make a relatively random value from the noise in the
* signal.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_hwRand
*/
2022-07-20 15:57:03 +00:00
hwRand: () => number;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Perform a standard 32 bit CRC (Cyclic redundancy check) on the supplied data (one byte at a time)
* and return the result as an unsigned integer.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_CRC32
*/
2022-07-20 15:57:03 +00:00
CRC32: (data: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Convert hue, saturation and brightness to red, green and blue (packed into an integer if `asArray==false` or an array if `asArray==true`).
2022-07-20 19:07:18 +00:00
*
* This replaces `Graphics.setColorHSB` and `Graphics.setBgColorHSB`. On devices with 24 bit colour it can
* be used as: `Graphics.setColor(E.HSBtoRGB(h, s, b))`
2022-07-20 19:07:18 +00:00
*
* You can quickly set RGB items in an Array or Typed Array using `array.set(E.HSBtoRGB(h, s, b,true), offset)`,
* which can be useful with arrays used with `require("neopixel").write`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_HSBtoRGB
*/
2022-07-20 15:57:03 +00:00
HSBtoRGB: (hue: number, sat: number, bri: number, asArray: boolean) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Set a password on the console (REPL). When powered on, Espruino will
2022-07-20 13:07:21 +00:00
* then demand a password before the console can be used. If you want to
* lock the console immediately after this you can call `E.lockConsole()`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* To remove the password, call this function with no arguments.
2022-07-20 19:07:18 +00:00
*
* **Note:** There is no protection against multiple password attempts, so someone
* could conceivably try every password in a dictionary.
2022-07-20 19:07:18 +00:00
*
* **Note:** This password is stored in memory in plain text. If someone is able
* to execute arbitrary JavaScript code on the device (eg, you use `eval` on input
* from unknown sources) or read the device's firmware then they may be able to
* obtain it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_setPassword
*/
2022-07-20 15:57:03 +00:00
setPassword: (password: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* If a password has been set with `E.setPassword()`, this will lock the console
* so the password needs to be entered to unlock it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_lockConsole
*/
2022-07-20 15:57:03 +00:00
lockConsole: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Set the time zone to be used with `Date` objects.
2022-07-20 19:07:18 +00:00
*
* For example `E.setTimeZone(1)` will be GMT+0100
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Note that `E.setTimeZone()` will have no effect when daylight savings time rules have been set with `E.setDST()`. The
* timezone value will be stored, but never used so long as DST settings are in effect.
2022-07-20 19:07:18 +00:00
*
* Time can be set with `setTime`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_setTimeZone
*/
2022-07-20 15:57:03 +00:00
setTimeZone: (zone: number) => void;
/**
* Set the daylight savings time parameters to be used with `Date` objects.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* The parameters are
*
* - dstOffset: The number of minutes daylight savings time adds to the clock (usually 60) - set to 0 to disable DST
* - timezone: The time zone, in minutes, when DST is not in effect - positive east of Greenwich
* - startDowNumber: The index of the day-of-week in the month when DST starts - 0 for first, 1 for second, 2 for third, 3 for fourth and 4 for last
* - startDow: The day-of-week for the DST start calculation - 0 for Sunday, 6 for Saturday
* - startMonth: The number of the month that DST starts - 0 for January, 11 for December
* - startDayOffset: The number of days between the selected day-of-week and the actual day that DST starts - usually 0
* - startTimeOfDay: The number of minutes elapsed in the day before DST starts
* - endDowNumber: The index of the day-of-week in the month when DST ends - 0 for first, 1 for second, 2 for third, 3 for fourth and 4 for last
* - endDow: The day-of-week for the DST end calculation - 0 for Sunday, 6 for Saturday
* - endMonth: The number of the month that DST ends - 0 for January, 11 for December
* - endDayOffset: The number of days between the selected day-of-week and the actual day that DST ends - usually 0
* - endTimeOfDay: The number of minutes elapsed in the day before DST ends
*
* To determine what the `dowNumber, dow, month, dayOffset, timeOfDay` parameters should be, start with a sentence of the form
* "DST starts on the last Sunday of March (plus 0 days) at 03:00". Since it's the last Sunday, we have startDowNumber = 4, and since
* it's Sunday, we have startDow = 0. That it is March gives us startMonth = 2, and that the offset is zero days, we have
* startDayOffset = 0. The time that DST starts gives us startTimeOfDay = 3*60.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* "DST ends on the Friday before the second Sunday in November at 02:00" would give us endDowNumber=1, endDow=0, endMonth=10, endDayOffset=-2 and endTimeOfDay=120.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Using Ukraine as an example, we have a time which is 2 hours ahead of GMT in winter (EET) and 3 hours in summer (EEST). DST starts at 03:00 EET on the last Sunday in March,
* and ends at 04:00 EEST on the last Sunday in October. So someone in Ukraine might call `E.setDST(60,120,4,0,2,0,180,4,0,9,0,240);`
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Note that when DST parameters are set (i.e. when `dstOffset` is not zero), `E.setTimeZone()` has no effect.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_setDST
*/
setDST: (params: any) => void;
/**
* Create an object where every field accesses a specific 32 bit address in the microcontroller's memory. This
* is perfect for accessing on-chip peripherals.
2022-07-20 19:07:18 +00:00
*
* ```
* // for NRF52 based chips
* var GPIO = E.memoryMap(0x50000000,{OUT:0x504, OUTSET:0x508, OUTCLR:0x50C, IN:0x510, DIR:0x514, DIRSET:0x518, DIRCLR:0x51C});
* GPIO.DIRSET = 1; // set GPIO0 to output
* GPIO.OUT ^= 1; // toggle the output state of GPIO0
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_memoryMap
*/
memoryMap: (baseAddress: any, registers: any) => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Provide assembly to Espruino.
2022-07-20 19:07:18 +00:00
*
* **This function is not part of Espruino**. Instead, it is detected
2022-07-20 13:07:21 +00:00
* by the Espruino IDE (or command-line tools) at upload time and is
* replaced with machine code and an `E.nativeCall` call.
2022-07-20 19:07:18 +00:00
*
* See [the documentation on the Assembler](http://www.espruino.com/Assembler) for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_asm
*/
2022-07-20 15:57:03 +00:00
asm: (callspec: any, assemblycode: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Provides the ability to write C code inside your JavaScript file.
2022-07-20 19:07:18 +00:00
*
* **This function is not part of Espruino**. Instead, it is detected
2022-07-20 13:07:21 +00:00
* by the Espruino IDE (or command-line tools) at upload time, is sent
* to our web service to be compiled, and is replaced with machine code
* and an `E.nativeCall` call.
2022-07-20 19:07:18 +00:00
*
* See [the documentation on Inline C](http://www.espruino.com/InlineC) for more information and examples.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_compiledC
*/
2022-07-20 15:57:03 +00:00
compiledC: (code: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Forces a hard reboot of the microcontroller - as close as possible
* to if the reset pin had been toggled.
2022-07-20 19:07:18 +00:00
*
* **Note:** This is different to `reset()`, which performs a software
2022-07-20 13:07:21 +00:00
* reset of Espruino (resetting the interpreter and pin states, but not
* all the hardware)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_reboot
*/
2022-07-20 15:57:03 +00:00
reboot: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* USB HID will only take effect next time you unplug and re-plug your Espruino. If you're
* disconnecting it from power you'll have to make sure you have `save()`d after calling
* this function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_setUSBHID
*/
2022-07-20 15:57:03 +00:00
setUSBHID: (opts: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l_E_sendUSBHID
2022-07-20 13:07:21 +00:00
*/
2022-07-20 15:57:03 +00:00
sendUSBHID: (data: any) => boolean;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* In devices that come with batteries, this function returns
* the battery charge percentage as an integer between 0 and 100.
2022-07-20 19:07:18 +00:00
*
* **Note:** this is an estimation only, based on battery voltage.
2022-07-20 13:07:21 +00:00
* The temperature of the battery (as well as the load being drawn
* from it at the time `E.getBattery` is called) will affect the
* readings.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getBattery
*/
2022-07-20 15:57:03 +00:00
getBattery: () => number;
/**
* Sets the RTC's prescaler's maximum value. This is the counter that counts up on each oscillation of the low
* speed oscillator. When the prescaler counts to the value supplied, one second is deemed to have passed.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* By default this is set to the oscillator's average speed as specified in the datasheet, and usually that is
* fine. However on early [Espruino Pico](https://espruino.com//Pico) boards the STM32F4's internal oscillator could vary by as
* much as 15% from the value in the datasheet. In that case you may want to alter this value to reflect the
* true RTC speed for more accurate timekeeping.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* To change the RTC's prescaler value to a computed value based on comparing against the high speed oscillator,
* just run the following command, making sure it's done a few seconds after the board starts up:
2022-07-20 19:07:18 +00:00
*
* ```
* E.setRTCPrescaler(E.getRTCPrescaler(true));
* ```
*
2022-07-20 15:57:03 +00:00
* When changing the RTC prescaler, the RTC 'follower' counters are reset and it can take a second or two before
* readings from getTime are stable again.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* To test, you can connect an input pin to a known frequency square wave and then use `setWatch`. If you don't
* have a frequency source handy, you can check against the high speed oscillator:
2022-07-20 19:07:18 +00:00
*
* ```
* // connect pin B3 to B4
* analogWrite(B3, 0.5, {freq:0.5});
* setWatch(function(e) {
* print(e.time - e.lastTime);
2022-07-20 15:57:03 +00:00
* }, B4, {repeat:true});
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* **Note:** This is only used on official Espruino boards containing an STM32 microcontroller. Other boards
* (even those using an STM32) don't use the RTC and so this has no effect.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_setRTCPrescaler
*/
setRTCPrescaler: (prescaler: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Gets the RTC's current prescaler value if `calibrate` is undefined or false.
2022-07-20 19:07:18 +00:00
*
* If `calibrate` is true, the low speed oscillator's speed is calibrated against the high speed
* oscillator (usually +/- 20 ppm) and a suggested value to be fed into `E.setRTCPrescaler(...)` is returned.
2022-07-20 19:07:18 +00:00
*
* See `E.setRTCPrescaler` for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_E_getRTCPrescaler
*/
2022-07-20 15:57:03 +00:00
getRTCPrescaler: (calibrate: boolean) => number;
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
/**
* Decode a UTF8 string.
*
* - Any decoded character less than 256 gets passed straight through
* - Otherwise if `lookup` is an array and an item with that char code exists in `lookup` then that is used
* - Otherwise if `lookup` is an object and an item with that char code (as lowercase hex) exists in `lookup` then that is used
* - Otherwise `replaceFn(charCode)` is called and the result used if `replaceFn` is a function
* - If `replaceFn` is a string, that is used
* - Or finally if nothing else matches, the character is ignored
*
* For instance:
2022-07-20 19:07:18 +00:00
*
* ```
* let unicodeRemap = {
* 0x20ac:"\u0080", // Euro symbol
* 0x2026:"\u0085", // Ellipsis
2022-07-20 15:57:03 +00:00
* };
2022-07-20 19:07:18 +00:00
* E.decodeUTF8("UTF-8 Euro: \u00e2\u0082\u00ac", unicodeRemap, &#x27;[?]&#x27;) == "UTF-8 Euro: \u0080"
* ```
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l_E_decodeUTF8
*/
decodeUTF8: (str: any, lookup: any, replaceFn: any) => any;
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* Creates an InternalError object
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l_InternalError_InternalError
*/
declare function InternalError(message: any): any;
type InternalError = {
}
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This is the built-in class for the Arduino-style pin namings on ST Nucleo boards
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#Nucleo
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const Nucleo: {
/**
* @url http://www.espruino.com/Reference#l_Nucleo_A0
*/
A0: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_A1
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
A1: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_A2
*/
A2: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_A3
*/
A3: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_A4
*/
A4: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_A5
*/
A5: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D0
*/
D0: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D1
*/
D1: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D2
*/
D2: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D3
*/
D3: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D4
*/
D4: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D5
*/
D5: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D6
*/
D6: Pin
/**
* @url http://www.espruino.com/Reference#l_Nucleo_D7
*/
D7: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D8
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D8: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D9
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D9: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D10
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D10: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D11
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D11: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D12
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D12: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D13
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D13: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D14
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D14: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Nucleo_D15
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
D15: Pin
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* This is a built-in class to allow you to use the ESP8266 NodeMCU boards's pin namings to access pins. It is only available on ESP8266-based boards.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#NodeMCU
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const NodeMCU: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_A0
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
A0: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D0
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D0: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D1
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D1: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D2
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D2: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D3
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D3: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D4
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D4: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l_NodeMCU_D5
*/
D5: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D6
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D6: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D7
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D7: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D8
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D8: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D9
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D9: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NodeMCU_D10
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
D10: Pin
2022-07-20 13:07:21 +00:00
2022-07-20 15:57:03 +00:00
};
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Class containing utility functions for the [ESP32](http://www.espruino.com/ESP32)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#ESP32
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare const ESP32: {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP32_setAtten
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
setAtten: (pin: Pin, atten: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Perform a hardware reset/reboot of the ESP32.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP32_reboot
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
reboot: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Put device in deepsleep state for "us" microseconds.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP32_deepSleep
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
deepSleep: (us: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Returns an object that contains details about the state of the ESP32 with the following fields:
*
* - `sdkVersion` - Version of the SDK.
* - `freeHeap` - Amount of free heap in bytes.
* - `BLE` - Status of BLE, enabled if true.
* - `Wifi` - Status of Wifi, enabled if true.
* - `minHeap` - Minimum heap, calculated by heap_caps_get_minimum_free_size
*
* @url http://www.espruino.com/Reference#l_ESP32_getState
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getState: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP32_setBLE_Debug
2022-07-20 13:35:57 +00:00
*/
2022-07-20 18:35:57 +00:00
setBLE_Debug: (level: number) => void;
2022-07-20 13:35:57 +00:00
2022-07-20 15:57:03 +00:00
/**
2022-07-20 18:35:57 +00:00
* Switches Bluetooth off/on, removes saved code from Flash, resets the board,
* and on restart creates jsVars depending on available heap (actual additional 1800)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP32_enableBLE
2022-07-20 15:57:03 +00:00
*/
2022-07-20 18:35:57 +00:00
enableBLE: (enable: boolean) => void;
2022-07-20 15:57:03 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Switches Wifi off/on, removes saved code from Flash, resets the board,
* and on restart creates jsVars depending on available heap (actual additional 3900)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_ESP32_enableWifi
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
enableWifi: (enable: boolean) => void;
};
/**
* Creates a Queue Object
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Queue_Queue
*/
declare function Queue(queueName: any): any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type Queue = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* reads one character from queue, if available
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Queue_read
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
read: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Writes one character to queue
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Queue_writeChar
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
writeChar: (char: any) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* logs list of queues
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Queue_log
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
log: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Creates a Task Object
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Task_Task
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function Task(taskName: any): any;
type Task = {
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Suspend task, be careful not to suspend Espruino task itself
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Task_suspend
2022-07-20 13:35:57 +00:00
*/
2022-07-20 18:35:57 +00:00
suspend: () => void;
2022-07-20 13:35:57 +00:00
2022-07-20 18:35:57 +00:00
/**
* Resumes a suspended task
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Task_resume
*/
resume: () => void;
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* returns name of actual task
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Task_getCurrent
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
getCurrent: () => any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Sends a binary notify to task
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Task_notify
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
notify: () => void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* logs list of tasks
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Task_log
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
log: () => void;
2022-07-20 13:07:21 +00:00
}
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* Creates a Timer Object
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Timer_Timer
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function Timer(timerName: any, group: number, index: number, isrIndex: number): any;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
type Timer = {
/**
* Starts a timer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Timer_start
*/
start: (duration: number) => void;
2022-07-20 13:07:21 +00:00
2022-07-20 18:35:57 +00:00
/**
* Reschedules a timer, needs to be started at least once
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Timer_reschedule
*/
reschedule: (duration: number) => void;
/**
* logs list of timers
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Timer_log
*/
log: () => void;
}
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Note:** This function is only available on the [BBC micro:bit](https://espruino.com//MicroBit) board
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Show an image on the in-built 5x5 LED screen.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Image can be:
*
* - A number where each bit represents a pixel (so 25 bits). eg. `5` or `0x1FFFFFF`
* - A string, eg: `show("10001")`. Newlines are ignored, and anything that is not
* a space or `0` is treated as a 1.
* - An array of 4 bytes (more will be ignored), eg `show([1,2,3,0])`
*
* For instance the following works for images:
2022-07-20 19:07:18 +00:00
*
* ```
* show("# #"+
* " # "+
* " # "+
* "# #"+
* " ### ")
* ```
*
2022-07-20 18:35:57 +00:00
* This means you can also use Espruino's graphics library:
2022-07-20 19:07:18 +00:00
*
* ```
* var g = Graphics.createArrayBuffer(5,5,1)
* g.drawString("E",0,0)
* show(g.buffer)
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_show
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function show(image: any): void;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Note:** This function is only available on the [BBC micro:bit](https://espruino.com//MicroBit) board
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Get the current acceleration of the micro:bit from the on-board accelerometer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **This is deprecated.** Please use `Microbit.accel` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_acceleration
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function acceleration(): any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
2022-07-20 18:35:57 +00:00
* **Note:** This function is only available on the [BBC micro:bit](https://espruino.com//MicroBit) board
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Get the current compass position for the micro:bit from the on-board magnetometer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **This is deprecated.** Please use `Microbit.mag` instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_compass
2022-07-20 13:07:21 +00:00
*/
2022-07-20 18:35:57 +00:00
declare function compass(): any;
2022-07-20 13:07:21 +00:00
2022-07-20 13:35:57 +00:00
/**
* The pin connected to the 'A' button. Reads as `1` when pressed, `0` when not
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_BTNA
*/
declare const BTNA: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to the 'B' button. Reads as `1` when pressed, `0` when not
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_BTNB
*/
declare const BTNB: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to the up button. Reads as `1` when pressed, `0` when not
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_BTNU
*/
declare const BTNU: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to the down button. Reads as `1` when pressed, `0` when not
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_BTND
*/
declare const BTND: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to the left button. Reads as `1` when pressed, `0` when not
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_BTNL
*/
declare const BTNL: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to the right button. Reads as `1` when pressed, `0` when not
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_BTNR
*/
declare const BTNR: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to Corner #1
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_CORNER1
*/
declare const CORNER1: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to Corner #2
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_CORNER2
*/
declare const CORNER2: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to Corner #3
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_CORNER3
*/
declare const CORNER3: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to Corner #4
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_CORNER4
*/
declare const CORNER4: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to Corner #5
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_CORNER5
*/
declare const CORNER5: Pin;
2022-07-20 13:35:57 +00:00
/**
* The pin connected to Corner #6
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_CORNER6
*/
declare const CORNER6: Pin;
2022-07-20 18:35:57 +00:00
/**
* On Puck.js V2 (not v1.0) this is the pin that controls the FET, for high-powered outputs.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_FET
*/
declare const FET: Pin;
/**
* The pin marked SDA on the Arduino pin footprint. This is connected directly to pin A4.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_SDA
*/
declare const SDA: Pin;
/**
* The pin marked SDA on the Arduino pin footprint. This is connected directly to pin A5.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_SCL
*/
declare const SCL: Pin;
2022-07-20 13:35:57 +00:00
/**
* The Bangle.js's vibration motor.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_VIBRATE
*/
declare const VIBRATE: Pin;
2022-07-20 13:35:57 +00:00
/**
* On most Espruino board there are LEDs, in which case `LED` will be an actual Pin.
2022-07-20 19:07:18 +00:00
*
* On Bangle.js there are no LEDs, so to remain compatible with example code that might
2022-07-20 13:07:21 +00:00
* expect an LED, this is an object that behaves like a pin, but which just displays
* a circle on the display
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_LED
*/
declare const LED: any;
2022-07-20 13:35:57 +00:00
/**
* On most Espruino board there are LEDs, in which case `LED1` will be an actual Pin.
2022-07-20 19:07:18 +00:00
*
* On Bangle.js there are no LEDs, so to remain compatible with example code that might
2022-07-20 13:07:21 +00:00
* expect an LED, this is an object that behaves like a pin, but which just displays
* a circle on the display
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_LED1
*/
declare const LED1: any;
2022-07-20 13:35:57 +00:00
/**
* On most Espruino board there are LEDs, in which case `LED2` will be an actual Pin.
2022-07-20 19:07:18 +00:00
*
* On Bangle.js there are no LEDs, so to remain compatible with example code that might
2022-07-20 13:07:21 +00:00
* expect an LED, this is an object that behaves like a pin, but which just displays
* a circle on the display
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_LED2
*/
declare const LED2: any;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_MOS1
2022-07-20 13:07:21 +00:00
*/
declare const MOS1: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_MOS2
2022-07-20 13:07:21 +00:00
*/
declare const MOS2: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_MOS3
2022-07-20 13:07:21 +00:00
*/
declare const MOS3: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_MOS4
2022-07-20 13:07:21 +00:00
*/
declare const MOS4: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_IOEXT0
2022-07-20 13:07:21 +00:00
*/
declare const IOEXT0: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_IOEXT1
2022-07-20 13:07:21 +00:00
*/
declare const IOEXT1: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_IOEXT2
2022-07-20 13:07:21 +00:00
*/
declare const IOEXT2: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_IOEXT3
2022-07-20 13:07:21 +00:00
*/
declare const IOEXT3: Pin;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_HIGH
2022-07-20 13:07:21 +00:00
*/
declare const HIGH: number;
2022-07-20 13:35:57 +00:00
/**
* @url http://www.espruino.com/Reference#l__global_LOW
2022-07-20 13:07:21 +00:00
*/
declare const LOW: number;
2022-07-20 18:35:57 +00:00
/**
* A variable containing the arguments given to the function:
2022-07-20 19:07:18 +00:00
*
* ```
* function hello() {
* console.log(arguments.length, JSON.stringify(arguments));
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* hello() // 0 []
* hello("Test") // 1 ["Test"]
* hello(1,2,3) // 3 [1,2,3]
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** Due to the way Espruino works this is doesn't behave exactly
* the same as in normal JavaScript. The length of the arguments array
* will never be less than the number of arguments specified in the
* function declaration: `(function(a){ return arguments.length; })() == 1`.
* Normal JavaScript interpreters would return `0` in the above case.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_arguments
*/
declare const arguments: any;
/**
* Load the given module, and return the exported functions and variables.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* For example:
2022-07-20 19:07:18 +00:00
*
* ```
* var s = require("Storage");
* s.write("test", "hello world");
* print(s.read("test"));
* // prints "hello world"
* ```
*
2022-07-20 18:35:57 +00:00
* Check out [the page on Modules](https://espruino.com//Modules) for an explanation
* of what modules are and how you can use them.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l__global_require
*/
declare function require<T extends keyof Modules>(moduleName: T): Modules[T];
declare function require<T extends Exclude<string, keyof Modules>>(moduleName: T): any;
2022-07-20 13:35:57 +00:00
/**
* Read 8 bits of memory at the given location - DANGEROUS!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_peek8
*/
declare function peek8(addr: number, count: number): any;
2022-07-20 13:35:57 +00:00
/**
* Write 8 bits of memory at the given location - VERY DANGEROUS!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_poke8
*/
declare function poke8(addr: number, value: any): void;
2022-07-20 13:35:57 +00:00
/**
* Read 16 bits of memory at the given location - DANGEROUS!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_peek16
*/
declare function peek16(addr: number, count: number): any;
2022-07-20 13:35:57 +00:00
/**
* Write 16 bits of memory at the given location - VERY DANGEROUS!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_poke16
*/
declare function poke16(addr: number, value: any): void;
2022-07-20 13:35:57 +00:00
/**
* Read 32 bits of memory at the given location - DANGEROUS!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_peek32
*/
declare function peek32(addr: number, count: number): any;
2022-07-20 13:35:57 +00:00
/**
* Write 32 bits of memory at the given location - VERY DANGEROUS!
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_poke32
*/
declare function poke32(addr: number, value: any): void;
2022-07-20 13:35:57 +00:00
/**
* Get the analog value of the given pin
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* This is different to Arduino which only returns an integer between 0 and 1023
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* However only pins connected to an ADC will work (see the datasheet)
2022-07-20 19:07:18 +00:00
*
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset pin's state to `"analog"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_analogRead
*/
declare function analogRead(pin: Pin): number;
2022-07-20 13:35:57 +00:00
/**
* Set the analog Value of a pin. It will be output using PWM.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* Objects can contain:
*
* - `freq` - pulse frequency in Hz, eg. `analogWrite(A0,0.5,{ freq : 10 });` - specifying a frequency will force PWM output, even if the pin has a DAC
* - `soft` - boolean, If true software PWM is used if hardware is not available.
* - `forceSoft` - boolean, If true software PWM is used even if hardware PWM or a DAC is available
*
2022-07-20 15:57:03 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_analogWrite
*/
declare function analogWrite(pin: Pin, value: number, options: any): void;
2022-07-20 13:35:57 +00:00
/**
* Pulse the pin with the value for the given time in milliseconds. It uses a hardware timer to produce accurate pulses, and returns immediately (before the pulse has finished). Use `digitalPulse(A0,1,0)` to wait until a previous pulse has finished.
2022-07-20 19:07:18 +00:00
*
* eg. `digitalPulse(A0,1,5);` pulses A0 high for 5ms. `digitalPulse(A0,1,[5,2,4]);` pulses A0 high for 5ms, low for 2ms, and high for 4ms
2022-07-20 19:07:18 +00:00
*
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
* digitalPulse is for SHORT pulses that need to be very accurate. If you're doing anything over a few milliseconds, use setTimeout instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_digitalPulse
*/
declare function digitalPulse(pin: Pin, value: boolean, time: any): void;
2022-07-20 13:35:57 +00:00
/**
* Set the digital value of the given pin.
2022-07-20 19:07:18 +00:00
*
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset pin's state to `"output"`
2022-07-20 19:07:18 +00:00
*
* If pin argument is an array of pins (eg. `[A2,A1,A0]`) the value argument will be treated
* as an array of bits where the last array element is the least significant bit.
2022-07-20 19:07:18 +00:00
*
* In this case, pin values are set least significant bit first (from the right-hand side
2022-07-20 13:07:21 +00:00
* of the array of pins). This means you can use the same pin multiple times, for
* example `digitalWrite([A1,A1,A0,A0],0b0101)` would pulse A0 followed by A1.
2022-07-20 19:07:18 +00:00
*
* If the pin argument is an object with a `write` method, the `write` method will
* be called with the value passed through.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_digitalWrite
*/
declare function digitalWrite(pin: Pin, value: number): void;
2022-07-20 13:35:57 +00:00
/**
* Get the digital value of the given pin.
2022-07-20 19:07:18 +00:00
*
* **Note:** if you didn't call `pinMode` beforehand then this function will also reset pin's state to `"input"`
2022-07-20 19:07:18 +00:00
*
* If the pin argument is an array of pins (eg. `[A2,A1,A0]`) the value returned will be an number where
* the last array element is the least significant bit, for example if `A0=A1=1` and `A2=0`, `digitalRead([A2,A1,A0]) == 0b011`
2022-07-20 19:07:18 +00:00
*
* If the pin argument is an object with a `read` method, the `read` method will be called and the integer value it returns
* passed back.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_digitalRead
*/
declare function digitalRead(pin: Pin): number;
2022-07-20 13:35:57 +00:00
/**
* Set the mode of the given pin.
*
* - `auto`/`undefined` - Don't change state, but allow `digitalWrite`/etc to automatically change state as appropriate
* - `analog` - Analog input
* - `input` - Digital input
* - `input_pullup` - Digital input with internal ~40k pull-up resistor
* - `input_pulldown` - Digital input with internal ~40k pull-down resistor
* - `output` - Digital output
* - `opendrain` - Digital output that only ever pulls down to 0v. Sending a logical `1` leaves the pin open circuit
* - `opendrain_pullup` - Digital output that pulls down to 0v. Sending a logical `1` enables internal ~40k pull-up resistor
* - `af_output` - Digital output from built-in peripheral
* - `af_opendrain` - Digital output from built-in peripheral that only ever pulls down to 0v. Sending a logical `1` leaves the pin open circuit
2022-07-20 15:57:03 +00:00
*
* **Note:** `digitalRead`/`digitalWrite`/etc set the pin mode automatically *unless* `pinMode` has been called first.
* If you want `digitalRead`/etc to set the pin mode automatically after you have called `pinMode`, simply call it again
* with no mode argument (`pinMode(pin)`), `auto` as the argument (`pinMode(pin, "auto")`), or with the 3rd 'automatic'
* argument set to true (`pinMode(pin, "output", true)`).
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_pinMode
*/
declare function pinMode(pin: Pin, mode: any, automatic: boolean): void;
2022-07-20 13:35:57 +00:00
/**
* Return the current mode of the given pin. See `pinMode` for more information on returned values.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_getPinMode
*/
declare function getPinMode(pin: Pin): any;
2022-07-20 15:57:03 +00:00
/**
* Shift an array of data out using the pins supplied *least significant bit first*,
* for example:
2022-07-20 19:07:18 +00:00
*
* ```
* // shift out to single clk+data
* shiftOut(A0, { clk : A1 }, [1,0,1,0]);
* ```
*
* ```
* // shift out a whole byte (like software SPI)
* shiftOut(A0, { clk : A1, repeat: 8 }, [1,2,3,4]);
* ```
*
* ```
* // shift out via 4 data pins
* shiftOut([A3,A2,A1,A0], { clk : A4 }, [1,2,3,4]);
* ```
*
2022-07-20 15:57:03 +00:00
* `options` is an object of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* clk : pin, // a pin to use as the clock (undefined = no pin)
* clkPol : bool, // clock polarity - default is 0 (so 1 normally, pulsing to 0 to clock data in)
* repeat : int, // number of clocks per array item
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* Each item in the `data` array will be output to the pins, with the first
* pin in the array being the MSB and the last the LSB, then the clock will be
* pulsed in the polarity given.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* `repeat` is the amount of times shift data out for each array item. For instance
* we may want to shift 8 bits out through 2 pins - in which case we need to set
* repeat to 4.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l__global_shiftOut
*/
declare function shiftOut(pins: any, options: any, data: any): void;
/**
* Call the function specified when the pin changes. Watches set with `setWatch` can be removed using `clearWatch`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* If the `options` parameter is an object, it can contain the following information (all optional):
2022-07-20 19:07:18 +00:00
*
* ```
* {
* // Whether to keep producing callbacks, or remove the watch after the first callback
* repeat: true/false(default),
* // Trigger on the rising or falling edge of the signal. Can be a string, or 1=&#x27;rising&#x27;, -1=&#x27;falling&#x27;, 0=&#x27;both&#x27;
* edge:&#x27;rising&#x27;(default for built-in buttons)/&#x27;falling&#x27;/&#x27;both&#x27;(default for pins),
* // Use software-debouncing to stop multiple calls if a switch bounces
* // This is the time in milliseconds to wait for bounces to subside, or 0 to disable
* debounce:10 (0 is default for pins, 25 is default for built-in buttons),
* // Advanced: If the function supplied is a &#x27;native&#x27; function (compiled or assembly)
* // setting irq:true will call that function in the interrupt itself
* irq : false(default)
* // Advanced: If specified, the given pin will be read whenever the watch is called
* // and the state will be included as a &#x27;data&#x27; field in the callback
2022-07-20 15:57:03 +00:00
* data : pin
2022-07-20 19:07:18 +00:00
* // Advanced: On Nordic devices, a watch may be &#x27;high&#x27; or &#x27;low&#x27; accuracy. By default low
* // accuracy is used (which is better for power consumption), but this means that
* // high speed pulses (less than 25us) may not be reliably received. Setting hispeed=true
* // allows for detecting high speed pulses at the expense of higher idle power consumption
* hispeed : true
2022-07-20 15:57:03 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 15:57:03 +00:00
* The `function` callback is called with an argument, which is an object of type `{state:bool, time:float, lastTime:float}`.
*
* - `state` is whether the pin is currently a `1` or a `0`
* - `time` is the time in seconds at which the pin changed state
* - `lastTime` is the time in seconds at which the **pin last changed state**. When using `edge:'rising'` or `edge:'falling'`, this is not the same as when the function was last called.
* - `data` is included if `data:pin` was specified in the options, and can be used for reading in clocked data
*
* For instance, if you want to measure the length of a positive pulse you could use `setWatch(function(e) { console.log(e.time-e.lastTime); }, BTN, { repeat:true, edge:'falling' });`.
* This will only be called on the falling edge of the pulse, but will be able to measure the width of the pulse because `e.lastTime` is the time of the rising edge.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* Internally, an interrupt writes the time of the pin's state change into a queue with the exact
* time that it happened, and the function supplied to `setWatch` is executed only from the main
* message loop. However, if the callback is a native function `void (bool state)` then you can
* add `irq:true` to options, which will cause the function to be called from within the IRQ.
* When doing this, interrupts will happen on both edges and there will be no debouncing.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** if you didn't call `pinMode` beforehand then this function will reset pin's state to `"input"`
2022-07-20 19:07:18 +00:00
*
* **Note:** The STM32 chip (used in the [Espruino Board](https://espruino.com//EspruinoBoard) and [Pico](https://espruino.com//Pico)) cannot
2022-07-20 15:57:03 +00:00
* watch two pins with the same number - eg `A0` and `B0`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* **Note:** On nRF52 chips (used in Puck.js, Pixl.js, MDBT42Q) `setWatch` disables the GPIO
* output on that pin. In order to be able to write to the pin again you need to disable
* the watch with `clearWatch`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l__global_setWatch
*/
declare function setWatch(fn: any, pin: Pin, options: any): any;
2022-07-20 13:35:57 +00:00
/**
* Clear the Watch that was created with setWatch. If no parameter is supplied, all watches will be removed.
2022-07-20 19:07:18 +00:00
*
* To avoid accidentally deleting all Watches, if a parameter is supplied but is `undefined` then an Exception will be thrown.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_clearWatch
*/
declare function clearWatch(id: any): void;
2022-07-20 13:35:57 +00:00
/**
* When Espruino is busy, set the pin specified here high. Set this to undefined to disable the feature.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_setBusyIndicator
*/
declare function setBusyIndicator(pin: Pin): void;
2022-07-20 13:35:57 +00:00
/**
* When Espruino is asleep, set the pin specified here low (when it's awake, set it high). Set this to undefined to disable the feature.
2022-07-20 19:07:18 +00:00
*
* Please see [http://www.espruino.com/Power+Consumption](http://www.espruino.com/Power+Consumption) for more details on this.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_setSleepIndicator
*/
declare function setSleepIndicator(pin: Pin): void;
2022-07-20 13:35:57 +00:00
/**
* Set whether we can enter deep sleep mode, which reduces power consumption to around 100uA. This only works on STM32 Espruino Boards (nRF52 boards sleep automatically).
2022-07-20 19:07:18 +00:00
*
* Please see [http://www.espruino.com/Power+Consumption](http://www.espruino.com/Power+Consumption) for more details on this.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_setDeepSleep
*/
declare function setDeepSleep(sleep: boolean): void;
2022-07-20 13:35:57 +00:00
/**
* Output debugging information
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* Note: This is not included on boards with low amounts of flash memory, or the Espruino board.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_trace
*/
declare function trace(root: any): void;
2022-07-20 13:35:57 +00:00
/**
* Output current interpreter state in a text form such that it can be copied to a new device
2022-07-20 19:07:18 +00:00
*
* Espruino keeps its current state in RAM (even if the function code is stored in Flash). When you type `dump()` it dumps the current state of code in RAM plus the hardware state, then if there's code saved in flash it writes "// Code saved with E.setBootCode" and dumps that too.
2022-07-20 19:07:18 +00:00
*
* **Note:** 'Internal' functions are currently not handled correctly. You will need to recreate these in the `onInit` function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_dump
*/
declare function dump(): void;
2022-07-20 13:35:57 +00:00
/**
* Restart and load the program out of flash - this has an effect similar to
2022-07-20 13:07:21 +00:00
* completely rebooting Espruino (power off/power on), but without actually
* performing a full reset of the hardware.
2022-07-20 19:07:18 +00:00
*
* This command only executes when the Interpreter returns to the Idle state - for
* instance `a=1;load();a=2;` will still leave 'a' as undefined (or what it was
* set to in the saved program).
2022-07-20 19:07:18 +00:00
*
* Espruino will resume from where it was when you last typed `save()`.
2022-07-20 13:07:21 +00:00
* If you want code to be executed right after loading (for instance to initialise
* devices connected to Espruino), add an `init` event handler to `E` with
* `E.on('init', function() { ... your_code ... });`. This will then be automatically
* executed by Espruino every time it starts.
2022-07-20 19:07:18 +00:00
*
* **If you specify a filename in the argument then that file will be loaded
* from Storage after reset** in much the same way as calling `reset()` then `eval(require("Storage").read(filename))`
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_load
*/
declare function load(filename: any): void;
2022-07-20 13:35:57 +00:00
/**
* Save the state of the interpreter into flash (including the results of calling
* `setWatch`, `setInterval`, `pinMode`, and any listeners). The state will then be loaded automatically
* every time Espruino powers on or is hard-reset. To see what will get saved you can call `dump()`.
2022-07-20 19:07:18 +00:00
*
* **Note:** If you set up intervals/etc in `onInit()` and you have already called `onInit`
* before running `save()`, when Espruino resumes there will be two copies of your intervals -
* the ones from before the save, and the ones from after - which may cause you problems.
2022-07-20 19:07:18 +00:00
*
* For more information about this and other options for saving, please see
* the [Saving code on Espruino](https://www.espruino.com/Saving) page.
2022-07-20 19:07:18 +00:00
*
* This command only executes when the Interpreter returns to the Idle state - for
* instance `a=1;save();a=2;` will save 'a' as 2.
2022-07-20 19:07:18 +00:00
*
* When Espruino powers on, it will resume from where it was when you typed `save()`.
2022-07-20 13:07:21 +00:00
* If you want code to be executed right after loading (for instance to initialise
* devices connected to Espruino), add a function called `onInit`, or add a `init`
* event handler to `E` with `E.on('init', function() { ... your_code ... });`.
* This will then be automatically executed by Espruino every time it starts.
2022-07-20 19:07:18 +00:00
*
* In order to stop the program saved with this command being loaded automatically,
* check out [the Troubleshooting guide](https://www.espruino.com/Troubleshooting#espruino-stopped-working-after-i-typed-save-)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_save
*/
declare function save(): void;
2022-07-20 13:35:57 +00:00
/**
* Reset the interpreter - clear program memory in RAM, and do not load a saved program from flash. This does NOT reset the underlying hardware (which allows you to reset the device without it disconnecting from USB).
2022-07-20 19:07:18 +00:00
*
* This command only executes when the Interpreter returns to the Idle state - for instance `a=1;reset();a=2;` will still leave 'a' as undefined.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* The safest way to do a full reset is to hit the reset button.
2022-07-20 19:07:18 +00:00
*
* If `reset()` is called with no arguments, it will reset the board's state in
2022-07-20 13:07:21 +00:00
* RAM but will not reset the state in flash. When next powered on (or when
* `load()` is called) the board will load the previously saved code.
2022-07-20 19:07:18 +00:00
*
* Calling `reset(true)` will cause *all saved code in flash memory to
* be cleared as well*.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_reset
*/
declare function reset(clearFlash: boolean): void;
2022-07-20 13:35:57 +00:00
/**
* Print the supplied string(s) to the console
2022-07-20 19:07:18 +00:00
*
* **Note:** If you're connected to a computer (not a wall adaptor) via USB but **you are not running a terminal app** then when you print data Espruino may pause execution and wait until the computer requests the data it is trying to print.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_print
2022-07-19 07:49:47 +00:00
*/
2022-07-20 13:07:21 +00:00
declare function print(text: any): void;
2022-07-19 07:49:47 +00:00
2022-07-20 13:35:57 +00:00
/**
* Fill the console with the contents of the given function, so you can edit it.
2022-07-20 19:07:18 +00:00
*
* NOTE: This is a convenience function - it will not edit 'inner functions'. For that, you must edit the 'outer function' and re-execute it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_edit
*/
declare function edit(funcName: any): void;
2022-07-19 07:49:47 +00:00
2022-07-20 13:35:57 +00:00
/**
* Should Espruino echo what you type back to you? true = yes (Default), false = no. When echo is off, the result of executing a command is not returned. Instead, you must use 'print' to send output.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_echo
*/
declare function echo(echoOn: boolean): void;
2022-07-19 07:49:47 +00:00
2022-07-20 13:35:57 +00:00
/**
* Return the current system time in Seconds (as a floating point number)
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_getTime
*/
declare function getTime(): number;
2022-07-19 07:49:47 +00:00
2022-07-20 15:57:03 +00:00
/**
* Set the current system time in seconds (`time` can be a floating
* point value).
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* This is used with `getTime`, the time reported from `setWatch`, as
* well as when using `new Date()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* `Date.prototype.getTime()` reports the time in milliseconds, so
* you can set the time to a `Date` object using:
2022-07-20 19:07:18 +00:00
*
* ```
* setTime((new Date("Tue, 19 Feb 2019 10:57")).getTime()/1000)
* ```
*
2022-07-20 15:57:03 +00:00
* To set the timezone for all new Dates, use `E.setTimeZone(hours)`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 15:57:03 +00:00
* @url http://www.espruino.com/Reference#l__global_setTime
*/
declare function setTime(time: number): void;
2022-07-20 13:35:57 +00:00
/**
* Get the serial number of this board
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_getSerial
*/
declare function getSerial(): any;
2022-07-19 07:49:47 +00:00
2022-07-20 13:35:57 +00:00
/**
* Change the Interval on a callback created with `setInterval`, for example:
2022-07-20 19:07:18 +00:00
*
* `var id = setInterval(function () { print('foo'); }, 1000); // every second`
2022-07-20 19:07:18 +00:00
*
* `changeInterval(id, 1500); // now runs every 1.5 seconds`
2022-07-20 19:07:18 +00:00
*
* This takes effect immediately and resets the timeout, so in the example above,
* regardless of when you call `changeInterval`, the next interval will occur 1500ms
* after it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 13:07:21 +00:00
* @url http://www.espruino.com/Reference#l__global_changeInterval
*/
declare function changeInterval(id: any, time: number): void;
2022-07-20 15:57:03 +00:00
2022-07-20 18:35:57 +00:00
type Modules = {
tensorflow: {
/**
* @url http://www.espruino.com/Reference#l_tensorflow_create
*/
create: (arenaSize: number, model: any) => TFMicroInterpreter;
};
fs: {
/**
* List all files in the supplied directory, returning them as an array of strings.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_readdir
*/
readdir: (path: any) => any;
/**
* List all files in the supplied directory, returning them as an array of strings.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_readdirSync
*/
readdirSync: (path: any) => any;
/**
* Write the data to the given file
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_writeFile
*/
writeFile: (path: any, data: any) => boolean;
/**
* Write the data to the given file
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_writeFileSync
*/
writeFileSync: (path: any, data: any) => boolean;
/**
* Append the data to the given file, created a new file if it doesn't exist
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_appendFile
*/
appendFile: (path: any, data: any) => boolean;
/**
* Append the data to the given file, created a new file if it doesn't exist
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_appendFileSync
*/
appendFileSync: (path: any, data: any) => boolean;
/**
* Read all data from a file and return as a string
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_readFile
*/
readFile: (path: any) => any;
/**
* Read all data from a file and return as a string.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** The size of files you can load using this method is limited by the amount of available RAM. To read files a bit at a time, see the `File` class.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_readFileSync
*/
readFileSync: (path: any) => any;
/**
* Delete the given file
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_unlink
*/
unlink: (path: any) => boolean;
/**
* Delete the given file
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_unlinkSync
*/
unlinkSync: (path: any) => boolean;
/**
* Return information on the given file. This returns an object with the following
* fields:
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* size: size in bytes
* dir: a boolean specifying if the file is a directory or not
* mtime: A Date structure specifying the time the file was last modified
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_statSync
*/
statSync: (path: any) => any;
/**
* Create the directory
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_mkdir
*/
mkdir: (path: any) => boolean;
/**
* Create the directory
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_fs_mkdirSync
*/
mkdirSync: (path: any) => boolean;
/**
* @url http://www.espruino.com/Reference#l_fs_pipe
*/
pipe: (source: any, destination: any, options: any) => void;
};
crypto: {
/**
* Class containing AES encryption/decryption
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_AES
*/
AES: any
/**
* Performs a SHA1 hash and returns the result as a 20 byte ArrayBuffer.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** On some boards (currently only Espruino Original) there
* isn't space for a fully unrolled SHA1 implementation so a slower
* all-JS implementation is used instead.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_SHA1
*/
SHA1: (message: any) => ArrayBuffer;
/**
* Performs a SHA224 hash and returns the result as a 28 byte ArrayBuffer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_SHA224
*/
SHA224: (message: any) => ArrayBuffer;
/**
* Performs a SHA256 hash and returns the result as a 32 byte ArrayBuffer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_SHA256
*/
SHA256: (message: any) => ArrayBuffer;
/**
* Performs a SHA384 hash and returns the result as a 48 byte ArrayBuffer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_SHA384
*/
SHA384: (message: any) => ArrayBuffer;
/**
* Performs a SHA512 hash and returns the result as a 64 byte ArrayBuffer
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_SHA512
*/
SHA512: (message: any) => ArrayBuffer;
/**
* Password-Based Key Derivation Function 2 algorithm, using SHA512
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_crypto_PBKDF2
*/
PBKDF2: (passphrase: any, salt: any, options: any) => ArrayBuffer;
};
NetworkJS: {
/**
* Initialise the network using the callbacks given and return the first argument. For instance:
2022-07-20 19:07:18 +00:00
*
* ```
* require("NetworkJS").create({
* create : function(host, port, socketType, options) {
* // Create a socket and return its index, host is a string, port is an integer.
* // If host isn&#x27;t defined, create a server socket
* console.log("Create",host,port);
* return 1;
2022-07-20 18:35:57 +00:00
* },
2022-07-20 19:07:18 +00:00
* close : function(sckt) {
* // Close the socket. returns nothing
2022-07-20 18:35:57 +00:00
* },
2022-07-20 19:07:18 +00:00
* accept : function(sckt) {
* // Accept the connection on the server socket. Returns socket number or -1 if no connection
* return -1;
2022-07-20 18:35:57 +00:00
* },
2022-07-20 19:07:18 +00:00
* recv : function(sckt, maxLen, socketType) {
* // Receive data. Returns a string (even if empty).
* // If non-string returned, socket is then closed
* return null;//or "";
2022-07-20 18:35:57 +00:00
* },
2022-07-20 19:07:18 +00:00
* send : function(sckt, data, socketType) {
* // Send data (as string). Returns the number of bytes sent - 0 is ok.
* // Less than 0
* return data.length;
2022-07-20 18:35:57 +00:00
* }
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* `socketType` is an integer - 2 for UDP, or see SocketType in [https://github.com/espruino/Espruino/blob/master/libs/network/network.h](https://github.com/espruino/Espruino/blob/master/libs/network/network.h)
* for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_NetworkJS_create
*/
create: (obj: any) => any;
};
TelnetServer: {
/**
* @url http://www.espruino.com/Reference#l_TelnetServer_setOptions
*/
setOptions: (options: any) => void;
};
net: {
/**
* Create a Server
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When a request to the server is made, the callback is called. In the callback you can use the methods on the connection to send data. You can also add `connection.on('data',function() { ... })` to listen for received data
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_net_createServer
*/
createServer: (callback: any) => Server;
/**
* Create a TCP socket connection
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_net_connect
*/
connect: (options: any, callback: any) => Socket;
};
dgram: {
/**
* Create a UDP socket
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_dgram_createSocket
*/
createSocket: (type: any, callback: any) => dgramSocket;
};
tls: {
/**
* Create a socket connection using TLS
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Options can have `ca`, `key` and `cert` fields, which should be the decoded content of the certificate.
2022-07-20 19:07:18 +00:00
*
* ```
* var options = url.parse("localhost:1234");
* options.key = atob("MIIJKQ ... OZs08C");
* options.cert = atob("MIIFi ... Uf93rN+");
* options.ca = atob("MIIFgDCC ... GosQML4sc=");
* require("tls").connect(options, ... );
* ```
*
2022-07-20 18:35:57 +00:00
* If you have the certificates as `.pem` files, you need to load these files, take the information between the lines beginning with `----`, remove the newlines from it so you have raw base64, and then feed it into `atob` as above.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You can also:
*
* - Just specify the filename (<=100 characters) and it will be loaded and parsed if you have an SD card connected. For instance `options.key = "key.pem";`
* - Specify a function, which will be called to retrieve the data. For instance `options.key = function() { eeprom.load_my_info(); };
*
* For more information about generating and using certificates, see:
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* [https://engineering.circle.com/https-authorized-certs-with-node-js/](https://engineering.circle.com/https-authorized-certs-with-node-js/)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* (You'll need to use 2048 bit certificates as opposed to 4096 bit shown above)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_tls_connect
*/
connect: (options: any, callback: any) => Socket;
};
CC3000: {
/**
* Initialise the CC3000 and return a WLAN object
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_CC3000_connect
*/
connect: (spi: any, cs: Pin, en: Pin, irq: Pin) => WLAN;
};
WIZnet: {
/**
* Initialise the WIZnet module and return an Ethernet object
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_WIZnet_connect
*/
connect: (spi: any, cs: Pin) => Ethernet;
};
Wifi: {
/**
* Disconnect the wifi station from an access point and disable the station mode. It is OK to call `disconnect` to turn off station mode even if no connection exists (for example, connection attempts may be failing). Station mode can be re-enabled by calling `connect` or `scan`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_disconnect
*/
disconnect: (callback: any) => void;
/**
* Stop being an access point and disable the AP operation mode. AP mode can be re-enabled by calling `startAP`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_stopAP
*/
stopAP: (callback: any) => void;
/**
* Connect to an access point as a station. If there is an existing connection to an AP it is first disconnected if the SSID or password are different from those passed as parameters. Put differently, if the passed SSID and password are identical to the currently connected AP then nothing is changed.
* When the connection attempt completes the callback function is invoked with one `err` parameter, which is NULL if there is no error and a string message if there is an error. If DHCP is enabled the callback occurs once an IP addres has been obtained, if a static IP is set the callback occurs once the AP's network has been joined. The callback is also invoked if a connection already exists and does not need to be changed.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The options properties may contain:
*
* - `password` - Password string to be used to access the network.
* - `dnsServers` (array of String) - An array of up to two DNS servers in dotted decimal format string.
* - `channel` - Wifi channel of the access point (integer, typ 0..14, 0 means any channel), only on ESP8266.
* - `bssid` - Mac address of the access point (string, type "00:00:00:00:00:00"), only on ESP8266.
*
* Notes:
*
* - the options should include the ability to set a static IP and associated netmask and gateway, this is a future enhancement.
* - the only error reported in the callback is "Bad password", all other errors (such as access point not found or DHCP timeout) just cause connection retries. If the reporting of such temporary errors is desired, the caller must use its own timeout and the `getDetails().status` field.
* - the `connect` call automatically enabled station mode, it can be disabled again by calling `disconnect`.
*
* @url http://www.espruino.com/Reference#l_Wifi_connect
*/
connect: (ssid: any, options: any, callback: any) => void;
/**
* Perform a scan for access points. This will enable the station mode if it is not currently enabled. Once the scan is complete the callback function is called with an array of APs found, each AP is an object with:
*
* - `ssid`: SSID string.
* - `mac`: access point MAC address in 00:00:00:00:00:00 format.
* - `authMode`: `open`, `wep`, `wpa`, `wpa2`, or `wpa_wpa2`.
* - `channel`: wifi channel 1..13.
* - `hidden`: true if the SSID is hidden (ESP32/ESP8266 only)
* - `rssi`: signal strength in dB in the range -110..0.
*
* Notes:
*
* - in order to perform the scan the station mode is turned on and remains on, use Wifi.disconnect() to turn it off again, if desired.
* - only one scan can be in progress at a time.
*
* @url http://www.espruino.com/Reference#l_Wifi_scan
*/
scan: (callback: any) => void;
/**
* Create a WiFi access point allowing stations to connect. If the password is NULL or an empty string the access point is open, otherwise it is encrypted.
* The callback function is invoked once the access point is set-up and receives one `err` argument, which is NULL on success and contains an error message string otherwise.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The `options` object can contain the following properties.
*
* - `authMode` - The authentication mode to use. Can be one of "open", "wpa2", "wpa", "wpa_wpa2". The default is open (but open access points are not recommended).
* - `password` - The password for connecting stations if authMode is not open.
* - `channel` - The channel to be used for the access point in the range 1..13. If the device is also connected to an access point as a station then that access point determines the channel.
* - `hidden` - The flag if visible or not (0:visible, 1:hidden), default is visible.
*
* Notes:
*
* - the options should include the ability to set the AP IP and associated netmask, this is a future enhancement.
* - the `startAP` call automatically enables AP mode. It can be disabled again by calling `stopAP`.
*
* @url http://www.espruino.com/Reference#l_Wifi_startAP
*/
startAP: (ssid: any, options: any, callback: any) => void;
/**
* Retrieve the current overall WiFi configuration. This call provides general information that pertains to both station and access point modes. The getDetails and getAPDetails calls provide more in-depth information about the station and access point configurations, respectively. The status object has the following properties:
*
* - `station` - Status of the wifi station: `off`, `connecting`, ...
* - `ap` - Status of the wifi access point: `disabled`, `enabled`.
* - `mode` - The current operation mode: `off`, `sta`, `ap`, `sta+ap`.
* - `phy` - Modulation standard configured: `11b`, `11g`, `11n` (the esp8266 docs are not very clear, but it is assumed that 11n means b/g/n). This setting limits the modulations that the radio will use, it does not indicate the current modulation used with a specific access point.
* - `powersave` - Power saving mode: `none` (radio is on all the time), `ps-poll` (radio is off between beacons as determined by the access point's DTIM setting). Note that in 'ap' and 'sta+ap' modes the radio is always on, i.e., no power saving is possible.
* - `savedMode` - The saved operation mode which will be applied at boot time: `off`, `sta`, `ap`, `sta+ap`.
*
* @url http://www.espruino.com/Reference#l_Wifi_getStatus
*/
getStatus: (callback: any) => any;
/**
* Sets a number of global wifi configuration settings. All parameters are optional and which are passed determines which settings are updated.
* The settings available are:
*
* - `phy` - Modulation standard to allow: `11b`, `11g`, `11n` (the esp8266 docs are not very clear, but it is assumed that 11n means b/g/n).
* - `powersave` - Power saving mode: `none` (radio is on all the time), `ps-poll` (radio is off between beacons as determined by the access point's DTIM setting). Note that in 'ap' and 'sta+ap' modes the radio is always on, i.e., no power saving is possible.
*
* Note: esp8266 SDK programmers may be missing an "opmode" option to set the sta/ap/sta+ap operation mode. Please use connect/scan/disconnect/startAP/stopAP, which all set the esp8266 opmode indirectly.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_setConfig
*/
setConfig: (settings: any) => void;
/**
* Retrieve the wifi station configuration and status details. The details object has the following properties:
*
* - `status` - Details about the wifi station connection, one of `off`, `connecting`, `wrong_password`, `no_ap_found`, `connect_fail`, or `connected`. The off, bad_password and connected states are stable, the other states are transient. The connecting state will either result in connected or one of the error states (bad_password, no_ap_found, connect_fail) and the no_ap_found and connect_fail states will result in a reconnection attempt after some interval.
* - `rssi` - signal strength of the connected access point in dB, typically in the range -110 to 0, with anything greater than -30 being an excessively strong signal.
* - `ssid` - SSID of the access point.
* - `password` - the password used to connect to the access point.
* - `authMode` - the authentication used: `open`, `wpa`, `wpa2`, `wpa_wpa2` (not currently supported).
* - `savedSsid` - the SSID to connect to automatically at boot time, null if none.
*
* @url http://www.espruino.com/Reference#l_Wifi_getDetails
*/
getDetails: (callback: any) => any;
/**
* Retrieve the current access point configuration and status. The details object has the following properties:
*
* - `status` - Current access point status: `enabled` or `disabled`
* - `stations` - an array of the stations connected to the access point. This array may be empty. Each entry in the array is an object describing the station which, at a minimum contains `ip` being the IP address of the station.
* - `ssid` - SSID to broadcast.
* - `password` - Password for authentication.
* - `authMode` - the authentication required of stations: `open`, `wpa`, `wpa2`, `wpa_wpa2`.
* - `hidden` - True if the SSID is hidden, false otherwise.
* - `maxConn` - Max number of station connections supported.
* - `savedSsid` - the SSID to broadcast automatically at boot time, null if the access point is to be disabled at boot.
*
* @url http://www.espruino.com/Reference#l_Wifi_getAPDetails
*/
getAPDetails: (callback: any) => any;
/**
* On boards where this is not available, just issue the `connect` commands you need to run at startup from an `onInit` function.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Save the current wifi configuration (station and access point) to flash and automatically apply this configuration at boot time, unless `what=="clear"`, in which case the saved configuration is cleared such that wifi remains disabled at boot. The saved configuration includes:
*
* - mode (off/sta/ap/sta+ap)
* - SSIDs & passwords
* - phy (11b/g/n)
* - powersave setting
* - DHCP hostname
*
* @url http://www.espruino.com/Reference#l_Wifi_save
*/
save: (what: any) => void;
/**
* Restores the saved Wifi configuration from flash. See `Wifi.save()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_restore
*/
restore: () => void;
/**
* Return the station IP information in an object as follows:
*
* - ip - IP address as string (e.g. "192.168.1.5")
* - netmask - The interface netmask as string (ESP8266/ESP32 only)
* - gw - The network gateway as string (ESP8266/ESP32 only)
* - mac - The MAC address as string of the form 00:00:00:00:00:00
*
* Note that the `ip`, `netmask`, and `gw` fields are omitted if no connection is established:
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_getIP
*/
getIP: (callback: any) => any;
/**
* Return the access point IP information in an object which contains:
*
* - ip - IP address as string (typ "192.168.4.1")
* - netmask - The interface netmask as string
* - gw - The network gateway as string
* - mac - The MAC address as string of the form 00:00:00:00:00:00
*
* @url http://www.espruino.com/Reference#l_Wifi_getAPIP
*/
getAPIP: (callback: any) => any;
/**
* Lookup the hostname and invoke a callback with the IP address as integer argument. If the lookup fails, the callback is invoked with a null argument.
* **Note:** only a single hostname lookup can be made at a time, concurrent lookups are not supported.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_getHostByName
*/
getHostByName: (hostname: any, callback: any) => void;
/**
* Returns the hostname announced to the DHCP server and broadcast via mDNS when connecting to an access point.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_getHostname
*/
getHostname: (callback: any) => any;
/**
* Set the hostname. Depending on implemenation, the hostname is sent with every DHCP request and is broadcast via mDNS. The DHCP hostname may be visible in the access point and may be forwarded into DNS as hostname.local.
* If a DHCP lease currently exists changing the hostname will cause a disconnect and reconnect in order to transmit the change to the DHCP server.
* The mDNS announcement also includes an announcement for the "espruino" service.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_setHostname
*/
setHostname: (hostname: any, callback: any) => void;
/**
* Starts the SNTP (Simple Network Time Protocol) service to keep the clock synchronized with the specified server. Note that the time zone is really just an offset to UTC and doesn't handle daylight savings time.
* The interval determines how often the time server is queried and Espruino's time is synchronized. The initial synchronization occurs asynchronously after setSNTP returns.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_setSNTP
*/
setSNTP: (server: any, tz_offset: any) => void;
/**
* The `settings` object must contain the following properties.
*
* - `ip` IP address as string (e.g. "192.168.5.100")
* - `gw` The network gateway as string (e.g. "192.168.5.1")
* - `netmask` The interface netmask as string (e.g. "255.255.255.0")
*
* @url http://www.espruino.com/Reference#l_Wifi_setIP
*/
setIP: (settings: any, callback: any) => void;
/**
* The `settings` object must contain the following properties.
*
* - `ip` IP address as string (e.g. "192.168.5.100")
* - `gw` The network gateway as string (e.g. "192.168.5.1")
* - `netmask` The interface netmask as string (e.g. "255.255.255.0")
*
* @url http://www.espruino.com/Reference#l_Wifi_setAPIP
*/
setAPIP: (settings: any, callback: any) => void;
/**
* Issues a ping to the given host, and calls a callback with the time when the ping is received.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Wifi_ping
*/
ping: (hostname: any, callback: any) => void;
/**
* Switch to using a higher communication speed with the WiFi module.
*
* - `true` = 921600 baud
* - `false` = 115200
* - `1843200` (or any number) = use a specific baud rate.
* - eg. `wifi.turbo(true,callback)` or `wifi.turbo(1843200,callback)`
*
* @url http://www.espruino.com/Reference#l_Wifi_turbo
*/
turbo: (enable: any, callback: any) => void;
};
http: {
/**
* Create an HTTP Server
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* When a request to the server is made, the callback is called. In the callback you can use the methods on the response (`httpSRs`) to send data. You can also add `request.on('data',function() { ... })` to listen for POSTed data
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_http_createServer
*/
createServer: (callback: any) => httpSrv;
/**
* Create an HTTP Request - `end()` must be called on it to complete the operation. `options` is of the form:
2022-07-20 19:07:18 +00:00
*
* ```
* var options = {
* host: &#x27;example.com&#x27;, // host name
* port: 80, // (optional) port, defaults to 80
* path: &#x27;/&#x27;, // path sent to server
* method: &#x27;GET&#x27;, // HTTP command sent to server (must be uppercase &#x27;GET&#x27;, &#x27;POST&#x27;, etc)
* protocol: &#x27;http:&#x27;, // optional protocol - https: or http:
* headers: { key : value, key : value } // (optional) HTTP headers
2022-07-20 18:35:57 +00:00
* };
2022-07-20 19:07:18 +00:00
* var req = require("http").request(options, function(res) {
* res.on(&#x27;data&#x27;, function(data) {
* console.log("HTTP> "+data);
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* res.on(&#x27;close&#x27;, function(data) {
* console.log("Connection closed");
2022-07-20 18:35:57 +00:00
* });
* });
2022-07-20 19:07:18 +00:00
* // You can req.write(...) here if your request requires data to be sent.
* req.end(); // called to finish the HTTP request and get the response
* ```
*
2022-07-20 18:35:57 +00:00
* You can easily pre-populate `options` from a URL using `var options = url.parse("http://www.example.com/foo.html")`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* There's an example of using [`http.request` for HTTP POST here](https://espruino.com//Internet#http-post)
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** if TLS/HTTPS is enabled, options can have `ca`, `key` and `cert` fields. See `tls.connect` for
* more information about these and how to use them.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_http_request
*/
request: (options: any, callback: any) => httpCRq;
/**
* Request a webpage over HTTP - a convenience function for `http.request()` that makes sure the HTTP command is 'GET', and that calls `end` automatically.
2022-07-20 19:07:18 +00:00
*
* ```
* require("http").get("http://pur3.co.uk/hello.txt", function(res) {
* res.on(&#x27;data&#x27;, function(data) {
* console.log("HTTP> "+data);
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* res.on(&#x27;close&#x27;, function(data) {
* console.log("Connection closed");
2022-07-20 18:35:57 +00:00
* });
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* See `http.request()` and [the Internet page](https://espruino.com//Internet) and ` for more usage examples.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_http_get
*/
get: (options: any, callback: any) => httpCRq;
};
tv: {
/**
* This initialises the TV output. Options for PAL are as follows:
2022-07-20 19:07:18 +00:00
*
* ```
* var g = require(&#x27;tv&#x27;).setup({ type : "pal",
* video : A7, // Pin - SPI MOSI Pin for Video output (MUST BE SPI1)
* sync : A6, // Pin - Timer pin to use for video sync
* width : 384,
* height : 270, // max 270
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* and for VGA:
2022-07-20 19:07:18 +00:00
*
* ```
* var g = require(&#x27;tv&#x27;).setup({ type : "vga",
* video : A7, // Pin - SPI MOSI Pin for Video output (MUST BE SPI1)
* hsync : A6, // Pin - Timer pin to use for video sync
* vsync : A5, // Pin - pin to use for video sync
* width : 220,
* height : 240,
* repeat : 2, // amount of times to repeat each line
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* or
2022-07-20 19:07:18 +00:00
*
* ```
* var g = require(&#x27;tv&#x27;).setup({ type : "vga",
* video : A7, // Pin - SPI MOSI Pin for Video output (MUST BE SPI1)
* hsync : A6, // Pin - Timer pin to use for video sync
* vsync : A5, // Pin - pin to use for video sync
* width : 220,
* height : 480,
* repeat : 1, // amount of times to repeat each line
2022-07-20 18:35:57 +00:00
* });
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* See the [Television](https://espruino.com//Television) page for more information.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_tv_setup
*/
setup: (options: any, width: number) => any;
};
heatshrink: {
/**
* @url http://www.espruino.com/Reference#l_heatshrink_compress
*/
compress: (data: any) => ArrayBuffer;
/**
* @url http://www.espruino.com/Reference#l_heatshrink_decompress
*/
decompress: (data: any) => ArrayBuffer;
};
neopixel: {
/**
* Write to a strip of NeoPixel/WS281x/APA104/APA106/SK6812-style LEDs
* attached to the given pin.
2022-07-20 19:07:18 +00:00
*
* ```
* // set just one pixel, red, green, blue
* require("neopixel").write(B15, [255,0,0]);
* ```
*
* ```
* // Produce an animated rainbow over 25 LEDs
* var rgb = new Uint8ClampedArray(25*3);
* var pos = 0;
* function getPattern() {
2022-07-20 18:35:57 +00:00
* pos++;
2022-07-20 19:07:18 +00:00
* for (var i=0;i<rgb.length;) {
* rgb[i++] = (1 + Math.sin((i+pos)*0.1324)) * 127;
* rgb[i++] = (1 + Math.sin((i+pos)*0.1654)) * 127;
* rgb[i++] = (1 + Math.sin((i+pos)*0.1)) * 127;
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* return rgb;
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* setInterval(function() {
* require("neopixel").write(B15, getPattern());
* }, 100);
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:**
*
* - Different types of LED have the data in different orders - so don't
* be surprised by RGB or BGR orderings!
*
* - Some LED strips (SK6812) actually take 4 bytes per LED (red, green, blue and white).
* These are still supported but the array of data supplied must still be a multiple of 3
* bytes long. Just round the size up - it won't cause any problems.
*
* - On some platforms like STM32, pins capable of hardware SPI MOSI
* are required.
*
* - Espruino devices tend to have 3.3v IO, while WS2812/etc run
* off of 5v. Many WS2812 will only register a logic '1' at 70%
* of their input voltage - so if powering them off 5v you will not
* be able to send them data reliably. You can work around this by
* powering the LEDs off a lower voltage (for example 3.7v from a LiPo
* battery), can put the output into the `af_opendrain` state and use
* a pullup resistor to 5v on STM32 based boards (nRF52 are not 5v tolerant
* so you can't do this), or can use a level shifter to shift the voltage up
* into the 5v range.
*
* @url http://www.espruino.com/Reference#l_neopixel_write
*/
write: (pin: Pin, data: any) => void;
};
Storage: {
/**
* Erase the flash storage area. This will remove all files
* created with `require("Storage").write(...)` as well
* as any code saved with `save()` or `E.setBootCode()`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_eraseAll
*/
eraseAll: () => void;
/**
* Erase a single file from the flash storage area.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This function should be used with normal files, and not
* `StorageFile`s created with `require("Storage").open(filename, ...)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_erase
*/
erase: (name: any) => void;
/**
* Read a file from the flash storage area that has
* been written with `require("Storage").write(...)`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This function returns a memory-mapped String that points to the actual
* memory area in read-only memory, so it won't use up RAM.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* As such you can check if a file exists efficiently using `require("Storage").read(filename)!==undefined`.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you evaluate this string with `eval`, any functions
* contained in the String will keep their code stored
* in flash memory.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This function should be used with normal files, and not
* `StorageFile`s created with `require("Storage").open(filename, ...)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_read
*/
read: (name: any, offset: number, length: number) => any;
/**
* Read a file from the flash storage area that has
* been written with `require("Storage").write(...)`,
* and parse JSON in it into a JavaScript object.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This is identical to `JSON.parse(require("Storage").read(...))`.
* It will throw an exception if the data in the file is not
* valid JSON.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This function should be used with normal files, and not
* `StorageFile`s created with `require("Storage").open(filename, ...)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_readJSON
*/
readJSON: (name: any, noExceptions: boolean) => any;
/**
* Read a file from the flash storage area that has
* been written with `require("Storage").write(...)`,
* and return the raw binary data as an ArrayBuffer.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This can be used:
*
* - In a `DataView` with `new DataView(require("Storage").readArrayBuffer("x"))`
* - In a `Uint8Array/Float32Array/etc` with `new Uint8Array(require("Storage").readArrayBuffer("x"))`
*
* **Note:** This function should be used with normal files, and not
* `StorageFile`s created with `require("Storage").open(filename, ...)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_readArrayBuffer
*/
readArrayBuffer: (name: any) => any;
/**
* Write/create a file in the flash storage area. This is
* nonvolatile and will not disappear when the device resets
* or power is lost.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Simply write `require("Storage").write("MyFile", "Some data")` to write
* a new file, and `require("Storage").read("MyFile")` to read it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* If you supply:
*
* - A String, it will be written as-is
* - An array, will be written as a byte array (but read back as a String)
* - An object, it will automatically be converted to
* a JSON string before being written.
*
* **Note:** If an array is supplied it will not be converted to JSON.
* To be explicit about the conversion you can use `Storage.writeJSON`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* You may also create a file and then populate data later **as long as you
* don't try and overwrite data that already exists**. For instance:
2022-07-20 19:07:18 +00:00
*
* ```
* var f = require("Storage");
* f.write("a","Hello",0,14);
* f.write("a"," ",5);
* f.write("a","World!!!",6);
* print(f.read("a")); // "Hello World!!!"
* f.write("a"," ",0); // Writing to location 0 again will cause the file to be re-written
* print(f.read("a")); // " "
* ```
*
2022-07-20 18:35:57 +00:00
* This can be useful if you've got more data to write than you
* have RAM available - for instance the Web IDE uses this method
* to write large files into onboard storage.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This function should be used with normal files, and not
* `StorageFile`s created with `require("Storage").open(filename, ...)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_write
*/
write: (name: any, data: any, offset: number, size: number) => boolean;
/**
* Write/create a file in the flash storage area. This is
* nonvolatile and will not disappear when the device resets
* or power is lost.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Simply write `require("Storage").writeJSON("MyFile", [1,2,3])` to write
* a new file, and `require("Storage").readJSON("MyFile")` to read it.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* This is equivalent to: `require("Storage").write(name, JSON.stringify(data))`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** This function should be used with normal files, and not
* `StorageFile`s created with `require("Storage").open(filename, ...)`
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_writeJSON
*/
writeJSON: (name: any, data: any) => boolean;
/**
* List all files in the flash storage area. An array of Strings is returned.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* By default this lists files created by `StorageFile` (`require("Storage").open`)
* which have a file number (`"\1"`/`"\2"`/etc) appended to them.
2022-07-20 19:07:18 +00:00
*
* ```
* // All files
* require("Storage").list()
* // Files ending in &#x27;.js&#x27;
* require("Storage").list(/\.js$/)
* // All Storage Files
* require("Storage").list(undefined, {sf:true})
* // All normal files (eg created with Storage.write)
* require("Storage").list(undefined, {sf:false})
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** This will output system files (eg. saved code) as well as
* files that you may have written.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_list
*/
list: (regex: any, filter: any) => any;
/**
* List all files in the flash storage area matching the specfied regex (ignores StorageFiles),
* and then hash their filenames *and* file locations.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Identical files may have different hashes (eg. if Storage is compacted and the file moves) but
* the changes of different files having the same hash are extremely small.
2022-07-20 19:07:18 +00:00
*
* ```
* // Hash files
* require("Storage").hash()
* // Files ending in &#x27;.boot.js&#x27;
* require("Storage").hash(/\.boot\.js$/)
* ```
*
2022-07-20 18:35:57 +00:00
* **Note:** This function is used by Bangle.js as a way to cache files.
* For instance the bootloader will add all `.boot.js` files together into
* a single `.boot0` file, but it needs to know quickly whether anything has
* changed.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_hash
*/
hash: (regex: any) => number;
/**
* The Flash Storage system is journaling. To make the most of the limited
* write cycles of Flash memory, Espruino marks deleted/replaced files as
* garbage and moves on to a fresh part of flash memory. Espruino only
* fully erases those files when it is running low on flash, or when
* `compact` is called.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* `compact` may fail if there isn't enough RAM free on the stack to
* use as swap space, however in this case it will not lose data.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** `compact` rearranges the contents of memory. If code is
* referencing that memory (eg. functions that have their code stored in flash)
* then they may become garbled when compaction happens. To avoid this,
* call `eraseFiles` before uploading data that you intend to reference to
* ensure that uploaded files are right at the start of flash and cannot be
* compacted further.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_compact
*/
compact: () => void;
/**
* This writes information about all blocks in flash
* memory to the console - and is only useful for debugging
* flash storage.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_debug
*/
debug: () => void;
/**
* Return the amount of free bytes available in
* Storage. Due to fragmentation there may be more
* bytes available, but this represents the maximum
* size of file that can be written.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_getFree
*/
getFree: () => number;
/**
* Returns:
2022-07-20 19:07:18 +00:00
*
* ```
* {
* totalBytes // Amount of bytes in filesystem
* freeBytes // How many bytes are left at the end of storage?
* fileBytes // How many bytes of allocated files do we have?
* fileCount // How many allocated files do we have?
* trashBytes // How many bytes of trash files do we have?
* trashCount // How many trash files do we have?
2022-07-20 18:35:57 +00:00
* }
2022-07-20 19:07:18 +00:00
* ```
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_getStats
*/
getStats: () => any;
/**
* Writes a lookup table for files into Bangle.js's storage. This allows any file stored
* up to that point to be accessed quickly.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_optimise
*/
optimise: () => void;
/**
* Open a file in the Storage area. This can be used for appending data
* (normal read/write operations only write the entire file).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* Please see `StorageFile` for more information (and examples).
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* **Note:** These files write through immediately - they do not need closing.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Storage_open
*/
open: (name: any, mode: any) => StorageFile;
};
Flash: {
/**
* Returns the start and length of the flash page containing the given address.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Flash_getPage
*/
getPage: (addr: number) => any;
/**
* This method returns an array of objects of the form `{addr : #, length : #}`, representing
* contiguous areas of flash memory in the chip that are not used for anything.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* The memory areas returned are on page boundaries. This means that you can
* safely erase the page containing any address here, and you won't risk
* deleting part of the Espruino firmware.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Flash_getFree
*/
getFree: () => any;
/**
* Erase a page of flash memory
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Flash_erasePage
*/
erasePage: (addr: any) => void;
/**
* Write data into memory at the given address
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* In flash memory you may only turn bits that are 1 into bits that are 0. If
* you're writing data into an area that you have already written (so `read`
* doesn't return all `0xFF`) you'll need to call `erasePage` to clear the
* entire page.
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Flash_write
*/
write: (data: any, addr: number) => void;
/**
* Read flash memory from the given address
2022-07-20 19:07:18 +00:00
*
2022-07-20 18:35:57 +00:00
* @url http://www.espruino.com/Reference#l_Flash_read
*/
read: (length: number, addr: number) => any;
};
}