master
Bryan 2024-01-13 08:54:03 -06:00
parent a28cc5def1
commit 260e4ec542
8 changed files with 391 additions and 108 deletions

View File

@ -1 +0,0 @@
require("heatshrink").decompress(atob("oFAwMB/4A/AH38RIkDA7M/EofDA7M8EgQHQ4E/A/4HdN5Sffb7wA/AH4"));

View File

@ -7,7 +7,6 @@
"supports": ["BANGLEJS2"],
"tags": "",
"storage": [
{"name":"widanibat.wid.js","url":"widget.js"},
{"name":"widanibat.img","url":"app-icon.js","evaluate":true}
{"name":"widanibat.wid.js","url":"widanibat.widget.js"},
]
}

View File

@ -0,0 +1,94 @@
(()=>{
const w = 26;
const h = 13;
const yOffset = 3;
const touchMargin = 20;
const animateUpdateInterval = 300;
const staticUpdateInterval = 1000 * 60 * 10; // 10 minutes
WIDGETS.widanibat={
area: "tr",
sortOrder: 30,
width: w,
height: h,
batWidth: w,
batHeight: h,
scale: 1,
dir: 0,
drawIntervalID: undefined,
showPercent: false,
draw: function(){
const midX = ((2 * this.x) + this.width)/2;
const midY = ((2 * (this.y + yOffset)) + this.height)/2;
g.setColor(g.theme.fg);
g.reset();
var drawBattery = () => {
var halfS = this.batWidth/2;
var halfT = this.batHeight/2;
g.clearRect(this.x, this.y, this.x+this.width, this.y+this.height+yOffset);
g.fillRect(midX-halfS, midY-halfT, midX+halfS-3, midY+halfT); // outer
g.clearRect(midX-halfS+2, midY-halfT+2, midX+halfS-3-2, midY+halfT-2); // centre
g.fillRect(midX+halfS-3, midY-2, midX+halfS, midY+2); // contact
g.fillRect(midX-halfS+3, midY-halfT+3,((this.batWidth-9)/100*E.getBattery())+midX-halfS+3, midY+halfT-3); // the level
};
var drawPercent = () => {
g.clearRect(this.x, this.y, this.x+this.width, this.y+this.height+yOffset);
g.drawRect(this.x, this.y, this.x+this.width, this.y+this.height+yOffset);
var str = E.getBattery() + "%";
g.setFont("6x15").getFontHeight();
var strW = g.stringWidth(str);
g.drawString(str, this.x + ((this.width - strW)/2), this.y + 3); //y = y + ((h + yOffset - strH)/2))
};
var animateBattery = () => {
this.batWidth = this.width * this.scale;
this.batHeight = this.height * this.scale;
drawBattery();
this.scale = this.dir==0?this.scale-0.1:this.scale+0.1;
if (this.scale <= 0.7) this.dir=1;
if (this.scale >= 1) this.dir=0;
};
if (this.showPercent) drawPercent();
else {
if (Bangle.isCharging()) animateBattery();
else drawBattery();
}
}, //draw
touchHandler: function(_b, t){
const maxX = this.x + this.width;
const maxY = this.y + this.height + yOffset;
if (t.x < this.x - touchMargin || t.x > maxX + touchMargin || t.y > maxY + touchMargin) return;
this.showPercent = true;
this.draw();
setTimeout(() => {
this.showPercent = false;
this.draw();
}, 2000);
}, //touchHandler
reset: function() {
this.scale = 1;
this.dir = 0;
this.showPercent = false;
this.batHeight = this.height;
this.batWidth = this.width;
} //reset
}
WIDGETS.widanibat.drawIntervalID = setInterval(() => WIDGETS.widanibat.draw(WIDGETS.widanibat), staticUpdateInterval);
Bangle.on('charging', (charging) => {
changeInterval(WIDGETS.widanibat.drawIntervalID, charging ? animateUpdateInterval : staticUpdateInterval);
if (! charging) WIDGETS.widanibat.reset();
WIDGETS.widanibat.draw();
});
Bangle.on('touch', (_b, xy) => WIDGETS.widanibat.touchHandler(WIDGETS.widanibat, xy));
})();

View File

