Skip to content

Commit

Permalink
In SAVE_ON_FLASH builds (Microbit 1) remove getSerial, Math.LN*/LOG*S…
Browse files Browse the repository at this point in the history
…QRT* constants, passwords, Serial/I2C/SPI.find, Date.toUTCString
  • Loading branch information
gfwilliams committed Dec 3, 2024
1 parent 10cd0eb commit 1d1707d
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README_BuildProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libs/graphics/jswrap_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"],
Expand Down
8 changes: 8 additions & 0 deletions src/jsinteractive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/jsinteractive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?

Expand Down
1 change: 1 addition & 0 deletions src/jsutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/jswrap_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
7 changes: 7 additions & 0 deletions src/jswrap_espruino.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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{
Expand Down Expand Up @@ -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;"
Expand Down
1 change: 1 addition & 0 deletions src/jswrap_interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Expand Down
6 changes: 6 additions & 0 deletions src/jswrap_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,41 +101,47 @@ 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"]
}*/
/*JSON{
"type" : "staticproperty",
"class" : "Math",
"name" : "LN10",
"ifndef" : "SAVE_ON_FLASH",
"generate_full" : "2.302585092994046",
"return" : ["float","The natural logarithm of 10 - 2.302585092994046"]
}*/
/*JSON{
"type" : "staticproperty",
"class" : "Math",
"name" : "LOG2E",
"ifndef" : "SAVE_ON_FLASH",
"generate_full" : "1.4426950408889634",
"return" : ["float","The base 2 logarithm of e - 1.4426950408889634"]
}*/
/*JSON{
"type" : "staticproperty",
"class" : "Math",
"name" : "LOG10E",
"ifndef" : "SAVE_ON_FLASH",
"generate_full" : "0.4342944819032518",
"return" : ["float","The base 10 logarithm of e - 0.4342944819032518"]
}*/
/*JSON{
"type" : "staticproperty",
"class" : "Math",
"name" : "SQRT2",
"ifndef" : "SAVE_ON_FLASH",
"generate_full" : "1.4142135623730951",
"return" : ["float","The square root of 2 - 1.4142135623730951"]
}*/
/*JSON{
"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"]
}*/
Expand Down
2 changes: 2 additions & 0 deletions src/jswrap_number.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand All @@ -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;"
Expand Down
1 change: 1 addition & 0 deletions src/jswrap_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions src/jswrap_spi_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 1d1707d

Please sign in to comment.