diff --git a/ChangeLog b/ChangeLog index b06d35c98..b0c16aa22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -65,6 +65,7 @@ STM32: Ensure we kick the WDT if auto kicking is enabled and in deep sleep (avoids having to to it manually and wait 30ms for USB to wake up/shut down) Allow a 'file receive' packet which can request Espruino sends a file as binary packets (also fix files not being closed if transmission fails) Fix parsing of semicolons in DO with a statement: `do print(a);while(a--);` + In SAVE_ON_FLASH builds (Microbit 1) remove getSerial, Math.LN*/LOG*SQRT* constants, passwords, Serial/I2C/SPI.find, Date.toUTCString 2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()' Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off) diff --git a/README_BuildProcess.md b/README_BuildProcess.md index 2c7e55151..f75ca93f4 100644 --- a/README_BuildProcess.md +++ b/README_BuildProcess.md @@ -179,6 +179,7 @@ These are set automatically when `SAVE_ON_FLASH` is set (see `jsutils.h`) * `ESPR_NO_LET_SCOPING` - don't create scopes for `let` (treat it like `var`, which was the 2v13 and earlier behaviour) * `ESPR_NO_PROMISES` - Don't include promise-handling functions * `ESPR_NO_PRETOKENISE` - Don't include code to pretokenise functions marked with `"ram"` - code pretokenised in the IDE can still be executed +* `ESPR_NO_PASSWORD` - Disable password protection on the console (E.setPassword/E.lockConsole) ### chip diff --git a/libs/graphics/jswrap_graphics.c b/libs/graphics/jswrap_graphics.c index 5c9245f01..e230340c4 100644 --- a/libs/graphics/jswrap_graphics.c +++ b/libs/graphics/jswrap_graphics.c @@ -1720,7 +1720,7 @@ It is recommended that you use `Graphics.setFont("4x6")` for more flexibility. "type" : "method", "class" : "Graphics", "name" : "setFontVector", - "ifndef" : "SAVE_ON_FLASH", + "#if" : "!defined(SAVE_ON_FLASH) && !defined(NO_VECTOR_FONT)", "generate_full" : "jswrap_graphics_setFontSizeX(parent, size, true)", "params" : [ ["size","int32","The height of the font, as an integer"] @@ -2807,7 +2807,7 @@ void jswrap_graphics_drawCString(JsGraphics *gfx, int x, int y, char *str) { "type" : "method", "class" : "Graphics", "name" : "getVectorFontPolys", - "#if" : "!defined(SAVE_ON_FLASH) || !defined(NO_VECTOR_FONT)", + "#if" : "!defined(SAVE_ON_FLASH) && !defined(NO_VECTOR_FONT)", "generate" : "jswrap_graphics_getVectorFontPolys", "params" : [ ["str","JsVar","The string"], diff --git a/src/jsinteractive.c b/src/jsinteractive.c index 8f49f8ba9..c5082ce18 100644 --- a/src/jsinteractive.c +++ b/src/jsinteractive.c @@ -170,7 +170,11 @@ NO_INLINE bool jsiEcho() { } NO_INLINE bool jsiPasswordProtected() { +#ifndef ESPR_NO_PASSWORD return ((jsiStatus&JSIS_PASSWORD_PROTECTED)!=0); +#else + return 0; +#endif } static bool jsiShowInputLine() { @@ -892,11 +896,13 @@ void jsiSemiInit(bool autoLoad, JsfFileName *loadedFilename) { jspSoftInit(); } +#ifndef ESPR_NO_PASSWORD // If a password was set, apply the lock JsVar *pwd = jsvObjectGetChildIfExists(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME); if (pwd) jsiStatus |= JSIS_PASSWORD_PROTECTED; jsvUnLock(pwd); +#endif // Softinit may run initialisation code that will overwrite defaults jsiSoftInit(!autoLoad); @@ -1800,6 +1806,7 @@ void jsiHandleChar(char ch) { // 27 then 79 then 72 - end // 27 then 10 - alt enter +#ifndef ESPR_NO_PASSWORD if (jsiPasswordProtected()) { if (ch=='\r' || ch==10) { JsVar *pwd = jsvObjectGetChildIfExists(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME); @@ -1819,6 +1826,7 @@ void jsiHandleChar(char ch) { jsiAppendToInputLine(ch); return; } +#endif if (ch==3 && IS_PACKET_TRANSFER(inputState)) execInfo.execute &= ~EXEC_CTRL_C_MASK; // if we got Ctrl-C, ignore it diff --git a/src/jsinteractive.h b/src/jsinteractive.h index 4aff5f25d..b1db59399 100644 --- a/src/jsinteractive.h +++ b/src/jsinteractive.h @@ -142,7 +142,9 @@ void jsiSetSleep(JsiSleepType isSleep); #define DEVICE_OPTIONS_NAME "_options" #define INIT_CALLBACK_NAME JS_EVENT_PREFIX"init" ///< Callback for `E.on('init'` #define KILL_CALLBACK_NAME JS_EVENT_PREFIX"kill" ///< Callback for `E.on('kill'` +#ifndef ESPR_NO_PASSWORD #define PASSWORD_VARIABLE_NAME "pwd" +#endif typedef enum { JSIS_NONE, @@ -159,7 +161,7 @@ typedef enum { JSIS_TODO_MASK = JSIS_TODO_FLASH_SAVE|JSIS_TODO_FLASH_LOAD|JSIS_TODO_RESET, JSIS_CONSOLE_FORCED = 1<<8, ///< see jsiSetConsoleDevice JSIS_WATCHDOG_AUTO = 1<<9, ///< Automatically kick the watchdog timer on idle - JSIS_PASSWORD_PROTECTED = 1<<10, ///< Password protected + JSIS_PASSWORD_PROTECTED = 1<<10, ///< Password protected (only ifndef ESPR_NO_PASSWORD) JSIS_COMPLETELY_RESET = 1<<11, ///< Has the board powered on *having not loaded anything from flash* JSIS_FIRST_BOOT = 1<<12, ///< Is this the first time we started, or has load/reset/etc been called? diff --git a/src/jsutils.h b/src/jsutils.h index 1319113d8..6e0550010 100755 --- a/src/jsutils.h +++ b/src/jsutils.h @@ -58,6 +58,7 @@ #define ESPR_NO_SOFTWARE_I2C 1 #endif #define ESPR_NO_REGEX_OPTIMISE 1 +#define ESPR_NO_PASSWORD 1 #endif // SAVE_ON_FLASH #ifdef SAVE_ON_FLASH_EXTREME #define ESPR_NO_BLUETOOTH_MESSAGES 1 diff --git a/src/jswrap_date.c b/src/jswrap_date.c index 235757690..fad337c4e 100644 --- a/src/jswrap_date.c +++ b/src/jswrap_date.c @@ -736,6 +736,7 @@ JsVar *jswrap_date_toString(JsVar *parent) { "type" : "method", "class" : "Date", "name" : "toUTCString", + "ifndef" : "SAVE_ON_FLASH", "generate" : "jswrap_date_toUTCString", "return" : ["JsVar","A String"], "typescript" : "toUTCString(): string;" diff --git a/src/jswrap_espruino.c b/src/jswrap_espruino.c index 20fa1d03f..d7ef62f23 100644 --- a/src/jswrap_espruino.c +++ b/src/jswrap_espruino.c @@ -2072,6 +2072,7 @@ JsVar *jswrap_espruino_HSBtoRGB(JsVarFloat hue, JsVarFloat sat, JsVarFloat bri, "type" : "staticmethod", "class" : "E", "name" : "setPassword", + "ifndef" : "SAVE_ON_FLASH", "generate" : "jswrap_espruino_setPassword", "params" : [ ["password","JsVar","The password - max 20 chars"] @@ -2093,25 +2094,30 @@ from unknown sources) or read the device's firmware then they may be able to obtain it. */ void jswrap_espruino_setPassword(JsVar *pwd) { +#ifndef ESPR_NO_PASSWORD if (pwd) pwd = jsvAsString(pwd); jsvUnLock(jsvObjectSetChild(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME, pwd)); +#endif } /*JSON{ "type" : "staticmethod", "class" : "E", "name" : "lockConsole", + "ifndef" : "SAVE_ON_FLASH", "generate" : "jswrap_espruino_lockConsole" } If a password has been set with `E.setPassword()`, this will lock the console so the password needs to be entered to unlock it. */ void jswrap_espruino_lockConsole() { +#ifndef ESPR_NO_PASSWORD JsVar *pwd = jsvObjectGetChildIfExists(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME); if (pwd) jsiStatus |= JSIS_PASSWORD_PROTECTED; jsvUnLock(pwd); +#endif } /*JSON{ @@ -2601,6 +2607,7 @@ type PowerUsage = { "type" : "staticmethod", "class" : "E", "name" : "getPowerUsage", + "ifndef" : "SAVE_ON_FLASH", "generate" : "jswrap_espruino_getPowerUsage", "return" : ["JsVar","An object detailing power usage in microamps"], "typescript" : "getPowerUsage(): PowerUsage;" diff --git a/src/jswrap_interactive.c b/src/jswrap_interactive.c index dde3b1eb4..c3164ff7c 100644 --- a/src/jswrap_interactive.c +++ b/src/jswrap_interactive.c @@ -347,6 +347,7 @@ void jswrap_interactive_setTime(JsVarFloat time) { /*JSON{ "type" : "function", "name" : "getSerial", + "ifndef" : "SAVE_ON_FLASH", "generate" : "jswrap_interface_getSerial", "return" : ["JsVar","The board's serial number"] } diff --git a/src/jswrap_math.c b/src/jswrap_math.c index 2652e3184..af13f791e 100644 --- a/src/jswrap_math.c +++ b/src/jswrap_math.c @@ -101,6 +101,7 @@ This is a standard JavaScript class that contains useful Maths routines "type" : "staticproperty", "class" : "Math", "name" : "LN2", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "0.6931471805599453", "return" : ["float","The natural logarithm of 2 - 0.6931471805599453"] }*/ @@ -108,6 +109,7 @@ This is a standard JavaScript class that contains useful Maths routines "type" : "staticproperty", "class" : "Math", "name" : "LN10", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "2.302585092994046", "return" : ["float","The natural logarithm of 10 - 2.302585092994046"] }*/ @@ -115,6 +117,7 @@ This is a standard JavaScript class that contains useful Maths routines "type" : "staticproperty", "class" : "Math", "name" : "LOG2E", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "1.4426950408889634", "return" : ["float","The base 2 logarithm of e - 1.4426950408889634"] }*/ @@ -122,6 +125,7 @@ This is a standard JavaScript class that contains useful Maths routines "type" : "staticproperty", "class" : "Math", "name" : "LOG10E", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "0.4342944819032518", "return" : ["float","The base 10 logarithm of e - 0.4342944819032518"] }*/ @@ -129,6 +133,7 @@ This is a standard JavaScript class that contains useful Maths routines "type" : "staticproperty", "class" : "Math", "name" : "SQRT2", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "1.4142135623730951", "return" : ["float","The square root of 2 - 1.4142135623730951"] }*/ @@ -136,6 +141,7 @@ This is a standard JavaScript class that contains useful Maths routines "type" : "staticproperty", "class" : "Math", "name" : "SQRT1_2", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "0.7071067811865476", "return" : ["float","The square root of 1/2 - 0.7071067811865476"] }*/ diff --git a/src/jswrap_number.c b/src/jswrap_number.c index f02290c65..0a03b638e 100644 --- a/src/jswrap_number.c +++ b/src/jswrap_number.c @@ -144,6 +144,7 @@ JsVar *jswrap_number_toFixed(JsVar *parent, int decimals) { /*JSON{ "type" : "variable", "name" : "HIGH", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "1", "return" : ["int32","Logic 1 for Arduino compatibility - this is the same as just typing `1`"], "typescript" : "declare const HIGH: true;" @@ -152,6 +153,7 @@ JsVar *jswrap_number_toFixed(JsVar *parent, int decimals) { /*JSON{ "type" : "variable", "name" : "LOW", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "0", "return" : ["int32","Logic 0 for Arduino compatibility - this is the same as just typing `0`"], "typescript" : "declare const LOW: false;" diff --git a/src/jswrap_serial.c b/src/jswrap_serial.c index 29774b5d9..788f5b405 100644 --- a/src/jswrap_serial.c +++ b/src/jswrap_serial.c @@ -104,6 +104,7 @@ Espruino boards) "type" : "staticmethod", "class" : "Serial", "name" : "find", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "jshGetDeviceObjectFor(JSH_USART1, JSH_USARTMAX, pin)", "params" : [ ["pin","pin","A pin to search with"] diff --git a/src/jswrap_spi_i2c.c b/src/jswrap_spi_i2c.c index dc1c417ad..5d21538de 100644 --- a/src/jswrap_spi_i2c.c +++ b/src/jswrap_spi_i2c.c @@ -73,6 +73,7 @@ JsVar *jswrap_spi_constructor() { "type" : "staticmethod", "class" : "SPI", "name" : "find", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "jshGetDeviceObjectFor(JSH_SPI1, JSH_SPIMAX, pin)", "params" : [ ["pin","pin","A pin to search with"] @@ -532,6 +533,7 @@ JsVar *jswrap_i2c_constructor() { "type" : "staticmethod", "class" : "I2C", "name" : "find", + "ifndef" : "SAVE_ON_FLASH", "generate_full" : "jshGetDeviceObjectFor(JSH_I2C1, JSH_I2CMAX, pin)", "params" : [ ["pin","pin","A pin to search with"]