@ -1,72 +0,0 @@
(()=>{
const w = 26;
const h = 13;
var s, t, scale, batInt;
const animateUpdateInterval = 300;
const staticUpdateInterval = 1000 * 60 * 10; // 10 minutes
function draw(){
if (s==undefined||!Bangle.isCharging()) s = w;
if (t==undefined||!Bangle.isCharging()) t = h;
if (scale==undefined||!Bangle.isCharging()) scale = 1;
const x = this.x;
const y = this.y + 4;
const midX = ((2 * x) + w)/2;
const midY = ((2 * y) + h)/2;
g.setColor(g.theme.fg);
g.reset();
drawBattery = ()=>{
var halfS = s/2;
var halfT = t/2;
g.clearRect(x, y, x+w, y+h);
g.fillRect(midX-halfS, midY-halfT, midX+halfS-3, midY+halfT); // outer
g.clearRect(midX-halfS+2, midY-halfT+2, midX+halfS-3-2, midY+halfT-2); // centre
g.fillRect(midX+halfS-3, midY-2, midX+halfS, midY+2); // contact
g.fillRect(midX-halfS+3, midY-halfT+3,((s-9)/100*E.getBattery())+midX-halfS+3, midY+halfT-3); // the level
};
animateBattery = ()=>{
scale = 1;
var dir = 0;
if (batInt) clearInterval(batInt);
batInt = setInterval(()=>{
s = w * scale;
t = h * scale;
drawBattery();
scale = dir==0?scale-0.1:scale+0.1;
if (scale <= 0.7) dir=1;
if (scale >= 1) dir=0;
}, animateUpdateInterval);
};
staticBattery = ()=>{
s = w;
t = h;
if (batInt) clearInterval(batInt);
batInt = setInterval(drawBattery, staticUpdateInterval);
drawBattery();
};
if (Bangle.isCharging()) {
animateBattery();
} else {
staticBattery();
}
}
WIDGETS["widanibat"]={
area:"tr",
width:w,
draw:draw
};
Bangle.on('charging', (charging)=>{WIDGETS.widanibat.draw();});
})();

View File

@ -2,7 +2,7 @@
"id": "widbat",
"name": "Battery Level Widget",
"version": "0.12",
"description": "Show the current battery level and charging status in the top right of the clock",
"description": "Show the current battery level, pulses when charging. Touching the battery icon will show percent.",
"icon": "widget.png",
"type": "widget",
"tags": "widget,battery",

View File

