Skip to content

Commit 1d1707d

Browse files
committed
In SAVE_ON_FLASH builds (Microbit 1) remove getSerial, Math.LN*/LOG*SQRT* constants, passwords, Serial/I2C/SPI.find, Date.toUTCString
1 parent 10cd0eb commit 1d1707d

13 files changed

+36
-3
lines changed

Diff for: ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
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)
6666
Allow a 'file receive' packet which can request Espruino sends a file as binary packets (also fix files not being closed if transmission fails)
6767
Fix parsing of semicolons in DO with a statement: `do print(a);while(a--);`
68+
In SAVE_ON_FLASH builds (Microbit 1) remove getSerial, Math.LN*/LOG*SQRT* constants, passwords, Serial/I2C/SPI.find, Date.toUTCString
6869

6970
2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'
7071
Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off)

Diff for: README_BuildProcess.md

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ These are set automatically when `SAVE_ON_FLASH` is set (see `jsutils.h`)
179179
* `ESPR_NO_LET_SCOPING` - don't create scopes for `let` (treat it like `var`, which was the 2v13 and earlier behaviour)
180180
* `ESPR_NO_PROMISES` - Don't include promise-handling functions
181181
* `ESPR_NO_PRETOKENISE` - Don't include code to pretokenise functions marked with `"ram"` - code pretokenised in the IDE can still be executed
182+
* `ESPR_NO_PASSWORD` - Disable password protection on the console (E.setPassword/E.lockConsole)
182183

183184

184185
### chip

Diff for: libs/graphics/jswrap_graphics.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ It is recommended that you use `Graphics.setFont("4x6")` for more flexibility.
17201720
"type" : "method",
17211721
"class" : "Graphics",
17221722
"name" : "setFontVector",
1723-
"ifndef" : "SAVE_ON_FLASH",
1723+
"#if" : "!defined(SAVE_ON_FLASH) && !defined(NO_VECTOR_FONT)",
17241724
"generate_full" : "jswrap_graphics_setFontSizeX(parent, size, true)",
17251725
"params" : [
17261726
["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) {
28072807
"type" : "method",
28082808
"class" : "Graphics",
28092809
"name" : "getVectorFontPolys",
2810-
"#if" : "!defined(SAVE_ON_FLASH) || !defined(NO_VECTOR_FONT)",
2810+
"#if" : "!defined(SAVE_ON_FLASH) && !defined(NO_VECTOR_FONT)",
28112811
"generate" : "jswrap_graphics_getVectorFontPolys",
28122812
"params" : [
28132813
["str","JsVar","The string"],

Diff for: src/jsinteractive.c

+8
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ NO_INLINE bool jsiEcho() {
170170
}
171171

172172
NO_INLINE bool jsiPasswordProtected() {
173+
#ifndef ESPR_NO_PASSWORD
173174
return ((jsiStatus&JSIS_PASSWORD_PROTECTED)!=0);
175+
#else
176+
return 0;
177+
#endif
174178
}
175179

176180
static bool jsiShowInputLine() {
@@ -892,11 +896,13 @@ void jsiSemiInit(bool autoLoad, JsfFileName *loadedFilename) {
892896
jspSoftInit();
893897
}
894898

899+
#ifndef ESPR_NO_PASSWORD
895900
// If a password was set, apply the lock
896901
JsVar *pwd = jsvObjectGetChildIfExists(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME);
897902
if (pwd)
898903
jsiStatus |= JSIS_PASSWORD_PROTECTED;
899904
jsvUnLock(pwd);
905+
#endif
900906

901907
// Softinit may run initialisation code that will overwrite defaults
902908
jsiSoftInit(!autoLoad);
@@ -1800,6 +1806,7 @@ void jsiHandleChar(char ch) {
18001806
// 27 then 79 then 72 - end
18011807
// 27 then 10 - alt enter
18021808

1809+
#ifndef ESPR_NO_PASSWORD
18031810
if (jsiPasswordProtected()) {
18041811
if (ch=='\r' || ch==10) {
18051812
JsVar *pwd = jsvObjectGetChildIfExists(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME);
@@ -1819,6 +1826,7 @@ void jsiHandleChar(char ch) {
18191826
jsiAppendToInputLine(ch);
18201827
return;
18211828
}
1829+
#endif
18221830

18231831
if (ch==3 && IS_PACKET_TRANSFER(inputState))
18241832
execInfo.execute &= ~EXEC_CTRL_C_MASK; // if we got Ctrl-C, ignore it

Diff for: src/jsinteractive.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ void jsiSetSleep(JsiSleepType isSleep);
142142
#define DEVICE_OPTIONS_NAME "_options"
143143
#define INIT_CALLBACK_NAME JS_EVENT_PREFIX"init" ///< Callback for `E.on('init'`
144144
#define KILL_CALLBACK_NAME JS_EVENT_PREFIX"kill" ///< Callback for `E.on('kill'`
145+
#ifndef ESPR_NO_PASSWORD
145146
#define PASSWORD_VARIABLE_NAME "pwd"
147+
#endif
146148

147149
typedef enum {
148150
JSIS_NONE,
@@ -159,7 +161,7 @@ typedef enum {
159161
JSIS_TODO_MASK = JSIS_TODO_FLASH_SAVE|JSIS_TODO_FLASH_LOAD|JSIS_TODO_RESET,
160162
JSIS_CONSOLE_FORCED = 1<<8, ///< see jsiSetConsoleDevice
161163
JSIS_WATCHDOG_AUTO = 1<<9, ///< Automatically kick the watchdog timer on idle
162-
JSIS_PASSWORD_PROTECTED = 1<<10, ///< Password protected
164+
JSIS_PASSWORD_PROTECTED = 1<<10, ///< Password protected (only ifndef ESPR_NO_PASSWORD)
163165
JSIS_COMPLETELY_RESET = 1<<11, ///< Has the board powered on *having not loaded anything from flash*
164166
JSIS_FIRST_BOOT = 1<<12, ///< Is this the first time we started, or has load/reset/etc been called?
165167

Diff for: src/jsutils.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#define ESPR_NO_SOFTWARE_I2C 1
5959
#endif
6060
#define ESPR_NO_REGEX_OPTIMISE 1
61+
#define ESPR_NO_PASSWORD 1
6162
#endif // SAVE_ON_FLASH
6263
#ifdef SAVE_ON_FLASH_EXTREME
6364
#define ESPR_NO_BLUETOOTH_MESSAGES 1

Diff for: src/jswrap_date.c

+1
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ JsVar *jswrap_date_toString(JsVar *parent) {
736736
"type" : "method",
737737
"class" : "Date",
738738
"name" : "toUTCString",
739+
"ifndef" : "SAVE_ON_FLASH",
739740
"generate" : "jswrap_date_toUTCString",
740741
"return" : ["JsVar","A String"],
741742
"typescript" : "toUTCString(): string;"

Diff for: src/jswrap_espruino.c

+7
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ JsVar *jswrap_espruino_HSBtoRGB(JsVarFloat hue, JsVarFloat sat, JsVarFloat bri,
20722072
"type" : "staticmethod",
20732073
"class" : "E",
20742074
"name" : "setPassword",
2075+
"ifndef" : "SAVE_ON_FLASH",
20752076
"generate" : "jswrap_espruino_setPassword",
20762077
"params" : [
20772078
["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
20932094
obtain it.
20942095
*/
20952096
void jswrap_espruino_setPassword(JsVar *pwd) {
2097+
#ifndef ESPR_NO_PASSWORD
20962098
if (pwd)
20972099
pwd = jsvAsString(pwd);
20982100
jsvUnLock(jsvObjectSetChild(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME, pwd));
2101+
#endif
20992102
}
21002103

21012104
/*JSON{
21022105
"type" : "staticmethod",
21032106
"class" : "E",
21042107
"name" : "lockConsole",
2108+
"ifndef" : "SAVE_ON_FLASH",
21052109
"generate" : "jswrap_espruino_lockConsole"
21062110
}
21072111
If a password has been set with `E.setPassword()`, this will lock the console so
21082112
the password needs to be entered to unlock it.
21092113
*/
21102114
void jswrap_espruino_lockConsole() {
2115+
#ifndef ESPR_NO_PASSWORD
21112116
JsVar *pwd = jsvObjectGetChildIfExists(execInfo.hiddenRoot, PASSWORD_VARIABLE_NAME);
21122117
if (pwd)
21132118
jsiStatus |= JSIS_PASSWORD_PROTECTED;
21142119
jsvUnLock(pwd);
2120+
#endif
21152121
}
21162122

21172123
/*JSON{
@@ -2601,6 +2607,7 @@ type PowerUsage = {
26012607
"type" : "staticmethod",
26022608
"class" : "E",
26032609
"name" : "getPowerUsage",
2610+
"ifndef" : "SAVE_ON_FLASH",
26042611
"generate" : "jswrap_espruino_getPowerUsage",
26052612
"return" : ["JsVar","An object detailing power usage in microamps"],
26062613
"typescript" : "getPowerUsage(): PowerUsage;"

Diff for: src/jswrap_interactive.c

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ void jswrap_interactive_setTime(JsVarFloat time) {
347347
/*JSON{
348348
"type" : "function",
349349
"name" : "getSerial",
350+
"ifndef" : "SAVE_ON_FLASH",
350351
"generate" : "jswrap_interface_getSerial",
351352
"return" : ["JsVar","The board's serial number"]
352353
}

Diff for: src/jswrap_math.c

+6
Original file line numberDiff line numberDiff line change
@@ -101,41 +101,47 @@ This is a standard JavaScript class that contains useful Maths routines
101101
"type" : "staticproperty",
102102
"class" : "Math",
103103
"name" : "LN2",
104+
"ifndef" : "SAVE_ON_FLASH",
104105
"generate_full" : "0.6931471805599453",
105106
"return" : ["float","The natural logarithm of 2 - 0.6931471805599453"]
106107
}*/
107108
/*JSON{
108109
"type" : "staticproperty",
109110
"class" : "Math",
110111
"name" : "LN10",
112+
"ifndef" : "SAVE_ON_FLASH",
111113
"generate_full" : "2.302585092994046",
112114
"return" : ["float","The natural logarithm of 10 - 2.302585092994046"]
113115
}*/
114116
/*JSON{
115117
"type" : "staticproperty",
116118
"class" : "Math",
117119
"name" : "LOG2E",
120+
"ifndef" : "SAVE_ON_FLASH",
118121
"generate_full" : "1.4426950408889634",
119122
"return" : ["float","The base 2 logarithm of e - 1.4426950408889634"]
120123
}*/
121124
/*JSON{
122125
"type" : "staticproperty",
123126
"class" : "Math",
124127
"name" : "LOG10E",
128+
"ifndef" : "SAVE_ON_FLASH",
125129
"generate_full" : "0.4342944819032518",
126130
"return" : ["float","The base 10 logarithm of e - 0.4342944819032518"]
127131
}*/
128132
/*JSON{
129133
"type" : "staticproperty",
130134
"class" : "Math",
131135
"name" : "SQRT2",
136+
"ifndef" : "SAVE_ON_FLASH",
132137
"generate_full" : "1.4142135623730951",
133138
"return" : ["float","The square root of 2 - 1.4142135623730951"]
134139
}*/
135140
/*JSON{
136141
"type" : "staticproperty",
137142
"class" : "Math",
138143
"name" : "SQRT1_2",
144+
"ifndef" : "SAVE_ON_FLASH",
139145
"generate_full" : "0.7071067811865476",
140146
"return" : ["float","The square root of 1/2 - 0.7071067811865476"]
141147
}*/

Diff for: src/jswrap_number.c

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ JsVar *jswrap_number_toFixed(JsVar *parent, int decimals) {
144144
/*JSON{
145145
"type" : "variable",
146146
"name" : "HIGH",
147+
"ifndef" : "SAVE_ON_FLASH",
147148
"generate_full" : "1",
148149
"return" : ["int32","Logic 1 for Arduino compatibility - this is the same as just typing `1`"],
149150
"typescript" : "declare const HIGH: true;"
@@ -152,6 +153,7 @@ JsVar *jswrap_number_toFixed(JsVar *parent, int decimals) {
152153
/*JSON{
153154
"type" : "variable",
154155
"name" : "LOW",
156+
"ifndef" : "SAVE_ON_FLASH",
155157
"generate_full" : "0",
156158
"return" : ["int32","Logic 0 for Arduino compatibility - this is the same as just typing `0`"],
157159
"typescript" : "declare const LOW: false;"

Diff for: src/jswrap_serial.c

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Espruino boards)
104104
"type" : "staticmethod",
105105
"class" : "Serial",
106106
"name" : "find",
107+
"ifndef" : "SAVE_ON_FLASH",
107108
"generate_full" : "jshGetDeviceObjectFor(JSH_USART1, JSH_USARTMAX, pin)",
108109
"params" : [
109110
["pin","pin","A pin to search with"]

Diff for: src/jswrap_spi_i2c.c

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ JsVar *jswrap_spi_constructor() {
7373
"type" : "staticmethod",
7474
"class" : "SPI",
7575
"name" : "find",
76+
"ifndef" : "SAVE_ON_FLASH",
7677
"generate_full" : "jshGetDeviceObjectFor(JSH_SPI1, JSH_SPIMAX, pin)",
7778
"params" : [
7879
["pin","pin","A pin to search with"]
@@ -532,6 +533,7 @@ JsVar *jswrap_i2c_constructor() {
532533
"type" : "staticmethod",
533534
"class" : "I2C",
534535
"name" : "find",
536+
"ifndef" : "SAVE_ON_FLASH",
535537
"generate_full" : "jshGetDeviceObjectFor(JSH_I2C1, JSH_I2CMAX, pin)",
536538
"params" : [
537539
["pin","pin","A pin to search with"]

0 commit comments

Comments
 (0)