@ -1,6 +1,6 @@
{
"id": "widclkmod",
"name": "Digital clock widget",
"name": "Digital clock widget mod",
"version": "0.01",
"description": "A simple digital clock widget that appears when not showing a fullscreen clock. Forked from widclk.",
"icon": "widget.png",

View File

@ -95,6 +95,7 @@ type BangleOptions<Boolean = boolean> = {
wakeOnBTN3: Boolean;
wakeOnFaceUp: Boolean;
wakeOnTouch: Boolean;
wakeOnDoubleTap: Boolean;
wakeOnTwist: Boolean;
unlockOnBTN1: Boolean;
unlockOnBTN2: Boolean;
@ -951,12 +952,12 @@ declare class Bangle {
static on(event: "HRM-raw", callback: (hrm: { raw: number, filt: number, bpm: number, confidence: number }) => void): void;
/**
* Called when an environment sample heart rate sensor data is available. On the newest VC31B based watches this is only 4 bit (0..15)
* Called when an environment sample heart rate sensor data is available (this is the amount of light received by the HRM sensor from the environment when its LED is off). On the newest VC31B based watches this is only 4 bit (0..15).
* To get it you need to turn the HRM on with `Bangle.setHRMPower(1)` and also set `Bangle.setOptions({hrmPushEnv:true})`.
* It is also possible to poke registers with `Bangle.hrmWr` to increase the poll rate if needed.
* It is also possible to poke registers with `Bangle.hrmWr` to increase the poll rate if needed. See https://banglejs.com/apps/?id=flashcount for an example of this.
* @param {string} event - The event to listen to.
* @param {(env: any) => void} callback - A function that is executed when the event occurs. Its arguments are:
* * `env` An integer containing current environment reading
* * `env` An integer containing current environment reading (light level)
* @url http://www.espruino.com/Reference#l_Bangle_HRM-env
*/
static on(event: "HRM-env", callback: (env: any) => void): void;
@ -995,11 +996,12 @@ declare class Bangle {
/**
* Has the screen been locked? Also see `Bangle.isLocked()`
* @param {string} event - The event to listen to.
* @param {(on: boolean) => void} callback - A function that is executed when the event occurs. Its arguments are:
* @param {(on: boolean, reason: string) => void} callback - A function that is executed when the event occurs. Its arguments are:
* * `on` `true` if screen is locked, `false` if it is unlocked and touchscreen/buttons will work
* * `reason` (2v20 onwards) If known, the reason for locking/unlocking - 'button','js','tap','doubleTap','faceUp','twist','timeout'
* @url http://www.espruino.com/Reference#l_Bangle_lock
*/
static on(event: "lock", callback: (on: boolean) => void): void;
static on(event: "lock", callback: (on: boolean, reason: string) => void): void;
/**
* If the watch is tapped, this event contains information on the way it was
@ -1301,8 +1303,11 @@ declare class Bangle {
* 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`
* * `wakeOnTouch` should the LCD turn on when the touchscreen is pressed? On Bangle.js 1 this
* is a physical press on the touchscreen, on Bangle.js 2 we have to use the accelerometer as
* the touchscreen cannot be left powered without running the battery down. default = `false`
* * `wakeOnDoubleTap` (2v20 onwards) should the LCD turn on when the watch is double-tapped on the screen?
* This uses the accelerometer, not the touchscreen itself. default = `false`
* * `wakeOnTwist` should the LCD turn on when the watch is twisted? default =
* `true`
* * `unlockOnBTN1` should the watch unlock when BTN1 is pressed? default = `true`
@ -1349,13 +1354,14 @@ declare class Bangle {
* 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.
* of the BPM reading. You must call this *before* `Bangle.setHRMPower` - calling
* when the HRM is already on will not affect the poll rate.
* * `hrmSportMode` - on the newest Bangle.js 2 builds with with the proprietary
* heart rate algorithm, this is the sport mode passed to the algorithm. See `libs/misc/vc31_binary/algo.h`
* for more info. -1 = auto, 0 = normal (default), 1 = running, 2 = ...
* * `hrmGreenAdjust` - (Bangle.js 2, 2v19+) if false (default is true) the green LED intensity won't be adjusted to get the HRM sensor 'exposure' correct
* * `hrmWearDetect` - (Bangle.js 2, 2v19+) if false (default is true) HRM readings won't be turned off if the watch isn't on your arm (based on HRM proximity sensor)
* * `hrmPushEnv` - (Bangle.js 2, 2v19+) if true (default is false) HRM environment readings will be produced as `Bangle.on(`HRM-env`, ...)` events
* * `hrmGreenAdjust` - (Bangle.js 2, 2v19+) if false (default is true) the green LED intensity won't be adjusted to get the HRM sensor 'exposure' correct. This is reset when the HRM is initialised with `Bangle.setHRMPower`.
* * `hrmWearDetect` - (Bangle.js 2, 2v19+) if false (default is true) HRM readings won't be turned off if the watch isn't on your arm (based on HRM proximity sensor). This is reset when the HRM is initialised with `Bangle.setHRMPower`.
* * `hrmPushEnv` - (Bangle.js 2, 2v19+) if true (default is false) HRM environment readings will be produced as `Bangle.on(`HRM-env`, ...)` events. This is reset when the HRM is initialised with `Bangle.setHRMPower`.
* * `seaLevelPressure` (Bangle.js 2) Normally 1013.25 millibars - this is used for
* calculating altitude with the pressure sensor
* Where accelerations are used they are in internal units, where `8192 = 1g`
@ -1801,11 +1807,27 @@ declare class Bangle {
/**
* Show a 'recovery' menu that allows you to perform certain tasks on your Bangle.
* You can also enter this menu by restarting while holding down the `BTN1`
* You can also enter this menu by restarting your Bangle while holding down the button.
* @url http://www.espruino.com/Reference#l_Bangle_showRecoveryMenu
*/
static showRecoveryMenu(): void;
/**
* @url http://www.espruino.com/Reference#l_Bangle_showRecoveryMenu
*/
static showRecoveryMenu(): void;
/**
* (2v20 and later) Show a test screen that lights green when each sensor on the Bangle
* works and reports within range.
* Swipe on the screen when all items are green and the Bangle will turn bluetooth off
* and display a `TEST PASS` screen for 60 minutes, after which it will turn off.
* You can enter this menu by restarting your Bangle while holding down the button,
* then choosing `Test` from the recovery menu.
* @url http://www.espruino.com/Reference#l_Bangle_showTestScreen
*/
static showTestScreen(): void;
/**
* This behaves the same as the global `load()` function, but if fast
* loading is possible (`Bangle.setUI` was called with a `remove` handler)
@ -2652,7 +2674,7 @@ declare class NRF {
* 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)
* phy: "1mbps/2mbps/coded" // (NRF52833/NRF52840 only) use the long-range coded phy for transmission (1mbps default)
* }
* ```
* Setting `connectable` and `scannable` to false gives the lowest power
@ -3385,9 +3407,9 @@ declare class NRF {
* * `active` - whether to perform active scanning (requesting 'scan response'
* packets from any devices that are found). e.g. `NRF.requestDevice({ active:true,
* filters: [ ... ] })`
* * `phy` - (NRF52840 only) use the long-range coded phy (`"1mbps"` default, can
* * `phy` - (NRF52833/NRF52840 only) use the long-range coded phy (`"1mbps"` default, can
* be `"1mbps/2mbps/both/coded"`)
* * `extended` - (NRF52840 only) support receiving extended-length advertising
* * `extended` - (NRF52833/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.
* The following filter types are implemented:
@ -4246,13 +4268,22 @@ declare class Graphics<IsBuffer extends boolean = boolean> {
stringWidth(str: string): number;
/**
* Return the width and height in pixels of a string of text in the current font
* Return the width and height in pixels of a string of text in the current font. The object returned contains:
* ```JS
* {
* width, // Width of the string in pixels
* height, // Height of the string in pixels
* unrenderableChars, // If true, the string contains characters that the current font isn't able to render.
* imageCount, // How many inline images are in this string?
* maxImageHeight, // If there are images, what is the maximum height of all images?
* }
* ```
*
* @param {any} str - The string
* @returns {any} An object containing `{width,height}` of the string
* @returns {any} An object containing `{width,height,etc}` for the string - see below
* @url http://www.espruino.com/Reference#l_Graphics_stringMetrics
*/
stringMetrics(str: string): { width: number, height: number };
stringMetrics(str: string): { width: number, height: number, unrenderableChars: boolean, imageCount : number, maxImageHeight : number };
/**
* Wrap a string to the given pixel width using the current font, and return the
@ -4482,6 +4513,8 @@ declare class Graphics<IsBuffer extends boolean = boolean> {
* disabled on devices without much flash memory available. If a Graphics object
* is supplied, it can also contain transparent/palette fields as if it were
* an image.
* See https://www.espruino.com/Graphics#images-bitmaps for more information about
* image formats.
* Draw an image at the specified position.
* * If the image is 1 bit, the graphics foreground/background colours will be
* used.
@ -6137,6 +6170,125 @@ declare class BluetoothRemoteGATTCharacteristic {
stopNotifications(): Promise<void>;
}
/**
* Class containing utility functions for the [Jolt.js Smart Bluetooth driver](http://www.espruino.com/Jolt.js)
* @url http://www.espruino.com/Reference#Jolt
*/
declare class Jolt {
/**
* `Q0` and `Q1` Qwiic connectors can have their power controlled by a 500mA FET connected to GND.
* The `sda` and `scl` pins on this port are also analog inputs - use `analogRead(Jolt.Q0.sda)`/etc
* To turn this connector on run `Jolt.Q0.setPower(1)`
* @returns {any} An object containing the pins for the Q0 connector on Jolt.js `{sda,scl,fet}`
* @url http://www.espruino.com/Reference#l_Jolt_Q0
*/
static Q0: Qwiic;
/**
* `Q0` and `Q1` Qwiic connectors can have their power controlled by a 500mA FET connected to GND.
* The `sda` and `scl` pins on this port are also analog inputs - use `analogRead(Jolt.Q1.sda)`/etc
* To turn this connector on run `Jolt.Q1.setPower(1)`
* @returns {any} An object containing the pins for the Q1 connector on Jolt.js `{sda,scl,fet}`
* @url http://www.espruino.com/Reference#l_Jolt_Q1
*/
static Q1: Qwiic;
/**
* `Q2` and `Q3` have all 4 pins connected to Jolt.js's GPIO (including those usually used for power).
* As such only around 8mA of power can be supplied to any connected device.
* To use this as a normal Qwiic connector, run `Jolt.Q2.setPower(1)`
* @returns {any} An object containing the pins for the Q2 connector on Jolt.js `{sda,scl,gnd,vcc}`
* @url http://www.espruino.com/Reference#l_Jolt_Q2
*/
static Q2: Qwiic;
/**
* `Q2` and `Q3` have all 4 pins connected to Jolt.js's GPIO (including those usually used for power).
* As such only around 8mA of power can be supplied to any connected device.
* To use this as a normal Qwiic connector, run `Jolt.Q3.setPower(1)`
* @returns {any} An object containing the pins for the Q3 connector on Jolt.js `{sda,scl,gnd,vcc}`
* @url http://www.espruino.com/Reference#l_Jolt_Q3
*/
static Q3: Qwiic;
/**
* Sets the mode of the motor drivers. Jolt.js has two motor drivers,
* one (`0`) for outputs 0..3, and one (`1`) for outputs 4..7. They
* can be controlled independently.
* Mode can be:
* * `undefined` / `false` / `"off"` - the motor driver is off, all motor driver pins are open circuit
* * `true` / `"output"` - **[recommended]** driver is set to "Independent bridge" mode. All 4 outputs are enabled and are either
* * `"motor"` - driver is set to "4 pin interface" mode where pins are paired up (V0+V1, V2+V3, etc). If both
* in a pair are 0 the output is open circuit (motor coast), if both are 1 both otputs are 0 (motor brake), and
* if both are different, those values are on the output:
* `output` mode:
* | V0 | V1 | Out 0 | Out 1 |
* |----|----|-------|-------|
* | 0 | 0 | Low | Low |
* | 0 | 1 | Low | High |
* | 1 | 0 | High | Low |
* | 1 | 1 | High | High |
* `motor` mode
* | V0 | V1 | Out 0 | Out 1 |
* |----|----|-------|-------|
* | 0 | 0 | Open | Open |
* | 0 | 1 | Low | High |
* | 1 | 0 | High | Low |
* | 1 | 1 | Low | Low |
*
* @param {number} driver - The number of the motor driver (0 or 1)
* @param {any} mode - The mode of the motor driver (see below)
* @url http://www.espruino.com/Reference#l_Jolt_setDriverMode
*/
static setDriverMode(driver: number, mode: any): void;
/**
* Run a self-test, and return true for a pass. This checks for shorts between
* pins, so your Jolt shouldn't have anything connected to it.
* **Note:** This self-test auto starts if you hold the button on your Jolt 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.
* If the self test fails, it'll set the Jolt.js Bluetooth advertising name to
* `Jolt.js !ERR` where ERR is a 3 letter error code.
* @returns {boolean} True if the self-test passed
* @url http://www.espruino.com/Reference#l_Jolt_selfTest
*/
static selfTest(): boolean;
}
/**
* Class containing utility functions for the Qwiic connectors
* on the [Jolt.js Smart Bluetooth driver](http://www.espruino.com/Jolt.js).
* Each class (available from `Jolt.Q0`/`Jolt.Q1`/`Jolt.Q2`/`Jolt.Q3`)
* has `sda` and `scl` fields with the pins for SDA and SCL on them.
* On Jolt.js, the four Qwiic connectors can be individually powered:
* * Q0/Q1 - GND is switched with a 500mA FET. The `fet` field contains the pin that controls the FET
* * Q2/Q3 - all 4 pins are connected to GPIO. `gnd` and `vcc` fields contain the pins for GND and VCC
* To control the power, use `Qwiic.setPower`, for example: `Jolt.Q0.setPower(true)`
* @url http://www.espruino.com/Reference#Qwiic
*/
declare class Qwiic {
/**
* This turns power for the given Qwiic connector on or off. See `Qwiic` for more information.
*
* @param {boolean} isOn - Whether the Qwiic connector is to be on or not
* @returns {any} The same Qwiic object (for call chaining)
* @url http://www.espruino.com/Reference#l_Qwiic_setPower
*/
setPower(isOn: boolean): any;
/**
* @returns {any} An I2C object using this Qwiic connector, already set up
* @url http://www.espruino.com/Reference#l_Qwiic_i2c
*/
i2c: any;
}
/**
* Class containing [micro:bit's](https://www.espruino.com/MicroBit) utility
* functions.
@ -8172,10 +8324,10 @@ declare class E {
/**
* Set the time zone to be used with `Date` objects.
* For example `E.setTimeZone(1)` will be GMT+0100
* 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.
* Time can be set with `setTime`.
* **Note:** If daylight savings time rules have been set with `E.setDST()`,
* calling `E.setTimeZone()` will remove them and move back to using a static
* timezone that doesn't change based on the time of year.
*
* @param {number} zone - The time zone in hours
* @url http://www.espruino.com/Reference#l_E_setTimeZone
@ -8220,10 +8372,20 @@ declare class E {
* 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);`
* Note that when DST parameters are set (i.e. when `dstOffset` is not zero),
* `E.setTimeZone()` has no effect.
* Examples:
* ```
* // United Kingdom
* E.setDST(60,0,4,0,2,0,60,4,0,9,0,120);
* // California, USA
* E.setDST(60,-480,1,0,2,0,120,0,0,10,0,120);
* // Or adjust -480 (-8 hours) for other US states
* // Ukraine
* E.setDST(60,120,4,0,2,0,180,4,0,9,0,240);
* ```
* **Note:** This is not compatible with `E.setTimeZone()`. Calling `E.setTimeZone()`
* after this will disable DST.
*
* @param {any} params - An array containing the settings for DST
* @param {any} params - An array containing the settings for DST, or `undefined` to disable
* @url http://www.espruino.com/Reference#l_E_setDST
*/
static setDST(dstOffset: number, timezone: number, startDowNumber: number, startDow: number, startMonth: number, startDayOffset: number, startTimeOfDay: number, endDowNumber: number, endDow: number, endMonth: number, endDayOffset: number, endTimeOfDay: number): void
@ -8494,6 +8656,44 @@ declare class Pin {
*/
toggle(): boolean;
/**
* (Added in 2v20) Pulse the pin with the value for the given time in milliseconds.
* ```
* LED.pulse(1, 100); // pulse LED on for 100ms
* LED.pulse(1, [100,1000,100]); // pulse LED on for 100ms, off for 1s, on for 100ms
* ```
* This is identical to `digitalPulse`.
*
* @param {boolean} value - Whether to pulse high (true) or low (false)
* @param {any} time - A time in milliseconds, or an array of times (in which case a square wave will be output starting with a pulse of 'value')
* @url http://www.espruino.com/Reference#l_Pin_pulse
*/
pulse(value: boolean, time: any): void;
/**
* (Added in 2v20) Get the analogue value of the given pin. See `analogRead` for more information.
* @returns {number} The analog Value of the Pin between 0 and 1
* @url http://www.espruino.com/Reference#l_Pin_analog
*/
analog(): number;
/**
* (Added in 2v20) Set the analog Value of a pin. It will be output using PWM.
* See `analogWrite` for more information.
* Objects can contain:
* * `freq` - pulse frequency in Hz, e.g. ```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
*
* @param {number} value - A value between 0 and 1
* @param {any} options
* An object containing options for analog output - see below
* @url http://www.espruino.com/Reference#l_Pin_pwm
*/
pwm(value: number, options: any): void;
/**
* Get information about this pin and its capabilities. Of the form:
* ```
@ -10601,7 +10801,7 @@ interface Float64ArrayConstructor {
* @constructor
*
* @param {any} arr - The array or typed array to base this off, or an integer which is the array length
* @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer)
* @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer). Maximum 65535.
* @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer)
* @returns {any} A typed array
* @url http://www.espruino.com/Reference#l_Float64Array_Float64Array
@ -10627,6 +10827,38 @@ interface consoleConstructor {
* @url http://www.espruino.com/Reference#l_console_log
*/
log(...text: any[]): void;
/**
* Implemented in Espruino as an alias of `console.log`
*
* @param {any} text - One or more arguments to print
* @url http://www.espruino.com/Reference#l_console_debug
*/
debug(...text: any[]): void;
/**
* Implemented in Espruino as an alias of `console.log`
*
* @param {any} text - One or more arguments to print
* @url http://www.espruino.com/Reference#l_console_info
*/
info(...text: any[]): void;
/**
* Implemented in Espruino as an alias of `console.log`
*
* @param {any} text - One or more arguments to print
* @url http://www.espruino.com/Reference#l_console_warn
*/
warn(...text: any[]): void;
/**
* Implemented in Espruino as an alias of `console.log`
*
* @param {any} text - One or more arguments to print
* @url http://www.espruino.com/Reference#l_console_error
*/
error(...text: any[]): void;
}
interface console {
@ -10986,7 +11218,7 @@ declare class I2C {
/**
* 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
* available and read functions. Sends a STOP unless `{address:X, stop:false}` is used.
*
* @param {any} address - The 7 bit address of the device to request bytes from, or an object of the form `{address:12, stop:false}` to send this data without a STOP signal.
* @param {number} quantity - The number of bytes to request
@ -10994,6 +11226,25 @@ declare class I2C {
* @url http://www.espruino.com/Reference#l_I2C_readFrom
*/
readFrom(address: any, quantity: number): Uint8Array;
/**
* Request bytes from a register on the given I2C slave device, and return them as a Uint8Array
* (packed array of bytes).
* This is the same as calling `I2C.writeTo` and `I2C.readFrom`:
* ```
* I2C.readReg = function(address, reg, quantity) {
* this.writeTo({address:address, stop:false}, reg);
* return this.readFrom(address, quantity);
* };
* ```
*
* @param {number} address - The 7 bit address of the device to request bytes from
* @param {number} reg - The register on the device to read bytes from
* @param {number} quantity - The number of bytes to request
* @returns {any} The data that was returned - as a Uint8Array
* @url http://www.espruino.com/Reference#l_I2C_readReg
*/
readReg(address: number, reg: number, quantity: number): Uint8Array;
}
/**
@ -11496,6 +11747,9 @@ declare function analogRead(pin: Pin): number;
* * `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
* On nRF52-based devices (Puck.js, Pixl.js, MDBT42Q, etc) hardware PWM runs at
* 16MHz, with a maximum output frequency of 4MHz (but with only 2 bit (0..3) accuracy).
* At 1Mhz, you have 4 bits (0..15), 1kHz = 14 bits and so on.
* **Note:** if you didn't call `pinMode` beforehand then this function will also
* reset pin's state to `"output"`
*
@ -13772,9 +14026,12 @@ declare module "Storage" {
* try and overwrite data that already exists**. For instance:
* ```
* var f = require("Storage");
* f.write("a","Hello",0,14);
* f.write("a"," ",5);
* f.write("a","World!!!",6);
* f.write("a","Hello",0,14); // Creates a new file, 14 chars long
* print(JSON.stringify(f.read("a"))); // read the file
* // any nonwritten chars will be char code 255:
* "Hello\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF"
* f.write("a"," ",5); // write within the file
* f.write("a","World!!!",6); // write again within the file
* 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")); // " "
@ -13787,7 +14044,7 @@ declare module "Storage" {
*
* @param {any} name - The filename - max 28 characters (case sensitive)
* @param {any} data - The data to write
* @param {number} [offset] - [optional] The offset within the file to write
* @param {number} [offset] - [optional] The offset within the file to write (if `0`/`undefined` a new file is created, otherwise Espruino attempts to write within an existing file if one exists)
* @param {number} [size] - [optional] The size of the file (if a file is to be created that is bigger than the data)
* @returns {boolean} True on success, false on failure
* @url http://www.espruino.com/Reference#l_Storage_write
@ -13799,9 +14056,15 @@ declare module "Storage" {
* disappear when the device resets or power is lost.
* Simply write `require("Storage").writeJSON("MyFile", [1,2,3])` to write a new
* file, and `require("Storage").readJSON("MyFile")` to read it.
* This is equivalent to: `require("Storage").write(name, JSON.stringify(data))`
* This is (almost) equivalent to `require("Storage").write(name, JSON.stringify(data))` (see the notes below)
* **Note:** This function should be used with normal files, and not `StorageFile`s
* created with `require("Storage").open(filename, ...)`
* **Note:** Normally `JSON.stringify` converts any non-standard character to an escape code with `\uXXXX`, but
* as of Espruino 2v20, when writing to a file we use the most compact form, like `\xXX` or `\X`, as well as
* skipping quotes on fields. This saves space and is faster, but also means that if a String wasn't a UTF8
* string but contained characters in the UTF8 codepoint range, when saved it won't end up getting reloaded as a UTF8 string.
* It does mean that you cannot parse the file with just `JSON.parse` as it's no longer standard JSON but is JS,
* so you must use `Storage.readJSON`
*
* @param {any} name - The filename - max 28 characters (case sensitive)
* @param {any} data - The JSON data to write